LLVM 17.0.0git
TypeMetadataUtils.h
Go to the documentation of this file.
1//===- TypeMetadataUtils.h - Utilities related to type metadata --*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains functions that make it easier to manipulate type metadata
10// for devirtualization.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_ANALYSIS_TYPEMETADATAUTILS_H
15#define LLVM_ANALYSIS_TYPEMETADATAUTILS_H
16
17#include <cstdint>
18
19namespace llvm {
20
21template <typename T> class SmallVectorImpl;
22class CallBase;
23class CallInst;
24class Constant;
25class Function;
26class DominatorTree;
27class Instruction;
28class Module;
29
30/// The type of CFI jumptable needed for a function.
35};
36
37/// A call site that could be devirtualized.
39 /// The offset from the address point to the virtual function.
41 /// The call site itself.
43};
44
45/// Given a call to the intrinsic \@llvm.type.test, find all devirtualizable
46/// call sites based on the call and return them in DevirtCalls.
49 SmallVectorImpl<CallInst *> &Assumes, const CallInst *CI,
50 DominatorTree &DT);
51
52/// Given a call to the intrinsic \@llvm.type.checked.load, find all
53/// devirtualizable call sites based on the call and return them in DevirtCalls.
57 SmallVectorImpl<Instruction *> &Preds, bool &HasNonCallUses,
58 const CallInst *CI, DominatorTree &DT);
59
60/// Processes a Constant recursively looking into elements of arrays, structs
61/// and expressions to find a trivial pointer element that is located at the
62/// given offset (relative to the beginning of the whole outer Constant).
63///
64/// Used for example from GlobalDCE to find an entry in a C++ vtable that
65/// matches a vcall offset.
66///
67/// To support Swift vtables, getPointerAtOffset can see through "relative
68/// pointers", i.e. (sub-)expressions of the form of:
69///
70/// @symbol = ... {
71/// i32 trunc (i64 sub (
72/// i64 ptrtoint (<type> @target to i64), i64 ptrtoint (... @symbol to i64)
73/// ) to i32)
74/// }
75///
76/// For such (sub-)expressions, getPointerAtOffset returns the @target pointer.
78 Constant *TopLevelGlobal = nullptr);
79
80/// Finds the same "relative pointer" pattern as described above, where the
81/// target is `F`, and replaces the entire pattern with a constant zero.
83
84} // namespace llvm
85
86#endif
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1184
This class represents a function call, abstracting a target machine's calling convention.
This is an important base class in LLVM.
Definition: Constant.h:41
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:577
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:406
void replaceRelativePointerUsersWithZero(Function *F)
Finds the same "relative pointer" pattern as described above, where the target is F,...
void findDevirtualizableCallsForTypeCheckedLoad(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< Instruction * > &LoadedPtrs, SmallVectorImpl< Instruction * > &Preds, bool &HasNonCallUses, const CallInst *CI, DominatorTree &DT)
Given a call to the intrinsic @llvm.type.checked.load, find all devirtualizable call sites based on t...
CfiFunctionLinkage
The type of CFI jumptable needed for a function.
@ CFL_WeakDeclaration
@ CFL_Definition
@ CFL_Declaration
void findDevirtualizableCallsForTypeTest(SmallVectorImpl< DevirtCallSite > &DevirtCalls, SmallVectorImpl< CallInst * > &Assumes, const CallInst *CI, DominatorTree &DT)
Given a call to the intrinsic @llvm.type.test, find all devirtualizable call sites based on the call ...
Constant * getPointerAtOffset(Constant *I, uint64_t Offset, Module &M, Constant *TopLevelGlobal=nullptr)
Processes a Constant recursively looking into elements of arrays, structs and expressions to find a t...
A call site that could be devirtualized.
uint64_t Offset
The offset from the address point to the virtual function.
CallBase & CB
The call site itself.