44 #define DEBUG_TYPE "lazy-value-info" 52 "Lazy Value Information Analysis",
false,
true)
134 class LazyValueInfoCache;
135 struct LVIValueHandle final :
public CallbackVH {
139 LazyValueInfoCache *Parent;
141 LVIValueHandle(
Value *V, LazyValueInfoCache *
P)
144 void deleted()
override;
145 void allUsesReplacedWith(
Value *V)
override {
154 class LazyValueInfoCache {
160 struct ValueCacheEntryTy {
161 ValueCacheEntryTy(
Value *V, LazyValueInfoCache *
P) : Handle(V, P) {}
162 LVIValueHandle Handle;
177 OverDefinedCacheTy OverDefinedCache;
188 OverDefinedCache[BB].insert(Val);
190 auto It = ValueCache.
find_as(Val);
191 if (It == ValueCache.
end()) {
192 ValueCache[Val] = make_unique<ValueCacheEntryTy>(Val,
this);
194 assert(It != ValueCache.
end() &&
"Val was just added to the map!");
196 It->second->BlockVals[BB] = Result;
201 auto ODI = OverDefinedCache.find(BB);
203 if (ODI == OverDefinedCache.end())
206 return ODI->second.count(V);
210 if (isOverdefined(V, BB))
214 if (
I == ValueCache.
end())
217 return I->second->BlockVals.count(BB);
221 if (isOverdefined(V, BB))
225 if (
I == ValueCache.
end())
227 auto BBI =
I->second->BlockVals.find(BB);
228 if (BBI ==
I->second->BlockVals.end())
237 OverDefinedCache.clear();
241 void eraseValue(
Value *V);
252 friend struct LVIValueHandle;
256 void LazyValueInfoCache::eraseValue(
Value *V) {
257 for (
auto I = OverDefinedCache.begin(),
E = OverDefinedCache.end();
I !=
E;) {
263 if (ValueSet.
empty())
264 OverDefinedCache.erase(Iter);
270 void LVIValueHandle::deleted() {
273 Parent->eraseValue(*
this);
276 void LazyValueInfoCache::eraseBlock(
BasicBlock *BB) {
279 if (I == SeenBlocks.
end())
283 auto ODI = OverDefinedCache.find(BB);
284 if (ODI != OverDefinedCache.end())
285 OverDefinedCache.erase(ODI);
287 for (
auto &I : ValueCache)
288 I.second->BlockVals.
erase(BB);
291 void LazyValueInfoCache::threadEdgeImpl(
BasicBlock *OldSucc,
303 std::vector<BasicBlock*> worklist;
304 worklist.push_back(OldSucc);
306 auto I = OverDefinedCache.find(OldSucc);
307 if (
I == OverDefinedCache.end())
315 while (!worklist.empty()) {
320 if (ToUpdate == NewSucc)
continue;
323 auto OI = OverDefinedCache.find(ToUpdate);
324 if (OI == OverDefinedCache.end())
328 bool changed =
false;
329 for (
Value *V : ValsToClear) {
330 if (!ValueSet.
erase(V))
337 if (ValueSet.
empty()) {
338 OverDefinedCache.erase(OI);
343 if (!changed)
continue;
353 class LazyValueInfoImpl;
355 LazyValueInfoImpl *LVIImpl;
363 LazyValueInfoAnnotatedWriter(LazyValueInfoImpl *L,
DominatorTree &DTree)
364 : LVIImpl(L), DT(DTree) {}
366 virtual void emitBasicBlockStartAnnot(
const BasicBlock *BB,
377 class LazyValueInfoImpl {
380 LazyValueInfoCache TheCache;
392 bool pushBlockValue(
const std::pair<BasicBlock *, Value *> &BV) {
393 if (!BlockValueSet.
insert(BV).second)
397 << BV.first->getName() <<
"\n");
430 void intersectAssumeOrGuardBlockValueConstantRange(
Value *Val,
460 LazyValueInfoAnnotatedWriter Writer(
this, DTree);
461 F.
print(OS, &Writer);
467 TheCache.eraseBlock(BB);
473 assert(!DisabledDT &&
"Both DT and DisabledDT are not nullptr!");
482 assert(!DT &&
"Both DT and DisabledDT are not nullptr!");
493 : AC(AC), DL(DL), DT(DT), DisabledDT(
nullptr) {}
500 BlockValueStack.begin(), BlockValueStack.end());
502 unsigned processedCount = 0;
503 while (!BlockValueStack.empty()) {
513 if (processedCount > MaxProcessedPerValue) {
515 dbgs() <<
"Giving up on stack because we are getting too deep\n");
517 while (!StartingStack.empty()) {
518 std::pair<BasicBlock *, Value *> &e = StartingStack.back();
519 TheCache.insertResult(e.second, e.first,
521 StartingStack.pop_back();
523 BlockValueSet.clear();
524 BlockValueStack.clear();
527 std::pair<BasicBlock *, Value *> e = BlockValueStack.back();
528 assert(BlockValueSet.count(e) &&
"Stack value should be in BlockValueSet!");
530 if (solveBlockValue(e.second, e.first)) {
532 assert(BlockValueStack.back() == e &&
"Nothing should have been pushed!");
533 assert(TheCache.hasCachedValueInfo(e.second, e.first) &&
534 "Result should be in cache!");
537 dbgs() <<
"POP " << *e.second <<
" in " << e.first->getName() <<
" = " 538 << TheCache.getCachedValueInfo(e.second, e.first) <<
"\n");
540 BlockValueStack.pop_back();
541 BlockValueSet.erase(e);
544 assert(BlockValueStack.back() != e &&
"Stack should have been pushed!");
551 if (isa<Constant>(Val))
554 return TheCache.hasCachedValueInfo(Val, BB);
563 return TheCache.getCachedValueInfo(Val, BB);
571 case Instruction::Invoke:
573 if (isa<IntegerType>(BBI->
getType())) {
584 if (isa<Constant>(Val))
587 if (TheCache.hasCachedValueInfo(Val, BB)) {
590 << TheCache.getCachedValueInfo(Val, BB) <<
'\n');
601 if (!solveBlockValueImpl(Res, Val, BB))
605 TheCache.insertResult(Val, BB, Res);
614 return solveBlockValueNonLocal(Res, Val, BB);
616 if (
PHINode *PN = dyn_cast<PHINode>(BBI))
617 return solveBlockValuePHINode(Res, PN, BB);
619 if (
auto *
SI = dyn_cast<SelectInst>(BBI))
620 return solveBlockValueSelect(Res,
SI, BB);
637 if (
auto *CI = dyn_cast<CastInst>(BBI))
638 return solveBlockValueCast(Res, CI, BB);
641 return solveBlockValueBinaryOp(Res, BO, BB);
645 <<
"' - unknown inst def found.\n");
651 if (
LoadInst *L = dyn_cast<LoadInst>(I)) {
652 return L->getPointerAddressSpace() == 0 &&
654 L->getModule()->getDataLayout()) == Ptr;
656 if (
StoreInst *S = dyn_cast<StoreInst>(I)) {
657 return S->getPointerAddressSpace() == 0 &&
659 S->getModule()->getDataLayout()) == Ptr;
662 if (
MI->isVolatile())
return false;
666 if (!Len || Len->
isZero())
return false;
668 if (
MI->getDestAddressSpace() == 0)
670 MI->getModule()->getDataLayout()) == Ptr)
673 if (MTI->getSourceAddressSpace() == 0)
675 MTI->getModule()->getDataLayout()) == Ptr)
706 assert(isa<Argument>(Val) &&
"Unknown live-in to the entry block");
733 if (!getEdgeValue(Val, *PI, BB, EdgeResult))
737 Result.
mergeIn(EdgeResult, DL);
743 <<
"' - overdefined because of pred (non local).\n");
777 if (!getEdgeValue(PhiVal, PhiBB, BB, EdgeResult, PN))
781 Result.
mergeIn(EdgeResult, DL);
787 <<
"' - overdefined because of pred (local).\n");
801 bool isTrueDest =
true);
805 void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
811 for (
auto &AssumeVH : AC->assumptionsFor(Val)) {
814 auto *
I = cast<CallInst>(AssumeVH);
824 if (!GuardDecl || GuardDecl->use_empty())
829 Value *Cond =
nullptr;
830 if (
match(&
I, m_Intrinsic<Intrinsic::experimental_guard>(
m_Value(Cond))))
840 if (pushBlockValue(std::make_pair(BB, SI->
getTrueValue())))
870 Value *LHS =
nullptr;
871 Value *RHS =
nullptr;
882 return TrueCR.
smin(FalseCR);
884 return TrueCR.
umin(FalseCR);
886 return TrueCR.
smax(FalseCR);
888 return TrueCR.
umax(FalseCR);
915 if (
auto *ICI = dyn_cast<ICmpInst>(Cond)) {
917 Value *A = ICI->getOperand(0);
918 if (
ConstantInt *CIBase = dyn_cast<ConstantInt>(ICI->getOperand(1))) {
932 auto ResNot = addConstants(CIBase, CIAdded);
940 auto ResNot = addConstants(CIBase, CIAdded);
960 if (pushBlockValue(std::make_pair(BB, I->
getOperand(Op))))
963 const unsigned OperandBitWidth =
968 intersectAssumeOrGuardBlockValueConstantRange(I->
getOperand(Op), Val,
I);
989 case Instruction::Trunc:
990 case Instruction::SExt:
991 case Instruction::ZExt:
992 case Instruction::BitCast:
997 <<
"' - overdefined (unknown cast).\n");
1026 "all operands to binary operators are sized");
1033 case Instruction::Sub:
1034 case Instruction::Mul:
1035 case Instruction::UDiv:
1036 case Instruction::Shl:
1037 case Instruction::LShr:
1038 case Instruction::AShr:
1039 case Instruction::And:
1040 case Instruction::Or:
1046 <<
"' - overdefined (unknown binary operator).\n");
1079 if (isa<Constant>(RHS)) {
1111 if (LHS == Val || Offset) {
1117 else if (
Instruction *I = dyn_cast<Instruction>(RHS))
1143 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Cond))
1151 if (!BO || (isTrueDest && BO->
getOpcode() != BinaryOperator::And) ||
1152 (!isTrueDest && BO->
getOpcode() != BinaryOperator::Or))
1161 if (BL == Cond || BR == Cond)
1171 auto I = Visited.
find(Cond);
1172 if (I != Visited.
end())
1176 Visited[Cond] = Result;
1182 assert(Cond &&
"precondition");
1197 return isa<CastInst>(Usr) || isa<BinaryOperator>(Usr);
1205 const APInt &OpConstVal,
1210 if (
auto *CI = dyn_cast<CastInst>(Usr)) {
1212 if (
auto *
C = dyn_cast_or_null<ConstantInt>(
1217 }
else if (
auto *BO = dyn_cast<BinaryOperator>(Usr)) {
1220 assert((Op0Match || Op1Match) &&
1221 "Operand 0 nor Operand 1 isn't a match");
1224 if (
auto *
C = dyn_cast_or_null<ConstantInt>(
1242 if (BI->isConditional() &&
1243 BI->getSuccessor(0) != BI->getSuccessor(1)) {
1244 bool isTrueDest = BI->getSuccessor(0) == BBTo;
1245 assert(BI->getSuccessor(!isTrueDest) == BBTo &&
1246 "BBTo isn't a successor of BBFrom");
1247 Value *Condition = BI->getCondition();
1251 if (Condition == Val) {
1263 if (
User *Usr = dyn_cast<User>(Val)) {
1278 APInt ConditionVal(1, isTrueDest ? 1 : 0);
1288 for (
unsigned i = 0; i < Usr->getNumOperands(); ++i) {
1289 Value *Op = Usr->getOperand(i);
1309 if (!isa<IntegerType>(Val->
getType()))
1311 bool ValUsesConditionAndMayBeFoldable =
false;
1312 if (Condition != Val) {
1314 if (
User *Usr = dyn_cast<User>(Val))
1317 if (!ValUsesConditionAndMayBeFoldable)
1320 assert((Condition == Val || ValUsesConditionAndMayBeFoldable) &&
1321 "Condition != Val nor Val doesn't use Condition");
1323 bool DefaultCase = SI->getDefaultDest() == BBTo;
1327 for (
auto Case : SI->cases()) {
1328 APInt CaseValue = Case.getCaseValue()->getValue();
1330 if (ValUsesConditionAndMayBeFoldable) {
1331 User *Usr = cast<User>(Val);
1346 if (Case.getCaseSuccessor() != BBTo && Condition == Val)
1348 }
else if (Case.getCaseSuccessor() == BBTo)
1349 EdgesVals = EdgesVals.
unionWith(EdgeVal);
1364 if (
Constant *
VC = dyn_cast<Constant>(Val)) {
1377 Result = LocalResult;
1381 if (!hasBlockValue(Val, BBFrom)) {
1382 if (pushBlockValue(std::make_pair(BBFrom, Val)))
1385 Result = LocalResult;
1391 intersectAssumeOrGuardBlockValueConstantRange(Val, InBlock,
1401 intersectAssumeOrGuardBlockValueConstantRange(Val, InBlock, CxtI);
1403 Result =
intersect(LocalResult, InBlock);
1409 LLVM_DEBUG(
dbgs() <<
"LVI Getting block end value " << *V <<
" at '" 1412 assert(BlockValueStack.empty() && BlockValueSet.empty());
1413 if (!hasBlockValue(V, BB)) {
1414 pushBlockValue(std::make_pair(BB, V));
1418 intersectAssumeOrGuardBlockValueConstantRange(V, Result, CxtI);
1428 if (
auto *
C = dyn_cast<Constant>(V))
1432 if (
auto *I = dyn_cast<Instruction>(V))
1434 intersectAssumeOrGuardBlockValueConstantRange(V, Result, CxtI);
1443 LLVM_DEBUG(
dbgs() <<
"LVI Getting edge value " << *V <<
" from '" 1448 if (!getEdgeValue(V, FromBB, ToBB, Result, CxtI)) {
1450 bool WasFastQuery = getEdgeValue(V, FromBB, ToBB, Result, CxtI);
1452 assert(WasFastQuery &&
"More work to do after problem solved?");
1461 TheCache.threadEdgeImpl(OldSucc, NewSucc);
1473 assert(DL &&
"getCache() called with a null DataLayout");
1474 PImpl =
new LazyValueInfoImpl(AC, *DL, DT);
1476 return *
static_cast<LazyValueInfoImpl*
>(PImpl);
1480 Info.AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
1484 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
1486 Info.TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
1508 delete &
getImpl(PImpl, AC,
nullptr);
1545 if (isa<AllocaInst>(V))
1558 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
1576 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
1584 "ConstantInt value must be represented as constantrange");
1595 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1614 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1623 "ConstantInt value must be represented as constantrange");
1634 if (
ConstantInt *ResCI = dyn_cast<ConstantInt>(Res))
1700 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1760 if (
auto *PHI = dyn_cast<PHINode>(V))
1761 if (PHI->getParent() == BB) {
1763 for (
unsigned i = 0, e = PHI->getNumIncomingValues(); i < e; i++) {
1764 Value *Incoming = PHI->getIncomingValue(i);
1765 BasicBlock *PredBB = PHI->getIncomingBlock(i);
1767 Tristate Result = getPredicateOnEdge(Pred, Incoming, C, PredBB, BB,
1772 Baseline = (i == 0) ? Result
1773 : (Baseline == Result ? Baseline : Unknown);
1774 if (Baseline == Unknown)
1777 if (Baseline != Unknown)
1784 if (!isa<Instruction>(V) ||
1785 cast<Instruction>(V)->
getParent() != BB) {
1789 Tristate Baseline = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI);
1790 if (Baseline != Unknown) {
1792 while (++PI != PE) {
1793 Tristate Ret = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI);
1794 if (Ret != Baseline)
break;
1810 getImpl(PImpl, AC, &DL, DT).threadEdge(PredBB, OldSucc, NewSucc);
1817 getImpl(PImpl, AC, &DL, DT).eraseBlock(BB);
1824 getImpl(PImpl, AC, DL, DT).printLVI(F, DTree, OS);
1830 getImpl(PImpl, AC, DL, DT).disableDT();
1835 getImpl(PImpl, AC, DL, DT).enableDT();
1839 void LazyValueInfoAnnotatedWriter::emitBasicBlockStartAnnot(
1843 for (
auto &
Arg :
F->args()) {
1845 const_cast<Argument *>(&
Arg), const_cast<BasicBlock *>(BB));
1848 OS <<
"; LatticeVal for: '" <<
Arg <<
"' is: " << Result <<
"\n";
1856 void LazyValueInfoAnnotatedWriter::emitInstructionAnnot(
1866 auto printResult = [&](
const BasicBlock *BB) {
1867 if (!BlocksContainingLVI.
insert(BB).second)
1870 const_cast<Instruction *>(I), const_cast<BasicBlock *>(BB));
1871 OS <<
"; LatticeVal for: '" << *I <<
"' in BB: '";
1873 OS <<
"' is: " << Result <<
"\n";
1876 printResult(ParentBB);
1880 if (DT.dominates(ParentBB, BBSucc))
1881 printResult(BBSucc);
1884 for (
auto *U : I->
users())
1885 if (
auto *UseI = dyn_cast<Instruction>(U))
1886 if (!isa<PHINode>(UseI) || DT.dominates(ParentBB, UseI->getParent()))
1887 printResult(UseI->getParent());
1909 dbgs() <<
"LVI for function '" << F.
getName() <<
"':\n";
1910 auto &LVI = getAnalysis<LazyValueInfoWrapperPass>().getLVI();
1911 auto &DTree = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1912 LVI.printLVI(F, DTree,
dbgs());
1920 "Lazy Value Info Printer Pass",
false,
false)
Pass interface - Implemented by all 'passes'.
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
Optional< APInt > asConstantInteger() const
A parsed version of the target data layout string in and methods for querying it. ...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
static bool InstructionDereferencesPointer(Instruction *I, Value *Ptr)
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
static IntegerType * getInt1Ty(LLVMContext &C)
INITIALIZE_PASS_BEGIN(LazyValueInfoWrapperPass, "lazy-value-info", "Lazy Value Information Analysis", false, true) INITIALIZE_PASS_END(LazyValueInfoWrapperPass
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
ConstantRange getConstantRange(Value *V, BasicBlock *BB, Instruction *CxtI=nullptr)
Return the ConstantRange constraint that is known to hold for the specified value at the end of the s...
ConstantRange unionWith(const ConstantRange &CR) const
Return the range that results from the union of this range with another range.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
BinaryOps getOpcode() const
Wrapper around LazyValueInfo.
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
Implements a dense probed hash-table based set.
void push_back(const T &Elt)
static ValueLatticeElement get(Constant *C)
An immutable pass that tracks lazily created AssumptionCache objects.
const Value * getTrueValue() const
A cache of @llvm.assume calls within a function.
LLVMContext & getContext() const
All values hold a context through their type.
bool erase(const ValueT &V)
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
bool isValidAssumeForContext(const Instruction *I, const Instruction *CxtI, const DominatorTree *DT=nullptr)
Return true if it is valid to use the assumptions provided by an assume intrinsic, I, at the point in the control-flow identified by the context instruction, CxtI.
Analysis pass which computes a DominatorTree.
block Block Frequency true
An instruction for reading from memory.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static bool hasSingleValue(const ValueLatticeElement &Val)
Returns true if this lattice value represents at most one possible value.
static ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)
Produce the smallest range such that all values that may satisfy the given predicate with any value c...
print alias Alias Set Printer
static const unsigned MaxProcessedPerValue
ConstantRange umax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned maximum of a value in ...
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
static ValueLatticeElement getFromRangeMetadata(Instruction *BBI)
bool match(Val *V, const Pattern &P)
AnalysisUsage & addRequired()
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
#define INITIALIZE_PASS_DEPENDENCY(depName)
Constant * getConstant(Value *V, BasicBlock *BB, Instruction *CxtI=nullptr)
Determine whether the specified value is known to be a constant at the end of the specified block...
StringRef getName(ID id)
Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
This class represents the LLVM 'select' instruction.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This is the base class for all instructions that perform data casts.
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
lazy value Lazy Value Information Analysis
bool isIntegerTy() const
True if this is an instance of IntegerType.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Result run(Function &F, FunctionAnalysisManager &FAM)
DominatorTree & getDomTree()
static ValueLatticeElement getNot(Constant *C)
static bool isKnownNonConstant(Value *V)
Returns true if we can statically tell that this value will never be a "useful" constant.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
const ConstantRange & getConstantRange() const
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Type * getType() const
All values are typed, get the type of this value.
const T & getValue() const LLVM_LVALUE_FUNCTION
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW=nullptr, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the function to an output stream with an optional AssemblyAnnotationWriter. ...
ConstantRange intersectWith(const ConstantRange &CR) const
Return the range that results from the intersection of this range with another range.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
const APInt & getValue() const
Return the constant as an APInt value reference.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static LazyValueInfo::Tristate getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val, const DataLayout &DL, TargetLibraryInfo *TLI)
An instruction for storing to memory.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
FunctionPass * createLazyValueInfoPass()
createLazyValueInfoPass - This creates an instance of the LazyValueInfo pass.
bool isOverdefined() const
ConstantRange castOp(Instruction::CastOps CastOp, uint32_t BitWidth) const
Return a new range representing the possible values resulting from an application of the specified ca...
Value * getOperand(unsigned i) const
Analysis containing CSE Info
Class to represent pointers.
Interval::succ_iterator succ_end(Interval *I)
iterator find(const_arg_type_t< KeyT > Val)
const BasicBlock & getEntryBlock() const
static bool runOnFunction(Function &F, bool PostInlining)
Control flow instructions. These all have token chains.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A set of analyses that are preserved following a run of a transformation pass.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static bool getEdgeValueLocal(Value *Val, BasicBlock *BBFrom, BasicBlock *BBTo, ValueLatticeElement &Result)
Compute the value of Val on the edge BBFrom -> BBTo.
Constant * getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Determine whether the specified value is known to be a constant on the specified edge.
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
LLVM Basic Block Representation.
Conditional or Unconditional Branch instruction.
ConstantRange umin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned minimum of a value in ...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
LLVM_NODISCARD bool empty() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
bool isPointerTy() const
True if this is an instance of PointerType.
std::pair< iterator, bool > insert(const ValueT &V)
bool isNotConstant() const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
static bool isOperationFoldable(User *Usr)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Value * SimplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
Represent the analysis usage information of a pass.
const Instruction & back() const
static ValueLatticeElement constantFoldUser(User *Usr, Value *Op, const APInt &OpConstVal, const DataLayout &DL)
This instruction compares its operands according to the predicate given to the constructor.
unsigned getAddressSpace() const
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
bool isConstantRange() const
FunctionPass class - This class is used to implement most global optimizations.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
Interval::pred_iterator pred_end(Interval *I)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
self_iterator getIterator()
const Value * getCondition() const
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
static ValueLatticeElement getRange(ConstantRange CR)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCompareInstOperands - Attempt to constant fold a compare instruction (icmp/fcmp) with the...
Constant * getConstant() const
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
Tristate
This is used to return true/false/dunno results.
static Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Determine whether the specified value comparison with a constant is known to be true or false on the ...
Constant * getNotConstant() const
Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C, Instruction *CxtI)
Determine whether the specified value comparison with a constant is known to be true or false at the ...
A function analysis which provides an AssumptionCache.
void enableDT()
Enables use of the DominatorTree within LVI.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
This is the common base class for memset/memcpy/memmove.
static ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, const APInt &Other)
Produce the exact range such that all values in the returned range satisfy the given predicate with a...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
SelectPatternFlavor Flavor
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Provides information about what library functions are available for the current target.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
This class represents a range of values.
ConstantRange smin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed minimum of a value in thi...
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Type * getDestTy() const
Return the destination type, as a convenience.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Class for arbitrary precision integers.
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to be non-zero when defined.
void setPreservesAll()
Set by analyses that do not transform their input at all.
iterator_range< user_iterator > users()
static void clear(coro::Shape &Shape)
const Value * getFalseValue() const
amdgpu Simplify well known AMD library false Value Value * Arg
ConstantRange smax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed maximum of a value in thi...
Predicate getPredicate() const
Return the predicate for this instruction.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This class wraps the llvm.memcpy/memmove intrinsics.
static ValueLatticeElement intersect(const ValueLatticeElement &A, const ValueLatticeElement &B)
Combine two sets of facts about the same value into a single set of facts.
void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc)
Inform the analysis cache that we have threaded an edge from PredBB to OldSucc to be from PredBB to N...
static ValueLatticeElement getValueFromConditionImpl(Value *Val, Value *Cond, bool isTrueDest, DenseMap< Value *, ValueLatticeElement > &Visited)
unsigned getIntegerBitWidth() const
static bool usesOperand(User *Usr, Value *Op)
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?
StringRef getName() const
Return a constant reference to the value's name.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
const Function * getParent() const
Return the enclosing method, or null if none.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Solution solve(PBQPRAGraph &G)
ilist_iterator< OptionsT, !IsReverse, IsConst > getReverse() const
Get a reverse iterator to the same node.
bool mergeIn(const ValueLatticeElement &RHS, const DataLayout &DL)
Updates this object to approximate both this object and RHS.
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
API to communicate dependencies between analyses during invalidation.
iterator find_as(const LookupKeyT &Val)
Alternate version of find() which allows a different, and possibly less expensive, key type.
bool isSingleElement() const
Return true if this set contains exactly one member.
Analysis pass providing the TargetLibraryInfo.
This pass computes, caches, and vends lazy value constraint information.
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
static ValueLatticeElement getValueFromCondition(Value *Val, Value *Cond, bool isTrueDest=true)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This templated class represents "all analyses that operate over <a particular IR unit>" (e...
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr, unsigned Depth=0)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
succ_range successors(Instruction *I)
static const Function * getParent(const Value *V)
This class implements an extremely fast bulk output stream that can only output to a stream...
static bool isObjectDereferencedInBlock(Value *Val, BasicBlock *BB)
Return true if the allocation associated with Val is ever dereferenced within the given basic block...
Value handle with callbacks on RAUW and destruction.
static ValueLatticeElement getOverdefined()
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS)
Print the Analysis.
ConstantRange getConstantRangeOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CxtI=nullptr)
Return the ConstantRage constraint that is known to hold for the specified value on the specified edg...
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
ConstantRange binaryOp(Instruction::BinaryOps BinOp, const ConstantRange &Other) const
Return a new range representing the possible values resulting from an application of the specified bi...
A special type used by analysis passes to provide an address that identifies that particular analysis...
void initializeLazyValueInfoPrinterPass(PassRegistry &)
static ValueLatticeElement getValueFromICmpCondition(Value *Val, ICmpInst *ICI, bool isTrueDest)
void disableDT()
Disables use of the DominatorTree within LVI.
Analysis to compute lazy value information.
const BasicBlock * getParent() const
static bool InBlock(const Value *V, const BasicBlock *BB)