44 #define DEBUG_TYPE "lazy-value-info" 55 "Lazy Value Information Analysis",
false,
true)
137 class LazyValueInfoCache;
138 struct LVIValueHandle final :
public CallbackVH {
142 LazyValueInfoCache *Parent;
144 LVIValueHandle(
Value *V, LazyValueInfoCache *
P)
147 void deleted()
override;
148 void allUsesReplacedWith(
Value *V)
override {
157 class LazyValueInfoCache {
163 struct ValueCacheEntryTy {
164 ValueCacheEntryTy(
Value *V, LazyValueInfoCache *
P) : Handle(V, P) {}
165 LVIValueHandle Handle;
180 OverDefinedCacheTy OverDefinedCache;
191 OverDefinedCache[BB].insert(Val);
193 auto It = ValueCache.
find_as(Val);
194 if (It == ValueCache.
end()) {
195 ValueCache[Val] = std::make_unique<ValueCacheEntryTy>(Val,
this);
197 assert(It != ValueCache.
end() &&
"Val was just added to the map!");
199 It->second->BlockVals[BB] = Result;
204 auto ODI = OverDefinedCache.find(BB);
206 if (ODI == OverDefinedCache.end())
209 return ODI->second.count(V);
213 if (isOverdefined(V, BB))
217 if (
I == ValueCache.
end())
220 return I->second->BlockVals.count(BB);
224 if (isOverdefined(V, BB))
228 if (
I == ValueCache.
end())
230 auto BBI =
I->second->BlockVals.find(BB);
231 if (BBI ==
I->second->BlockVals.end())
240 OverDefinedCache.clear();
244 void eraseValue(
Value *V);
255 friend struct LVIValueHandle;
259 void LazyValueInfoCache::eraseValue(
Value *V) {
260 for (
auto I = OverDefinedCache.begin(),
E = OverDefinedCache.end();
I !=
E;) {
266 if (ValueSet.
empty())
267 OverDefinedCache.erase(Iter);
273 void LVIValueHandle::deleted() {
276 Parent->eraseValue(*
this);
279 void LazyValueInfoCache::eraseBlock(
BasicBlock *BB) {
282 if (I == SeenBlocks.
end())
286 auto ODI = OverDefinedCache.find(BB);
287 if (ODI != OverDefinedCache.end())
288 OverDefinedCache.erase(ODI);
290 for (
auto &I : ValueCache)
291 I.second->BlockVals.
erase(BB);
294 void LazyValueInfoCache::threadEdgeImpl(
BasicBlock *OldSucc,
306 std::vector<BasicBlock*> worklist;
307 worklist.push_back(OldSucc);
309 auto I = OverDefinedCache.find(OldSucc);
310 if (
I == OverDefinedCache.end())
318 while (!worklist.empty()) {
323 if (ToUpdate == NewSucc)
continue;
326 auto OI = OverDefinedCache.find(ToUpdate);
327 if (OI == OverDefinedCache.end())
331 bool changed =
false;
332 for (
Value *V : ValsToClear) {
333 if (!ValueSet.
erase(V))
340 if (ValueSet.
empty()) {
341 OverDefinedCache.erase(OI);
346 if (!changed)
continue;
356 class LazyValueInfoImpl;
358 LazyValueInfoImpl *LVIImpl;
366 LazyValueInfoAnnotatedWriter(LazyValueInfoImpl *L,
DominatorTree &DTree)
367 : LVIImpl(L), DT(DTree) {}
369 virtual void emitBasicBlockStartAnnot(
const BasicBlock *BB,
380 class LazyValueInfoImpl {
383 LazyValueInfoCache TheCache;
395 bool pushBlockValue(
const std::pair<BasicBlock *, Value *> &BV) {
396 if (!BlockValueSet.
insert(BV).second)
400 << BV.first->getName() <<
"\n");
429 bool solveBlockValueBinaryOpImpl(
437 bool solveBlockValueOverflowIntrinsic(
445 void intersectAssumeOrGuardBlockValueConstantRange(
Value *Val,
475 LazyValueInfoAnnotatedWriter Writer(
this, DTree);
476 F.
print(OS, &Writer);
482 TheCache.eraseBlock(BB);
488 assert(!DisabledDT &&
"Both DT and DisabledDT are not nullptr!");
497 assert(!DT &&
"Both DT and DisabledDT are not nullptr!");
508 : AC(AC), DL(DL), DT(DT), DisabledDT(
nullptr) {}
515 BlockValueStack.begin(), BlockValueStack.end());
517 unsigned processedCount = 0;
518 while (!BlockValueStack.empty()) {
528 if (processedCount > MaxProcessedPerValue) {
530 dbgs() <<
"Giving up on stack because we are getting too deep\n");
532 while (!StartingStack.empty()) {
533 std::pair<BasicBlock *, Value *> &
e = StartingStack.back();
534 TheCache.insertResult(e.second, e.first,
536 StartingStack.pop_back();
538 BlockValueSet.clear();
539 BlockValueStack.clear();
542 std::pair<BasicBlock *, Value *>
e = BlockValueStack.back();
543 assert(BlockValueSet.count(e) &&
"Stack value should be in BlockValueSet!");
545 if (solveBlockValue(e.second, e.first)) {
547 assert(BlockValueStack.back() == e &&
"Nothing should have been pushed!");
548 assert(TheCache.hasCachedValueInfo(e.second, e.first) &&
549 "Result should be in cache!");
552 dbgs() <<
"POP " << *e.second <<
" in " << e.first->getName() <<
" = " 553 << TheCache.getCachedValueInfo(e.second, e.first) <<
"\n");
555 BlockValueStack.pop_back();
556 BlockValueSet.erase(e);
559 assert(BlockValueStack.back() != e &&
"Stack should have been pushed!");
566 if (isa<Constant>(Val))
569 return TheCache.hasCachedValueInfo(Val, BB);
578 return TheCache.getCachedValueInfo(Val, BB);
586 case Instruction::Invoke:
588 if (isa<IntegerType>(BBI->
getType())) {
599 if (isa<Constant>(Val))
602 if (TheCache.hasCachedValueInfo(Val, BB)) {
605 << TheCache.getCachedValueInfo(Val, BB) <<
'\n');
616 if (!solveBlockValueImpl(Res, Val, BB))
620 TheCache.insertResult(Val, BB, Res);
629 return solveBlockValueNonLocal(Res, Val, BB);
631 if (
PHINode *PN = dyn_cast<PHINode>(BBI))
632 return solveBlockValuePHINode(Res, PN, BB);
634 if (
auto *
SI = dyn_cast<SelectInst>(BBI))
635 return solveBlockValueSelect(Res,
SI, BB);
652 if (
auto *CI = dyn_cast<CastInst>(BBI))
653 return solveBlockValueCast(Res, CI, BB);
656 return solveBlockValueBinaryOp(Res, BO, BB);
658 if (
auto *EVI = dyn_cast<ExtractValueInst>(BBI))
659 return solveBlockValueExtractValue(Res, EVI, BB);
661 if (
auto *II = dyn_cast<IntrinsicInst>(BBI))
662 return solveBlockValueIntrinsic(Res, II, BB);
666 <<
"' - unknown inst def found.\n");
672 if (
LoadInst *L = dyn_cast<LoadInst>(I)) {
673 return L->getPointerAddressSpace() == 0 &&
675 L->getModule()->getDataLayout()) == Ptr;
677 if (
StoreInst *S = dyn_cast<StoreInst>(I)) {
678 return S->getPointerAddressSpace() == 0 &&
680 S->getModule()->getDataLayout()) == Ptr;
683 if (
MI->isVolatile())
return false;
687 if (!Len || Len->
isZero())
return false;
689 if (
MI->getDestAddressSpace() == 0)
691 MI->getModule()->getDataLayout()) == Ptr)
694 if (MTI->getSourceAddressSpace() == 0)
696 MTI->getModule()->getDataLayout()) == Ptr)
727 assert(isa<Argument>(Val) &&
"Unknown live-in to the entry block");
754 if (!getEdgeValue(Val, *PI, BB, EdgeResult))
758 Result.
mergeIn(EdgeResult, DL);
764 <<
"' - overdefined because of pred (non local).\n");
798 if (!getEdgeValue(PhiVal, PhiBB, BB, EdgeResult, PN))
802 Result.
mergeIn(EdgeResult, DL);
808 <<
"' - overdefined because of pred (local).\n");
822 bool isTrueDest =
true);
826 void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
832 for (
auto &AssumeVH : AC->assumptionsFor(Val)) {
835 auto *
I = cast<CallInst>(AssumeVH);
845 if (!GuardDecl || GuardDecl->use_empty())
852 Value *Cond =
nullptr;
853 if (
match(&
I, m_Intrinsic<Intrinsic::experimental_guard>(
m_Value(Cond))))
863 if (pushBlockValue(std::make_pair(BB, SI->
getTrueValue())))
893 Value *LHS =
nullptr;
894 Value *RHS =
nullptr;
905 return TrueCR.
smin(FalseCR);
907 return TrueCR.
umin(FalseCR);
909 return TrueCR.
smax(FalseCR);
911 return TrueCR.
umax(FalseCR);
959 if (
auto *ICI = dyn_cast<ICmpInst>(Cond)) {
961 Value *A = ICI->getOperand(0);
962 if (
ConstantInt *CIBase = dyn_cast<ConstantInt>(ICI->getOperand(1))) {
976 auto ResNot = addConstants(CIBase, CIAdded);
984 auto ResNot = addConstants(CIBase, CIAdded);
1004 if (pushBlockValue(std::make_pair(BB, I->
getOperand(Op))))
1007 const unsigned OperandBitWidth =
1009 ConstantRange Range = ConstantRange::getFull(OperandBitWidth);
1012 intersectAssumeOrGuardBlockValueConstantRange(I->
getOperand(Op), Val,
I);
1033 case Instruction::Trunc:
1034 case Instruction::SExt:
1035 case Instruction::ZExt:
1036 case Instruction::BitCast:
1041 <<
"' - overdefined (unknown cast).\n");
1065 bool LazyValueInfoImpl::solveBlockValueBinaryOpImpl(
1090 "all operands to binary operators are sized");
1091 if (BO->
getOpcode() == Instruction::Xor) {
1094 <<
"' - overdefined (unknown binary operator).\n");
1099 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(BO)) {
1100 unsigned NoWrapKind = 0;
1101 if (OBO->hasNoUnsignedWrap())
1103 if (OBO->hasNoSignedWrap())
1106 return solveBlockValueBinaryOpImpl(
1113 return solveBlockValueBinaryOpImpl(
1119 bool LazyValueInfoImpl::solveBlockValueOverflowIntrinsic(
1121 return solveBlockValueBinaryOpImpl(BBLV, WO, BB,
1127 bool LazyValueInfoImpl::solveBlockValueSaturatingIntrinsic(
1130 case Intrinsic::uadd_sat:
1131 return solveBlockValueBinaryOpImpl(
1135 case Intrinsic::usub_sat:
1136 return solveBlockValueBinaryOpImpl(
1140 case Intrinsic::sadd_sat:
1141 return solveBlockValueBinaryOpImpl(
1145 case Intrinsic::ssub_sat:
1146 return solveBlockValueBinaryOpImpl(
1158 if (
auto *SI = dyn_cast<SaturatingInst>(II))
1159 return solveBlockValueSaturatingIntrinsic(BBLV, SI, BB);
1162 <<
"' - overdefined (unknown intrinsic).\n");
1167 bool LazyValueInfoImpl::solveBlockValueExtractValue(
1171 return solveBlockValueOverflowIntrinsic(BBLV, WO, BB);
1178 if (!hasBlockValue(V, BB)) {
1179 if (pushBlockValue({ BB, V }))
1184 BBLV = getBlockValue(V, BB);
1189 <<
"' - overdefined (unknown extractvalue).\n");
1200 if (isa<Constant>(RHS)) {
1232 if (LHS == Val || Offset) {
1238 else if (
Instruction *I = dyn_cast<Instruction>(RHS))
1239 if (
auto *Ranges = I->
getMetadata(LLVMContext::MD_range))
1286 if (
ICmpInst *ICI = dyn_cast<ICmpInst>(Cond))
1289 if (
auto *EVI = dyn_cast<ExtractValueInst>(Cond))
1299 if (!BO || (isTrueDest && BO->
getOpcode() != BinaryOperator::And) ||
1300 (!isTrueDest && BO->
getOpcode() != BinaryOperator::Or))
1309 if (BL == Cond || BR == Cond)
1319 auto I = Visited.
find(Cond);
1320 if (I != Visited.
end())
1324 Visited[Cond] = Result;
1330 assert(Cond &&
"precondition");
1345 return isa<CastInst>(Usr) || isa<BinaryOperator>(Usr);
1353 const APInt &OpConstVal,
1358 if (
auto *CI = dyn_cast<CastInst>(Usr)) {
1360 if (
auto *
C = dyn_cast_or_null<ConstantInt>(
1365 }
else if (
auto *BO = dyn_cast<BinaryOperator>(Usr)) {
1368 assert((Op0Match || Op1Match) &&
1369 "Operand 0 nor Operand 1 isn't a match");
1372 if (
auto *
C = dyn_cast_or_null<ConstantInt>(
1390 if (BI->isConditional() &&
1391 BI->getSuccessor(0) != BI->getSuccessor(1)) {
1392 bool isTrueDest = BI->getSuccessor(0) == BBTo;
1393 assert(BI->getSuccessor(!isTrueDest) == BBTo &&
1394 "BBTo isn't a successor of BBFrom");
1395 Value *Condition = BI->getCondition();
1399 if (Condition == Val) {
1411 if (
User *Usr = dyn_cast<User>(Val)) {
1426 APInt ConditionVal(1, isTrueDest ? 1 : 0);
1436 for (
unsigned i = 0; i < Usr->getNumOperands(); ++i) {
1437 Value *Op = Usr->getOperand(i);
1456 Value *Condition = SI->getCondition();
1457 if (!isa<IntegerType>(Val->
getType()))
1459 bool ValUsesConditionAndMayBeFoldable =
false;
1460 if (Condition != Val) {
1462 if (
User *Usr = dyn_cast<User>(Val))
1465 if (!ValUsesConditionAndMayBeFoldable)
1468 assert((Condition == Val || ValUsesConditionAndMayBeFoldable) &&
1469 "Condition != Val nor Val doesn't use Condition");
1471 bool DefaultCase = SI->getDefaultDest() == BBTo;
1475 for (
auto Case : SI->cases()) {
1476 APInt CaseValue = Case.getCaseValue()->getValue();
1478 if (ValUsesConditionAndMayBeFoldable) {
1479 User *Usr = cast<User>(Val);
1494 if (Case.getCaseSuccessor() != BBTo && Condition == Val)
1496 }
else if (Case.getCaseSuccessor() == BBTo)
1497 EdgesVals = EdgesVals.
unionWith(EdgeVal);
1512 if (
Constant *
VC = dyn_cast<Constant>(Val)) {
1525 Result = LocalResult;
1529 if (!hasBlockValue(Val, BBFrom)) {
1530 if (pushBlockValue(std::make_pair(BBFrom, Val)))
1533 Result = LocalResult;
1539 intersectAssumeOrGuardBlockValueConstantRange(Val, InBlock,
1549 intersectAssumeOrGuardBlockValueConstantRange(Val, InBlock, CxtI);
1551 Result =
intersect(LocalResult, InBlock);
1557 LLVM_DEBUG(
dbgs() <<
"LVI Getting block end value " << *V <<
" at '" 1560 assert(BlockValueStack.empty() && BlockValueSet.empty());
1561 if (!hasBlockValue(V, BB)) {
1562 pushBlockValue(std::make_pair(BB, V));
1566 intersectAssumeOrGuardBlockValueConstantRange(V, Result, CxtI);
1576 if (
auto *
C = dyn_cast<Constant>(V))
1580 if (
auto *I = dyn_cast<Instruction>(V))
1582 intersectAssumeOrGuardBlockValueConstantRange(V, Result, CxtI);
1591 LLVM_DEBUG(
dbgs() <<
"LVI Getting edge value " << *V <<
" from '" 1596 if (!getEdgeValue(V, FromBB, ToBB, Result, CxtI)) {
1598 bool WasFastQuery = getEdgeValue(V, FromBB, ToBB, Result, CxtI);
1600 assert(WasFastQuery &&
"More work to do after problem solved?");
1609 TheCache.threadEdgeImpl(OldSucc, NewSucc);
1621 assert(DL &&
"getCache() called with a null DataLayout");
1622 PImpl =
new LazyValueInfoImpl(AC, *DL, DT);
1624 return *
static_cast<LazyValueInfoImpl*
>(PImpl);
1628 Info.AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F);
1632 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
1634 Info.TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
1656 delete &
getImpl(PImpl, AC,
nullptr);
1693 if (isa<AllocaInst>(V))
1706 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
1724 getImpl(PImpl, AC, &DL, DT).getValueInBlock(V, BB, CxtI);
1726 return ConstantRange::getEmpty(Width);
1732 "ConstantInt value must be represented as constantrange");
1733 return ConstantRange::getFull(Width);
1743 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1762 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1765 return ConstantRange::getEmpty(Width);
1771 "ConstantInt value must be represented as constantrange");
1772 return ConstantRange::getFull(Width);
1782 if (
ConstantInt *ResCI = dyn_cast<ConstantInt>(Res))
1848 getImpl(PImpl, AC, &DL, DT).getValueOnEdge(V, FromBB, ToBB, CxtI);
1908 if (
auto *PHI = dyn_cast<PHINode>(V))
1909 if (PHI->getParent() == BB) {
1911 for (
unsigned i = 0,
e = PHI->getNumIncomingValues(); i <
e; i++) {
1912 Value *Incoming = PHI->getIncomingValue(i);
1913 BasicBlock *PredBB = PHI->getIncomingBlock(i);
1915 Tristate Result = getPredicateOnEdge(Pred, Incoming, C, PredBB, BB,
1920 Baseline = (i == 0) ? Result
1921 : (Baseline == Result ? Baseline :
Unknown);
1922 if (Baseline == Unknown)
1932 if (!isa<Instruction>(V) ||
1933 cast<Instruction>(V)->
getParent() != BB) {
1937 Tristate Baseline = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI);
1940 while (++PI != PE) {
1941 Tristate Ret = getPredicateOnEdge(Pred, V, C, *PI, BB, CxtI);
1942 if (Ret != Baseline)
break;
1958 getImpl(PImpl, AC, &DL, DT).threadEdge(PredBB, OldSucc, NewSucc);
1965 getImpl(PImpl, AC, &DL, DT).eraseBlock(BB);
1972 getImpl(PImpl, AC, DL, DT).printLVI(F, DTree, OS);
1978 getImpl(PImpl, AC, DL, DT).disableDT();
1983 getImpl(PImpl, AC, DL, DT).enableDT();
1987 void LazyValueInfoAnnotatedWriter::emitBasicBlockStartAnnot(
1991 for (
auto &
Arg :
F->args()) {
1993 const_cast<Argument *>(&
Arg), const_cast<BasicBlock *>(BB));
1996 OS <<
"; LatticeVal for: '" <<
Arg <<
"' is: " << Result <<
"\n";
2004 void LazyValueInfoAnnotatedWriter::emitInstructionAnnot(
2014 auto printResult = [&](
const BasicBlock *BB) {
2015 if (!BlocksContainingLVI.
insert(BB).second)
2018 const_cast<Instruction *>(I), const_cast<BasicBlock *>(BB));
2019 OS <<
"; LatticeVal for: '" << *I <<
"' in BB: '";
2021 OS <<
"' is: " << Result <<
"\n";
2024 printResult(ParentBB);
2028 if (DT.dominates(ParentBB, BBSucc))
2029 printResult(BBSucc);
2032 for (
auto *U : I->
users())
2033 if (
auto *UseI = dyn_cast<Instruction>(U))
2034 if (!isa<PHINode>(UseI) || DT.dominates(ParentBB, UseI->getParent()))
2035 printResult(UseI->getParent());
2057 dbgs() <<
"LVI for function '" << F.
getName() <<
"':\n";
2058 auto &LVI = getAnalysis<LazyValueInfoWrapperPass>().
getLVI();
2059 auto &DTree = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
2060 LVI.printLVI(F, DTree,
dbgs());
2068 "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.
LazyValueInfoWrapperPass()
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...
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.
Represents an op.with.overflow intrinsic.
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
void initializeLazyValueInfoWrapperPassPass(PassRegistry &)
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)
ConstantRange sub(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a subtraction of a value in this r...
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
unsigned getNoWrapKind() const
Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
static const unsigned MaxProcessedPerValue
iterator begin()
Instruction iterator methods.
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)
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
AnalysisUsage & addRequired()
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
Value * SimplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an ExtractValueInst, fold the result or return null.
#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).
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.
ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
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. ...
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)
ConstantRange usub_sat(const ConstantRange &Other) const
Perform an unsigned saturating subtraction of two constant ranges.
const BasicBlock & getEntryBlock() const
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.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt...
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
ConstantRange sadd_sat(const ConstantRange &Other) const
Perform a signed saturating addition of two constant ranges.
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.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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.
self_iterator getIterator()
const Value * getCondition() const
static ValueLatticeElement getValueFromOverflowCondition(Value *Val, WithOverflowInst *WO, bool IsTrueDest)
const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
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...
ConstantRange overflowingBinaryOp(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind) const
Return a new range representing the possible values resulting from an application of the specified ov...
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 ...
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
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...
Represents a saturating add/sub intrinsic.
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 uadd_sat(const ConstantRange &Other) const
Perform an unsigned saturating addition of two constant ranges.
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
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.
Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
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?
ConstantRange ssub_sat(const ConstantRange &Other) const
Perform a signed saturating subtraction of two constant ranges.
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.
ConstantRange abs() const
Calculate absolute value range.
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.
virtual void print(raw_ostream &OS, const Module *M) const
print - Print out the internal state of the pass.
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.
ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
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...
static ConstantRange makeExactNoWrapRegion(Instruction::BinaryOps BinOp, const APInt &Other, unsigned NoWrapKind)
Produce the range that contains X if and only if "X BinOp Other" does not wrap.
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...
print Print MemDeps of function
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 APInt getNullValue(unsigned numBits)
Get the '0' value.
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.
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
static bool InBlock(const Value *V, const BasicBlock *BB)