51#define DEBUG_TYPE "lazy-value-info"
60 "Lazy Value Information Analysis",
false,
true)
94 class LazyValueInfoCache;
95 struct LVIValueHandle final :
public CallbackVH {
96 LazyValueInfoCache *Parent;
98 LVIValueHandle(
Value *
V, LazyValueInfoCache *
P =
nullptr)
99 : CallbackVH(
V), Parent(
P) { }
101 void deleted()
override;
102 void allUsesReplacedWith(
Value *
V)
override {
110using BBLatticeElementMap =
112using PredecessorValueLatticeMap =
117class LazyValueInfoCache {
122 struct BlockCacheEntry {
123 SmallDenseMap<AssertingVH<Value>, ValueLatticeElement, 4> LatticeElements;
124 SmallDenseSet<AssertingVH<Value>, 4> OverDefined;
127 std::optional<NonNullPointerSet> NonNullPointers;
131 std::optional<PredecessorValueLatticeMap> PredecessorLatticeElements;
134 const bool PerPredRanges;
139 DenseSet<LVIValueHandle, DenseMapInfo<Value *>> ValueHandles;
141 unsigned BlockNumberEpoch;
143 const BlockCacheEntry *getBlockEntry(BasicBlock *BB)
const {
146 return BlockCache[BB->
getNumber()].get();
150 BlockCacheEntry *getOrCreateBlockEntry(BasicBlock *BB) {
156 if (BlockCacheEntry *Entry = BlockCache[
Number].
get())
159 BlockCache[
Number] = std::make_unique<BlockCacheEntry>();
161 BlockCache[
Number]->PredecessorLatticeElements =
162 std::make_optional<PredecessorValueLatticeMap>();
164 return BlockCache[
Number].get();
167 void addValueHandle(
Value *Val) {
168 auto HandleIt = ValueHandles.
find_as(Val);
169 if (HandleIt == ValueHandles.
end())
170 ValueHandles.
insert({Val,
this});
174 LazyValueInfoCache(
const Function *
F,
bool PerPredRanges)
175 : PerPredRanges(PerPredRanges),
176 BlockNumberEpoch(
F->getBlockNumberEpoch()) {}
178 void insertResult(
Value *Val, BasicBlock *BB,
179 const ValueLatticeElement &Result) {
180 BlockCacheEntry *
Entry = getOrCreateBlockEntry(BB);
184 if (
Result.isOverdefined())
185 Entry->OverDefined.insert(Val);
192 void insertPredecessorResults(
Value *Val, BasicBlock *BB,
193 BBLatticeElementMap &PredLatticeElements) {
194 BlockCacheEntry *
Entry = getOrCreateBlockEntry(BB);
196 Entry->PredecessorLatticeElements->insert({Val, PredLatticeElements});
201 std::optional<BBLatticeElementMap>
202 getCachedPredecessorInfo(
Value *
V, BasicBlock *BB)
const {
203 const BlockCacheEntry *
Entry = getBlockEntry(BB);
207 auto LatticeIt =
Entry->PredecessorLatticeElements->find_as(
V);
208 if (LatticeIt ==
Entry->PredecessorLatticeElements->end())
211 return LatticeIt->second;
214 std::optional<ValueLatticeElement> getCachedValueInfo(
Value *
V,
215 BasicBlock *BB)
const {
216 const BlockCacheEntry *
Entry = getBlockEntry(BB);
220 if (
Entry->OverDefined.count(
V))
223 auto LatticeIt =
Entry->LatticeElements.find_as(
V);
224 if (LatticeIt ==
Entry->LatticeElements.end())
227 return LatticeIt->second;
231 isNonNullAtEndOfBlock(
Value *
V, BasicBlock *BB,
232 function_ref<NonNullPointerSet(BasicBlock *)> InitFn) {
233 BlockCacheEntry *
Entry = getOrCreateBlockEntry(BB);
234 if (!
Entry->NonNullPointers) {
235 Entry->NonNullPointers = InitFn(BB);
240 return Entry->NonNullPointers->count(
V);
246 ValueHandles.
clear();
250 void eraseValue(
Value *
V);
259 void threadEdgeImpl(BasicBlock *OldSucc, BasicBlock *NewSucc);
263void LazyValueInfoCache::eraseValue(
Value *
V) {
264 for (
auto &Elem : BlockCache) {
268 Elem->LatticeElements.erase(
V);
269 Elem->OverDefined.erase(
V);
270 if (Elem->NonNullPointers)
271 Elem->NonNullPointers->erase(
V);
273 Elem->PredecessorLatticeElements->erase(
V);
276 auto HandleIt = ValueHandles.
find_as(
V);
277 if (HandleIt != ValueHandles.
end())
278 ValueHandles.
erase(HandleIt);
281void LVIValueHandle::deleted() {
284 Parent->eraseValue(*
this);
287void LazyValueInfoCache::eraseBlock(
BasicBlock *BB) {
291 for (
auto &Elem : BlockCache)
293 Elem->PredecessorLatticeElements->clear();
298void LazyValueInfoCache::threadEdgeImpl(
BasicBlock *OldSucc,
310 std::vector<BasicBlock*> worklist;
311 worklist.push_back(OldSucc);
313 const BlockCacheEntry *
Entry = getBlockEntry(OldSucc);
314 if (!Entry ||
Entry->OverDefined.empty())
317 Entry->OverDefined.end());
323 while (!worklist.empty()) {
328 if (ToUpdate == NewSucc)
continue;
331 BlockCacheEntry *WorklistEntry =
332 ToUpdate->
getNumber() < BlockCache.size()
333 ? BlockCache[ToUpdate->
getNumber()].get()
335 if (!WorklistEntry || WorklistEntry->OverDefined.empty())
337 auto &ValueSet = WorklistEntry->OverDefined;
339 bool changed =
false;
340 for (
Value *
V : ValsToClear) {
341 if (!ValueSet.erase(
V))
349 if (!changed)
continue;
360 LazyValueInfoImpl *LVIImpl;
366 LazyValueInfoAnnotatedWriter(LazyValueInfoImpl *L, DominatorTree &DTree)
367 : LVIImpl(
L), DT(DTree) {}
369 void emitBasicBlockStartAnnot(
const BasicBlock *BB,
370 formatted_raw_ostream &OS)
override;
372 void emitInstructionAnnot(
const Instruction *
I,
373 formatted_raw_ostream &OS)
override;
378 const bool PerPredRanges;
381 LazyValueInfoCache TheCache;
393 bool pushBlockValue(
const std::pair<BasicBlock *, Value *> &BV) {
394 if (!BlockValueSet.insert(BV).second)
398 << BV.first->getName() <<
"\n");
399 BlockValueStack.push_back(BV);
410 std::optional<ValueLatticeElement> getBlockValue(
Value *Val,
BasicBlock *BB,
420 std::optional<ValueLatticeElement> solveBlockValueImpl(
Value *Val,
422 std::optional<ValueLatticeElement> solveBlockValueNonLocal(
Value *Val,
424 std::optional<ValueLatticeElement> solveBlockValuePHINode(
PHINode *PN,
426 std::optional<ValueLatticeElement> solveBlockValueSelect(
SelectInst *S,
430 std::optional<ValueLatticeElement> solveBlockValueBinaryOpImpl(
434 std::optional<ValueLatticeElement>
436 std::optional<ValueLatticeElement> solveBlockValueCast(
CastInst *CI,
438 std::optional<ValueLatticeElement>
440 std::optional<ValueLatticeElement> solveBlockValueIntrinsic(
IntrinsicInst *
II,
442 std::optional<ValueLatticeElement>
444 std::optional<ValueLatticeElement>
447 void intersectAssumeOrGuardBlockValueConstantRange(
Value *Val,
457 std::optional<ValueLatticeElement>
462 std::optional<ValueLatticeElement>
463 getValueFromICmpCondition(
Value *Val,
ICmpInst *ICI,
bool isTrueDest,
468 std::optional<ValueLatticeElement>
470 bool UseBlockValue,
unsigned Depth = 0);
472 std::optional<ValueLatticeElement> getEdgeValueLocal(
Value *Val,
499 bool AssumeFrozen =
false);
508 LazyValueInfoAnnotatedWriter Writer(
this, DTree);
509 F.print(OS, &Writer);
519 TheCache.eraseBlock(BB);
529 TheCache(
F, PerPredRanges), AC(AC), DL(DL), GuardDecl(GuardDecl) {}
533void LazyValueInfoImpl::solve() {
537 unsigned processedCount = 0;
538 while (!BlockValueStack.empty()) {
550 dbgs() <<
"Giving up on stack because we are getting too deep\n");
552 while (!StartingStack.
empty()) {
553 std::pair<BasicBlock *, Value *> &
e = StartingStack.
back();
554 TheCache.insertResult(
e.second,
e.first,
558 BlockValueSet.clear();
559 BlockValueStack.clear();
562 std::pair<BasicBlock *, Value *>
e = BlockValueStack.back();
563 assert(BlockValueSet.count(e) &&
"Stack value should be in BlockValueSet!");
564 unsigned StackSize = BlockValueStack.size();
567 if (solveBlockValue(
e.second,
e.first)) {
569 assert(BlockValueStack.size() == StackSize &&
570 BlockValueStack.back() == e &&
"Nothing should have been pushed!");
572 std::optional<ValueLatticeElement> BBLV =
573 TheCache.getCachedValueInfo(
e.second,
e.first);
574 assert(BBLV &&
"Result should be in cache!");
576 dbgs() <<
"POP " << *
e.second <<
" in " <<
e.first->getName() <<
" = "
580 BlockValueStack.pop_back();
581 BlockValueSet.erase(e);
584 assert(BlockValueStack.size() == StackSize + 1 &&
585 "Exactly one element should have been pushed!");
590std::optional<ValueLatticeElement>
597 if (std::optional<ValueLatticeElement> OptLatticeVal =
598 TheCache.getCachedValueInfo(Val, BB)) {
599 intersectAssumeOrGuardBlockValueConstantRange(Val, *OptLatticeVal, CtxI);
600 return OptLatticeVal;
604 if (!pushBlockValue({ BB, Val }))
615 case Instruction::Call:
616 case Instruction::Invoke:
620 case Instruction::Load:
634 assert(!TheCache.getCachedValueInfo(Val, BB) &&
635 "Value should not be in cache");
639 std::optional<ValueLatticeElement> Res = solveBlockValueImpl(Val, BB);
644 TheCache.insertResult(Val, BB, *Res);
648std::optional<ValueLatticeElement>
652 return solveBlockValueNonLocal(Val, BB);
655 return solveBlockValuePHINode(PN, BB);
658 return solveBlockValueSelect(SI, BB);
675 return solveBlockValueCast(CI, BB);
678 return solveBlockValueBinaryOp(BO, BB);
681 return solveBlockValueInsertElement(IEI, BB);
684 return solveBlockValueExtractValue(EVI, BB);
687 return solveBlockValueIntrinsic(
II, BB);
691 <<
"' - unknown inst def found.\n");
696 bool IsDereferenced =
true) {
710 if (
MI->isVolatile())
return;
714 if (!Len || Len->isZero())
return;
720 for (
auto &U : CB->args()) {
721 if (U->getType()->isPointerTy() &&
722 CB->paramHasNonNullAttr(CB->getArgOperandNo(&U),
729bool LazyValueInfoImpl::isNonNullAtEndOfBlock(
Value *Val,
BasicBlock *BB) {
735 return TheCache.isNonNullAtEndOfBlock(Val, BB, [](BasicBlock *BB) {
736 NonNullPointerSet NonNullPointers;
737 for (Instruction &
I : *BB)
739 return NonNullPointers;
743std::optional<ValueLatticeElement>
744LazyValueInfoImpl::solveBlockValueNonLocal(
Value *Val,
BasicBlock *BB) {
745 ValueLatticeElement
Result;
764 std::optional<BBLatticeElementMap> PredLatticeElements;
766 PredLatticeElements = std::make_optional<BBLatticeElementMap>();
771 std::optional<ValueLatticeElement> EdgeResult = getEdgeValue(Val,
Pred, BB);
776 Result.mergeIn(*EdgeResult);
780 if (
Result.isOverdefined()) {
782 <<
"' - overdefined because of pred '"
783 <<
Pred->getName() <<
"' (non local).\n");
787 PredLatticeElements->insert({
Pred, *EdgeResult});
791 TheCache.insertPredecessorResults(Val, BB, *PredLatticeElements);
798std::optional<ValueLatticeElement>
800 ValueLatticeElement
Result;
805 std::optional<BBLatticeElementMap> PredLatticeElements;
807 PredLatticeElements = std::make_optional<BBLatticeElementMap>();
814 std::optional<ValueLatticeElement> EdgeResult =
815 getEdgeValue(PhiVal, PhiBB, BB, PN);
820 Result.mergeIn(*EdgeResult);
824 if (
Result.isOverdefined()) {
826 <<
"' - overdefined because of pred (local).\n");
832 PredLatticeElements->insert({PhiBB, *EdgeResult});
836 TheCache.insertPredecessorResults(PN, BB, *PredLatticeElements);
839 assert(!
Result.isOverdefined() &&
"Possible PHI in entry block?");
845void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange(
852 for (
auto &AssumeVH : AC->assumptionsFor(Val)) {
865 auto OBU =
I->getOperandBundleAt(AssumeVH.Index);
867 case BundleAttr::Range: {
876 I->getOperandBundleAt(AssumeVH.Index)))
881 BBLV = BBLV.
intersect(*getValueFromCondition(Val,
I->getArgOperand(0),
888 if (GuardDecl && !GuardDecl->use_empty() &&
890 for (Instruction &
I :
905 isNonNullAtEndOfBlock(Val, BB))
910std::optional<ValueLatticeElement>
913 std::optional<ValueLatticeElement> OptTrueVal =
914 getBlockValue(
SI->getTrueValue(), BB, SI);
917 ValueLatticeElement &
TrueVal = *OptTrueVal;
919 std::optional<ValueLatticeElement> OptFalseVal =
920 getBlockValue(
SI->getFalseValue(), BB, SI);
923 ValueLatticeElement &
FalseVal = *OptFalseVal;
926 const ConstantRange &TrueCR =
TrueVal.asConstantRange(
SI->getType());
927 const ConstantRange &FalseCR =
FalseVal.asConstantRange(
SI->getType());
934 ((
LHS ==
SI->getTrueValue() &&
RHS ==
SI->getFalseValue()) ||
935 (
RHS ==
SI->getTrueValue() &&
LHS ==
SI->getFalseValue()))) {
936 ConstantRange ResultCR = [&]() {
941 return TrueCR.
smin(FalseCR);
943 return TrueCR.
umin(FalseCR);
945 return TrueCR.
smax(FalseCR);
947 return TrueCR.
umax(FalseCR);
951 ResultCR,
TrueVal.isConstantRangeIncludingUndef() ||
952 FalseVal.isConstantRangeIncludingUndef());
956 if (
LHS ==
SI->getTrueValue())
958 TrueCR.
abs(),
TrueVal.isConstantRangeIncludingUndef());
959 if (
LHS ==
SI->getFalseValue())
961 FalseCR.
abs(),
FalseVal.isConstantRangeIncludingUndef());
966 if (
LHS ==
SI->getTrueValue())
969 if (
LHS ==
SI->getFalseValue())
983 TrueVal.intersect(*getValueFromCondition(
SI->getTrueValue(),
Cond,
987 FalseVal.intersect(*getValueFromCondition(
SI->getFalseValue(),
Cond,
996std::optional<ConstantRange>
998 std::optional<ValueLatticeElement> OptVal = getBlockValue(
V, BB, CtxI);
1000 return std::nullopt;
1001 return OptVal->asConstantRange(
V->getType());
1004std::optional<ValueLatticeElement>
1010 case Instruction::Trunc:
1011 case Instruction::SExt:
1012 case Instruction::ZExt:
1017 <<
"' - overdefined (unknown cast).\n");
1024 std::optional<ConstantRange> LHSRes = getRangeFor(CI->
getOperand(0), CI, BB);
1027 return std::nullopt;
1028 const ConstantRange &LHSRange = *LHSRes;
1035 ConstantRange Res = ConstantRange::getEmpty(ResultBitWidth);
1037 Res = LHSRange.
truncate(ResultBitWidth,
Trunc->getNoWrapKind());
1044std::optional<ValueLatticeElement>
1045LazyValueInfoImpl::solveBlockValueBinaryOpImpl(
1052 auto ThreadBinOpOverSelect =
1053 [&](
Value *
X,
const ConstantRange &CRX, SelectInst *
Y,
1054 bool XIsLHS) -> std::optional<ValueLatticeElement> {
1059 return std::nullopt;
1062 return std::nullopt;
1064 return std::nullopt;
1066 ConstantRange TrueX =
1067 CRX.intersectWith(getValueFromCondition(
X,
Cond,
true,
1069 ->asConstantRange(
X->getType()));
1070 ConstantRange FalseX =
1071 CRX.intersectWith(getValueFromCondition(
X,
Cond,
false,
1073 ->asConstantRange(
X->getType()));
1079 OpFn(TrueX, TrueY).unionWith(OpFn(FalseX, FalseY)));
1081 OpFn(TrueY, TrueX).unionWith(OpFn(FalseY, FalseX)));
1088 std::optional<ConstantRange> LHSRes = getRangeFor(
LHS,
I, BB);
1090 return std::nullopt;
1094 if (
auto Res = ThreadBinOpOverSelect(
LHS, *LHSRes, SI,
true))
1098 std::optional<ConstantRange> RHSRes = getRangeFor(
RHS,
I, BB);
1100 return std::nullopt;
1104 if (
auto Res = ThreadBinOpOverSelect(
RHS, *RHSRes, SI,
false))
1108 const ConstantRange &LHSRange = *LHSRes;
1109 const ConstantRange &RHSRange = *RHSRes;
1111 std::optional<ValueLatticeElement> MergedResult =
1115 return MergedResult;
1117 std::optional<BBLatticeElementMap> PredLHS =
1118 TheCache.getCachedPredecessorInfo(
LHS, BB);
1120 return MergedResult;
1121 std::optional<BBLatticeElementMap> PredRHS =
1122 TheCache.getCachedPredecessorInfo(
RHS, BB);
1124 return MergedResult;
1126 const BBLatticeElementMap &LHSPredMap = *PredLHS;
1127 const BBLatticeElementMap &RHSPredMap = *PredRHS;
1129 BBLatticeElementMap PredLatticeElements;
1130 ValueLatticeElement OverallPredResult;
1132 auto LHSIt = LHSPredMap.find_as(
Pred);
1133 if (LHSIt == LHSPredMap.end())
1134 return MergedResult;
1135 const ValueLatticeElement &LHSFromPred = LHSIt->second;
1136 std::optional<ConstantRange> LHSFromPredRes =
1138 if (!LHSFromPredRes)
1139 return MergedResult;
1141 auto RHSIt = RHSPredMap.find_as(
Pred);
1142 if (RHSIt == RHSPredMap.end())
1143 return MergedResult;
1144 const ValueLatticeElement &RHSFromPred = RHSIt->second;
1145 std::optional<ConstantRange> RHSFromPredRes =
1147 if (!RHSFromPredRes)
1148 return MergedResult;
1150 const ConstantRange &LHSFromPredRange = *LHSFromPredRes;
1151 const ConstantRange &RHSFromPredRange = *RHSFromPredRes;
1152 std::optional<ValueLatticeElement> PredResult =
1155 return MergedResult;
1156 if (PredResult->isOverdefined()) {
1158 dbgs() <<
" pred BB '" <<
Pred->getName() <<
"' for BB '"
1160 <<
"' overdefined. Discarding all predecessor intervals.\n");
1161 return MergedResult;
1163 PredLatticeElements.insert({
Pred, *PredResult});
1164 OverallPredResult.
mergeIn(*PredResult);
1170 TheCache.insertPredecessorResults(
I, BB, PredLatticeElements);
1173 <<
" to: " << OverallPredResult <<
".\n");
1176 return OverallPredResult;
1179 << OverallPredResult <<
" and " << MergedResult <<
".\n");
1180 return MergedResult->intersect(OverallPredResult);
1183std::optional<ValueLatticeElement>
1186 "all operands to binary operators are sized");
1188 return solveBlockValueBinaryOpImpl(
1189 BO, BB, [BO](
const ConstantRange &CR1,
const ConstantRange &CR2) {
1194std::optional<ValueLatticeElement>
1197 return solveBlockValueBinaryOpImpl(
1198 WO, BB, [WO](
const ConstantRange &CR1,
const ConstantRange &CR2) {
1203std::optional<ValueLatticeElement>
1208 <<
"' - unknown intrinsic.\n");
1214 std::optional<ConstantRange>
Range = getRangeFor(
Op,
II, BB);
1216 return std::nullopt;
1225std::optional<ValueLatticeElement>
1228 std::optional<ValueLatticeElement> OptEltVal =
1231 return std::nullopt;
1232 ValueLatticeElement &Res = *OptEltVal;
1234 std::optional<ValueLatticeElement> OptVecVal =
1237 return std::nullopt;
1243 if (OptEltVal->isConstant())
1250std::optional<ValueLatticeElement>
1255 return solveBlockValueOverflowIntrinsic(WO, BB);
1262 return getBlockValue(
V, BB, EVI);
1265 <<
"' - overdefined (unknown extractvalue).\n");
1303std::optional<ValueLatticeElement>
1308 bool UseBlockValue) {
1312 RHSRange =
C->toConstantRange();
1313 }
else if (UseBlockValue) {
1314 std::optional<ValueLatticeElement>
R =
1317 return std::nullopt;
1321 ConstantRange TrueValues =
1326static std::optional<ConstantRange>
1329 bool Invert =
false;
1336 if (
RHS.isMaxSignedValue())
1337 return std::nullopt;
1341 if (
auto CR = Fn(
RHS))
1342 return Invert ? CR->inverse() : CR;
1343 return std::nullopt;
1349 unsigned BitWidth =
RHS->getType()->getScalarSizeInBits();
1368static std::optional<ConstantRange>
1371 if (!
V->getType()->isIntegerTy())
1372 return std::nullopt;
1376 return std::nullopt;
1383 ConstantRange::getFull(
V->getType()->getScalarSizeInBits());
1390 return std::nullopt;
1394std::optional<ValueLatticeElement> LazyValueInfoImpl::getValueFromICmpCondition(
1395 Value *Val,
ICmpInst *ICI,
bool isTrueDest,
bool UseBlockValue) {
1409 Result.setMayHaveDifferentProvenance(
true);
1427 return getValueFromSimpleICmpCondition(EdgePred,
RHS,
Offset, ICI,
1432 return getValueFromSimpleICmpCondition(SwappedPred,
LHS,
Offset, ICI,
1438 const APInt *
Mask, *
C;
1472 const APInt *ShAmtC;
1477 EdgePred, *
C, [&](
const APInt &
RHS) -> std::optional<ConstantRange> {
1478 APInt
New =
RHS << *ShAmtC;
1479 if ((
New.ashr(*ShAmtC)) !=
RHS)
1480 return std::nullopt;
1510 if (
Trunc->getOperand(0) != Val)
1515 if (
Trunc->hasNoUnsignedWrap()) {
1548std::optional<ValueLatticeElement>
1550 bool IsTrueDest,
bool UseBlockValue,
1553 return getValueFromICmpCondition(Val, ICI, IsTrueDest, UseBlockValue);
1556 return getValueFromTrunc(Val,
Trunc, IsTrueDest);
1568 return getValueFromCondition(Val,
N, !IsTrueDest, UseBlockValue,
Depth);
1579 std::optional<ValueLatticeElement> LV =
1580 getValueFromCondition(Val, L, IsTrueDest, UseBlockValue,
Depth);
1582 return std::nullopt;
1583 std::optional<ValueLatticeElement> RV =
1584 getValueFromCondition(Val, R, IsTrueDest, UseBlockValue,
Depth);
1586 return std::nullopt;
1592 if (IsTrueDest ^ IsAnd) {
1597 return LV->intersect(*RV);
1618 const APInt &OpConstVal,
1633 assert((Op0Match || Op1Match) &&
1634 "Operand 0 nor Operand 1 isn't a match");
1649std::optional<ValueLatticeElement>
1657 if (BI->getSuccessor(0) != BI->getSuccessor(1)) {
1658 bool isTrueDest = BI->getSuccessor(0) == BBTo;
1659 assert(BI->getSuccessor(!isTrueDest) == BBTo &&
1660 "BBTo isn't a successor of BBFrom");
1661 Value *Condition = BI->getCondition();
1666 if (Condition == Val)
1672 std::optional<ValueLatticeElement>
Result =
1673 getValueFromCondition(Val, Condition, isTrueDest, UseBlockValue);
1675 return std::nullopt;
1677 if (!
Result->isOverdefined())
1681 assert(
Result->isOverdefined() &&
"Result isn't overdefined");
1687 Value *TempCond = Condition;
1698 APInt ConditionVal(1, isTrueDest ^ (TempCond != Condition) ? 1 : 0);
1701 ValueLatticeElement OpLatticeVal =
1702 *getValueFromCondition(Usr->getOperand(0), Condition,
1706 const unsigned ResultBitWidth =
1707 Usr->getType()->getScalarSizeInBits();
1711 ResultBitWidth,
Trunc->getNoWrapKind()));
1732 for (
unsigned i = 0; i < Usr->getNumOperands(); ++i) {
1733 Value *
Op = Usr->getOperand(i);
1734 ValueLatticeElement OpLatticeVal = *getValueFromCondition(
1735 Op, Condition, isTrueDest,
false);
1736 if (std::optional<APInt> OpConst =
1745 if (!
Result->isOverdefined())
1753 Value *Condition =
SI->getCondition();
1756 bool ValUsesConditionAndMayBeFoldable =
false;
1757 if (Condition != Val) {
1762 if (!ValUsesConditionAndMayBeFoldable)
1765 assert((Condition == Val || ValUsesConditionAndMayBeFoldable) &&
1766 "Condition != Val nor Val doesn't use Condition");
1768 bool DefaultCase =
SI->getDefaultDest() == BBTo;
1770 ConstantRange EdgesVals(
BitWidth, DefaultCase);
1772 for (
auto Case :
SI->cases()) {
1773 APInt CaseValue = Case.getCaseValue()->getValue();
1774 ConstantRange EdgeVal(CaseValue);
1775 if (ValUsesConditionAndMayBeFoldable) {
1778 ValueLatticeElement EdgeLatticeVal =
1791 if (Case.getCaseSuccessor() != BBTo && Condition == Val)
1792 EdgesVals = EdgesVals.difference(EdgeVal);
1793 }
else if (Case.getCaseSuccessor() == BBTo)
1794 EdgesVals = EdgesVals.unionWith(EdgeVal);
1803std::optional<ValueLatticeElement>
1810 std::optional<ValueLatticeElement> LocalResult =
1811 getEdgeValueLocal(Val, BBFrom, BBTo,
true);
1813 return std::nullopt;
1819 std::optional<ValueLatticeElement> OptInBlock =
1822 return std::nullopt;
1823 ValueLatticeElement &
InBlock = *OptInBlock;
1833 intersectAssumeOrGuardBlockValueConstantRange(Val,
InBlock, CtxI);
1835 return LocalResult->intersect(
InBlock);
1840 LLVM_DEBUG(
dbgs() <<
"LVI Getting block end value " << *V <<
" at '"
1843 assert(BlockValueStack.empty() && BlockValueSet.empty());
1844 std::optional<ValueLatticeElement> OptResult = getBlockValue(V, BB, CtxI);
1847 OptResult = getBlockValue(V, BB, CtxI);
1848 assert(OptResult &&
"Value not available after solving");
1865 intersectAssumeOrGuardBlockValueConstantRange(V, Result, CtxI);
1874 LLVM_DEBUG(
dbgs() <<
"LVI Getting edge value " << *V <<
" from '"
1878 std::optional<ValueLatticeElement> Result =
1879 getEdgeValue(V, FromBB, ToBB, CtxI);
1885 Result = getEdgeValue(V, FromBB, ToBB, CtxI);
1894 bool AssumeFrozen) {
1902 const Use *CurrU = &U;
1903 const unsigned MaxUsesToInspect = 6;
1904 for (
unsigned I = 0;
I < MaxUsesToInspect; ++
I) {
1905 std::optional<ValueLatticeElement> CondVal;
1909 if (DebugUsers && CurrU != &U)
1917 if (
I != 0 && !
isa<PHINode>(CurrI) && CurrI->getParent() != LastQueriedBB) {
1930 if (CurrU->getOperandNo() == 1)
1932 *getValueFromCondition(V,
SI->getCondition(),
true,
1934 else if (CurrU->getOperandNo() == 2)
1936 *getValueFromCondition(V,
SI->getCondition(),
false,
1940 CondVal = *getEdgeValueLocal(V,
PHI->getIncomingBlock(*CurrU),
1941 PHI->getParent(),
false);
1955 if (!CurrI->hasOneUse() ||
1971 TheCache.threadEdgeImpl(OldSucc, NewSucc);
1982 if (
auto *Impl = Info.getImpl())
2002 F->getParent(), Intrinsic::experimental_guard);
2014 if (
auto *Impl = getImpl()) {
2021 FunctionAnalysisManager::Invalidator &Inv) {
2047 V =
V->stripPointerCasts();
2063 if (Result.isConstant())
2064 C = Result.getConstant();
2065 else if (Result.isConstantRange())
2066 if (
const APInt *SingleVal = Result.getConstantRange().getSingleElement())
2067 C = ConstantInt::get(
V->getType(), *SingleVal);
2071 if (Result.mayHaveDifferentProvenance()) {
2074 assert(U->get() ==
V &&
"Must be a use of V.");
2093 bool UndefAllowed) {
2096 return Result.asConstantRange(V->getType(), UndefAllowed);
2100 const Use &U,
bool UndefAllowed,
2103 getOrCreateImpl().getValueAtUse(U, DebugUsers, AssumeFrozen);
2104 return Result.asConstantRange(U->getType(), UndefAllowed);
2113 getOrCreateImpl().getValueOnEdge(V, FromBB, ToBB, CtxI);
2122 getOrCreateImpl().getValueOnEdge(V, FromBB, ToBB, CtxI);
2124 return Result.asConstantRange(V->getType(),
true);
2174 getOrCreateImpl().getValueOnEdge(V, FromBB, ToBB, CtxI);
2181 bool UseBlockValue) {
2191 if (V->getType()->isPointerTy() &&
C->isNullValue() &&
2200 auto &Impl = getOrCreateImpl();
2202 UseBlockValue ? Impl.getValueInBlock(V, CtxI->
getParent(), CtxI)
2203 : Impl.getValueAt(V, CtxI);
2243 if (
PHI->getParent() == BB) {
2245 for (
unsigned i = 0, e =
PHI->getNumIncomingValues(); i < e; i++) {
2246 Value *Incoming =
PHI->getIncomingValue(i);
2254 Baseline = (i == 0) ? Result
2255 : (Baseline == Result ? Baseline
2274 while (++PI != PE) {
2276 if (Ret != Baseline)
2291 bool UseBlockValue) {
2301 if (UseBlockValue) {
2303 getOrCreateImpl().getValueInBlock(LHS, CtxI->
getParent(), CtxI);
2304 if (L.isOverdefined())
2308 getOrCreateImpl().getValueInBlock(RHS, CtxI->
getParent(), CtxI);
2317 if (
auto *Impl = getImpl())
2318 Impl->threadEdge(PredBB, OldSucc, NewSucc);
2322 if (
auto *Impl = getImpl())
2323 Impl->forgetValue(V);
2327 if (
auto *Impl = getImpl())
2328 Impl->eraseBlock(BB);
2332 if (
auto *Impl = getImpl())
2337 if (
auto *Impl = getImpl())
2338 Impl->printLVI(F, DTree, OS);
2342void LazyValueInfoAnnotatedWriter::emitBasicBlockStartAnnot(
2346 for (
const auto &Arg :
F->args()) {
2349 if (Result.isUnknown())
2351 OS <<
"; LatticeVal for: '" << Arg <<
"' is: " << Result <<
"\n";
2359void LazyValueInfoAnnotatedWriter::emitInstructionAnnot(
2360 const Instruction *
I, formatted_raw_ostream &OS) {
2363 SmallPtrSet<const BasicBlock*, 16> BlocksContainingLVI;
2369 auto printResult = [&](
const BasicBlock *BB) {
2370 if (!BlocksContainingLVI.
insert(BB).second)
2374 OS <<
"; LatticeVal for: '" << *
I <<
"' in BB: '";
2376 OS <<
"' is: " <<
Result <<
"\n";
2379 printResult(ParentBB);
2382 for (
const auto *BBSucc :
successors(ParentBB))
2384 printResult(BBSucc);
2387 for (
const auto *U :
I->users())
2390 printResult(UseI->getParent());
2396 OS <<
"LVI for function '" <<
F.getName() <<
"':\n";
2399 LVI.printLVI(
F, DTree, OS);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static const Function * getParent(const Value *V)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseSet and SmallDenseSet classes.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Module.h This file contains the declarations for the Module class.
static bool isOperationFoldable(User *Usr)
static std::optional< ConstantRange > getRangeForNUWMulSquare(const Value *V, CmpInst::Predicate Pred, const Value *LHS, const Value *RHS)
Get the unsigned range for V from a mul nuw V, V comparison.
static void AddNonNullPointer(Value *Ptr, NonNullPointerSet &PtrSet, bool IsDereferenced=true)
static void AddNonNullPointersByInstruction(Instruction *I, NonNullPointerSet &PtrSet)
static Constant * getConstantFromLattice(const ValueLatticeElement &Result, Value *V, const Use *U, const DataLayout &DL)
Return the constant V is known to be equal to from Result, if any.
static std::optional< ConstantRange > getRangeViaSLT(CmpInst::Predicate Pred, APInt RHS, function_ref< std::optional< ConstantRange >(const APInt &)> Fn)
static const unsigned MaxProcessedPerValue
static ValueLatticeElement getValueFromICmpCtpop(ICmpInst::Predicate Pred, Value *RHS)
Get value range for a "ctpop(Val) Pred RHS" condition.
static bool usesOperand(User *Usr, Value *Op)
static ValueLatticeElement constantFoldUser(User *Usr, Value *Op, const APInt &OpConstVal, const DataLayout &DL)
static ValueLatticeElement getFromRangeMetadata(Instruction *BBI)
static Constant * getPredicateResult(CmpInst::Predicate Pred, Constant *C, const ValueLatticeElement &Val, const DataLayout &DL)
static ValueLatticeElement getValueFromOverflowCondition(Value *Val, WithOverflowInst *WO, bool IsTrueDest)
static bool isKnownNonConstant(Value *V)
Returns true if we can statically tell that this value will never be a "useful" constant.
static bool matchICmpOperand(APInt &Offset, Value *LHS, Value *Val, ICmpInst::Predicate Pred)
static void eraseBlock(MachineBasicBlock *MBB, LiveIntervals &LIS, MachineDomTreeUpdater &MDTU)
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
SmallVector< MachineOperand, 4 > Cond
static bool InBlock(const Value *V, const BasicBlock *BB)
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
Class for arbitrary precision integers.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
This templated class represents "all analyses that operate over <aparticular IR unit>" (e....
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
This class represents an incoming formal argument to a Function.
A function analysis which provides an AssumptionCache.
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
unsigned getNumber() const
iterator begin()
Instruction iterator methods.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI bool isEntryBlock() const
Return true if this is the entry block of the containing function.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
LLVM_ABI unsigned getNoWrapKind() const
Returns one of OBO::NoSignedWrap or OBO::NoUnsignedWrap.
LLVM_ABI Instruction::BinaryOps getBinaryOp() const
Returns the binary operation underlying the intrinsic.
BinaryOps getOpcode() const
Value handle with callbacks on RAUW and destruction.
This is the base class for all instructions that perform data casts.
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Type * getDestTy() const
Return the destination type, as a convenience.
static Type * makeCmpResultType(Type *opnd_type)
Create a result type for fcmp/icmp.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ ICMP_ULT
unsigned less than
@ ICMP_SGE
signed greater or equal
@ ICMP_ULE
unsigned less or equal
Predicate getSwappedPredicate() const
For example, EQ->EQ, SLE->SGE, ULT->UGT, OEQ->OEQ, ULE->UGE, OLT->OGT, etc.
Predicate getInversePredicate() const
For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...
Predicate getPredicate() const
Return the predicate for this instruction.
This is the shared class of boolean and integer constants.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
This class represents a range of values.
LLVM_ABI ConstantRange subtract(const APInt &CI) const
Subtract the specified constant from the endpoints of this constant range.
static LLVM_ABI ConstantRange fromKnownBits(const KnownBits &Known, bool IsSigned)
Initialize a range based on a known bits constraint.
LLVM_ABI ConstantRange sqrtFloor() const
Calculate sqrtFloor range. See APInt::sqrtFloor().
LLVM_ABI 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...
LLVM_ABI ConstantRange umin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned minimum of a value in ...
LLVM_ABI APInt getUnsignedMin() const
Return the smallest unsigned value contained in the ConstantRange.
LLVM_ABI bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type.
LLVM_ABI bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const
Does the predicate Pred hold between ranges this and Other?
static LLVM_ABI ConstantRange intrinsic(Intrinsic::ID IntrinsicID, ArrayRef< ConstantRange > Ops)
Compute range of intrinsic result for the given operand ranges.
LLVM_ABI bool isEmptySet() const
Return true if this set contains no members.
LLVM_ABI ConstantRange abs(bool IntMinIsPoison=false) const
Calculate absolute value range.
static LLVM_ABI bool isIntrinsicSupported(Intrinsic::ID IntrinsicID)
Returns true if ConstantRange calculations are supported for intrinsic with IntrinsicID.
bool isSingleElement() const
Return true if this set contains exactly one member.
LLVM_ABI ConstantRange truncate(uint32_t BitWidth, unsigned NoWrapKind=0) const
Return a new range in the specified integer type, which must be strictly smaller than the current typ...
LLVM_ABI ConstantRange umax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an unsigned maximum of a value in ...
static LLVM_ABI 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 LLVM_ABI 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...
LLVM_ABI ConstantRange inverse() const
Return a new range that is the logical not of the current set.
LLVM_ABI APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
static LLVM_ABI ConstantRange makeMaskNotEqualRange(const APInt &Mask, const APInt &C)
Initialize a range containing all values X that satisfy (X & Mask) / != C.
static ConstantRange getNonEmpty(APInt Lower, APInt Upper)
Create non-empty constant range with the given bounds.
LLVM_ABI ConstantRange smin(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed minimum of a value in thi...
uint32_t getBitWidth() const
Get the bit width of this ConstantRange.
LLVM_ABI ConstantRange smax(const ConstantRange &Other) const
Return a new range representing the possible values resulting from a signed maximum of a value in thi...
LLVM_ABI 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...
static LLVM_ABI 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.
This is an important base class in LLVM.
static LLVM_ABI 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...
LLVM_ABI ConstantRange toConstantRange() const
Convert constant to an approximate constant range.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
Implements a dense probed hash-table based set.
Analysis pass which computes a DominatorTree.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
FunctionPass class - This class is used to implement most global optimizations.
unsigned getMaxBlockNumber() const
Return a value larger than the largest block number.
unsigned getBlockNumberEpoch() const
Return the "epoch" of current block numbers.
Module * getParent()
Get the module that this global value is contained inside of...
This instruction compares its operands according to the predicate given to the constructor.
static bool isEquality(Predicate P)
Return true if this predicate is either EQ or NE.
This instruction inserts a single (scalar) element into a VectorType value.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
A wrapper class for inspecting calls to intrinsic functions.
Analysis to compute lazy value information.
LLVM_ABI Result run(Function &F, FunctionAnalysisManager &FAM)
LazyValueInfoImpl(Function *F, AssumptionCache *AC, const DataLayout &DL, Function *GuardDecl)
ValueLatticeElement getValueOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CtxI=nullptr)
This is the query interface to determine the lattice value for the specified Value* that is true on t...
ValueLatticeElement getValueAt(Value *V, Instruction *CtxI)
This is the query interface to determine the lattice value for the specified Value* at the specified ...
ValueLatticeElement getValueInBlock(Value *V, BasicBlock *BB, Instruction *CtxI=nullptr)
This is the query interface to determine the lattice value for the specified Value* at the context in...
void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc)
This is the update interface to inform the cache that an edge from PredBB to OldSucc has been threade...
ValueLatticeElement getValueAtUse(const Use &U, SmallVectorImpl< DbgVariableRecord * > *DebugUsers=nullptr, bool AssumeFrozen=false)
void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS)
Printing the LazyValueInfo Analysis.
void forgetValue(Value *V)
This is part of the update interface to remove information related to this value from the cache.
void eraseBlock(BasicBlock *BB)
This is part of the update interface to inform the cache that a block has been deleted.
void clear()
Complete flush all previously computed values.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Wrapper around LazyValueInfo.
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void releaseMemory() override
releaseMemory() - This member can be implemented by a pass if it wants to be able to release its memo...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
LazyValueInfoWrapperPass()
This pass computes, caches, and vends lazy value constraint information.
LLVM_ABI ConstantRange getConstantRangeAtUse(const Use &U, bool UndefAllowed, SmallVectorImpl< DbgVariableRecord * > *DebugUsers=nullptr, bool AssumeFrozen=false)
Return the ConstantRange constraint that is known to hold for the value at a specific use-site.
LLVM_ABI void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
LLVM_ABI Constant * getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CtxI=nullptr, const Use *U=nullptr)
Determine whether the specified value is known to be a constant on the specified edge.
LLVM_ABI 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...
LLVM_ABI void releaseMemory()
LLVM_ABI Constant * getConstant(Value *V, Instruction *CtxI, const Use *U=nullptr)
Determine whether the specified value is known to be a constant at the specified instruction.
LLVM_ABI void printLVI(Function &F, DominatorTree &DTree, raw_ostream &OS)
Print the \LazyValueInfo Analysis.
LLVM_ABI Constant * getPredicateAt(CmpInst::Predicate Pred, Value *V, Constant *C, Instruction *CtxI, bool UseBlockValue)
Determine whether the specified value comparison with a constant is known to be true or false at the ...
LLVM_ABI void forgetValue(Value *V)
Remove information related to this value from the cache.
LLVM_ABI ConstantRange getConstantRange(Value *V, Instruction *CtxI, bool UndefAllowed)
Return the ConstantRange constraint that is known to hold for the specified value at the specified in...
LLVM_ABI void clear()
Complete flush all previously computed values.
LLVM_ABI ConstantRange getConstantRangeOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CtxI=nullptr)
Return the ConstantRage constraint that is known to hold for the specified value on the specified edg...
LLVM_ABI ~LazyValueInfo()
LLVM_ABI bool invalidate(Function &F, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
LLVM_ABI Constant * getPredicateOnEdge(CmpInst::Predicate Pred, Value *V, Constant *C, BasicBlock *FromBB, BasicBlock *ToBB, Instruction *CtxI=nullptr)
Determine whether the specified value comparison with a constant is known to be true or false on the ...
An instruction for reading from memory.
This is the common base class for memset/memcpy/memmove.
This class wraps the llvm.memcpy/memmove intrinsics.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
This class represents the LLVM 'select' instruction.
Implements a dense probed hash-table based set with some number of buckets stored inline.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
This class represents a truncation of integer types.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getIntegerBitWidth() const
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isSized() const
Return true if it makes sense to take the size of this type.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
This class represents lattice values for constants.
static ValueLatticeElement getRange(ConstantRange CR, bool MayIncludeUndef=false)
bool isOverdefined() const
static ValueLatticeElement getNot(Constant *C)
ConstantRange asConstantRange(unsigned BW, bool UndefAllowed=false) const
bool isNotConstant() const
std::optional< APInt > asConstantInteger() const
const ConstantRange & getConstantRange(bool UndefAllowed=true) const
Returns the constant range for this value.
bool isConstantRange(bool UndefAllowed=true) const
Returns true if this value is a constant range.
static ValueLatticeElement get(Constant *C)
Constant * getNotConstant() const
LLVM_ABI ValueLatticeElement intersect(const ValueLatticeElement &Other) const
Combine two sets of facts about the same value into a single set of facts.
Constant * getConstant() const
bool mergeIn(const ValueLatticeElement &RHS, MergeOptions Opts=MergeOptions())
Updates this object to approximate both this object and RHS.
static ValueLatticeElement getOverdefined()
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
LLVM_ABI 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.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
Represents an op.with.overflow intrinsic.
std::pair< iterator, bool > insert(const ValueT &V)
bool erase(const ValueT &V)
iterator find_as(const LookupKeyT &Val)
Alternative version of find() which allows a different, and possibly less expensive,...
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
self_iterator getIterator()
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
@ BasicBlock
Various leaf nodes.
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
BinaryOp_match< SrcTy, SpecificConstantMatch, TargetOpcode::G_XOR, true > m_Not(const SrcTy &&Src)
Matches a register not-ed by a G_XOR.
match_combine_or< Ty... > m_CombineOr(const Ty &...Ps)
Combine pattern matchers matching any of Ps patterns.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
PtrToIntSameSize_match< OpTy > m_PtrToIntSameSize(const DataLayout &DL, const OpTy &Op)
BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::URem > m_URem(const LHS &L, const RHS &R)
ap_match< APInt > m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
BinaryOp_match< LHS, RHS, Instruction::And, true > m_c_And(const LHS &L, const RHS &R)
Matches an And with LHS and RHS in either order.
CastInst_match< OpTy, TruncInst > m_Trunc(const OpTy &Op)
Matches Trunc.
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
auto m_Value()
Match an arbitrary value and ignore it.
auto m_Ctpop(const Opnd0 &Op0)
auto m_LogicalOr()
Matches L || R where L and R are arbitrary values.
OverflowingBinaryOp_match< LHS, RHS, Instruction::Mul, OverflowingBinaryOperator::NoUnsignedWrap > m_NUWMul(const LHS &L, const RHS &R)
match_combine_or< BinaryOp_match< LHS, RHS, Instruction::Add >, DisjointOr_match< LHS, RHS > > m_AddLike(const LHS &L, const RHS &R)
Match either "add" or "or disjoint".
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
auto m_LogicalAnd()
Matches L && R where L and R are arbitrary values.
BinaryOp_match< LHS, RHS, Instruction::Or, true > m_c_Or(const LHS &L, const RHS &R)
Matches an Or with LHS and RHS in either order.
BinaryOp_match< LHS, RHS, Instruction::Sub > m_Sub(const LHS &L, const RHS &R)
@ User
could "use" a pointer
friend class Instruction
Iterator for Instructions in a `BasicBlock.
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
This is an optimization pass for GlobalISel generic memory operations.
BundleAttr getBundleAttrFromOBU(OperandBundleUse OBU)
@ Known
Known to have no common set bits.
auto pred_end(const MachineBasicBlock *BB)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
static ConstantRange getRange(Value *Op, SCCPSolver &Solver, const SmallPtrSetImpl< Value * > &InsertedValues)
Helper for getting ranges from Solver.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
LLVM_ABI bool assumeBundleImpliesNonNull(const Value *Val, const Function *Context, OperandBundleUse OBU)
LLVM_ABI bool isGuaranteedNotToBeUndef(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Returns true if V cannot be undef, but may be poison.
LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI Value * simplifyCastInst(unsigned CastOpc, Value *Op, Type *Ty, const SimplifyQuery &Q)
Given operands for a CastInst, fold the result or return null.
LLVM_ABI FunctionPass * createLazyValueInfoPass()
createLazyValueInfoPass - This creates an instance of the LazyValueInfo pass.
LLVM_ABI Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const Function *CtxF=nullptr)
Attempt to constant fold a compare instruction (icmp/fcmp) with the specified operands.
LLVM_ABI bool isValidAssumeForContext(const Instruction *I, const Instruction *CtxI, const DominatorTree *DT=nullptr, bool AllowEphemerals=false)
Return true if it is valid to use the assumptions provided by an assume intrinsic,...
const AnalysisOptions & getAnalysisOptions(const LLVMContext &C)
auto dyn_cast_or_null(const Y &Val)
constexpr unsigned MaxAnalysisRecursionDepth
LLVM_ABI bool canReplacePointersInUseIfEqual(const Use &U, const Value *To, const DataLayout &DL)
@ SPF_ABS
Floating point maxnum.
@ SPF_NABS
Absolute value.
@ SPF_UMIN
Signed minimum.
@ SPF_UMAX
Signed maximum.
@ SPF_SMAX
Unsigned minimum.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth, bool MustPreserveProvenance=false)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI Value * simplifyExtractValueInst(Value *Agg, ArrayRef< unsigned > Idxs, const SimplifyQuery &Q)
Given operands for an ExtractValueInst, fold the result or return null.
LLVM_ABI bool isNotCrossLaneOperation(const Instruction *I)
Return true if the instruction doesn't potentially cross vector lanes.
LLVM_ABI bool isKnownNonZero(const Value *V, const SimplifyQuery &Q, unsigned Depth=0)
Return true if the given value is known to be non-zero when defined.
LLVM_ABI Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
DWARFExpression::Operation Op
bool isSafeToSpeculativelyExecuteWithVariableReplaced(const Instruction *I, bool IgnoreUBImplyingAttrs=true)
Don't use information from its non-constant operands.
PredIterator< BasicBlock, Value::user_iterator > pred_iterator
static bool hasSingleValue(const ValueLatticeElement &Val)
constexpr unsigned BitWidth
auto pred_begin(const MachineBasicBlock *BB)
LLVM_ABI AssumeRangeInfo getAssumeRangeInfo(OperandBundleUse)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI 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...
LLVM_ABI void findDbgUsers(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the debug info records describing a value.
A special type used by analysis passes to provide an address that identifies that particular analysis...
SelectPatternFlavor Flavor
static bool isMinOrMax(SelectPatternFlavor SPF)
When implementing this min/max pattern as fcmp; select, does the fcmp have to be ordered?