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"
26
27using namespace llvm;
28
29namespace llvm {
31 "assume-preserve-all", cl::init(false), cl::Hidden,
32 cl::desc("enable preservation of all attributes. even those that are "
33 "unlikely to be useful"));
34
36 "enable-knowledge-retention", cl::init(false), cl::Hidden,
38 "enable preservation of attributes throughout code transformation"));
39} // namespace llvm
40
41#define DEBUG_TYPE "assume-builder"
42
43STATISTIC(NumAssumeBuilt, "Number of assume built by the assume builder");
44STATISTIC(NumBundlesInAssumes, "Total number of Bundles in the assume built");
45STATISTIC(NumAssumesMerged,
46 "Number of assume merged by the assume simplify pass");
47STATISTIC(NumAssumesRemoved,
48 "Number of assume removed by the assume simplify pass");
49
50DEBUG_COUNTER(BuildAssumeCounter, "assume-builder-counter",
51 "Controls which assumes gets created");
52
53namespace {
54
55bool isUsefullToPreserve(Attribute::AttrKind Kind) {
56 switch (Kind) {
57 case Attribute::NonNull:
58 case Attribute::NoUndef:
59 case Attribute::Alignment:
60 case Attribute::Dereferenceable:
61 case Attribute::DereferenceableOrNull:
62 case Attribute::Cold:
63 return true;
64 default:
65 return false;
66 }
67}
68
69/// This function will try to transform the given knowledge into a more
70/// canonical one. the canonical knowledge maybe the given one.
71RetainedKnowledge canonicalizedKnowledge(RetainedKnowledge RK,
72 const DataLayout &DL) {
73 switch (RK.AttrKind) {
74 default:
75 return RK;
76 case Attribute::NonNull:
78 return RK;
79 case Attribute::Alignment: {
80 Value *V = RK.WasOn->stripInBoundsOffsets([&](const Value *Strip) {
81 if (auto *GEP = dyn_cast<GEPOperator>(Strip))
82 RK.ArgValue =
83 MinAlign(RK.ArgValue, GEP->getMaxPreservedAlignment(DL).value());
84 });
85 RK.WasOn = V;
86 return RK;
87 }
88 case Attribute::Dereferenceable:
89 case Attribute::DereferenceableOrNull: {
90 int64_t Offset = 0;
92 /*AllowNonInBounds*/ false);
93 if (Offset < 0)
94 return RK;
95 RK.ArgValue = RK.ArgValue + Offset;
96 RK.WasOn = V;
97 }
98 }
99 return RK;
100}
101
102/// This class contain all knowledge that have been gather while building an
103/// llvm.assume and the function to manipulate it.
104struct AssumeBuilderState {
105 Module *M;
106
107 using MapKey = std::pair<Value *, Attribute::AttrKind>;
108 SmallMapVector<MapKey, uint64_t, 8> AssumedKnowledgeMap;
109 Instruction *InstBeingModified = nullptr;
110 AssumptionCache* AC = nullptr;
111 DominatorTree* DT = nullptr;
112
113 AssumeBuilderState(Module *M, Instruction *I = nullptr,
114 AssumptionCache *AC = nullptr, DominatorTree *DT = nullptr)
115 : M(M), InstBeingModified(I), AC(AC), DT(DT) {}
116
117 bool tryToPreserveWithoutAddingAssume(RetainedKnowledge RK) {
118 if (!InstBeingModified || !RK.WasOn || !AC)
119 return false;
120 bool HasBeenPreserved = false;
121 Use* ToUpdate = nullptr;
123 RK.WasOn, {RK.AttrKind}, *AC,
124 [&](RetainedKnowledge RKOther, Instruction *Assume,
125 const CallInst::BundleOpInfo *Bundle) {
126 if (!isValidAssumeForContext(Assume, InstBeingModified, DT))
127 return false;
128 if (RKOther.ArgValue >= RK.ArgValue) {
129 HasBeenPreserved = true;
130 return true;
131 } else if (isValidAssumeForContext(InstBeingModified, Assume, DT)) {
132 HasBeenPreserved = true;
133 IntrinsicInst *Intr = cast<IntrinsicInst>(Assume);
134 ToUpdate = &Intr->op_begin()[Bundle->Begin + ABA_Argument];
135 return true;
136 }
137 return false;
138 });
139 if (ToUpdate)
140 ToUpdate->set(
141 ConstantInt::get(Type::getInt64Ty(M->getContext()), RK.ArgValue));
142 return HasBeenPreserved;
143 }
144
145 bool isKnowledgeWorthPreserving(RetainedKnowledge RK) {
146 if (!RK)
147 return false;
148 if (!RK.WasOn)
149 return true;
150 if (RK.WasOn->getType()->isPointerTy()) {
151 Value *UnderlyingPtr = getUnderlyingObject(RK.WasOn);
152 if (isa<AllocaInst>(UnderlyingPtr) || isa<GlobalValue>(UnderlyingPtr))
153 return false;
154 }
155 if (auto *Arg = dyn_cast<Argument>(RK.WasOn)) {
156 if (Arg->hasAttribute(RK.AttrKind) &&
158 Arg->getAttribute(RK.AttrKind).getValueAsInt() >= RK.ArgValue))
159 return false;
160 return true;
161 }
162 if (auto *Inst = dyn_cast<Instruction>(RK.WasOn))
164 if (RK.WasOn->use_empty())
165 return false;
166 Use *SingleUse = RK.WasOn->getSingleUndroppableUse();
167 if (SingleUse && SingleUse->getUser() == InstBeingModified)
168 return false;
169 }
170 return true;
171 }
172
173 void addKnowledge(RetainedKnowledge RK) {
174 RK = canonicalizedKnowledge(RK, M->getDataLayout());
175
176 if (!isKnowledgeWorthPreserving(RK))
177 return;
178
179 if (tryToPreserveWithoutAddingAssume(RK))
180 return;
181 MapKey Key{RK.WasOn, RK.AttrKind};
182 auto [Lookup, Inserted] = AssumedKnowledgeMap.try_emplace(Key, RK.ArgValue);
183 if (Inserted)
184 return;
185 assert(((Lookup->second == 0 && RK.ArgValue == 0) ||
186 (Lookup->second != 0 && RK.ArgValue != 0)) &&
187 "inconsistent argument value");
188
189 /// This is only desirable because for all attributes taking an argument
190 /// higher is better.
191 Lookup->second = std::max(Lookup->second, RK.ArgValue);
192 }
193
194 void addAttribute(Attribute Attr, Value *WasOn) {
195 if (Attr.isTypeAttribute() || Attr.isStringAttribute() ||
197 !isUsefullToPreserve(Attr.getKindAsEnum())))
198 return;
199 uint64_t AttrArg = 0;
200 if (Attr.isIntAttribute())
201 AttrArg = Attr.getValueAsInt();
202 addKnowledge({Attr.getKindAsEnum(), AttrArg, WasOn});
203 }
204
205 void addCall(const CallBase *Call) {
206 auto addAttrList = [&](AttributeList AttrList, unsigned NumArgs) {
207 for (unsigned Idx = 0; Idx < NumArgs; Idx++)
208 for (Attribute Attr : AttrList.getParamAttrs(Idx)) {
209 bool IsPoisonAttr = Attr.hasAttribute(Attribute::NonNull) ||
210 Attr.hasAttribute(Attribute::Alignment);
211 if (!IsPoisonAttr || Call->isPassingUndefUB(Idx))
212 addAttribute(Attr, Call->getArgOperand(Idx));
213 }
214 for (Attribute Attr : AttrList.getFnAttrs())
215 addAttribute(Attr, nullptr);
216 };
217 addAttrList(Call->getAttributes(), Call->arg_size());
218 if (Function *Fn = Call->getCalledFunction())
219 addAttrList(Fn->getAttributes(), Fn->arg_size());
220 }
221
222 AssumeInst *build() {
223 if (AssumedKnowledgeMap.empty())
224 return nullptr;
225 if (!DebugCounter::shouldExecute(BuildAssumeCounter))
226 return nullptr;
227 Function *FnAssume =
228 Intrinsic::getOrInsertDeclaration(M, Intrinsic::assume);
229 LLVMContext &C = M->getContext();
231 for (auto &MapElem : AssumedKnowledgeMap) {
233 if (MapElem.first.first)
234 Args.push_back(MapElem.first.first);
235
236 /// This is only valid because for all attribute that currently exist a
237 /// value of 0 is useless. and should not be preserved.
238 if (MapElem.second)
239 Args.push_back(ConstantInt::get(Type::getInt64Ty(M->getContext()),
240 MapElem.second));
242 std::string(Attribute::getNameFromAttrKind(MapElem.first.second)),
243 Args));
244 NumBundlesInAssumes++;
245 }
246 NumAssumeBuilt++;
248 FnAssume, ArrayRef<Value *>({ConstantInt::getTrue(C)}), OpBundle));
249 }
250
251 void addAccessedPtr(Instruction *MemInst, Value *Pointer, Type *AccType,
252 MaybeAlign MA) {
253 unsigned DerefSize = MemInst->getModule()
254 ->getDataLayout()
255 .getTypeStoreSize(AccType)
257 if (DerefSize != 0) {
258 addKnowledge({Attribute::Dereferenceable, DerefSize, Pointer});
259 if (!NullPointerIsDefined(MemInst->getFunction(),
260 Pointer->getType()->getPointerAddressSpace()))
261 addKnowledge({Attribute::NonNull, 0u, Pointer});
262 }
263 if (MA.valueOrOne() > 1)
264 addKnowledge({Attribute::Alignment, MA.valueOrOne().value(), Pointer});
265 }
266
267 void addInstruction(Instruction *I) {
268 if (auto *Call = dyn_cast<CallBase>(I))
269 return addCall(Call);
270 if (auto *Load = dyn_cast<LoadInst>(I))
271 return addAccessedPtr(I, Load->getPointerOperand(), Load->getType(),
272 Load->getAlign());
273 if (auto *Store = dyn_cast<StoreInst>(I))
274 return addAccessedPtr(I, Store->getPointerOperand(),
275 Store->getValueOperand()->getType(),
276 Store->getAlign());
277 if (auto *RMW = dyn_cast<AtomicRMWInst>(I))
278 return addAccessedPtr(I, RMW->getPointerOperand(),
279 RMW->getValOperand()->getType(), RMW->getAlign());
280 if (auto *CmpXchg = dyn_cast<AtomicCmpXchgInst>(I))
281 return addAccessedPtr(I, CmpXchg->getPointerOperand(),
282 CmpXchg->getCompareOperand()->getType(),
283 CmpXchg->getAlign());
284 // TODO: Maybe we should look around and merge with other llvm.assume.
285 }
286};
287
288} // namespace
289
292 return nullptr;
293 AssumeBuilderState Builder(I->getModule());
294 Builder.addInstruction(I);
295 return Builder.build();
296}
297
299 DominatorTree *DT) {
300 if (!EnableKnowledgeRetention || I->isTerminator())
301 return false;
302 bool Changed = false;
303 AssumeBuilderState Builder(I->getModule(), I, AC, DT);
304 Builder.addInstruction(I);
305 if (auto *Intr = Builder.build()) {
306 Intr->insertBefore(I->getIterator());
307 Changed = true;
308 if (AC)
309 AC->registerAssumption(Intr);
310 }
311 return Changed;
312}
313
316 AssumptionCache *AC,
317 DominatorTree *DT) {
318 AssumeBuilderState Builder(Assume->getModule(), Assume, AC, DT);
319 RK = canonicalizedKnowledge(RK, Assume->getDataLayout());
320
321 if (!Builder.isKnowledgeWorthPreserving(RK))
323
324 if (Builder.tryToPreserveWithoutAddingAssume(RK))
326 return RK;
327}
328
329namespace {
330
331struct AssumeSimplify {
332 Function &F;
333 AssumptionCache &AC;
334 DominatorTree *DT;
335 LLVMContext &C;
337 StringMapEntry<uint32_t> *IgnoreTag;
339 bool MadeChange = false;
340
341 AssumeSimplify(Function &F, AssumptionCache &AC, DominatorTree *DT,
342 LLVMContext &C)
343 : F(F), AC(AC), DT(DT), C(C),
344 IgnoreTag(C.getOrInsertBundleTag(IgnoreBundleTag)) {}
345
346 void buildMapping(bool FilterBooleanArgument) {
347 BBToAssume.clear();
348 for (Value *V : AC.assumptions()) {
349 if (!V)
350 continue;
351 IntrinsicInst *Assume = cast<IntrinsicInst>(V);
352 if (FilterBooleanArgument) {
353 auto *Arg = dyn_cast<ConstantInt>(Assume->getOperand(0));
354 if (!Arg || Arg->isZero())
355 continue;
356 }
357 BBToAssume[Assume->getParent()].push_back(Assume);
358 }
359
360 for (auto &Elem : BBToAssume) {
361 llvm::sort(Elem.second,
362 [](const IntrinsicInst *LHS, const IntrinsicInst *RHS) {
363 return LHS->comesBefore(RHS);
364 });
365 }
366 }
367
368 /// Remove all asumes in CleanupToDo if there boolean argument is true and
369 /// ForceCleanup is set or the assume doesn't hold valuable knowledge.
370 void RunCleanup(bool ForceCleanup) {
371 for (IntrinsicInst *Assume : CleanupToDo) {
372 auto *Arg = dyn_cast<ConstantInt>(Assume->getOperand(0));
373 if (!Arg || Arg->isZero() ||
374 (!ForceCleanup &&
376 continue;
377 MadeChange = true;
378 if (ForceCleanup)
379 NumAssumesMerged++;
380 else
381 NumAssumesRemoved++;
382 Assume->eraseFromParent();
383 }
384 CleanupToDo.clear();
385 }
386
387 /// Remove knowledge stored in assume when it is already know by an attribute
388 /// or an other assume. This can when valid update an existing knowledge in an
389 /// attribute or an other assume.
390 void dropRedundantKnowledge() {
391 struct MapValue {
392 IntrinsicInst *Assume;
393 uint64_t ArgValue;
394 CallInst::BundleOpInfo *BOI;
395 };
396 buildMapping(false);
397 SmallDenseMap<std::pair<Value *, Attribute::AttrKind>,
399 Knowledge;
400 for (BasicBlock *BB : depth_first(&F))
401 for (Value *V : BBToAssume[BB]) {
402 if (!V)
403 continue;
404 IntrinsicInst *Assume = cast<IntrinsicInst>(V);
405 for (CallInst::BundleOpInfo &BOI : Assume->bundle_op_infos()) {
406 auto RemoveFromAssume = [&]() {
407 CleanupToDo.insert(Assume);
408 if (BOI.Begin != BOI.End) {
409 Use *U = &Assume->op_begin()[BOI.Begin + ABA_WasOn];
410 U->set(PoisonValue::get(U->get()->getType()));
411 }
412 BOI.Tag = IgnoreTag;
413 };
414 if (BOI.Tag == IgnoreTag) {
415 CleanupToDo.insert(Assume);
416 continue;
417 }
418 RetainedKnowledge RK =
420 if (auto *Arg = dyn_cast_or_null<Argument>(RK.WasOn)) {
421 bool HasSameKindAttr = Arg->hasAttribute(RK.AttrKind);
422 if (HasSameKindAttr)
423 if (!Attribute::isIntAttrKind(RK.AttrKind) ||
424 Arg->getAttribute(RK.AttrKind).getValueAsInt() >=
425 RK.ArgValue) {
426 RemoveFromAssume();
427 continue;
428 }
430 Assume, &*F.getEntryBlock().getFirstInsertionPt()) ||
431 Assume == &*F.getEntryBlock().getFirstInsertionPt()) {
432 if (HasSameKindAttr)
433 Arg->removeAttr(RK.AttrKind);
434 Arg->addAttr(Attribute::get(C, RK.AttrKind, RK.ArgValue));
435 MadeChange = true;
436 RemoveFromAssume();
437 continue;
438 }
439 }
440 auto &Lookup = Knowledge[{RK.WasOn, RK.AttrKind}];
441 for (MapValue &Elem : Lookup) {
442 if (!isValidAssumeForContext(Elem.Assume, Assume, DT))
443 continue;
444 if (Elem.ArgValue >= RK.ArgValue) {
445 RemoveFromAssume();
446 continue;
447 } else if (isValidAssumeForContext(Assume, Elem.Assume, DT)) {
448 Elem.Assume->op_begin()[Elem.BOI->Begin + ABA_Argument].set(
449 ConstantInt::get(Type::getInt64Ty(C), RK.ArgValue));
450 MadeChange = true;
451 RemoveFromAssume();
452 continue;
453 }
454 }
455 Lookup.push_back({Assume, RK.ArgValue, &BOI});
456 }
457 }
458 }
459
460 using MergeIterator = SmallVectorImpl<IntrinsicInst *>::iterator;
461
462 /// Merge all Assumes from Begin to End in and insert the resulting assume as
463 /// high as possible in the basicblock.
464 void mergeRange(BasicBlock *BB, MergeIterator Begin, MergeIterator End) {
465 if (Begin == End || std::next(Begin) == End)
466 return;
467 /// Provide no additional information so that AssumeBuilderState doesn't
468 /// try to do any punning since it already has been done better.
469 AssumeBuilderState Builder(F.getParent());
470
471 /// For now it is initialized to the best value it could have
472 BasicBlock::iterator InsertPt = BB->getFirstNonPHIIt();
473 if (isa<LandingPadInst>(InsertPt))
474 InsertPt = std::next(InsertPt);
475 for (IntrinsicInst *I : make_range(Begin, End)) {
476 CleanupToDo.insert(I);
477 for (CallInst::BundleOpInfo &BOI : I->bundle_op_infos()) {
478 RetainedKnowledge RK =
480 if (!RK)
481 continue;
482 Builder.addKnowledge(RK);
483 if (auto *I = dyn_cast_or_null<Instruction>(RK.WasOn))
484 if (I->getParent() == InsertPt->getParent() &&
485 (InsertPt->comesBefore(I) || &*InsertPt == I))
486 InsertPt = I->getNextNode()->getIterator();
487 }
488 }
489
490 /// Adjust InsertPt if it is before Begin, since mergeAssumes only
491 /// guarantees we can place the resulting assume between Begin and End.
492 if (InsertPt->comesBefore(*Begin))
493 for (auto It = (*Begin)->getIterator(), E = InsertPt->getIterator();
494 It != E; --It)
496 InsertPt = std::next(It);
497 break;
498 }
499 auto *MergedAssume = Builder.build();
500 if (!MergedAssume)
501 return;
502 MadeChange = true;
503 MergedAssume->insertBefore(InsertPt);
504 AC.registerAssumption(MergedAssume);
505 }
506
507 /// Merge assume when they are in the same BasicBlock and for all instruction
508 /// between them isGuaranteedToTransferExecutionToSuccessor returns true.
509 void mergeAssumes() {
510 buildMapping(true);
511
513 for (auto &Elem : BBToAssume) {
514 SmallVectorImpl<IntrinsicInst *> &AssumesInBB = Elem.second;
515 if (AssumesInBB.size() < 2)
516 continue;
517 /// AssumesInBB is already sorted by order in the block.
518
519 BasicBlock::iterator It = AssumesInBB.front()->getIterator();
520 BasicBlock::iterator E = AssumesInBB.back()->getIterator();
521 SplitPoints.push_back(AssumesInBB.begin());
522 MergeIterator LastSplit = AssumesInBB.begin();
523 for (; It != E; ++It)
525 for (; (*LastSplit)->comesBefore(&*It); ++LastSplit)
526 ;
527 if (SplitPoints.back() != LastSplit)
528 SplitPoints.push_back(LastSplit);
529 }
530 SplitPoints.push_back(AssumesInBB.end());
531 for (auto SplitIt = SplitPoints.begin();
532 SplitIt != std::prev(SplitPoints.end()); SplitIt++) {
533 mergeRange(Elem.first, *SplitIt, *(SplitIt + 1));
534 }
535 SplitPoints.clear();
536 }
537 }
538};
539
540bool simplifyAssumes(Function &F, AssumptionCache *AC, DominatorTree *DT) {
541 AssumeSimplify AS(F, *AC, DT, F.getContext());
542
543 /// Remove knowledge that is already known by a dominating other assume or an
544 /// attribute.
545 AS.dropRedundantKnowledge();
546
547 /// Remove assume that are empty.
548 AS.RunCleanup(false);
549
550 /// Merge assume in the same basicblock when possible.
551 AS.mergeAssumes();
552
553 /// Remove assume that were merged.
554 AS.RunCleanup(true);
555 return AS.MadeChange;
556}
557
558} // namespace
559
571
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")
#define LLVM_ABI
Definition Compiler.h:213
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:278
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:159
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:291
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:314
bool isPointerTy() const
True if this is an instance of PointerType.
Definition Type.h:284
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:820
LLVM_ABI Use * getSingleUndroppableUse()
Return true if there is exactly one use of this value that cannot be dropped.
Definition Value.cpp:172
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:557
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,...
LLVM_ABI RetainedKnowledge simplifyRetainedKnowledge(AssumeInst *Assume, RetainedKnowledge RK, AssumptionCache *AC, DominatorTree *DT)
canonicalize the RetainedKnowledge RK.
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
LLVM_ABI cl::opt< bool > ShouldPreserveAllAttributes("assume-preserve-all", cl::init(false), cl::Hidden, cl::desc("enable preservation of all attributes. even those that are " "unlikely to be useful"))
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
static RetainedKnowledge none()