|
|
|||
File indexing completed on 2026-05-10 08:43:19
0001 //===- TypeMetadataUtils.h - Utilities related to type metadata --*- C++ -*-==// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 // 0009 // This file contains functions that make it easier to manipulate type metadata 0010 // for devirtualization. 0011 // 0012 //===----------------------------------------------------------------------===// 0013 0014 #ifndef LLVM_ANALYSIS_TYPEMETADATAUTILS_H 0015 #define LLVM_ANALYSIS_TYPEMETADATAUTILS_H 0016 0017 #include <cstdint> 0018 #include <utility> 0019 0020 namespace llvm { 0021 0022 template <typename T> class SmallVectorImpl; 0023 class CallBase; 0024 class CallInst; 0025 class Constant; 0026 class Function; 0027 class DominatorTree; 0028 class GlobalVariable; 0029 class Instruction; 0030 class Module; 0031 0032 /// The type of CFI jumptable needed for a function. 0033 enum CfiFunctionLinkage { 0034 CFL_Definition = 0, 0035 CFL_Declaration = 1, 0036 CFL_WeakDeclaration = 2 0037 }; 0038 0039 /// A call site that could be devirtualized. 0040 struct DevirtCallSite { 0041 /// The offset from the address point to the virtual function. 0042 uint64_t Offset; 0043 /// The call site itself. 0044 CallBase &CB; 0045 }; 0046 0047 /// Given a call to the intrinsic \@llvm.type.test, find all devirtualizable 0048 /// call sites based on the call and return them in DevirtCalls. 0049 void findDevirtualizableCallsForTypeTest( 0050 SmallVectorImpl<DevirtCallSite> &DevirtCalls, 0051 SmallVectorImpl<CallInst *> &Assumes, const CallInst *CI, 0052 DominatorTree &DT); 0053 0054 /// Given a call to the intrinsic \@llvm.type.checked.load, find all 0055 /// devirtualizable call sites based on the call and return them in DevirtCalls. 0056 void findDevirtualizableCallsForTypeCheckedLoad( 0057 SmallVectorImpl<DevirtCallSite> &DevirtCalls, 0058 SmallVectorImpl<Instruction *> &LoadedPtrs, 0059 SmallVectorImpl<Instruction *> &Preds, bool &HasNonCallUses, 0060 const CallInst *CI, DominatorTree &DT); 0061 0062 /// Processes a Constant recursively looking into elements of arrays, structs 0063 /// and expressions to find a trivial pointer element that is located at the 0064 /// given offset (relative to the beginning of the whole outer Constant). 0065 /// 0066 /// Used for example from GlobalDCE to find an entry in a C++ vtable that 0067 /// matches a vcall offset. 0068 /// 0069 /// To support relative vtables, getPointerAtOffset can see through "relative 0070 /// pointers", i.e. (sub-)expressions of the form of: 0071 /// 0072 /// @symbol = ... { 0073 /// i32 trunc (i64 sub ( 0074 /// i64 ptrtoint (<type> @target to i64), i64 ptrtoint (... @symbol to i64) 0075 /// ) to i32) 0076 /// } 0077 /// 0078 /// For such (sub-)expressions, getPointerAtOffset returns the @target pointer. 0079 Constant *getPointerAtOffset(Constant *I, uint64_t Offset, Module &M, 0080 Constant *TopLevelGlobal = nullptr); 0081 0082 /// Given a vtable and a specified offset, returns the function and the trivial 0083 /// pointer at the specified offset in pair iff the pointer at the specified 0084 /// offset is a function or an alias to a function. Returns a pair of nullptr 0085 /// otherwise. 0086 std::pair<Function *, Constant *> 0087 getFunctionAtVTableOffset(GlobalVariable *GV, uint64_t Offset, Module &M); 0088 0089 /// Finds the same "relative pointer" pattern as described above, where the 0090 /// target is `C`, and replaces the entire pattern with a constant zero. 0091 void replaceRelativePointerUsersWithZero(Constant *C); 0092 0093 } // namespace llvm 0094 0095 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|