LLVM 24.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/// A call site that could be devirtualized.
35 /// The offset from the address point to the virtual function.
37 /// The call site itself.
39};
40
41/// Given a call to the intrinsic \@llvm.type.test, find all devirtualizable
42/// call sites based on the call and return them in DevirtCalls.
45 SmallVectorImpl<CallInst *> &Assumes, const CallInst *CI,
46 DominatorTree &DT);
47
48/// Given a call to the intrinsic \@llvm.type.checked.load, find all
49/// devirtualizable call sites based on the call and return them in DevirtCalls.
53 SmallVectorImpl<Instruction *> &Preds, bool &HasNonCallUses,
54 const CallInst *CI, DominatorTree &DT);
55
56/// Processes a Constant recursively looking into elements of arrays, structs
57/// and expressions to find a trivial pointer element that is located at the
58/// given offset (relative to the beginning of the whole outer Constant).
59///
60/// Used for example from GlobalDCE to find an entry in a C++ vtable that
61/// matches a vcall offset.
62///
63/// To support relative vtables, getPointerAtOffset can see through "relative
64/// pointers", i.e. (sub-)expressions of the form of:
65///
66/// @symbol = ... {
67/// i32 trunc (i64 sub (
68/// i64 ptrtoint (<type> @target to i64), i64 ptrtoint (... @symbol to i64)
69/// ) to i32)
70/// }
71///
72/// For such (sub-)expressions, getPointerAtOffset returns the @target pointer.
74 Constant *TopLevelGlobal = nullptr);
75
76/// Given a vtable and a specified offset, returns the function and the trivial
77/// pointer at the specified offset in pair iff the pointer at the specified
78/// offset is a function or an alias to a function. Returns a pair of nullptr
79/// otherwise.
80LLVM_ABI std::pair<Function *, Constant *>
82
83/// Finds the same "relative pointer" pattern as described above, where the
84/// target is `C`, and replaces the entire pattern with a constant zero.
86
87} // namespace llvm
88
89#endif
unsigned uint64_t
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define LLVM_ABI
Definition Compiler.h:215
#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:122
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...
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:577
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,...
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.