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