38 using namespace PatternMatch;
40 #define DEBUG_TYPE "lazy-value-info"
44 "Lazy Value Information Analysis",
false,
true)
98 LVILatticeVal() :
Tag(undefined), Val(nullptr), Range(1,
true) {}
102 if (!isa<UndefValue>(
C))
106 static LVILatticeVal getNot(
Constant *
C) {
108 if (!isa<UndefValue>(C))
109 Res.markNotConstant(C);
114 Res.markConstantRange(std::move(CR));
117 static LVILatticeVal getOverdefined() {
119 Res.markOverdefined();
123 bool isUndefined()
const {
return Tag == undefined; }
124 bool isConstant()
const {
return Tag == constant; }
125 bool isNotConstant()
const {
return Tag == notconstant; }
126 bool isConstantRange()
const {
return Tag == constantrange; }
127 bool isOverdefined()
const {
return Tag == overdefined; }
130 assert(isConstant() &&
"Cannot get the constant of a non-constant!");
135 assert(isNotConstant() &&
"Cannot get the constant of a non-notconstant!");
140 assert(isConstantRange() &&
141 "Cannot get the constant-range of a non-constant-range!");
146 void markOverdefined() {
153 assert(V &&
"Marking constant with NULL");
158 if (isa<UndefValue>(V))
161 assert((!isConstant() || getConstant() == V) &&
162 "Marking constant with different value");
169 assert(V &&
"Marking constant with NULL");
171 markConstantRange(
ConstantRange(CI->getValue()+1, CI->getValue()));
174 if (isa<UndefValue>(V))
177 assert((!isConstant() || getConstant() != V) &&
178 "Marking constant !constant with same value");
179 assert((!isNotConstant() || getNotConstant() == V) &&
180 "Marking !constant with different value");
181 assert(isUndefined() || isConstant());
187 if (isConstantRange()) {
191 Range = std::move(NewR);
201 Range = std::move(NewR);
209 void mergeIn(
const LVILatticeVal &RHS,
const DataLayout &DL) {
210 if (RHS.isUndefined() || isOverdefined())
212 if (RHS.isOverdefined()) {
223 if (RHS.isConstant() && Val == RHS.Val)
229 if (isNotConstant()) {
230 if (RHS.isNotConstant() && Val == RHS.Val)
236 assert(isConstantRange() &&
"New LVILattice type?");
237 if (!RHS.isConstantRange()) {
247 markConstantRange(NewR);
257 if (Val.isUndefined())
258 return OS <<
"undefined";
259 if (Val.isOverdefined())
260 return OS <<
"overdefined";
262 if (Val.isNotConstant())
263 return OS <<
"notconstant<" << *Val.getNotConstant() <<
'>';
264 if (Val.isConstantRange())
265 return OS <<
"constantrange<" << Val.getConstantRange().getLower() <<
", "
266 << Val.getConstantRange().getUpper() <<
'>';
267 return OS <<
"constant<" << *Val.getConstant() <<
'>';
275 if (Val.isConstantRange() &&
276 Val.getConstantRange().isSingleElement())
279 if (Val.isConstant())
299 static LVILatticeVal
intersect(LVILatticeVal
A, LVILatticeVal
B) {
308 if (A.isOverdefined())
310 if (B.isOverdefined())
320 if (!A.isConstantRange() || !B.isConstantRange()) {
327 A.getConstantRange().intersectWith(B.getConstantRange());
331 return LVILatticeVal::getRange(std::move(Range));
340 class LazyValueInfoCache;
341 struct LVIValueHandle final :
public CallbackVH {
345 LazyValueInfoCache *Parent;
347 LVIValueHandle(
Value *V, LazyValueInfoCache *
P)
350 void deleted()
override;
351 void allUsesReplacedWith(
Value *V)
override {
360 class LazyValueInfoCache {
366 struct ValueCacheEntryTy {
367 ValueCacheEntryTy(
Value *V, LazyValueInfoCache *
P) : Handle(V, P) {}
368 LVIValueHandle Handle;
380 OverDefinedCacheTy OverDefinedCache;
387 void insertResult(
Value *Val,
BasicBlock *BB,
const LVILatticeVal &Result) {
392 if (Result.isOverdefined())
393 OverDefinedCache[BB].insert(Val);
395 auto It = ValueCache.find_as(Val);
396 if (It == ValueCache.end()) {
397 ValueCache[Val] = make_unique<ValueCacheEntryTy>(Val,
this);
398 It = ValueCache.find_as(Val);
399 assert(It != ValueCache.end() &&
"Val was just added to the map!");
401 It->second->BlockVals[BB] = Result;
406 auto ODI = OverDefinedCache.find(BB);
408 if (ODI == OverDefinedCache.end())
411 return ODI->second.count(V);
415 if (isOverdefined(V, BB))
418 auto I = ValueCache.find_as(V);
419 if (
I == ValueCache.end())
422 return I->second->BlockVals.count(BB);
426 if (isOverdefined(V, BB))
427 return LVILatticeVal::getOverdefined();
429 auto I = ValueCache.find_as(V);
430 if (
I == ValueCache.end())
431 return LVILatticeVal();
432 auto BBI =
I->second->BlockVals.find(BB);
433 if (BBI ==
I->second->BlockVals.end())
434 return LVILatticeVal();
442 OverDefinedCache.clear();
446 void eraseValue(
Value *V);
457 friend struct LVIValueHandle;
461 void LazyValueInfoCache::eraseValue(
Value *V) {
463 for (
auto &
I : OverDefinedCache) {
466 if (ValueSet.
empty())
469 for (
auto &BB : ToErase)
470 OverDefinedCache.erase(BB);
475 void LVIValueHandle::deleted() {
478 Parent->eraseValue(*
this);
481 void LazyValueInfoCache::eraseBlock(
BasicBlock *BB) {
484 if (I == SeenBlocks.
end())
488 auto ODI = OverDefinedCache.find(BB);
489 if (ODI != OverDefinedCache.end())
490 OverDefinedCache.erase(ODI);
492 for (
auto &I : ValueCache)
493 I.second->BlockVals.
erase(BB);
496 void LazyValueInfoCache::threadEdgeImpl(
BasicBlock *OldSucc,
508 std::vector<BasicBlock*> worklist;
509 worklist.push_back(OldSucc);
511 auto I = OverDefinedCache.
find(OldSucc);
512 if (I == OverDefinedCache.
end())
520 while (!worklist.empty()) {
525 if (ToUpdate == NewSucc)
continue;
528 auto OI = OverDefinedCache.find(ToUpdate);
529 if (OI == OverDefinedCache.end())
533 bool changed =
false;
534 for (
Value *V : ValsToClear) {
535 if (!ValueSet.
erase(V))
542 if (ValueSet.
empty()) {
543 OverDefinedCache.erase(OI);
548 if (!changed)
continue;
558 class LazyValueInfoImpl {
561 LazyValueInfoCache TheCache;
566 std::stack<std::pair<BasicBlock*, Value*> > BlockValueStack;
573 bool pushBlockValue(
const std::pair<BasicBlock *, Value *> &BV) {
574 if (!BlockValueSet.insert(BV).second)
577 DEBUG(
dbgs() <<
"PUSH: " << *BV.second <<
" in " << BV.first->getName()
579 BlockValueStack.push(BV);
589 LVILatticeVal &Result,
Instruction *CxtI =
nullptr);
596 bool solveBlockValueImpl(LVILatticeVal &Res,
Value *Val,
BasicBlock *BB);
597 bool solveBlockValueNonLocal(LVILatticeVal &BBLV,
Value *Val,
BasicBlock *BB);
599 bool solveBlockValueSelect(LVILatticeVal &BBLV,
SelectInst *S,
601 bool solveBlockValueBinaryOp(LVILatticeVal &BBLV,
Instruction *BBI,
603 bool solveBlockValueCast(LVILatticeVal &BBLV,
Instruction *BBI,
605 void intersectAssumeOrGuardBlockValueConstantRange(
Value *Val,
635 TheCache.eraseBlock(BB);
644 : AC(AC), DL(DL), DT(DT) {}
649 while (!BlockValueStack.empty()) {
650 std::pair<BasicBlock*, Value*> &e = BlockValueStack.top();
651 assert(BlockValueSet.count(e) &&
"Stack value should be in BlockValueSet!");
653 if (solveBlockValue(e.second, e.first)) {
655 assert(BlockValueStack.top() == e &&
"Nothing should have been pushed!");
656 assert(TheCache.hasCachedValueInfo(e.second, e.first) &&
657 "Result should be in cache!");
659 DEBUG(
dbgs() <<
"POP " << *e.second <<
" in " << e.first->getName()
660 <<
" = " << TheCache.getCachedValueInfo(e.second, e.first) <<
"\n");
662 BlockValueStack.pop();
663 BlockValueSet.erase(e);
666 assert(BlockValueStack.top() != e &&
"Stack should have been pushed!");
673 if (isa<Constant>(Val))
676 return TheCache.hasCachedValueInfo(Val, BB);
679 LVILatticeVal LazyValueInfoImpl::getBlockValue(
Value *Val,
BasicBlock *BB) {
682 return LVILatticeVal::get(
VC);
684 return TheCache.getCachedValueInfo(Val, BB);
692 case Instruction::Invoke:
694 if (isa<IntegerType>(BBI->
getType())) {
700 return LVILatticeVal::getOverdefined();
704 if (isa<Constant>(Val))
707 if (TheCache.hasCachedValueInfo(Val, BB)) {
710 <<
"' val=" << TheCache.getCachedValueInfo(Val, BB) <<
'\n');
721 if (!solveBlockValueImpl(Res, Val, BB))
725 TheCache.insertResult(Val, BB, Res);
729 bool LazyValueInfoImpl::solveBlockValueImpl(LVILatticeVal &Res,
734 return solveBlockValueNonLocal(Res, Val, BB);
736 if (
PHINode *PN = dyn_cast<PHINode>(BBI))
737 return solveBlockValuePHINode(Res, PN, BB);
739 if (
auto *SI = dyn_cast<SelectInst>(BBI))
740 return solveBlockValueSelect(Res, SI, BB);
757 if (isa<CastInst>(BBI))
758 return solveBlockValueCast(Res, BBI, BB);
761 if (BO && isa<ConstantInt>(BO->
getOperand(1)))
762 return solveBlockValueBinaryOp(Res, BBI, BB);
766 <<
"' - unknown inst def found.\n");
772 if (
LoadInst *
L = dyn_cast<LoadInst>(I)) {
773 return L->getPointerAddressSpace() == 0 &&
775 L->getModule()->getDataLayout()) == Ptr;
777 if (
StoreInst *S = dyn_cast<StoreInst>(I)) {
778 return S->getPointerAddressSpace() == 0 &&
780 S->getModule()->getDataLayout()) == Ptr;
783 if (
MI->isVolatile())
return false;
787 if (!Len || Len->
isZero())
return false;
789 if (
MI->getDestAddressSpace() == 0)
791 MI->getModule()->getDataLayout()) == Ptr)
794 if (MTI->getSourceAddressSpace() == 0)
796 MTI->getModule()->getDataLayout()) == Ptr)
820 bool LazyValueInfoImpl::solveBlockValueNonLocal(LVILatticeVal &BBLV,
822 LVILatticeVal Result;
827 assert(isa<Argument>(Val) &&
"Unknown live-in to the entry block");
835 Result = LVILatticeVal::getOverdefined();
843 bool EdgesMissing =
false;
845 LVILatticeVal EdgeResult;
846 EdgesMissing |= !getEdgeValue(Val, *PI, BB, EdgeResult);
850 Result.mergeIn(EdgeResult, DL);
854 if (Result.isOverdefined()) {
856 <<
"' - overdefined because of pred (non local).\n");
873 assert(!Result.isOverdefined());
878 bool LazyValueInfoImpl::solveBlockValuePHINode(LVILatticeVal &BBLV,
880 LVILatticeVal Result;
884 bool EdgesMissing =
false;
888 LVILatticeVal EdgeResult;
892 EdgesMissing |= !getEdgeValue(PhiVal, PhiBB, BB, EdgeResult, PN);
896 Result.mergeIn(EdgeResult, DL);
900 if (Result.isOverdefined()) {
902 <<
"' - overdefined because of pred (local).\n");
912 assert(!Result.isOverdefined() &&
"Possible PHI in entry block?");
918 bool isTrueDest =
true);
922 void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
928 for (
auto &AssumeVH : AC->assumptionsFor(Val)) {
931 auto *I = cast<CallInst>(AssumeVH);
941 if (!GuardDecl || GuardDecl->use_empty())
946 Value *Cond =
nullptr;
947 if (
match(&I, m_Intrinsic<Intrinsic::experimental_guard>(
m_Value(Cond))))
952 bool LazyValueInfoImpl::solveBlockValueSelect(LVILatticeVal &BBLV,
957 if (pushBlockValue(std::make_pair(BB, SI->
getTrueValue())))
959 BBLV = LVILatticeVal::getOverdefined();
962 LVILatticeVal TrueVal = getBlockValue(SI->
getTrueValue(), BB);
965 if (TrueVal.isOverdefined()) {
966 BBLV = LVILatticeVal::getOverdefined();
973 BBLV = LVILatticeVal::getOverdefined();
976 LVILatticeVal FalseVal = getBlockValue(SI->
getFalseValue(), BB);
979 if (FalseVal.isOverdefined()) {
980 BBLV = LVILatticeVal::getOverdefined();
984 if (TrueVal.isConstantRange() && FalseVal.isConstantRange()) {
987 Value *LHS =
nullptr;
988 Value *RHS =
nullptr;
999 return TrueCR.
smin(FalseCR);
1001 return TrueCR.
umin(FalseCR);
1003 return TrueCR.
smax(FalseCR);
1005 return TrueCR.
umax(FalseCR);
1008 BBLV = LVILatticeVal::getRange(ResultCR);
1032 if (
auto *ICI = dyn_cast<ICmpInst>(Cond)) {
1034 Value *
A = ICI->getOperand(0);
1035 if (
ConstantInt *CIBase = dyn_cast<ConstantInt>(ICI->getOperand(1))) {
1049 auto ResNot = addConstants(CIBase, CIAdded);
1051 LVILatticeVal::getNot(ResNot));
1057 auto ResNot = addConstants(CIBase, CIAdded);
1059 LVILatticeVal::getNot(ResNot));
1066 LVILatticeVal Result;
1067 Result.mergeIn(TrueVal, DL);
1068 Result.mergeIn(FalseVal, DL);
1073 bool LazyValueInfoImpl::solveBlockValueCast(LVILatticeVal &BBLV,
1079 BBLV = LVILatticeVal::getOverdefined();
1087 case Instruction::Trunc:
1088 case Instruction::SExt:
1089 case Instruction::ZExt:
1090 case Instruction::BitCast:
1095 <<
"' - overdefined (unknown cast).\n");
1096 BBLV = LVILatticeVal::getOverdefined();
1104 if (pushBlockValue(std::make_pair(BB, BBI->
getOperand(0))))
1108 const unsigned OperandBitWidth =
1112 LVILatticeVal LHSVal = getBlockValue(BBI->
getOperand(0), BB);
1113 intersectAssumeOrGuardBlockValueConstantRange(BBI->
getOperand(0), LHSVal,
1115 if (LHSVal.isConstantRange())
1116 LHSRange = LHSVal.getConstantRange();
1119 const unsigned ResultBitWidth =
1126 BBLV = LVILatticeVal::getRange(LHSRange.
castOp(CastOp, ResultBitWidth));
1130 bool LazyValueInfoImpl::solveBlockValueBinaryOp(LVILatticeVal &BBLV,
1135 "all operands to binary operators are sized");
1142 case Instruction::Sub:
1143 case Instruction::Mul:
1144 case Instruction::UDiv:
1145 case Instruction::Shl:
1146 case Instruction::LShr:
1154 <<
"' - overdefined (unknown binary operator).\n");
1155 BBLV = LVILatticeVal::getOverdefined();
1163 if (pushBlockValue(std::make_pair(BB, BBI->
getOperand(0))))
1167 const unsigned OperandBitWidth =
1171 LVILatticeVal LHSVal = getBlockValue(BBI->
getOperand(0), BB);
1172 intersectAssumeOrGuardBlockValueConstantRange(BBI->
getOperand(0), LHSVal,
1174 if (LHSVal.isConstantRange())
1175 LHSRange = LHSVal.getConstantRange();
1185 BBLV = LVILatticeVal::getRange(LHSRange.
binaryOp(BinOp, RHSRange));
1195 if (isa<Constant>(RHS)) {
1200 return LVILatticeVal::get(cast<Constant>(RHS));
1202 return LVILatticeVal::getNot(cast<Constant>(RHS));
1207 return LVILatticeVal::getOverdefined();
1227 if (LHS == Val || Offset) {
1233 else if (
Instruction *I = dyn_cast<Instruction>(RHS))
1246 return LVILatticeVal::getRange(std::move(TrueValues));
1249 return LVILatticeVal::getOverdefined();
1252 static LVILatticeVal
1256 static LVILatticeVal
1259 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Cond))
1265 return LVILatticeVal::getOverdefined();
1269 return LVILatticeVal::getOverdefined();
1276 static LVILatticeVal
1279 auto I = Visited.
find(Cond);
1280 if (I != Visited.
end())
1284 Visited[Cond] = Result;
1289 assert(Cond &&
"precondition");
1304 if (BI->isConditional() &&
1305 BI->getSuccessor(0) != BI->getSuccessor(1)) {
1306 bool isTrueDest = BI->getSuccessor(0) == BBTo;
1307 assert(BI->getSuccessor(!isTrueDest) == BBTo &&
1308 "BBTo isn't a successor of BBFrom");
1312 if (BI->getCondition() == Val) {
1321 if (!Result.isOverdefined())
1332 bool DefaultCase = SI->getDefaultDest() == BBTo;
1341 if (
i.getCaseSuccessor() != BBTo)
1343 }
else if (
i.getCaseSuccessor() == BBTo)
1344 EdgesVals = EdgesVals.
unionWith(EdgeVal);
1346 Result = LVILatticeVal::getRange(std::move(EdgesVals));
1358 if (
Constant *
VC = dyn_cast<Constant>(Val)) {
1359 Result = LVILatticeVal::get(
VC);
1363 LVILatticeVal LocalResult;
1367 LocalResult = LVILatticeVal::getOverdefined();
1371 Result = LocalResult;
1375 if (!hasBlockValue(Val, BBFrom)) {
1376 if (pushBlockValue(std::make_pair(BBFrom, Val)))
1379 Result = LocalResult;
1384 LVILatticeVal
InBlock = getBlockValue(Val, BBFrom);
1385 intersectAssumeOrGuardBlockValueConstantRange(Val, InBlock,
1395 intersectAssumeOrGuardBlockValueConstantRange(Val, InBlock, CxtI);
1397 Result =
intersect(LocalResult, InBlock);
1401 LVILatticeVal LazyValueInfoImpl::getValueInBlock(
Value *V,
BasicBlock *BB,
1403 DEBUG(
dbgs() <<
"LVI Getting block end value " << *V <<
" at '"
1406 assert(BlockValueStack.empty() && BlockValueSet.empty());
1407 if (!hasBlockValue(V, BB)) {
1408 pushBlockValue(std::make_pair(BB, V));
1411 LVILatticeVal Result = getBlockValue(V, BB);
1412 intersectAssumeOrGuardBlockValueConstantRange(V, Result, CxtI);
1414 DEBUG(
dbgs() <<
" Result = " << Result <<
"\n");
1419 DEBUG(
dbgs() <<
"LVI Getting value " << *V <<
" at '"
1422 if (
auto *C = dyn_cast<Constant>(V))
1423 return LVILatticeVal::get(C);
1425 LVILatticeVal Result = LVILatticeVal::getOverdefined();
1426 if (
auto *I = dyn_cast<Instruction>(V))
1428 intersectAssumeOrGuardBlockValueConstantRange(V, Result, CxtI);
1430 DEBUG(
dbgs() <<
" Result = " << Result <<
"\n");
1434 LVILatticeVal LazyValueInfoImpl::
1437 DEBUG(
dbgs() <<
"LVI Getting edge value " << *V <<
" from '"
1440 LVILatticeVal Result;
1441 if (!getEdgeValue(V, FromBB, ToBB, Result, CxtI)) {
1443 bool WasFastQuery = getEdgeValue(V, FromBB, ToBB, Result, CxtI);
1445 assert(WasFastQuery &&
"More work to do after problem solved?");
1448 DEBUG(
dbgs() <<
" Result = " << Result <<
"\n");
1454 TheCache.threadEdgeImpl(OldSucc, NewSucc);
1466 assert(DL &&
"getCache() called with a null DataLayout");
1467 PImpl =
new LazyValueInfoImpl(AC, *DL, DT);
1469 return *
static_cast<LazyValueInfoImpl*
>(PImpl);
1473 Info.AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
1477 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
1478 Info.DT = DTWP ? &DTWP->
getDomTree() :
nullptr;
1479 Info.TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
1482 getImpl(Info.PImpl, Info.AC, &DL, Info.DT).clear();
1501 delete &
getImpl(PImpl, AC,
nullptr);
1525 if (isa<AllocaInst>(V))
1537 LVILatticeVal Result =
1538 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
1540 if (Result.isConstant())
1541 return Result.getConstant();
1542 if (Result.isConstantRange()) {
1555 LVILatticeVal Result =
1556 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
1557 if (Result.isUndefined())
1559 if (Result.isConstantRange())
1560 return Result.getConstantRange();
1563 assert(!(Result.isConstant() && isa<ConstantInt>(Result.getConstant())) &&
1564 "ConstantInt value must be represented as constantrange");
1574 LVILatticeVal Result =
1575 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1577 if (Result.isConstant())
1578 return Result.getConstant();
1579 if (Result.isConstantRange()) {
1588 LVILatticeVal &Result,
1594 if (Result.isConstant()) {
1597 if (
ConstantInt *ResCI = dyn_cast<ConstantInt>(Res))
1602 if (Result.isConstantRange()) {
1631 if (Result.isNotConstant()) {
1637 Result.getNotConstant(),
C, DL,
1644 Result.getNotConstant(),
C, DL,
1662 LVILatticeVal Result =
1663 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1683 LVILatticeVal Result =
getImpl(PImpl, AC, &DL, DT).getValueAt(V, CxtI);
1723 if (
auto *PHI = dyn_cast<PHINode>(V))
1724 if (PHI->getParent() == BB) {
1726 for (
unsigned i = 0, e = PHI->getNumIncomingValues();
i < e;
i++) {
1727 Value *Incoming = PHI->getIncomingValue(
i);
1730 Tristate Result = getPredicateOnEdge(Pred, Incoming, C, PredBB, BB,
1735 Baseline = (
i == 0) ? Result
1736 : (Baseline == Result ? Baseline :
Unknown);
1737 if (Baseline == Unknown)
1747 if (!isa<Instruction>(V) ||
1748 cast<Instruction>(V)->
getParent() != BB) {
1752 Tristate Baseline = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI);
1755 while (++PI != PE) {
1756 Tristate Ret = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI);
1757 if (Ret != Baseline)
break;
1773 getImpl(PImpl, AC, &DL, DT).threadEdge(PredBB, OldSucc, NewSucc);
1780 getImpl(PImpl, AC, &DL, DT).eraseBlock(BB);
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type (if unknown returns 0).
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
static bool InstructionDereferencesPointer(Instruction *I, Value *Ptr)
static IntegerType * getInt1Ty(LLVMContext &C)
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...
const Instruction & back() const
Wrapper around LazyValueInfo.
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
iterator find(const ValueT &V)
Implements a dense probed hash-table based set.
ilist_iterator< OptionsT,!IsReverse, IsConst > getReverse() const
Get a reverse iterator to the same node.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE, etc.
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of .assume calls within a function.
bool erase(const ValueT &V)
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
const Function * getParent() const
Return the enclosing method, or null if none.
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.
bool isSingleElement() const
Return true if this set contains exactly one member.
Analysis pass which computes a DominatorTree.
An instruction for reading from memory.
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...
static LazyValueInfo::Tristate getPredicateResult(unsigned Pred, Constant *C, LVILatticeVal &Result, const DataLayout &DL, TargetLibraryInfo *TLI)
ConstantRange smax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed maximum of a value in thi...
StringRef getName() const
Return a constant reference to the value's name.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
bool match(Val *V, const Pattern &P)
static LVILatticeVal getValueFromCondition(Value *Val, Value *Cond, bool isTrueDest=true)
AnalysisUsage & addRequired()
#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.
const APInt & getValue() const
Return the constant as an APInt value reference.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
lazy value Lazy Value Information Analysis
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 bool isKnownNonConstant(Value *V)
Returns true if we can statically tell that this value will never be a "useful" constant.
static LVILatticeVal intersect(LVILatticeVal A, LVILatticeVal B)
Combine two sets of facts about the same value into a single set of facts.
BinaryOp_match< LHS, RHS, Instruction::Add > m_Add(const LHS &L, const RHS &R)
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 contains(const APInt &Val) const
Return true if the specified value is in the set.
static bool getEdgeValueLocal(Value *Val, BasicBlock *BBFrom, BasicBlock *BBTo, LVILatticeVal &Result)
Compute the value of Val on the edge BBFrom -> BBTo.
ConstantRange unionWith(const ConstantRange &CR) const
Return the range that results from the union of this range with another range.
class_match< ConstantInt > m_ConstantInt()
Match an arbitrary ConstantInt and ignore it.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
An instruction for storing to memory.
ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
FunctionPass * createLazyValueInfoPass()
createLazyValueInfoPass - This creates an instance of the LazyValueInfo pass.
static LVILatticeVal getValueFromConditionImpl(Value *Val, Value *Cond, bool isTrueDest, DenseMap< Value *, LVILatticeVal > &Visited)
Class to represent pointers.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
unsigned getNumIncomingValues() const
Return the number of incoming edges.
Interval::succ_iterator succ_end(Interval *I)
SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, Instruction::CastOps *CastOp=nullptr)
Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind and providing the out param...
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
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.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
LLVM Basic Block Representation.
static LVILatticeVal getFromRangeMetadata(Instruction *BBI)
Conditional or Unconditional Branch instruction.
This is an important base class in LLVM.
const Value * getCondition() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(const ValueT &V)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
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...
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
Represent the analysis usage information of a pass.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
static bool hasSingleValue(const LVILatticeVal &Val)
Returns true if this lattice value represents at most one possible value.
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...
This instruction compares its operands according to the predicate given to the constructor.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
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...
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...
Value * getOperand(unsigned i) const
Interval::pred_iterator pred_end(Interval *I)
self_iterator getIterator()
unsigned getIntegerBitWidth() const
Predicate getPredicate() const
Return the predicate for this instruction.
LLVM_NODISCARD bool empty() const
bool isEmptySet() const
Return true if this set contains no members.
ConstantRange difference(const ConstantRange &CR) const
Subtract the specified range from this range (aka relative complement of the sets).
bool isPointerTy() const
True if this is an instance of PointerType.
LLVMContext & getContext() const
All values hold a context through their type.
const Value * getTrueValue() const
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...
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Tristate
This is used to return true/false/dunno results.
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 ...
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.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
BinaryOps getOpcode() const
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...
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...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
ConstantRange inverse() const
Return a new range that is the logical not of the current set.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
This class represents a range of values.
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
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.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
const BasicBlock & getEntryBlock() const
ConstantRange umin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned minimum of a value in ...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Class for arbitrary precision integers.
bool isIntegerTy() const
True if this is an instance of IntegerType.
void setPreservesAll()
Set by analyses that do not transform their input at all.
static void clear(coro::Shape &Shape)
static LVILatticeVal getValueFromICmpCondition(Value *Val, ICmpInst *ICI, bool isTrueDest)
INITIALIZE_PASS_BEGIN(LazyValueInfoWrapperPass,"lazy-value-info","Lazy Value Information Analysis", false, true) INITIALIZE_PASS_END(LazyValueInfoWrapperPass
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
ConstantRange umax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned maximum of a value in ...
This class wraps the llvm.memcpy/memmove intrinsics.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isKnownNonNull(const Value *V)
Return true if this pointer couldn't possibly be null by its definition.
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 bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
iterator find(const KeyT &Val)
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)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
lazy value Lazy Value Information false
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
Analysis pass providing the TargetLibraryInfo.
This pass computes, caches, and vends lazy value constraint information.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
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 const Function * getParent(const Value *V)
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
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...
const Value * getFalseValue() const
Value handle with callbacks on RAUW and destruction.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
static LazyValueInfoImpl & getImpl(void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
This lazily constructs the LazyValueInfoImpl.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
A special type used by analysis passes to provide an address that identifies that particular analysis...
const BasicBlock * getParent() const
static bool InBlock(const Value *V, const BasicBlock *BB)
#define LLVM_ATTRIBUTE_USED