LLVM 23.0.0git
AssumeBundleBuilder.cpp
Go to the documentation of this file.
1//===- AssumeBundleBuilder.cpp - tools to preserve informations -*- 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
11#include "llvm/ADT/MapVector.h"
12#include "llvm/ADT/Statistic.h"
16#include "llvm/IR/Dominators.h"
17#include "llvm/IR/Function.h"
20#include "llvm/IR/Module.h"
21#include "llvm/IR/Operator.h"
25
26using namespace llvm;
27
28namespace llvm {
30 "enable-knowledge-retention", cl::init(false), cl::Hidden,
32 "enable preservation of attributes throughout code transformation"));
33} // namespace llvm
34
35#define DEBUG_TYPE "assume-builder"
36
37STATISTIC(NumAssumeBuilt, "Number of assume built by the assume builder");
38STATISTIC(NumBundlesInAssumes, "Total number of Bundles in the assume built");
39STATISTIC(NumAssumesMerged,
40 "Number of assume merged by the assume simplify pass");
41STATISTIC(NumAssumesRemoved,
42 "Number of assume removed by the assume simplify pass");
43
44DEBUG_COUNTER(BuildAssumeCounter, "assume-builder-counter",
45 "Controls which assumes gets created");
46
47namespace {
48
49bool isUsefullToPreserve(Attribute::AttrKind Kind) {
50 switch (Kind) {
51 case Attribute::NonNull:
52 case Attribute::NoUndef:
53 case Attribute::Alignment:
54 case Attribute::Dereferenceable:
55 case Attribute::DereferenceableOrNull:
56 case Attribute::Cold:
57 return true;
58 default:
59 return false;
60 }
61}
62
63/// This function will try to transform the given knowledge into a more
64/// canonical one. the canonical knowledge maybe the given one.
65RetainedKnowledge canonicalizedKnowledge(RetainedKnowledge RK,
66 const DataLayout &DL) {
67 switch (RK.AttrKind) {
68 default:
69 return RK;
70 case Attribute::NonNull:
72 return RK;
73 case Attribute::Alignment: {
74 Value *V = RK.WasOn->stripInBoundsOffsets([&](const Value *Strip) {
75 if (auto *GEP = dyn_cast<GEPOperator>(Strip))
76 RK.ArgValue =
77 MinAlign(RK.ArgValue, GEP->getMaxPreservedAlignment(DL).value());
78 });
79 RK.WasOn = V;
80 return RK;
81 }
82 case Attribute::Dereferenceable:
83 case Attribute::DereferenceableOrNull: {
84 int64_t Offset = 0;
86 /*AllowNonInBounds*/ false);
87 if (Offset < 0)
88 return RK;
89 RK.ArgValue = RK.ArgValue + Offset;
90 RK.WasOn = V;
91 }
92 }
93 return RK;
94}
95
96/// This class contain all knowledge that have been gather while building an
97/// llvm.assume and the function to manipulate it.
98struct AssumeBuilderState {
99 Module *M;
100
101 using MapKey = std::pair<Value *, Attribute::AttrKind>;
102 SmallMapVector<MapKey, uint64_t, 8> AssumedKnowledgeMap;
103 Instruction *InstBeingModified = nullptr;
104 AssumptionCache* AC = nullptr;
105 DominatorTree* DT = nullptr;
106
107 AssumeBuilderState(Module *M, Instruction *I = nullptr,
108 AssumptionCache *AC = nullptr, DominatorTree *DT = nullptr)
109 : M(M), InstBeingModified(I), AC(AC), DT(DT) {}
110
111 bool tryToPreserveWithoutAddingAssume(RetainedKnowledge RK) {
112 if (!InstBeingModified || !RK.WasOn || !AC)
113 return false;
114 bool HasBeenPreserved = false;
115 Use* ToUpdate = nullptr;
117 RK.WasOn, {RK.AttrKind}, *AC,
118 [&](RetainedKnowledge RKOther, Instruction *Assume,
119 const CallInst::BundleOpInfo *Bundle) {
120 if (!isValidAssumeForContext(Assume, InstBeingModified, DT))
121 return false;
122 if (RKOther.ArgValue >= RK.ArgValue) {
123 HasBeenPreserved = true;
124 return true;
125 } else if (isValidAssumeForContext(InstBeingModified, Assume, DT)) {
126 HasBeenPreserved = true;
127 IntrinsicInst *Intr = cast<IntrinsicInst>(Assume);
128 ToUpdate = &Intr->op_begin()[Bundle->Begin + ABA_Argument];
129 return true;
130 }
131 return false;
132 });
133 if (ToUpdate)
134 ToUpdate->set(
135 ConstantInt::get(Type::getInt64Ty(M->getContext()), RK.ArgValue));
136 return HasBeenPreserved;
137 }
138
139 bool isKnowledgeWorthPreserving(RetainedKnowledge RK) {
140 if (!RK)
141 return false;
142 if (!RK.WasOn)
143 return true;
144 if (RK.WasOn->getType()->isPointerTy()) {
145 Value *UnderlyingPtr = getUnderlyingObject(RK.WasOn);
146 if (isa<AllocaInst>(UnderlyingPtr) || isa<GlobalValue>(UnderlyingPtr))
147 return false;
148 }
149 if (auto *Arg = dyn_cast<Argument>(RK.WasOn)) {
150 if (Arg->hasAttribute(RK.AttrKind) &&
152 Arg->getAttribute(RK.AttrKind).getValueAsInt() >= RK.ArgValue))
153 return false;
154 return true;
155 }
156 if (auto *Inst = dyn_cast<Instruction>(RK.WasOn))
158 if (RK.WasOn->use_empty())
159 return false;
160 Use *SingleUse = RK.WasOn->getSingleUndroppableUse();
161 if (SingleUse && SingleUse->getUser() == InstBeingModified)
162 return false;
163 }
164 return true;
165 }
166
167 void addKnowledge(RetainedKnowledge RK) {
168 RK = canonicalizedKnowledge(RK, M->getDataLayout());
169
170 if (!isKnowledgeWorthPreserving(RK))
171 return;
172
173 if (tryToPreserveWithoutAddingAssume(RK))
174 return;
175 MapKey Key{RK.WasOn, RK.AttrKind};
176 auto [Lookup, Inserted] = AssumedKnowledgeMap.try_emplace(Key, RK.ArgValue);
177 if (Inserted)
178 return;
179 assert(((Lookup->second == 0 && RK.ArgValue == 0) ||
180 (Lookup->second != 0 && RK.ArgValue != 0)) &&
181 "inconsistent argument value");
182
183 /// This is only desirable because for all attributes taking an argument
184 /// higher is better.
185 Lookup->second = std::max(Lookup->second, RK.ArgValue);
186 }
187
188 void addAttribute(Attribute Attr, Value *WasOn) {
189 if (Attr.isTypeAttribute() || Attr.isStringAttribute() ||
190 !isUsefullToPreserve(Attr.getKindAsEnum()))
191 return;
192 uint64_t AttrArg = 0;
193 if (Attr.isIntAttribute())
194 AttrArg = Attr.getValueAsInt();
195 addKnowledge({Attr.getKindAsEnum(), AttrArg, WasOn});
196 }
197
198 void addCall(const CallBase *Call) {
199 auto addAttrList = [&](AttributeList AttrList, unsigned NumArgs) {
200 for (unsigned Idx = 0; Idx < NumArgs; Idx++)
201 for (Attribute Attr : AttrList.getParamAttrs(Idx)) {
202 bool IsPoisonAttr = Attr.hasAttribute(Attribute::NonNull) ||
203 Attr.hasAttribute(Attribute::Alignment);
204 if (!IsPoisonAttr || Call->isPassingUndefUB(Idx))
205 addAttribute(Attr, Call->getArgOperand(Idx));
206 }
207 for (Attribute Attr : AttrList.getFnAttrs())
208 addAttribute(Attr, nullptr);
209 };
210 addAttrList(Call->getAttributes(), Call->arg_size());
211 if (Function *Fn = Call->getCalledFunction())
212 addAttrList(Fn->getAttributes(), Fn->arg_size());
213 }
214
215 AssumeInst *build() {
216 if (AssumedKnowledgeMap.empty())
217 return nullptr;
218 if (!DebugCounter::shouldExecute(BuildAssumeCounter))
219 return nullptr;
220 Function *FnAssume =
221 Intrinsic::getOrInsertDeclaration(M, Intrinsic::assume);
222 LLVMContext &C = M->getContext();
224 for (auto &MapElem : AssumedKnowledgeMap) {
226 if (MapElem.first.first)
227 Args.push_back(MapElem.first.first);
228
229 /// This is only valid because for all attribute that currently exist a
230 /// value of 0 is useless. and should not be preserved.
231 if (MapElem.second)
232 Args.push_back(ConstantInt::get(Type::getInt64Ty(M->getContext()),
233 MapElem.second));
235 std::string(Attribute::getNameFromAttrKind(MapElem.first.second)),
236 Args));
237 NumBundlesInAssumes++;
238 }
239 NumAssumeBuilt++;
241 FnAssume, ArrayRef<Value *>({ConstantInt::getTrue(C)}), OpBundle));
242 }
243
244 void addAccessedPtr(Instruction *MemInst, Value *Pointer, Type *AccType,
245 MaybeAlign MA) {
246 unsigned DerefSize = MemInst->getModule()
247 ->getDataLayout()
248 .getTypeStoreSize(AccType)
250 if (DerefSize != 0) {
251 addKnowledge({Attribute::Dereferenceable, DerefSize, Pointer});
252 if (!NullPointerIsDefined(MemInst->getFunction(),
253 Pointer->getType()->getPointerAddressSpace()))
254 addKnowledge({Attribute::NonNull, 0u, Pointer});
255 }
256 if (MA.valueOrOne() > 1)
257 addKnowledge({Attribute::Alignment, MA.valueOrOne().value(), Pointer});
258 }
259
260 void addInstruction(Instruction *I) {
261 if (auto *Call = dyn_cast<CallBase>(I))
262 return addCall(Call);
263 if (auto *Load = dyn_cast<LoadInst>(I))
264 return addAccessedPtr(I, Load->getPointerOperand(), Load->getType(),
265 Load->getAlign());
266 if (auto *Store = dyn_cast<StoreInst>(I))
267 return addAccessedPtr(I, Store->getPointerOperand(),
268 Store->getValueOperand()->getType(),
269 Store->getAlign());
270 if (auto *RMW = dyn_cast<AtomicRMWInst>(I))
271 return addAccessedPtr(I, RMW->getPointerOperand(),
272 RMW->getValOperand()->getType(), RMW->getAlign());
273 if (auto *CmpXchg = dyn_cast<AtomicCmpXchgInst>(I))
274 return addAccessedPtr(I, CmpXchg->getPointerOperand(),
275 CmpXchg->getCompareOperand()->getType(),
276 CmpXchg->getAlign());
277 // TODO: Maybe we should look around and merge with other llvm.assume.
278 }
279};
280
281} // namespace
282
285 return nullptr;
286 AssumeBuilderState Builder(I->getModule());
287 Builder.addInstruction(I);
288 return Builder.build();
289}
290
292 DominatorTree *DT) {
293 if (!EnableKnowledgeRetention || I->isTerminator())
294 return false;
295 bool Changed = false;
296 AssumeBuilderState Builder(I->getModule(), I, AC, DT);
297 Builder.addInstruction(I);
298 if (auto *Intr = Builder.build()) {
299 Intr->insertBefore(I->getIterator());
300 Changed = true;
301 if (AC)
302 AC->registerAssumption(Intr);
303 }
304 return Changed;
305}
306
307namespace {
308
309struct AssumeSimplify {
310 Function &F;
311 AssumptionCache &AC;
312 DominatorTree *DT;
313 LLVMContext &C;
315 StringMapEntry<uint32_t> *IgnoreTag;
317 bool MadeChange = false;
318
319 AssumeSimplify(Function &F, AssumptionCache &AC, DominatorTree *DT,
320 LLVMContext &C)
321 : F(F), AC(AC), DT(DT), C(C),
322 IgnoreTag(C.getOrInsertBundleTag(IgnoreBundleTag)) {}
323
324 void buildMapping(bool FilterBooleanArgument) {
325 BBToAssume.clear();
326 for (Value *V : AC.assumptions()) {
327 if (!V)
328 continue;
329 IntrinsicInst *Assume = cast<IntrinsicInst>(V);
330 if (FilterBooleanArgument) {
331 auto *Arg = dyn_cast<ConstantInt>(Assume->getOperand(0));
332 if (!Arg || Arg->isZero())
333 continue;
334 }
335 BBToAssume[Assume->getParent()].push_back(Assume);
336 }
337
338 for (auto &Elem : BBToAssume) {
339 llvm::sort(Elem.second,
340 [](const IntrinsicInst *LHS, const IntrinsicInst *RHS) {
341 return LHS->comesBefore(RHS);
342 });
343 }
344 }
345
346 /// Remove all asumes in CleanupToDo if there boolean argument is true and
347 /// ForceCleanup is set or the assume doesn't hold valuable knowledge.
348 void RunCleanup(bool ForceCleanup) {
349 for (IntrinsicInst *Assume : CleanupToDo) {
350 auto *Arg = dyn_cast<ConstantInt>(Assume->getOperand(0));
351 if (!Arg || Arg->isZero() ||
352 (!ForceCleanup &&
354 continue;
355 MadeChange = true;
356 if (ForceCleanup)
357 NumAssumesMerged++;
358 else
359 NumAssumesRemoved++;
360 Assume->eraseFromParent();
361 }
362 CleanupToDo.clear();
363 }
364
365 /// Remove knowledge stored in assume when it is already know by an attribute
366 /// or an other assume. This can when valid update an existing knowledge in an
367 /// attribute or an other assume.
368 void dropRedundantKnowledge() {
369 struct MapValue {
370 IntrinsicInst *Assume;
371 uint64_t ArgValue;
372 CallInst::BundleOpInfo *BOI;
373 };
374 buildMapping(false);
375 SmallDenseMap<std::pair<Value *, Attribute::AttrKind>,
377 Knowledge;
378 for (BasicBlock *BB : depth_first(&F))
379 for (Value *V : BBToAssume[BB]) {
380 if (!V)
381 continue;
382 IntrinsicInst *Assume = cast<IntrinsicInst>(V);
383 for (CallInst::BundleOpInfo &BOI : Assume->bundle_op_infos()) {
384 auto RemoveFromAssume = [&]() {
385 CleanupToDo.insert(Assume);
386 if (BOI.Begin != BOI.End) {
387 Use *U = &Assume->op_begin()[BOI.Begin + ABA_WasOn];
388 U->set(PoisonValue::get(U->get()->getType()));
389 }
390 BOI.Tag = IgnoreTag;
391 };
392 if (BOI.Tag == IgnoreTag) {
393 CleanupToDo.insert(Assume);
394 continue;
395 }
396 RetainedKnowledge RK =
398 if (auto *Arg = dyn_cast_or_null<Argument>(RK.WasOn)) {
399 bool HasSameKindAttr = Arg->hasAttribute(RK.AttrKind);
400 if (HasSameKindAttr)
401 if (!Attribute::isIntAttrKind(RK.AttrKind) ||
402 Arg->getAttribute(RK.AttrKind).getValueAsInt() >=
403 RK.ArgValue) {
404 RemoveFromAssume();
405 continue;
406 }
408 Assume, &*F.getEntryBlock().getFirstInsertionPt()) ||
409 Assume == &*F.getEntryBlock().getFirstInsertionPt()) {
410 if (HasSameKindAttr)
411 Arg->removeAttr(RK.AttrKind);
412 Arg->addAttr(Attribute::get(C, RK.AttrKind, RK.ArgValue));
413 MadeChange = true;
414 RemoveFromAssume();
415 continue;
416 }
417 }
418 auto &Lookup = Knowledge[{RK.WasOn, RK.AttrKind}];
419 for (MapValue &Elem : Lookup) {
420 if (!isValidAssumeForContext(Elem.Assume, Assume, DT))
421 continue;
422 if (Elem.ArgValue >= RK.ArgValue) {
423 RemoveFromAssume();
424 continue;
425 } else if (isValidAssumeForContext(Assume, Elem.Assume, DT)) {
426 Elem.Assume->op_begin()[Elem.BOI->Begin + ABA_Argument].set(
427 ConstantInt::get(Type::getInt64Ty(C), RK.ArgValue));
428 MadeChange = true;
429 RemoveFromAssume();
430 continue;
431 }
432 }
433 Lookup.push_back({Assume, RK.ArgValue, &BOI});
434 }
435 }
436 }
437
438 using MergeIterator = SmallVectorImpl<IntrinsicInst *>::iterator;
439
440 /// Merge all Assumes from Begin to End in and insert the resulting assume as
441 /// high as possible in the basicblock.
442 void mergeRange(BasicBlock *BB, MergeIterator Begin, MergeIterator End) {
443 if (Begin == End || std::next(Begin) == End)
444 return;
445 /// Provide no additional information so that AssumeBuilderState doesn't
446 /// try to do any punning since it already has been done better.
447 AssumeBuilderState Builder(F.getParent());
448
449 /// For now it is initialized to the best value it could have
450 BasicBlock::iterator InsertPt = BB->getFirstNonPHIIt();
451 if (isa<LandingPadInst>(InsertPt))
452 InsertPt = std::next(InsertPt);
453 for (IntrinsicInst *I : make_range(Begin, End)) {
454 CleanupToDo.insert(I);
455 for (CallInst::BundleOpInfo &BOI : I->bundle_op_infos()) {
456 RetainedKnowledge RK =
458 if (!RK)
459 continue;
460 Builder.addKnowledge(RK);
461 if (auto *I = dyn_cast_or_null<Instruction>(RK.WasOn))
462 if (I->getParent() == InsertPt->getParent() &&
463 (InsertPt->comesBefore(I) || &*InsertPt == I))
464 InsertPt = I->getNextNode()->getIterator();
465 }
466 }
467
468 /// Adjust InsertPt if it is before Begin, since mergeAssumes only
469 /// guarantees we can place the resulting assume between Begin and End.
470 if (InsertPt->comesBefore(*Begin))
471 for (auto It = (*Begin)->getIterator(), E = InsertPt->getIterator();
472 It != E; --It)
474 InsertPt = std::next(It);
475 break;
476 }
477 auto *MergedAssume = Builder.build();
478 if (!MergedAssume)
479 return;
480 MadeChange = true;
481 MergedAssume->insertBefore(InsertPt);
482 AC.registerAssumption(MergedAssume);
483 }
484
485 /// Merge assume when they are in the same BasicBlock and for all instruction
486 /// between them isGuaranteedToTransferExecutionToSuccessor returns true.
487 void mergeAssumes() {
488 buildMapping(true);
489
491 for (auto &Elem : BBToAssume) {
492 SmallVectorImpl<IntrinsicInst *> &AssumesInBB = Elem.second;
493 if (AssumesInBB.size() < 2)
494 continue;
495 /// AssumesInBB is already sorted by order in the block.
496
497 BasicBlock::iterator It = AssumesInBB.front()->getIterator();
498 BasicBlock::iterator E = AssumesInBB.back()->getIterator();
499 SplitPoints.push_back(AssumesInBB.begin());
500 MergeIterator LastSplit = AssumesInBB.begin();
501 for (; It != E; ++It)
503 for (; (*LastSplit)->comesBefore(&*It); ++LastSplit)
504 ;
505 if (SplitPoints.back() != LastSplit)
506 SplitPoints.push_back(LastSplit);
507 }
508 SplitPoints.push_back(AssumesInBB.end());
509 for (auto SplitIt = SplitPoints.begin();
510 SplitIt != std::prev(SplitPoints.end()); SplitIt++) {
511 mergeRange(Elem.first, *SplitIt, *(SplitIt + 1));
512 }
513 SplitPoints.clear();
514 }
515 }
516};
517
518bool simplifyAssumes(Function &F, AssumptionCache *AC, DominatorTree *DT) {
519 AssumeSimplify AS(F, *AC, DT, F.getContext());
520
521 /// Remove knowledge that is already known by a dominating other assume or an
522 /// attribute.
523 AS.dropRedundantKnowledge();
524
525 /// Remove assume that are empty.
526 AS.RunCleanup(false);
527
528 /// Merge assume in the same basicblock when possible.
529 AS.mergeAssumes();
530
531 /// Remove assume that were merged.
532 AS.RunCleanup(true);
533 return AS.MadeChange;
534}
535
536} // namespace
537
549
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file provides an implementation of debug counters.
#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC)
This file builds on the ADT/GraphTraits.h file to build generic depth first graph iterator.
Hexagon Common GEP
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Machine Check Debug Module
This file implements a map that provides insertion order iteration.
if(PassOpts->AAPipeline)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
static int Lookup(ArrayRef< TableEntry > Table, unsigned Opcode)
Value * RHS
Value * LHS
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
This represents the llvm.assume intrinsic.
A function analysis which provides an AssumptionCache.
A cache of @llvm.assume calls within a function.
LLVM_ABI void registerAssumption(AssumeInst *CI)
Add an @llvm.assume intrinsic to this function's cache.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
LLVM_ABI bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
LLVM_ABI bool isIntAttribute() const
Return true if the attribute is an integer attribute.
LLVM_ABI uint64_t getValueAsInt() const
Return the attribute's value as an integer.
LLVM_ABI Attribute::AttrKind getKindAsEnum() const
Return the attribute's kind as an enum (Attribute::AttrKind).
static LLVM_ABI StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind)
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
Definition Attributes.h:124
LLVM_ABI bool isTypeAttribute() const
Return true if the attribute is a type attribute.
static bool isIntAttrKind(AttrKind Kind)
Definition Attributes.h:140
LLVM_ABI bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
InstListType::iterator iterator
Instruction iterators...
Definition BasicBlock.h:170
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:64
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type.
Definition DataLayout.h:579
static bool shouldExecute(CounterInfo &Counter)
Analysis pass which computes a DominatorTree.
Definition Dominators.h:270
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:151
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
std::pair< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
Definition MapVector.h:118
bool empty() const
Definition MapVector.h:79
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition Module.h:280
A container for an operand bundle being viewed as a set of values rather than a set of uses.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition DenseSet.h:301
typename SuperClass::iterator iterator
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
Definition Type.cpp:310
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:282
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
op_iterator op_begin()
Definition User.h:259
LLVM Value Representation.
Definition Value.h:75
Type * getType() const
All values are typed, get the type of this value.
Definition Value.h:255
LLVM_ABI const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
Definition Value.cpp:824
LLVM_ABI Use * getSingleUndroppableUse()
Return true if there is exactly one use of this value that cannot be dropped.
Definition Value.cpp:173
bool use_empty() const
Definition Value.h:346
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
Definition TypeSize.h:165
CallInst * Call
Changed
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
initializer< Ty > init(const Ty &Val)
LLVM_ABI Error build(ArrayRef< Module * > Mods, SmallVector< char, 0 > &Symtab, StringTableBuilder &StrtabBuilder, BumpPtrAllocator &Alloc)
Fills in Symtab and StrtabBuilder with a valid symbol and string table for Mods.
Definition IRSymtab.cpp:349
NodeAddr< UseNode * > Use
Definition RDFGraph.h:385
friend class Instruction
Iterator for Instructions in a `BasicBlock.
Definition BasicBlock.h:73
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI cl::opt< bool > EnableKnowledgeRetention
@ Offset
Definition DWP.cpp:558
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
LLVM_ABI RetainedKnowledge getKnowledgeForValue(const Value *V, ArrayRef< Attribute::AttrKind > AttrKinds, AssumptionCache &AC, function_ref< bool(RetainedKnowledge, Instruction *, const CallBase::BundleOpInfo *)> Filter=[](auto...) { return true;})
Return a valid Knowledge associated to the Value V if its Attribute kind is in AttrKinds and it match...
LLVM_ABI bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr, bool AllowEphemerals=false)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr StringRef IgnoreBundleTag
Tag in operand bundle indicating that this bundle should be ignored.
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL, bool AllowNonInbounds=true)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset.
LLVM_ABI bool isAssumeWithEmptyBundle(const AssumeInst &Assume)
Return true iff the operand bundles of the provided llvm.assume doesn't contain any valuable informat...
constexpr T MinAlign(U A, V B)
A and B are either alignments or offsets.
Definition MathExtras.h:357
LLVM_ABI RetainedKnowledge getKnowledgeFromBundle(AssumeInst &Assume, const CallBase::BundleOpInfo &BOI)
This extracts the Knowledge from an element of an operand bundle.
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1635
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
LLVM_ABI bool wouldInstructionBeTriviallyDead(const Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction would have no side effects if it was not used.
Definition Local.cpp:422
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI bool salvageKnowledge(Instruction *I, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr)
Calls BuildAssumeFromInst and if the resulting llvm.assume is valid insert if before I.
LLVM_ABI bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Value * MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr, const MetadataPredicate *IdentityMD=nullptr)
Look up or compute a value in the value map.
iterator_range< df_iterator< T > > depth_first(const T &G)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
LLVM_ABI AssumeInst * buildAssumeFromInst(Instruction *I)
Build a call to llvm.assume to preserve informations that can be derived from the given instruction.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
uint32_t Begin
The index in the Use& vector where operands for this operand bundle starts.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
Definition Alignment.h:130
Represent one information held inside an operand bundle of an llvm.assume.
Attribute::AttrKind AttrKind