LLVM  16.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 
19 namespace llvm {
20 
21 template <typename T> class SmallVectorImpl;
22 class CallBase;
23 class CallInst;
24 class Constant;
25 class Function;
26 class DominatorTree;
27 class Instruction;
28 class 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
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::Function
Definition: Function.h:60
llvm::replaceRelativePointerUsersWithZero
void replaceRelativePointerUsersWithZero(Function *F)
Finds the same "relative pointer" pattern as described above, where the target is F,...
Definition: TypeMetadataUtils.cpp:202
llvm::DominatorTree
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
llvm::CFL_Definition
@ CFL_Definition
Definition: TypeMetadataUtils.h:32
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::ISD::Constant
@ Constant
Definition: ISDOpcodes.h:76
llvm::CFL_WeakDeclaration
@ CFL_WeakDeclaration
Definition: TypeMetadataUtils.h:34
llvm::DevirtCallSite::Offset
uint64_t Offset
The offset from the address point to the virtual function.
Definition: TypeMetadataUtils.h:40
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
uint64_t
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::DevirtCallSite
A call site that could be devirtualized.
Definition: TypeMetadataUtils.h:38
llvm::DevirtCallSite::CB
CallBase & CB
The call site itself.
Definition: TypeMetadataUtils.h:42
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::findDevirtualizableCallsForTypeCheckedLoad
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...
Definition: TypeMetadataUtils.cpp:96
llvm::CfiFunctionLinkage
CfiFunctionLinkage
The type of CFI jumptable needed for a function.
Definition: TypeMetadataUtils.h:31
llvm::getPointerAtOffset
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...
Definition: TypeMetadataUtils.cpp:130
llvm::SmallVectorImpl
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APFloat.h:42
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1175
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1474
llvm::CFL_Declaration
@ CFL_Declaration
Definition: TypeMetadataUtils.h:33
llvm::findDevirtualizableCallsForTypeTest
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 ...
Definition: TypeMetadataUtils.cpp:74
llvm::codeview::PublicSymFlags::Function
@ Function