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 20namespace llvm { 21 22class CallBase; 23class CallInst; 24class Constant; 25class DominatorTree; 26class Instruction; 27class Module; 28 29/// The type of CFI jumptable needed for a function. 30enum CfiFunctionLinkage { 31 CFL_Definition = 0, 32 CFL_Declaration = 1, 33 CFL_WeakDeclaration = 2 34}; 35 36/// A call site that could be devirtualized. 37struct 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. 46void 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. 53void findDevirtualizableCallsForTypeCheckedLoad( 54 SmallVectorImpl<DevirtCallSite> &DevirtCalls, 55 SmallVectorImpl<Instruction *> &LoadedPtrs, 56 SmallVectorImpl<Instruction *> &Preds, bool &HasNonCallUses, 57 const CallInst *CI, DominatorTree &DT); 58 59Constant *getPointerAtOffset(Constant *I, uint64_t Offset, Module &M); 60} 61 62#endif 63