LLVM 20.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#include <utility>
19
20namespace llvm {
21
22template <typename T> class SmallVectorImpl;
23class CallBase;
24class CallInst;
25class Constant;
26class Function;
27class DominatorTree;
28class GlobalVariable;
29class Instruction;
30class Module;
31
32/// The type of CFI jumptable needed for a function.
37};
38
39/// A call site that could be devirtualized.
41 /// The offset from the address point to the virtual function.
43 /// The call site itself.
45};
46
47/// Given a call to the intrinsic \@llvm.type.test, find all devirtualizable
48/// call sites based on the call and return them in DevirtCalls.
51 SmallVectorImpl<CallInst *> &Assumes, const CallInst *CI,
52 DominatorTree &DT);
53
54/// Given a call to the intrinsic \@llvm.type.checked.load, find all
55/// devirtualizable call sites based on the call and return them in DevirtCalls.
59 SmallVectorImpl<Instruction *> &Preds, bool &HasNonCallUses,
60 const CallInst *CI, DominatorTree &DT);
61
62/// Processes a Constant recursively looking into elements of arrays, structs
63/// and expressions to find a trivial pointer element that is located at the
64/// given offset (relative to the beginning of the whole outer Constant).
65///
66/// Used for example from GlobalDCE to find an entry in a C++ vtable that
67/// matches a vcall offset.
68///
69/// To support relative vtables, getPointerAtOffset can see through "relative
70/// pointers", i.e. (sub-)expressions of the form of:
71///
72/// @symbol = ... {
73/// i32 trunc (i64 sub (
74/// i64 ptrtoint (<type> @target to i64), i64 ptrtoint (... @symbol to i64)
75/// ) to i32)
76/// }
77///
78/// For such (sub-)expressions, getPointerAtOffset returns the @target pointer.
80 Constant *TopLevelGlobal = nullptr);
81
82/// Given a vtable and a specified offset, returns the function and the trivial
83/// pointer at the specified offset in pair iff the pointer at the specified
84/// offset is a function or an alias to a function. Returns a pair of nullptr
85/// otherwise.
86std::pair<Function *, Constant *>
88
89/// Finds the same "relative pointer" pattern as described above, where the
90/// target is `C`, and replaces the entire pattern with a constant zero.
92
93} // namespace llvm
94
95#endif
#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:1236
This class represents a function call, abstracting a target machine's calling convention.
This is an important base class in LLVM.
Definition: Constant.h:42
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:162
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:586
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
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...
void replaceRelativePointerUsersWithZero(Constant *C)
Finds the same "relative pointer" pattern as described above, where the target is C,...
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...
std::pair< Function *, Constant * > getFunctionAtVTableOffset(GlobalVariable *GV, uint64_t Offset, Module &M)
Given a vtable and a specified offset, returns the function and the trivial pointer at the specified ...
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.