36using namespace PatternMatch;
38#define DEBUG_TYPE "sccp"
69 CallBase *CB = dyn_cast<CallBase>(V);
79 <<
" as a constant\n");
83 LLVM_DEBUG(
dbgs() <<
" Constant: " << *Const <<
" = " << *V <<
'\n');
86 V->replaceAllUsesWith(Const);
95 if (
auto *Const = dyn_cast<Constant>(
Op))
96 return Const->toConstantRange();
98 unsigned Bitwidth =
Op->getType()->getScalarSizeInBits();
99 return ConstantRange::getFull(Bitwidth);
109 bool Changed =
false;
110 auto GetRange = [&Solver, &InsertedValues](
Value *
Op) {
114 if (isa<OverflowingBinaryOperator>(Inst)) {
124 if (NUWRange.contains(RangeA)) {
133 if (NSWRange.contains(RangeA)) {
138 }
else if (isa<PossiblyNonNegInst>(Inst) && !Inst.
hasNonNeg()) {
144 }
else if (
TruncInst *TI = dyn_cast<TruncInst>(&Inst)) {
145 if (TI->hasNoSignedWrap() && TI->hasNoUnsignedWrap())
149 uint64_t DestWidth = TI->getDestTy()->getScalarSizeInBits();
150 if (!TI->hasNoUnsignedWrap()) {
152 TI->setHasNoUnsignedWrap(
true);
156 if (!TI->hasNoSignedWrap()) {
158 TI->setHasNoSignedWrap(
true);
162 }
else if (
auto *
GEP = dyn_cast<GetElementPtrInst>(&Inst)) {
163 if (
GEP->hasNoUnsignedWrap() || !
GEP->hasNoUnsignedSignedWrap())
167 [&](
Value *V) { return GetRange(V).isAllNonNegative(); })) {
168 GEP->setNoWrapFlags(
GEP->getNoWrapFlags() |
182 auto isNonNegative = [&Solver, &InsertedValues](
Value *V) {
188 case Instruction::SIToFP:
189 case Instruction::SExt: {
192 if (!isNonNegative(Op0))
196 : Instruction::UIToFP,
201 case Instruction::AShr: {
204 if (!isNonNegative(Op0))
210 case Instruction::SDiv:
211 case Instruction::SRem: {
214 if (!isNonNegative(Op0) || !isNonNegative(Op1))
216 auto NewOpcode = Inst.
getOpcode() == Instruction::SDiv ? Instruction::UDiv
219 if (Inst.
getOpcode() == Instruction::SDiv)
228 assert(NewInst &&
"Expected replacement instruction");
230 InsertedValues.
insert(NewInst);
242 auto GetRange = [&Solver, &InsertedValues](
Value *
Op) {
256 if (
auto *Cmp = dyn_cast<CmpIntrinsic>(&Inst)) {
273 if (!RHSLower.
icmp(Pred, LRange) || !LRange.
icmp(Pred, RHSUpper))
294 bool MadeChanges =
false;
296 if (Inst.getType()->isVoidTy())
300 Inst.eraseFromParent();
310 Inst.replaceAllUsesWith(V);
311 Inst.eraseFromParent();
322 bool HasNonFeasibleEdges =
false;
325 FeasibleSuccessors.
insert(Succ);
327 HasNonFeasibleEdges =
true;
331 if (!HasNonFeasibleEdges)
336 assert((isa<BranchInst>(TI) || isa<SwitchInst>(TI) ||
337 isa<IndirectBrInst>(TI)) &&
338 "Terminator must be a br, switch or indirectbr");
340 if (FeasibleSuccessors.
size() == 0) {
345 Succ->removePredecessor(BB);
346 if (SeenSuccs.
insert(Succ).second)
352 }
else if (FeasibleSuccessors.
size() == 1) {
356 bool HaveSeenOnlyFeasibleSuccessor =
false;
358 if (Succ == OnlyFeasibleSuccessor && !HaveSeenOnlyFeasibleSuccessor) {
361 HaveSeenOnlyFeasibleSuccessor =
true;
365 Succ->removePredecessor(BB);
373 }
else if (FeasibleSuccessors.
size() > 1) {
379 BasicBlock *DefaultDest = SI->getDefaultDest();
380 if (!FeasibleSuccessors.
contains(DefaultDest)) {
381 if (!NewUnreachableBB) {
391 SI->setDefaultDest(NewUnreachableBB);
396 for (
auto CI = SI->case_begin(); CI != SI->case_end();) {
397 if (FeasibleSuccessors.
contains(CI->getCaseSuccessor())) {
425 Attribute OldAttr =
F->getAttributeAtIndex(AttrIndex, Attribute::Range);
429 F->addAttributeAtIndex(
436 !
F->hasAttributeAtIndex(AttrIndex, Attribute::NonNull)) {
437 F->addAttributeAtIndex(AttrIndex,
452 if (!
A.getType()->isStructTy())
488 TrackedMultipleRetVals;
520 using Edge = std::pair<BasicBlock *, BasicBlock *>;
540 void pushUsersToWorkList(
Value *V);
550 bool MayIncludeUndef =
false);
553 assert(!V->getType()->isStructTy() &&
"structs should use mergeInValue");
554 return markConstant(ValueState[V], V,
C);
585 assert(!V->getType()->isStructTy() &&
586 "non-structs should use markConstant");
587 return mergeInValue(ValueState[V], V, MergeWithV, Opts);
594 assert(!V->getType()->isStructTy() &&
"Should use getStructValueState");
602 if (
auto *
C = dyn_cast<Constant>(V))
613 assert(V->getType()->isStructTy() &&
"Should use getValueState");
614 assert(i < cast<StructType>(V->getType())->getNumElements() &&
615 "Invalid element #");
617 auto I = StructValueState.
insert(
624 if (
auto *
C = dyn_cast<Constant>(V)) {
625 Constant *Elt =
C->getAggregateElement(i);
643 while (!ToInvalidate.
empty()) {
646 if (!Invalidated.
insert(Inst).second)
649 if (!BBExecutable.count(Inst->
getParent()))
655 if (
auto *RetInst = dyn_cast<ReturnInst>(Inst)) {
656 Function *
F = RetInst->getParent()->getParent();
657 if (
auto It = TrackedRetVals.
find(
F); It != TrackedRetVals.
end()) {
660 }
else if (MRVFunctionsTracked.
count(
F)) {
661 auto *STy = cast<StructType>(
F->getReturnType());
662 for (
unsigned I = 0, E = STy->getNumElements();
I != E; ++
I)
666 }
else if (
auto *STy = dyn_cast<StructType>(Inst->
getType())) {
667 for (
unsigned I = 0, E = STy->getNumElements();
I != E; ++
I) {
668 if (
auto It = StructValueState.
find({Inst, I});
669 It != StructValueState.
end()) {
674 }
else if (
auto It = ValueState.
find(Inst); It != ValueState.
end()) {
682 for (
User *U : V->users())
683 if (
auto *UI = dyn_cast<Instruction>(U))
686 auto It = AdditionalUsers.
find(V);
687 if (It != AdditionalUsers.
end())
688 for (
User *U : It->second)
689 if (
auto *UI = dyn_cast<Instruction>(U))
704 void addAdditionalUser(
Value *V,
User *U) { AdditionalUsers[V].
insert(U); }
707 void handleCallOverdefined(
CallBase &CB);
708 void handleCallResult(
CallBase &CB);
709 void handleCallArguments(
CallBase &CB);
736 markOverdefined(&CPI);
737 visitTerminator(CPI);
754 visitTerminator(CBI);
769 FnPredicateInfo.
insert({&
F, std::make_unique<PredicateInfo>(
770 F, DT, AC, PredicateInfoAllocator)});
774 auto It = FnPredicateInfo.
find(&
F);
775 if (It == FnPredicateInfo.
end())
780 if (
auto *BC = dyn_cast<BitCastInst>(&Inst)) {
781 if (BC->getType() == BC->getOperand(0)->getType()) {
782 if (It->second->getPredicateInfoFor(&Inst)) {
784 Inst.replaceAllUsesWith(
Op);
785 Inst.eraseFromParent();
798 auto It = FnPredicateInfo.
find(
I->getParent()->getParent());
799 if (It == FnPredicateInfo.
end())
801 return It->second->getPredicateInfoFor(
I);
807 :
DL(
DL), GetTLI(GetTLI), Ctx(Ctx) {}
819 if (
auto *STy = dyn_cast<StructType>(
F->getReturnType())) {
821 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
822 TrackedMultipleRetVals.
try_emplace(std::make_pair(
F, i));
823 }
else if (!
F->getReturnType()->isVoidTy())
828 MustPreserveReturnsInFunctions.
insert(
F);
832 return MustPreserveReturnsInFunctions.
count(
F);
836 TrackingIncomingArguments.
insert(
F);
840 return TrackingIncomingArguments.
count(
F);
844 return TrackingIncomingArguments;
854 return BBExecutable.count(BB);
860 std::vector<ValueLatticeElement> StructValues;
861 auto *STy = dyn_cast<StructType>(V->getType());
862 assert(STy &&
"getStructLatticeValueFor() can be called only on structs");
863 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
864 auto I = StructValueState.
find(std::make_pair(V, i));
865 assert(
I != StructValueState.
end() &&
"Value not in valuemap!");
866 StructValues.push_back(
I->second);
879 assert(!
F->getReturnType()->isVoidTy() &&
880 (TrackedRetVals.
count(
F) || MRVFunctionsTracked.
count(
F)) &&
881 "All non void specializations should be tracked");
883 handleCallResult(*Call);
887 assert(!V->getType()->isStructTy() &&
888 "Should use getStructLatticeValueFor");
892 "V not found in ValueState nor Paramstate map!");
897 return TrackedRetVals;
902 return TrackedGlobals;
906 return MRVFunctionsTracked;
910 if (
auto *STy = dyn_cast<StructType>(V->getType()))
911 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
912 markOverdefined(getStructValueState(V, i), V);
914 markOverdefined(ValueState[V], V);
918 if (
A->getType()->isIntOrIntVectorTy()) {
919 if (std::optional<ConstantRange>
Range =
A->getRange())
922 if (
A->hasNonNullAttr())
929 if (
A->getType()->isStructTy())
930 return (
void)markOverdefined(
A);
945 BBExecutable.erase(&BB);
949 bool ResolvedUndefs =
true;
950 while (ResolvedUndefs) {
952 ResolvedUndefs =
false;
959 bool ResolvedUndefs =
true;
960 while (ResolvedUndefs) {
962 ResolvedUndefs =
false;
969 bool ResolvedUndefs =
true;
970 while (ResolvedUndefs) {
972 ResolvedUndefs =
false;
973 for (
Value *V : Invalidated)
974 if (
auto *
I = dyn_cast<Instruction>(V))
984 if (!BBExecutable.insert(BB).second)
987 BBWorkList.push_back(BB);
996 if (CurI &&
I->getParent() == CurI->
getParent() && !
I->comesBefore(CurI))
1000 if (BBVisited.contains(
I->getParent()))
1001 InstWorkList.insert(
I);
1004void SCCPInstVisitor::pushUsersToWorkList(
Value *V) {
1005 for (
User *U : V->users())
1006 if (
auto *UI = dyn_cast<Instruction>(U))
1009 auto Iter = AdditionalUsers.find(V);
1010 if (Iter != AdditionalUsers.end()) {
1014 for (
User *U : Iter->second)
1015 if (
auto *UI = dyn_cast<Instruction>(U))
1025 pushUsersToWorkList(V);
1030 if (!
IV.markConstant(
C, MayIncludeUndef))
1033 pushUsersToWorkList(V);
1039 if (!
IV.markNotConstant(
C))
1041 LLVM_DEBUG(
dbgs() <<
"markNotConstant: " << *
C <<
": " << *V <<
'\n');
1042 pushUsersToWorkList(V);
1048 if (!
IV.markConstantRange(CR))
1050 LLVM_DEBUG(
dbgs() <<
"markConstantRange: " << CR <<
": " << *V <<
'\n');
1051 pushUsersToWorkList(V);
1056 if (!
IV.markOverdefined())
1060 if (
auto *
F = dyn_cast<Function>(V))
dbgs()
1061 <<
"Function '" <<
F->getName() <<
"'\n";
1062 else dbgs() << *V <<
'\n');
1064 pushUsersToWorkList(V);
1070 const auto &It = TrackedMultipleRetVals.find(std::make_pair(
F, i));
1071 assert(It != TrackedMultipleRetVals.end());
1083 assert(
C->getType() == Ty &&
"Type mismatch");
1097 if (V->getType()->isStructTy()) {
1101 std::vector<Constant *> ConstVals;
1102 auto *ST = cast<StructType>(V->getType());
1103 for (
unsigned I = 0,
E = ST->getNumElements();
I !=
E; ++
I) {
1117 assert(Const &&
"Constant is nullptr here!");
1123 assert(!Args.empty() &&
"Specialization without arguments");
1124 assert(
F->arg_size() == Args[0].Formal->getParent()->arg_size() &&
1125 "Functions should have the same number of arguments");
1127 auto Iter = Args.begin();
1130 for (
auto End =
F->arg_end(); NewArg !=
End; ++NewArg, ++OldArg) {
1137 if (Iter != Args.end() && Iter->Formal == &*OldArg) {
1138 if (
auto *STy = dyn_cast<StructType>(NewArg->
getType())) {
1139 for (
unsigned I = 0,
E = STy->getNumElements();
I !=
E; ++
I) {
1141 NewValue.
markConstant(Iter->Actual->getAggregateElement(
I));
1144 ValueState[&*NewArg].markConstant(Iter->Actual);
1148 if (
auto *STy = dyn_cast<StructType>(NewArg->
getType())) {
1149 for (
unsigned I = 0,
E = STy->getNumElements();
I !=
E; ++
I) {
1151 NewValue = StructValueState[{&*OldArg,
I}];
1155 NewValue = ValueState[&*OldArg];
1161void SCCPInstVisitor::visitInstruction(
Instruction &
I) {
1164 LLVM_DEBUG(
dbgs() <<
"SCCP: Don't know how to handle: " <<
I <<
'\n');
1165 markOverdefined(&
I);
1171 if (
IV.mergeIn(MergeWithV, Opts)) {
1172 pushUsersToWorkList(V);
1173 LLVM_DEBUG(
dbgs() <<
"Merged " << MergeWithV <<
" into " << *V <<
" : "
1181 if (!KnownFeasibleEdges.
insert(Edge(Source, Dest)).second)
1189 <<
" -> " << Dest->
getName() <<
'\n');
1192 pushToWorkList(&PN);
1199void SCCPInstVisitor::getFeasibleSuccessors(
Instruction &TI,
1202 if (
auto *BI = dyn_cast<BranchInst>(&TI)) {
1203 if (BI->isUnconditional()) {
1214 Succs[0] = Succs[1] =
true;
1219 Succs[CI->
isZero()] =
true;
1230 if (
auto *SI = dyn_cast<SwitchInst>(&TI)) {
1231 if (!
SI->getNumCases()) {
1238 Succs[
SI->findCaseValue(CI)->getSuccessorIndex()] =
true;
1246 unsigned ReachableCaseCount = 0;
1247 for (
const auto &Case :
SI->cases()) {
1248 const APInt &CaseValue = Case.getCaseValue()->getValue();
1250 Succs[Case.getSuccessorIndex()] =
true;
1251 ++ReachableCaseCount;
1255 Succs[
SI->case_default()->getSuccessorIndex()] =
1268 if (
auto *IBR = dyn_cast<IndirectBrInst>(&TI)) {
1272 getConstant(IBRValue, IBR->getAddress()->getType()));
1282 "Block address of a different function ?");
1283 for (
unsigned i = 0; i < IBR->getNumSuccessors(); ++i) {
1285 if (IBR->getDestination(i) ==
T) {
1296 LLVM_DEBUG(
dbgs() <<
"Unknown terminator instruction: " << TI <<
'\n');
1306 return KnownFeasibleEdges.
count(Edge(
From, To));
1326void SCCPInstVisitor::visitPHINode(
PHINode &PN) {
1330 return (
void)markOverdefined(&PN);
1332 if (getValueState(&PN).isOverdefined())
1338 return (
void)markOverdefined(&PN);
1340 unsigned NumActiveIncoming = 0;
1354 NumActiveIncoming++;
1364 mergeInValue(&PN, PhiState,
1366 NumActiveIncoming + 1));
1372void SCCPInstVisitor::visitReturnInst(
ReturnInst &
I) {
1373 if (
I.getNumOperands() == 0)
1377 Value *ResultOp =
I.getOperand(0);
1381 auto TFRVI = TrackedRetVals.find(
F);
1382 if (TFRVI != TrackedRetVals.end()) {
1383 mergeInValue(TFRVI->second,
F, getValueState(ResultOp));
1389 if (!TrackedMultipleRetVals.empty()) {
1390 if (
auto *STy = dyn_cast<StructType>(ResultOp->
getType()))
1391 if (MRVFunctionsTracked.count(
F))
1392 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
1393 mergeInValue(TrackedMultipleRetVals[std::make_pair(
F, i)],
F,
1394 getStructValueState(ResultOp, i));
1398void SCCPInstVisitor::visitTerminator(
Instruction &TI) {
1400 getFeasibleSuccessors(TI, SuccFeasible);
1405 for (
unsigned i = 0, e = SuccFeasible.
size(); i != e; ++i)
1406 if (SuccFeasible[i])
1410void SCCPInstVisitor::visitCastInst(
CastInst &
I) {
1413 if (ValueState[&
I].isOverdefined())
1416 if (
auto *BC = dyn_cast<BitCastInst>(&
I)) {
1417 if (BC->getType() == BC->getOperand(0)->getType()) {
1419 handlePredicate(&
I,
I.getOperand(0), PI);
1433 return (
void)markConstant(&
I,
C);
1437 if (
I.getDestTy()->isIntOrIntVectorTy() &&
1438 I.getSrcTy()->isIntOrIntVectorTy() &&
1439 I.getOpcode() != Instruction::BitCast) {
1440 auto &LV = getValueState(&
I);
1444 Type *DestTy =
I.getDestTy();
1446 if (
auto *Trunc = dyn_cast<TruncInst>(&
I))
1448 Trunc->getNoWrapKind());
1453 markOverdefined(&
I);
1462 addAdditionalUser(
LHS, &EVI);
1463 addAdditionalUser(
RHS, &EVI);
1464 if (
L.isUnknownOrUndef() ||
R.isUnknownOrUndef())
1474 assert(
Idx == 1 &&
"Index can only be 0 or 1");
1479 markOverdefined(&EVI);
1487 return (
void)markOverdefined(&EVI);
1491 if (ValueState[&EVI].isOverdefined())
1492 return (
void)markOverdefined(&EVI);
1496 return (
void)markOverdefined(&EVI);
1501 if (
auto *WO = dyn_cast<WithOverflowInst>(AggVal))
1502 return handleExtractOfWithOverflow(EVI, WO, i);
1504 mergeInValue(getValueState(&EVI), &EVI, EltVal);
1507 return (
void)markOverdefined(&EVI);
1512 auto *STy = dyn_cast<StructType>(IVI.
getType());
1514 return (
void)markOverdefined(&IVI);
1518 if (ValueState[&IVI].isOverdefined())
1519 return (
void)markOverdefined(&IVI);
1524 return (
void)markOverdefined(&IVI);
1530 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
1534 mergeInValue(getStructValueState(&IVI, i), &IVI, EltVal);
1541 markOverdefined(getStructValueState(&IVI, i), &IVI);
1544 mergeInValue(getStructValueState(&IVI, i), &IVI, InVal);
1549void SCCPInstVisitor::visitSelectInst(
SelectInst &
I) {
1552 if (
I.getType()->isStructTy())
1553 return (
void)markOverdefined(&
I);
1557 if (ValueState[&
I].isOverdefined())
1558 return (
void)markOverdefined(&
I);
1566 Value *OpVal = CondCB->isZero() ?
I.getFalseValue() :
I.getTrueValue();
1567 mergeInValue(&
I, getValueState(OpVal));
1578 bool Changed = State.
mergeIn(TVal);
1579 Changed |= State.
mergeIn(FVal);
1581 pushUsersToWorkListMsg(State, &
I);
1585void SCCPInstVisitor::visitUnaryOperator(
Instruction &
I) {
1591 if (
IV.isOverdefined())
1592 return (
void)markOverdefined(&
I);
1601 return (
void)markConstant(
IV, &
I,
C);
1603 markOverdefined(&
I);
1606void SCCPInstVisitor::visitFreezeInst(
FreezeInst &
I) {
1609 if (
I.getType()->isStructTy())
1610 return (
void)markOverdefined(&
I);
1616 if (
IV.isOverdefined())
1617 return (
void)markOverdefined(&
I);
1627 markOverdefined(&
I);
1631void SCCPInstVisitor::visitBinaryOperator(
Instruction &
I) {
1636 if (
IV.isOverdefined())
1644 return (
void)markOverdefined(&
I);
1656 auto *
C = dyn_cast_or_null<Constant>(R);
1665 return (
void)mergeInValue(&
I, NewV);
1670 if (!
I.getType()->isIntOrIntVectorTy())
1671 return markOverdefined(&
I);
1679 auto *BO = cast<BinaryOperator>(&
I);
1680 ConstantRange R = ConstantRange::getEmpty(
I.getType()->getScalarSizeInBits());
1681 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(BO))
1682 R =
A.overflowingBinaryOp(BO->getOpcode(),
B, OBO->getNoWrapKind());
1684 R =
A.binaryOp(BO->getOpcode(),
B);
1693void SCCPInstVisitor::visitCmpInst(
CmpInst &
I) {
1696 if (ValueState[&
I].isOverdefined())
1697 return (
void)markOverdefined(&
I);
1699 Value *Op1 =
I.getOperand(0);
1700 Value *Op2 =
I.getOperand(1);
1704 auto V1State = getValueState(Op1);
1705 auto V2State = getValueState(Op2);
1711 mergeInValue(&
I, CV);
1720 markOverdefined(&
I);
1726 if (ValueState[&
I].isOverdefined())
1727 return (
void)markOverdefined(&
I);
1735 if (
I.hasNoUnsignedWrap() ||
1738 return (
void)markNotNull(ValueState[&
I], &
I);
1739 return (
void)markOverdefined(&
I);
1745 for (
unsigned i = 0, e =
I.getNumOperands(); i != e; ++i) {
1755 return (
void)markOverdefined(&
I);
1759 markConstant(&
I,
C);
1761 markOverdefined(&
I);
1764void SCCPInstVisitor::visitAllocaInst(
AllocaInst &
I) {
1766 return (
void)markNotNull(ValueState[&
I], &
I);
1768 markOverdefined(&
I);
1771void SCCPInstVisitor::visitStoreInst(
StoreInst &SI) {
1773 if (
SI.getOperand(0)->getType()->isStructTy())
1776 if (TrackedGlobals.empty() || !isa<GlobalVariable>(
SI.getOperand(1)))
1780 auto I = TrackedGlobals.find(GV);
1781 if (
I == TrackedGlobals.end())
1785 mergeInValue(
I->second, GV, getValueState(
SI.getOperand(0)),
1787 if (
I->second.isOverdefined())
1788 TrackedGlobals.erase(
I);
1792 if (
const auto *CB = dyn_cast<CallBase>(
I)) {
1793 if (CB->getType()->isIntOrIntVectorTy())
1794 if (std::optional<ConstantRange>
Range = CB->getRange())
1796 if (CB->getType()->isPointerTy() && CB->isReturnNonNull())
1801 if (
I->getType()->isIntOrIntVectorTy())
1802 if (
MDNode *Ranges =
I->getMetadata(LLVMContext::MD_range))
1805 if (
I->hasMetadata(LLVMContext::MD_nonnull))
1814void SCCPInstVisitor::visitLoadInst(
LoadInst &
I) {
1817 if (
I.getType()->isStructTy() ||
I.isVolatile())
1818 return (
void)markOverdefined(&
I);
1822 if (ValueState[&
I].isOverdefined())
1823 return (
void)markOverdefined(&
I);
1835 if (isa<ConstantPointerNull>(
Ptr)) {
1837 return (
void)markOverdefined(
IV, &
I);
1843 if (
auto *GV = dyn_cast<GlobalVariable>(
Ptr)) {
1844 if (!TrackedGlobals.empty()) {
1846 auto It = TrackedGlobals.find(GV);
1847 if (It != TrackedGlobals.end()) {
1856 return (
void)markConstant(
IV, &
I,
C);
1863void SCCPInstVisitor::visitCallBase(
CallBase &CB) {
1864 handleCallResult(CB);
1865 handleCallArguments(CB);
1868void SCCPInstVisitor::handleCallOverdefined(
CallBase &CB) {
1877 return (
void)markOverdefined(&CB);
1884 if (
A.get()->getType()->isStructTy())
1885 return markOverdefined(&CB);
1886 if (
A.get()->getType()->isMetadataTy())
1893 return (
void)markOverdefined(&CB);
1899 return (
void)markOverdefined(&CB);
1904 return (
void)markConstant(&CB,
C);
1911void SCCPInstVisitor::handleCallArguments(
CallBase &CB) {
1916 if (TrackingIncomingArguments.count(
F)) {
1925 if (AI->hasByValAttr() && !
F->onlyReadsMemory()) {
1926 markOverdefined(&*AI);
1930 if (
auto *STy = dyn_cast<StructType>(AI->getType())) {
1931 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
1933 mergeInValue(getStructValueState(&*AI, i), &*AI, CallArg,
1947 const std::optional<PredicateConstraint> &Constraint = PI->
getConstraint();
1949 mergeInValue(ValueState[
I],
I, CopyOfVal);
1954 Value *OtherOp = Constraint->OtherOp;
1957 if (getValueState(OtherOp).isUnknown()) {
1958 addAdditionalUser(OtherOp,
I);
1966 ConstantRange::getFull(
DL.getTypeSizeInBits(CopyOf->
getType()));
1978 if (CopyOfCR.isEmptySet())
1979 CopyOfCR = ConstantRange::getFull(CopyOfCR.getBitWidth());
1980 auto NewCR = ImposedCR.intersectWith(CopyOfCR);
1984 if (!CopyOfCR.contains(NewCR) && CopyOfCR.getSingleMissingElement())
1992 addAdditionalUser(OtherOp,
I);
2000 addAdditionalUser(OtherOp,
I);
2001 mergeInValue(
IV,
I, CondVal);
2005 addAdditionalUser(OtherOp,
I);
2010 return (
void)mergeInValue(
IV,
I, CopyOfVal);
2013void SCCPInstVisitor::handleCallResult(
CallBase &CB) {
2016 if (
auto *
II = dyn_cast<IntrinsicInst>(&CB)) {
2017 if (
II->getIntrinsicID() == Intrinsic::vscale) {
2045 if (!
F ||
F->isDeclaration())
2046 return handleCallOverdefined(CB);
2049 if (
auto *STy = dyn_cast<StructType>(
F->getReturnType())) {
2050 if (!MRVFunctionsTracked.count(
F))
2051 return handleCallOverdefined(CB);
2055 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
2056 mergeInValue(getStructValueState(&CB, i), &CB,
2057 TrackedMultipleRetVals[std::make_pair(
F, i)],
2060 auto TFRVI = TrackedRetVals.find(
F);
2061 if (TFRVI == TrackedRetVals.end())
2062 return handleCallOverdefined(CB);
2071 while (!BBWorkList.empty() || !InstWorkList.empty()) {
2073 while (!InstWorkList.empty()) {
2083 while (!BBWorkList.empty()) {
2085 BBVisited.insert(BB);
2099 if (
I.getType()->isVoidTy())
2102 if (
auto *STy = dyn_cast<StructType>(
I.getType())) {
2106 if (
auto *CB = dyn_cast<CallBase>(&
I))
2108 if (MRVFunctionsTracked.count(
F))
2113 if (isa<ExtractValueInst>(
I) || isa<InsertValueInst>(
I))
2117 for (
unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
2120 markOverdefined(LV, &
I);
2136 if (
auto *CB = dyn_cast<CallBase>(&
I))
2138 if (TrackedRetVals.count(
F))
2141 if (isa<LoadInst>(
I)) {
2148 markOverdefined(&
I);
2166 bool MadeChange =
false;
2168 if (!BBExecutable.count(&BB))
2176 <<
"\nResolved undefs in " <<
F.getName() <<
'\n');
2195 Visitor->addPredicateInfo(
F, DT, AC);
2199 Visitor->removeSSACopies(
F);
2203 return Visitor->markBlockExecutable(BB);
2207 return Visitor->getPredicateInfoFor(
I);
2211 Visitor->trackValueOfGlobalVariable(GV);
2215 Visitor->addTrackedFunction(
F);
2219 Visitor->addToMustPreserveReturnsInFunctions(
F);
2223 return Visitor->mustPreserveReturn(
F);
2227 Visitor->addArgumentTrackedFunction(
F);
2231 return Visitor->isArgumentTrackedFunction(
F);
2236 return Visitor->getArgumentTrackedFunctions();
2242 return Visitor->resolvedUndefsIn(
F);
2246 Visitor->solveWhileResolvedUndefsIn(M);
2251 Visitor->solveWhileResolvedUndefsIn(WorkList);
2255 Visitor->solveWhileResolvedUndefs();
2259 return Visitor->isBlockExecutable(BB);
2263 return Visitor->isEdgeFeasible(
From, To);
2266std::vector<ValueLatticeElement>
2268 return Visitor->getStructLatticeValueFor(V);
2272 return Visitor->removeLatticeValueFor(V);
2276 Visitor->resetLatticeValueFor(Call);
2280 return Visitor->getLatticeValueFor(V);
2285 return Visitor->getTrackedRetVals();
2290 return Visitor->getTrackedGlobals();
2294 return Visitor->getMRVFunctionsTracked();
2300 Visitor->trackValueOfArgument(V);
2304 return Visitor->isStructLatticeConstant(
F, STy);
2309 return Visitor->getConstant(LV, Ty);
2313 return Visitor->getConstantOrNull(V);
2318 Visitor->setLatticeValueForSpecializationArguments(
F, Args);
2322 Visitor->markFunctionUnreachable(
F);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
mir Rename Register Operands
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
static ValueLatticeElement::MergeOptions getMaxWidenStepsOpts()
Returns MergeOptions with MaxWidenSteps set to MaxNumRangeExtensions.
static const unsigned MaxNumRangeExtensions
static ValueLatticeElement getValueFromMetadata(const Instruction *I)
This file implements a set that has insertion order iteration characteristics.
static ConstantInt * getConstantInt(Value *V, const DataLayout &DL)
Extract ConstantInt from value, looking through IntToPtr and PointerNullValue.
static const uint32_t IV[8]
Class for arbitrary precision integers.
bool ule(const APInt &RHS) const
Unsigned less or equal comparison.
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
A cache of @llvm.assume calls within a function.
LLVM_ABI const ConstantRange & getRange() const
Returns the value of the range attribute.
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
bool isValid() const
Return true if the attribute is any kind of attribute.
LLVM Basic Block Representation.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
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...
LLVM_ABI void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
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.
static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
The address of a basic block.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
Allocate memory in an ever growing pool, as if by bump-pointer.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
LLVM_ABI bool isMustTailCall() const
Tests if this call site must be tail call optimized.
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
CallBr instruction, tracking function calls that may not return control but instead transfer it to a ...
This class represents a function call, abstracting a target machine's calling convention.
This is the base class for all instructions that perform data casts.
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
This class is the base class for the comparison instructions.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLE
signed less or equal
@ ICMP_ULE
unsigned less or equal
This is the shared class of boolean and integer constants.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
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 add(const ConstantRange &Other) const
Return a new range representing the possible values resulting from an addition of a value in this ran...
LLVM_ABI unsigned getActiveBits() const
Compute the maximal number of active bits needed to represent every value in this range.
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
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 bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const
Does the predicate Pred hold between ranges this and Other? NOTE: false does not mean that inverse pr...
static LLVM_ABI ConstantRange intrinsic(Intrinsic::ID IntrinsicID, ArrayRef< ConstantRange > Ops)
Compute range of intrinsic result for the given operand ranges.
LLVM_ABI bool isSizeLargerThan(uint64_t MaxSize) const
Compare set size of this range with Value.
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 bool isAllNonNegative() const
Return true if all values in this range are non-negative.
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...
LLVM_ABI bool contains(const APInt &Val) const
Return true if the specified value is in the set.
LLVM_ABI APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
LLVM_ABI ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
static LLVM_ABI ConstantRange makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind)
Produce the largest range containing all X such that "X BinOp Y" is guaranteed not to wrap (overflow)...
LLVM_ABI unsigned getMinSignedBits() const
Compute the maximal number of bits needed to represent every value in this signed range.
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...
LLVM_ABI 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 LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
This is an important base class in LLVM.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
static DebugLoc getTemporary()
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
bool erase(const KeyT &Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
static constexpr UpdateKind Delete
static constexpr UpdateKind Insert
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
An instruction for ordering other memory operations.
This class represents a freeze function that returns random concrete value if an operand is either a ...
static GEPNoWrapFlags noUnsignedWrap()
void applyUpdatesPermissive(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a SExt or Trunc from the integer value V to DestTy.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
This instruction inserts a struct field of array element value into an aggregate value.
Value * getInsertedValueOperand()
Value * getAggregateOperand()
unsigned getNumIndices() const
idx_iterator idx_begin() const
Base class for instruction visitors.
void visit(Iterator Start, Iterator End)
LLVM_ABI void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI bool hasNoUnsignedWrap() const LLVM_READONLY
Determine whether the no unsigned wrap flag is set.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
LLVM_ABI bool hasNoSignedWrap() const LLVM_READONLY
Determine whether the no signed wrap flag is set.
LLVM_ABI void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI bool isExact() const LLVM_READONLY
Determine whether the exact flag is set.
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
LLVM_ABI void setNonNeg(bool b=true)
Set or clear the nneg flag on this instruction, which must be a zext instruction.
LLVM_ABI bool hasNonNeg() const LLVM_READONLY
Determine whether the the nneg flag is set.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
LLVM_ABI void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
bool isSpecialTerminator() const
This is an important class for using LLVM in a threaded context.
@ OB_clang_arc_attachedcall
An instruction for reading from memory.
This class implements a map that also provides access to all stored values in a deterministic order.
size_type count(const KeyT &Key) const
iterator find(const KeyT &Key)
std::pair< iterator, bool > try_emplace(const KeyT &Key, Ts &&...Args)
A Module instance is used to store all the information related to an LLVM module.
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.
LLVM_ABI std::optional< PredicateConstraint > getConstraint() const
Fetch condition in the form of PredicateConstraint, if possible.
Resume the propagation of an exception.
Return a value (possibly void), from a function.
Helper class for SCCPSolver.
const MapVector< Function *, ValueLatticeElement > & getTrackedRetVals() const
const PredicateBase * getPredicateInfoFor(Instruction *I)
std::vector< ValueLatticeElement > getStructLatticeValueFor(Value *V) const
bool resolvedUndef(Instruction &I)
void markFunctionUnreachable(Function *F)
bool markBlockExecutable(BasicBlock *BB)
bool resolvedUndefsIn(Function &F)
While solving the dataflow for a function, we don't compute a result for operations with an undef ope...
Constant * getConstant(const ValueLatticeElement &LV, Type *Ty) const
SCCPInstVisitor(const DataLayout &DL, std::function< const TargetLibraryInfo &(Function &)> GetTLI, LLVMContext &Ctx)
const DenseMap< GlobalVariable *, ValueLatticeElement > & getTrackedGlobals() const
const ValueLatticeElement & getLatticeValueFor(Value *V) const
void removeLatticeValueFor(Value *V)
void trackValueOfArgument(Argument *A)
void visitCallInst(CallInst &I)
void markOverdefined(Value *V)
bool isArgumentTrackedFunction(Function *F)
void addTrackedFunction(Function *F)
void solveWhileResolvedUndefs()
void solveWhileResolvedUndefsIn(Module &M)
void trackValueOfGlobalVariable(GlobalVariable *GV)
Constant * getConstantOrNull(Value *V) const
void removeSSACopies(Function &F)
const SmallPtrSet< Function *, 16 > & getMRVFunctionsTracked() const
const SmallPtrSetImpl< Function * > & getArgumentTrackedFunctions() const
void resetLatticeValueFor(CallBase *Call)
Invalidate the Lattice Value of Call and its users after specializing the call.
ValueLatticeElement getArgAttributeVL(Argument *A)
void addPredicateInfo(Function &F, DominatorTree &DT, AssumptionCache &AC)
void addToMustPreserveReturnsInFunctions(Function *F)
void addArgumentTrackedFunction(Function *F)
bool isStructLatticeConstant(Function *F, StructType *STy)
void solveWhileResolvedUndefsIn(SmallVectorImpl< Function * > &WorkList)
bool isBlockExecutable(BasicBlock *BB) const
bool mustPreserveReturn(Function *F)
void setLatticeValueForSpecializationArguments(Function *F, const SmallVectorImpl< ArgInfo > &Args)
bool isEdgeFeasible(BasicBlock *From, BasicBlock *To) const
SCCPSolver - This interface class is a general purpose solver for Sparse Conditional Constant Propaga...
LLVM_ABI void visitCall(CallInst &I)
LLVM_ABI void resetLatticeValueFor(CallBase *Call)
Invalidate the Lattice Value of Call and its users after specializing the call.
LLVM_ABI void trackValueOfGlobalVariable(GlobalVariable *GV)
trackValueOfGlobalVariable - Clients can use this method to inform the SCCPSolver that it should trac...
LLVM_ABI bool tryToReplaceWithConstant(Value *V)
LLVM_ABI void inferArgAttributes() const
LLVM_ABI bool isStructLatticeConstant(Function *F, StructType *STy)
LLVM_ABI void addPredicateInfo(Function &F, DominatorTree &DT, AssumptionCache &AC)
LLVM_ABI void solve()
Solve - Solve for constants and executable blocks.
LLVM_ABI void visit(Instruction *I)
LLVM_ABI void trackValueOfArgument(Argument *V)
trackValueOfArgument - Mark the specified argument overdefined unless it have range attribute.
LLVM_ABI const DenseMap< GlobalVariable *, ValueLatticeElement > & getTrackedGlobals() const
getTrackedGlobals - Get and return the set of inferred initializers for global variables.
LLVM_ABI void addTrackedFunction(Function *F)
addTrackedFunction - If the SCCP solver is supposed to track calls into and out of the specified func...
LLVM_ABI void solveWhileResolvedUndefsIn(Module &M)
LLVM_ABI const PredicateBase * getPredicateInfoFor(Instruction *I)
LLVM_ABI const SmallPtrSetImpl< Function * > & getArgumentTrackedFunctions() const
LLVM_ABI const SmallPtrSet< Function *, 16 > & getMRVFunctionsTracked() const
getMRVFunctionsTracked - Get the set of functions which return multiple values tracked by the pass.
LLVM_ABI bool resolvedUndefsIn(Function &F)
resolvedUndefsIn - While solving the dataflow for a function, we assume that branches on undef values...
LLVM_ABI void addArgumentTrackedFunction(Function *F)
LLVM_ABI void solveWhileResolvedUndefs()
LLVM_ABI void removeLatticeValueFor(Value *V)
LLVM_ABI std::vector< ValueLatticeElement > getStructLatticeValueFor(Value *V) const
LLVM_ABI Constant * getConstantOrNull(Value *V) const
Return either a Constant or nullptr for a given Value.
LLVM_ABI bool simplifyInstsInBlock(BasicBlock &BB, SmallPtrSetImpl< Value * > &InsertedValues, Statistic &InstRemovedStat, Statistic &InstReplacedStat)
LLVM_ABI Constant * getConstant(const ValueLatticeElement &LV, Type *Ty) const
Helper to return a Constant if LV is either a constant or a constant range with a single element.
LLVM_ABI const ValueLatticeElement & getLatticeValueFor(Value *V) const
LLVM_ABI void addToMustPreserveReturnsInFunctions(Function *F)
Add function to the list of functions whose return cannot be modified.
LLVM_ABI bool removeNonFeasibleEdges(BasicBlock *BB, DomTreeUpdater &DTU, BasicBlock *&NewUnreachableBB) const
LLVM_ABI bool isBlockExecutable(BasicBlock *BB) const
LLVM_ABI void inferReturnAttributes() const
LLVM_ABI bool markBlockExecutable(BasicBlock *BB)
markBlockExecutable - This method can be used by clients to mark all of the blocks that are known to ...
LLVM_ABI void setLatticeValueForSpecializationArguments(Function *F, const SmallVectorImpl< ArgInfo > &Args)
Set the Lattice Value for the arguments of a specialization F.
static LLVM_ABI bool isConstant(const ValueLatticeElement &LV)
LLVM_ABI const MapVector< Function *, ValueLatticeElement > & getTrackedRetVals() const
getTrackedRetVals - Get the inferred return value map.
LLVM_ABI bool isEdgeFeasible(BasicBlock *From, BasicBlock *To) const
LLVM_ABI bool mustPreserveReturn(Function *F)
Returns true if the return of the given function cannot be modified.
static LLVM_ABI bool isOverdefined(const ValueLatticeElement &LV)
LLVM_ABI void markFunctionUnreachable(Function *F)
Mark all of the blocks in function F non-executable.
LLVM_ABI bool isArgumentTrackedFunction(Function *F)
Returns true if the given function is in the solver's set of argument-tracked functions.
LLVM_ABI SCCPSolver(const DataLayout &DL, std::function< const TargetLibraryInfo &(Function &)> GetTLI, LLVMContext &Ctx)
LLVM_ABI void markOverdefined(Value *V)
markOverdefined - Mark the specified value overdefined.
LLVM_ABI void removeSSACopies(Function &F)
This class represents the LLVM 'select' instruction.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
A SetVector that performs no allocations if smaller than a certain size.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void assign(size_type NumElts, ValueParamT Elt)
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.
Class to represent struct types.
unsigned getNumElements() const
Random access to the elements.
A wrapper class to simplify modification of SwitchInst cases along with their prof branch_weights met...
Provides information about what library functions are available for the current target.
This class represents a truncation of integer types.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isSingleValueType() const
Return true if the type is a valid type for a register in codegen.
bool isStructTy() const
True if this is an instance of StructType.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isVoidTy() const
Return true if this is 'void'.
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
This function has undefined behavior.
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
LLVM_ABI Constant * getCompare(CmpInst::Predicate Pred, Type *Ty, const ValueLatticeElement &Other, const DataLayout &DL) const
true, false or undef constants, or nullptr if the comparison cannot be evaluated.
bool isConstantRangeIncludingUndef() const
static ValueLatticeElement getNot(Constant *C)
ConstantRange asConstantRange(unsigned BW, bool UndefAllowed=false) const
bool isNotConstant() const
void setNumRangeExtensions(unsigned N)
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.
unsigned getNumRangeExtensions() const
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.
bool isUnknownOrUndef() const
Constant * getConstant() const
bool mergeIn(const ValueLatticeElement &RHS, MergeOptions Opts=MergeOptions())
Updates this object to approximate both this object and RHS.
bool markConstant(Constant *V, bool MayIncludeUndef=false)
static ValueLatticeElement getOverdefined()
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI std::string getNameOrAsOperand() const
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Represents an op.with.overflow intrinsic.
std::pair< iterator, bool > insert(const ValueT &V)
bool erase(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
cst_pred_ty< is_lowbit_mask > m_LowBitMask()
Match an integer or vector with only the low bit(s) set.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
bool match(Val *V, const Pattern &P)
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
static bool replaceSignedInst(SCCPSolver &Solver, SmallPtrSetImpl< Value * > &InsertedValues, Instruction &Inst)
Try to replace signed instructions with their unsigned equivalent.
LLVM_ABI bool canConstantFoldCallTo(const CallBase *Call, const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function.
auto successors(const MachineBasicBlock *BB)
static ConstantRange getRange(Value *Op, SCCPSolver &Solver, const SmallPtrSetImpl< Value * > &InsertedValues)
Helper for getting ranges from Solver.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI Constant * ConstantFoldCall(const CallBase *Call, Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=nullptr, bool AllowNonDeterministic=true)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Constant * ConstantFoldUnaryOpOperand(unsigned Opcode, Constant *Op, const DataLayout &DL)
Attempt to constant fold a unary operation with the specified operand.
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 bool wouldInstructionBeTriviallyDead(const Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction would have no side effects if it was not used.
LLVM_ABI ConstantRange getVScaleRange(const Function *F, unsigned BitWidth)
Determine the possible constant range of vscale with the given bit width, based on the vscale_range f...
LLVM_ABI Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
LLVM_ABI Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
@ Sub
Subtraction of integers.
DWARFExpression::Operation Op
LLVM_ABI bool isGuaranteedNotToBeUndefOrPoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Return true if this function can prove that V does not have undef bits and is never poison.
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt Offset, const DataLayout &DL)
Return the value that a load from C with offset Offset would produce if it is constant and determinab...
LLVM_ABI Constant * ConstantFoldInstOperands(const Instruction *I, ArrayRef< Constant * > Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, bool AllowNonDeterministic=true)
ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands.
static bool refineInstruction(SCCPSolver &Solver, const SmallPtrSetImpl< Value * > &InsertedValues, Instruction &Inst)
Try to use Inst's value range from Solver to infer the NUW flag.
static void inferAttribute(Function *F, unsigned AttrIndex, const ValueLatticeElement &Val)
Implement std::hash so that hash_code can be used in STL containers.
Struct to control some aspects related to merging constant ranges.
MergeOptions & setMaxWidenSteps(unsigned Steps=1)
MergeOptions & setCheckWiden(bool V=true)