43 #define DEBUG_TYPE "lazy-value-info" 51 "Lazy Value Information Analysis",
false,
true)
133 class LazyValueInfoCache;
134 struct LVIValueHandle final :
public CallbackVH {
138 LazyValueInfoCache *Parent;
140 LVIValueHandle(
Value *V, LazyValueInfoCache *
P)
143 void deleted()
override;
144 void allUsesReplacedWith(
Value *V)
override {
153 class LazyValueInfoCache {
159 struct ValueCacheEntryTy {
160 ValueCacheEntryTy(
Value *V, LazyValueInfoCache *
P) : Handle(V, P) {}
161 LVIValueHandle Handle;
176 OverDefinedCacheTy OverDefinedCache;
187 OverDefinedCache[BB].insert(Val);
189 auto It = ValueCache.
find_as(Val);
190 if (It == ValueCache.
end()) {
191 ValueCache[Val] = make_unique<ValueCacheEntryTy>(Val,
this);
193 assert(It != ValueCache.
end() &&
"Val was just added to the map!");
195 It->second->BlockVals[BB] = Result;
200 auto ODI = OverDefinedCache.find(BB);
202 if (ODI == OverDefinedCache.end())
205 return ODI->second.count(V);
209 if (isOverdefined(V, BB))
213 if (
I == ValueCache.
end())
216 return I->second->BlockVals.count(BB);
220 if (isOverdefined(V, BB))
224 if (
I == ValueCache.
end())
226 auto BBI =
I->second->BlockVals.find(BB);
227 if (BBI ==
I->second->BlockVals.end())
236 OverDefinedCache.clear();
240 void eraseValue(
Value *V);
251 friend struct LVIValueHandle;
255 void LazyValueInfoCache::eraseValue(
Value *V) {
256 for (
auto I = OverDefinedCache.begin(),
E = OverDefinedCache.end();
I !=
E;) {
262 if (ValueSet.
empty())
263 OverDefinedCache.erase(Iter);
269 void LVIValueHandle::deleted() {
272 Parent->eraseValue(*
this);
275 void LazyValueInfoCache::eraseBlock(
BasicBlock *BB) {
278 if (I == SeenBlocks.
end())
282 auto ODI = OverDefinedCache.find(BB);
283 if (ODI != OverDefinedCache.end())
284 OverDefinedCache.erase(ODI);
286 for (
auto &I : ValueCache)
287 I.second->BlockVals.
erase(BB);
290 void LazyValueInfoCache::threadEdgeImpl(
BasicBlock *OldSucc,
302 std::vector<BasicBlock*> worklist;
303 worklist.push_back(OldSucc);
305 auto I = OverDefinedCache.find(OldSucc);
306 if (
I == OverDefinedCache.end())
314 while (!worklist.empty()) {
319 if (ToUpdate == NewSucc)
continue;
322 auto OI = OverDefinedCache.find(ToUpdate);
323 if (OI == OverDefinedCache.end())
327 bool changed =
false;
328 for (
Value *V : ValsToClear) {
329 if (!ValueSet.
erase(V))
336 if (ValueSet.
empty()) {
337 OverDefinedCache.erase(OI);
342 if (!changed)
continue;
352 class LazyValueInfoImpl;
354 LazyValueInfoImpl *LVIImpl;
362 LazyValueInfoAnnotatedWriter(LazyValueInfoImpl *L,
DominatorTree &DTree)
363 : LVIImpl(L), DT(DTree) {}
365 virtual void emitBasicBlockStartAnnot(
const BasicBlock *BB,
376 class LazyValueInfoImpl {
379 LazyValueInfoCache TheCache;
391 bool pushBlockValue(
const std::pair<BasicBlock *, Value *> &BV) {
392 if (!BlockValueSet.
insert(BV).second)
396 << BV.first->getName() <<
"\n");
427 void intersectAssumeOrGuardBlockValueConstantRange(
Value *Val,
457 LazyValueInfoAnnotatedWriter Writer(
this, DTree);
458 F.
print(OS, &Writer);
464 TheCache.eraseBlock(BB);
470 assert(!DisabledDT &&
"Both DT and DisabledDT are not nullptr!");
479 assert(!DT &&
"Both DT and DisabledDT are not nullptr!");
490 : AC(AC), DL(DL), DT(DT), DisabledDT(
nullptr) {}
497 BlockValueStack.begin(), BlockValueStack.end());
499 unsigned processedCount = 0;
500 while (!BlockValueStack.empty()) {
510 if (processedCount > MaxProcessedPerValue) {
512 dbgs() <<
"Giving up on stack because we are getting too deep\n");
514 while (!StartingStack.empty()) {
515 std::pair<BasicBlock *, Value *> &e = StartingStack.back();
516 TheCache.insertResult(e.second, e.first,
518 StartingStack.pop_back();
520 BlockValueSet.clear();
521 BlockValueStack.clear();
524 std::pair<BasicBlock *, Value *> e = BlockValueStack.back();
525 assert(BlockValueSet.count(e) &&
"Stack value should be in BlockValueSet!");
527 if (solveBlockValue(e.second, e.first)) {
529 assert(BlockValueStack.back() == e &&
"Nothing should have been pushed!");
530 assert(TheCache.hasCachedValueInfo(e.second, e.first) &&
531 "Result should be in cache!");
534 dbgs() <<
"POP " << *e.second <<
" in " << e.first->getName() <<
" = " 535 << TheCache.getCachedValueInfo(e.second, e.first) <<
"\n");
537 BlockValueStack.pop_back();
538 BlockValueSet.erase(e);
541 assert(BlockValueStack.back() != e &&
"Stack should have been pushed!");
548 if (isa<Constant>(Val))
551 return TheCache.hasCachedValueInfo(Val, BB);
560 return TheCache.getCachedValueInfo(Val, BB);
568 case Instruction::Invoke:
570 if (isa<IntegerType>(BBI->
getType())) {
581 if (isa<Constant>(Val))
584 if (TheCache.hasCachedValueInfo(Val, BB)) {
587 << TheCache.getCachedValueInfo(Val, BB) <<
'\n');
598 if (!solveBlockValueImpl(Res, Val, BB))
602 TheCache.insertResult(Val, BB, Res);
611 return solveBlockValueNonLocal(Res, Val, BB);
613 if (
PHINode *PN = dyn_cast<PHINode>(BBI))
614 return solveBlockValuePHINode(Res, PN, BB);
616 if (
auto *
SI = dyn_cast<SelectInst>(BBI))
617 return solveBlockValueSelect(Res,
SI, BB);
634 if (
auto *CI = dyn_cast<CastInst>(BBI))
635 return solveBlockValueCast(Res, CI, BB);
638 if (BO && isa<ConstantInt>(BO->
getOperand(1)))
639 return solveBlockValueBinaryOp(Res, BO, BB);
643 <<
"' - unknown inst def found.\n");
649 if (
LoadInst *L = dyn_cast<LoadInst>(I)) {
650 return L->getPointerAddressSpace() == 0 &&
652 L->getModule()->getDataLayout()) == Ptr;
654 if (
StoreInst *S = dyn_cast<StoreInst>(I)) {
655 return S->getPointerAddressSpace() == 0 &&
657 S->getModule()->getDataLayout()) == Ptr;
660 if (
MI->isVolatile())
return false;
664 if (!Len || Len->
isZero())
return false;
666 if (
MI->getDestAddressSpace() == 0)
668 MI->getModule()->getDataLayout()) == Ptr)
671 if (MTI->getSourceAddressSpace() == 0)
673 MTI->getModule()->getDataLayout()) == Ptr)
704 assert(isa<Argument>(Val) &&
"Unknown live-in to the entry block");
731 if (!getEdgeValue(Val, *PI, BB, EdgeResult))
735 Result.
mergeIn(EdgeResult, DL);
741 <<
"' - overdefined because of pred (non local).\n");
775 if (!getEdgeValue(PhiVal, PhiBB, BB, EdgeResult, PN))
779 Result.
mergeIn(EdgeResult, DL);
785 <<
"' - overdefined because of pred (local).\n");
799 bool isTrueDest =
true);
803 void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
809 for (
auto &AssumeVH : AC->assumptionsFor(Val)) {
812 auto *
I = cast<CallInst>(AssumeVH);
822 if (!GuardDecl || GuardDecl->use_empty())
827 Value *Cond =
nullptr;
828 if (
match(&
I, m_Intrinsic<Intrinsic::experimental_guard>(
m_Value(Cond))))
838 if (pushBlockValue(std::make_pair(BB, SI->
getTrueValue())))
868 Value *LHS =
nullptr;
869 Value *RHS =
nullptr;
880 return TrueCR.
smin(FalseCR);
882 return TrueCR.
umin(FalseCR);
884 return TrueCR.
smax(FalseCR);
886 return TrueCR.
umax(FalseCR);
913 if (
auto *ICI = dyn_cast<ICmpInst>(Cond)) {
915 Value *A = ICI->getOperand(0);
916 if (
ConstantInt *CIBase = dyn_cast<ConstantInt>(ICI->getOperand(1))) {
930 auto ResNot = addConstants(CIBase, CIAdded);
938 auto ResNot = addConstants(CIBase, CIAdded);
968 case Instruction::Trunc:
969 case Instruction::SExt:
970 case Instruction::ZExt:
971 case Instruction::BitCast:
976 <<
"' - overdefined (unknown cast).\n");
985 if (pushBlockValue(std::make_pair(BB, CI->
getOperand(0))))
989 const unsigned OperandBitWidth =
994 intersectAssumeOrGuardBlockValueConstantRange(CI->
getOperand(0), LHSVal,
1015 "all operands to binary operators are sized");
1022 case Instruction::Sub:
1023 case Instruction::Mul:
1024 case Instruction::UDiv:
1025 case Instruction::Shl:
1026 case Instruction::LShr:
1027 case Instruction::AShr:
1028 case Instruction::And:
1029 case Instruction::Or:
1035 <<
"' - overdefined (unknown binary operator).\n");
1044 if (pushBlockValue(std::make_pair(BB, BO->
getOperand(0))))
1048 const unsigned OperandBitWidth =
1053 intersectAssumeOrGuardBlockValueConstantRange(BO->
getOperand(0), LHSVal,
1076 if (isa<Constant>(RHS)) {
1108 if (LHS == Val || Offset) {
1140 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Cond))
1148 if (!BO || (isTrueDest && BO->
getOpcode() != BinaryOperator::And) ||
1149 (!isTrueDest && BO->
getOpcode() != BinaryOperator::Or))
1158 if (BL == Cond || BR == Cond)
1168 auto I = Visited.
find(Cond);
1169 if (
I != Visited.
end())
1179 assert(Cond &&
"precondition");
1194 return isa<CastInst>(Usr) || isa<BinaryOperator>(Usr);
1202 const APInt &OpConstVal,
1207 if (
auto *CI = dyn_cast<CastInst>(Usr)) {
1209 if (
auto *
C = dyn_cast_or_null<ConstantInt>(
1214 }
else if (
auto *BO = dyn_cast<BinaryOperator>(Usr)) {
1217 assert((Op0Match || Op1Match) &&
1218 "Operand 0 nor Operand 1 isn't a match");
1221 if (
auto *
C = dyn_cast_or_null<ConstantInt>(
1239 if (BI->isConditional() &&
1240 BI->getSuccessor(0) != BI->getSuccessor(1)) {
1241 bool isTrueDest = BI->getSuccessor(0) == BBTo;
1242 assert(BI->getSuccessor(!isTrueDest) == BBTo &&
1243 "BBTo isn't a successor of BBFrom");
1244 Value *Condition = BI->getCondition();
1248 if (Condition == Val) {
1260 if (
User *Usr = dyn_cast<User>(Val)) {
1275 APInt ConditionVal(1, isTrueDest ? 1 : 0);
1285 for (
unsigned i = 0; i < Usr->getNumOperands(); ++i) {
1286 Value *
Op = Usr->getOperand(i);
1306 if (!isa<IntegerType>(Val->
getType()))
1308 bool ValUsesConditionAndMayBeFoldable =
false;
1309 if (Condition != Val) {
1311 if (
User *Usr = dyn_cast<User>(Val))
1314 if (!ValUsesConditionAndMayBeFoldable)
1317 assert((Condition == Val || ValUsesConditionAndMayBeFoldable) &&
1318 "Condition != Val nor Val doesn't use Condition");
1320 bool DefaultCase = SI->getDefaultDest() == BBTo;
1324 for (
auto Case : SI->cases()) {
1325 APInt CaseValue = Case.getCaseValue()->getValue();
1327 if (ValUsesConditionAndMayBeFoldable) {
1328 User *Usr = cast<User>(Val);
1343 if (Case.getCaseSuccessor() != BBTo && Condition == Val)
1345 }
else if (Case.getCaseSuccessor() == BBTo)
1346 EdgesVals = EdgesVals.
unionWith(EdgeVal);
1361 if (
Constant *
VC = dyn_cast<Constant>(Val)) {
1374 Result = LocalResult;
1378 if (!hasBlockValue(Val, BBFrom)) {
1379 if (pushBlockValue(std::make_pair(BBFrom, Val)))
1382 Result = LocalResult;
1388 intersectAssumeOrGuardBlockValueConstantRange(Val, InBlock,
1398 intersectAssumeOrGuardBlockValueConstantRange(Val, InBlock, CxtI);
1400 Result =
intersect(LocalResult, InBlock);
1406 LLVM_DEBUG(
dbgs() <<
"LVI Getting block end value " << *V <<
" at '" 1409 assert(BlockValueStack.empty() && BlockValueSet.empty());
1410 if (!hasBlockValue(V, BB)) {
1411 pushBlockValue(std::make_pair(BB, V));
1415 intersectAssumeOrGuardBlockValueConstantRange(V, Result, CxtI);
1425 if (
auto *
C = dyn_cast<Constant>(V))
1429 if (
auto *
I = dyn_cast<Instruction>(V))
1431 intersectAssumeOrGuardBlockValueConstantRange(V, Result, CxtI);
1440 LLVM_DEBUG(
dbgs() <<
"LVI Getting edge value " << *V <<
" from '" 1445 if (!getEdgeValue(V, FromBB, ToBB, Result, CxtI)) {
1447 bool WasFastQuery = getEdgeValue(V, FromBB, ToBB, Result, CxtI);
1449 assert(WasFastQuery &&
"More work to do after problem solved?");
1458 TheCache.threadEdgeImpl(OldSucc, NewSucc);
1470 assert(DL &&
"getCache() called with a null DataLayout");
1471 PImpl =
new LazyValueInfoImpl(AC, *DL, DT);
1473 return *
static_cast<LazyValueInfoImpl*
>(PImpl);
1477 Info.AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
1481 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
1482 Info.DT = DTWP ? &DTWP->
getDomTree() :
nullptr;
1483 Info.TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
1486 getImpl(Info.PImpl, Info.AC, &DL, Info.DT).clear();
1505 delete &
getImpl(PImpl, AC,
nullptr);
1542 if (isa<AllocaInst>(V))
1555 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
1573 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
1581 "ConstantInt value must be represented as constantrange");
1592 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1611 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1620 "ConstantInt value must be represented as constantrange");
1631 if (
ConstantInt *ResCI = dyn_cast<ConstantInt>(Res))
1697 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1757 if (
auto *PHI = dyn_cast<PHINode>(V))
1758 if (PHI->getParent() == BB) {
1760 for (
unsigned i = 0, e = PHI->getNumIncomingValues(); i < e; i++) {
1761 Value *Incoming = PHI->getIncomingValue(i);
1762 BasicBlock *PredBB = PHI->getIncomingBlock(i);
1764 Tristate Result = getPredicateOnEdge(Pred, Incoming, C, PredBB, BB,
1769 Baseline = (i == 0) ? Result
1770 : (Baseline == Result ? Baseline : Unknown);
1771 if (Baseline == Unknown)
1774 if (Baseline != Unknown)
1781 if (!isa<Instruction>(V) ||
1782 cast<Instruction>(V)->
getParent() != BB) {
1786 Tristate Baseline = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI);
1787 if (Baseline != Unknown) {
1789 while (++PI != PE) {
1790 Tristate Ret = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI);
1791 if (Ret != Baseline)
break;
1807 getImpl(PImpl, AC, &DL, DT).threadEdge(PredBB, OldSucc, NewSucc);
1814 getImpl(PImpl, AC, &DL, DT).eraseBlock(BB);
1821 getImpl(PImpl, AC, DL, DT).printLVI(F, DTree, OS);
1827 getImpl(PImpl, AC, DL, DT).disableDT();
1832 getImpl(PImpl, AC, DL, DT).enableDT();
1836 void LazyValueInfoAnnotatedWriter::emitBasicBlockStartAnnot(
1840 for (
auto &
Arg :
F->args()) {
1842 const_cast<Argument *>(&
Arg), const_cast<BasicBlock *>(BB));
1845 OS <<
"; LatticeVal for: '" <<
Arg <<
"' is: " << Result <<
"\n";
1853 void LazyValueInfoAnnotatedWriter::emitInstructionAnnot(
1863 auto printResult = [&](
const BasicBlock *BB) {
1864 if (!BlocksContainingLVI.
insert(BB).second)
1867 const_cast<Instruction *>(I), const_cast<BasicBlock *>(BB));
1868 OS <<
"; LatticeVal for: '" << *I <<
"' in BB: '";
1870 OS <<
"' is: " << Result <<
"\n";
1873 printResult(ParentBB);
1877 if (DT.dominates(ParentBB, BBSucc))
1878 printResult(BBSucc);
1881 for (
auto *U : I->
users())
1882 if (
auto *UseI = dyn_cast<Instruction>(U))
1883 if (!isa<PHINode>(UseI) || DT.dominates(ParentBB, UseI->getParent()))
1884 printResult(UseI->getParent());
1906 dbgs() <<
"LVI for function '" << F.
getName() <<
"':\n";
1907 auto &LVI = getAnalysis<LazyValueInfoWrapperPass>().getLVI();
1908 auto &DTree = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
1909 LVI.printLVI(F, DTree,
dbgs());
1917 "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...
void push_back(const T &Elt)
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.
Compute iterated dominance frontiers using a linear time algorithm.
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.
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.
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.
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
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.
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.
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 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.
succ_range successors(BasicBlock *BB)
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...
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...
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given value is known to be non-zero when defined.
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...
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
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)