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 "llvm/ADT/SmallVector.h" 18 #include <cstdint> 19 20 namespace llvm { 21 22 class CallBase; 23 class CallInst; 24 class Constant; 25 class DominatorTree; 26 class Instruction; 27 class Module; 28 29 /// The type of CFI jumptable needed for a function. 30 enum CfiFunctionLinkage { 31 CFL_Definition = 0, 32 CFL_Declaration = 1, 33 CFL_WeakDeclaration = 2 34 }; 35 36 /// A call site that could be devirtualized. 37 struct DevirtCallSite { 38 /// The offset from the address point to the virtual function. 39 uint64_t Offset; 40 /// The call site itself. 41 CallBase &CB; 42 }; 43 44 /// Given a call to the intrinsic \@llvm.type.test, find all devirtualizable 45 /// call sites based on the call and return them in DevirtCalls. 46 void findDevirtualizableCallsForTypeTest( 47 SmallVectorImpl<DevirtCallSite> &DevirtCalls, 48 SmallVectorImpl<CallInst *> &Assumes, const CallInst *CI, 49 DominatorTree &DT); 50 51 /// Given a call to the intrinsic \@llvm.type.checked.load, find all 52 /// devirtualizable call sites based on the call and return them in DevirtCalls. 53 void findDevirtualizableCallsForTypeCheckedLoad( 54 SmallVectorImpl<DevirtCallSite> &DevirtCalls, 55 SmallVectorImpl<Instruction *> &LoadedPtrs, 56 SmallVectorImpl<Instruction *> &Preds, bool &HasNonCallUses, 57 const CallInst *CI, DominatorTree &DT); 58 59 Constant *getPointerAtOffset(Constant *I, uint64_t Offset, Module &M); 60 } 61 62 #endif 63