LLVM: lib/Analysis/TypeMetadataUtils.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

20

21using namespace llvm;

22

23

24static void

28 for (const Use &U : FPtr->uses()) {

30

31

32

33

34

35

37 continue;

39 continue;

42 DT);

47 } else if (HasNonCallUses) {

48 *HasNonCallUses = true;

49 }

50 }

51}

52

53

58 return;

59

60 for (const Use &U : VPtr->uses()) {

67

68 if (VPtr == GEP->getPointerOperand() && GEP->hasAllConstantIndices()) {

70 int64_t GEPOffset = M->getDataLayout().getIndexedOffsetInType(

71 GEP->getSourceElementType(), Indices);

73 CI, DT);

74 }

76 if (Call->getIntrinsicID() == llvm::Intrinsic::load_relative) {

79 Offset + LoadOffset->getSExtValue(), CI,

80 DT);

81 }

82 }

83 }

84 }

85}

86

93 Intrinsic::public_type_test);

94

95 const Module *M = CI->getParent()->getParent()->getParent();

96

97

98 for (const Use &CIU : CI->uses())

101

102

103

104 if (!Assumes.empty())

107}

108

115 Intrinsic::type_checked_load ||

117 Intrinsic::type_checked_load_relative);

118

121 HasNonCallUses = true;

122 return;

123 }

124

125 for (const Use &U : CI->uses()) {

126 auto CIU = U.getUser();

128 if (EVI->getNumIndices() == 1 && EVI->getIndices()[0] == 0) {

130 continue;

131 }

132 if (EVI->getNumIndices() == 1 && EVI->getIndices()[0] == 1) {

134 continue;

135 }

136 }

137 HasNonCallUses = true;

138 }

139

140 for (Value *LoadedPtr : LoadedPtrs)

142 Offset->getZExtValue(), CI, DT);

143}

144

147

148

149

151 I = Equiv->getGlobalValue();

152

153 if (I->getType()->isPointerTy()) {

155 return I;

156 return nullptr;

157 }

158

160

162 const StructLayout *SL = DL.getStructLayout(C->getType());

164 return nullptr;

165

169 TopLevelGlobal);

170 }

174

175 unsigned Op = Offset / ElemSize;

176 if (Op >= C->getNumOperands())

177 return nullptr;

178

180 Offset % ElemSize, M, TopLevelGlobal);

181 }

182

183

185 if (Offset == 0 && CI->isZero()) {

186 return I;

187 }

188 }

190 switch (C->getOpcode()) {

191 case Instruction::Trunc:

192 case Instruction::PtrToInt:

194 TopLevelGlobal);

195 case Instruction::Sub: {

198

199 auto StripGEP = [](Constant *C) {

201 if (!CE)

202 return C;

203 if (CE->getOpcode() != Instruction::GetElementPtr)

204 return C;

205 return CE->getOperand(0);

206 };

207 auto *Operand1TargetGlobal = StripGEP(getPointerAtOffset(Operand1, 0, M));

208

209

210

211 if (Operand1TargetGlobal != TopLevelGlobal)

212 return nullptr;

213

215 }

216 default:

217 return nullptr;

218 }

219 }

220 return nullptr;

221}

222

223std::pair<Function *, Constant *>

227 if (!Ptr)

228 return std::pair<Function *, Constant *>(nullptr, nullptr);

229

231

234 if (!Fn && A)

236

237 if (!Fn)

238 return std::pair<Function *, Constant *>(nullptr, nullptr);

239

240 return std::pair<Function *, Constant *>(Fn, C);

241}

242

245 if (!PtrExpr || PtrExpr->getOpcode() != Instruction::PtrToInt)

246 return;

247

248 for (auto *PtrToIntUser : PtrExpr->users()) {

250 if (!SubExpr || SubExpr->getOpcode() != Instruction::Sub)

251 return;

252

253 SubExpr->replaceNonMetadataUsesWith(

254 ConstantInt::get(SubExpr->getType(), 0));

255 }

256}

257

259 for (auto *U : C->users()) {

262 else

264 }

265}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

This file contains the declarations for the subclasses of Constant, which represent the different fla...

Module.h This file contains the declarations for the Module class.

uint64_t IntrinsicInst * II

Class to represent array types.

Type * getElementType() const

Function * getCalledFunction() const

Returns the function called, or null if this is an indirect function invocation or the function signa...

Value * getArgOperand(unsigned i) const

This class represents a function call, abstracting a target machine's calling convention.

This is an important base class in LLVM.

const Constant * stripPointerCasts() const

A parsed version of the target data layout string in and methods for querying it.

Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.

LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const

Return true if the (end of the) basic block BB dominates the use U.

Intrinsic::ID getIntrinsicID() const LLVM_READONLY

getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...

const Constant * getInitializer() const

getInitializer - Return the initializer for this global variable.

LLVM_ABI const Function * getFunction() const

Return the function this instruction belongs to.

A Module instance is used to store all the information related to an LLVM module.

This class consists of common code factored out of the SmallVector class to reduce code duplication b...

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...

TypeSize getSizeInBytes() const

LLVM_ABI unsigned getElementContainingOffset(uint64_t FixedOffset) const

Given a valid byte offset into the structure, returns the structure index that contains it.

TypeSize getElementOffset(unsigned Idx) const

A Use represents the edge between a Value definition and its users.

LLVM Value Representation.

bool hasUseList() const

Check if this Value has a use-list.

LLVM_ABI const Value * stripPointerCasts() const

Strip off pointer casts, all-zero GEPs and address space casts.

iterator_range< use_iterator > uses()

const ParentTy * getParent() const

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

auto drop_begin(T &&RangeOrContainer, size_t N=1)

Return a range covering RangeOrContainer with the first N elements excluded.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

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...

Definition TypeMetadataUtils.cpp:109

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

DWARFExpression::Operation Op

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

void replaceRelativePointerUsersWithZero(Constant *C)

Finds the same "relative pointer" pattern as described above, where the target is C,...

Definition TypeMetadataUtils.cpp:258

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 ...

Definition TypeMetadataUtils.cpp:87

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...

Definition TypeMetadataUtils.cpp:145

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 ...

Definition TypeMetadataUtils.cpp:224