Go to the documentation of this file.
88 #define DEBUG_TYPE "local"
90 STATISTIC(NumRemoved,
"Number of unreachable basic blocks removed");
91 STATISTIC(NumPHICSEs,
"Number of PHI's that got CSE'd");
95 #ifdef EXPENSIVE_CHECKS
101 cl::desc(
"Perform extra assertion checking to verify that PHINodes's hash "
102 "function is well-behaved w.r.t. its isEqual predicate"));
107 "When the basic block contains not more than this number of PHI nodes, "
108 "perform a (faster!) exhaustive search instead of set-driven one."));
132 if (
auto *BI = dyn_cast<BranchInst>(
T)) {
133 if (BI->isUnconditional())
return false;
138 if (Dest2 == Dest1) {
144 assert(BI->getParent() &&
"Terminator not inserted in block!");
151 NewBI->
copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
152 LLVMContext::MD_annotation});
155 BI->eraseFromParent();
156 if (DeleteDeadConditions)
161 if (
auto *
Cond = dyn_cast<ConstantInt>(BI->getCondition())) {
175 NewBI->
copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
176 LLVMContext::MD_annotation});
178 BI->eraseFromParent();
187 if (
auto *
SI = dyn_cast<SwitchInst>(
T)) {
190 auto *CI = dyn_cast<ConstantInt>(
SI->getCondition());
196 SI->getNumCases() > 0) {
197 TheOnlyDest =
SI->case_begin()->getCaseSuccessor();
200 bool Changed =
false;
203 for (
auto i =
SI->case_begin(),
e =
SI->case_end();
i !=
e;) {
205 if (
i->getCaseValue() == CI) {
206 TheOnlyDest =
i->getCaseSuccessor();
212 if (
i->getCaseSuccessor() == DefaultDest) {
213 MDNode *MD =
SI->getMetadata(LLVMContext::MD_prof);
214 unsigned NCases =
SI->getNumCases();
222 auto *CI = mdconst::extract<ConstantInt>(MD->
getOperand(MD_i));
223 Weights.push_back(CI->getValue().getZExtValue());
226 unsigned idx =
i->getCaseIndex();
227 Weights[0] += Weights[idx+1];
229 std::swap(Weights[idx+1], Weights.back());
231 SI->setMetadata(LLVMContext::MD_prof,
233 createBranchWeights(Weights));
238 i =
SI->removeCase(
i);
247 if (
i->getCaseSuccessor() != TheOnlyDest)
248 TheOnlyDest =
nullptr;
254 if (CI && !TheOnlyDest) {
257 TheOnlyDest =
SI->getDefaultDest();
272 if (DTU && Succ != TheOnlyDest)
273 RemovedSuccessors.
insert(Succ);
275 if (Succ == SuccToKeep) {
276 SuccToKeep =
nullptr;
284 SI->eraseFromParent();
285 if (DeleteDeadConditions)
288 std::vector<DominatorTree::UpdateType> Updates;
289 Updates.reserve(RemovedSuccessors.
size());
290 for (
auto *RemovedSuccessor : RemovedSuccessors)
297 if (
SI->getNumCases() == 1) {
300 auto FirstCase = *
SI->case_begin();
302 FirstCase.getCaseValue(),
"cond");
306 FirstCase.getCaseSuccessor(),
307 SI->getDefaultDest());
308 MDNode *MD =
SI->getMetadata(LLVMContext::MD_prof);
311 mdconst::dyn_extract<ConstantInt>(MD->
getOperand(2));
313 mdconst::dyn_extract<ConstantInt>(MD->
getOperand(1));
323 MDNode *MakeImplicitMD =
SI->getMetadata(LLVMContext::MD_make_implicit);
325 NewBr->
setMetadata(LLVMContext::MD_make_implicit, MakeImplicitMD);
328 SI->eraseFromParent();
334 if (
auto *IBI = dyn_cast<IndirectBrInst>(
T)) {
337 dyn_cast<BlockAddress>(IBI->getAddress()->stripPointerCasts())) {
338 BasicBlock *TheOnlyDest = BA->getBasicBlock();
345 for (
unsigned i = 0,
e = IBI->getNumDestinations();
i !=
e; ++
i) {
347 if (DTU && DestBB != TheOnlyDest)
348 RemovedSuccessors.
insert(DestBB);
349 if (IBI->getDestination(
i) == SuccToKeep) {
350 SuccToKeep =
nullptr;
355 Value *Address = IBI->getAddress();
356 IBI->eraseFromParent();
357 if (DeleteDeadConditions)
364 BA->destroyConstant();
370 BB->getTerminator()->eraseFromParent();
375 std::vector<DominatorTree::UpdateType> Updates;
376 Updates.reserve(RemovedSuccessors.
size());
377 for (
auto *RemovedSuccessor : RemovedSuccessors)
407 if (II->getIntrinsicID() == Intrinsic::stacksave ||
408 II->getIntrinsicID() == Intrinsic::launder_invariant_group ||
409 II->isLifetimeStartOrEnd())
416 if (
I->isTerminator())
427 if (DDI->getAddress())
432 if (DVI->hasArgList() || DVI->getValue(0))
442 if (!
I->willReturn())
445 if (!
I->mayHaveSideEffects())
452 if (II->getIntrinsicID() == Intrinsic::stacksave ||
453 II->getIntrinsicID() == Intrinsic::launder_invariant_group)
456 if (II->isLifetimeStartOrEnd()) {
457 auto *
Arg = II->getArgOperand(1);
459 if (isa<UndefValue>(
Arg))
463 if (isa<AllocaInst>(
Arg) || isa<GlobalValue>(
Arg) || isa<Argument>(
Arg))
465 if (IntrinsicInst *IntrinsicUse =
466 dyn_cast<IntrinsicInst>(Use.getUser()))
467 return IntrinsicUse->isLifetimeStartOrEnd();
477 if ((II->getIntrinsicID() == Intrinsic::assume &&
479 II->getIntrinsicID() == Intrinsic::experimental_guard) {
481 return !
Cond->isZero();
486 if (
auto *FPI = dyn_cast<ConstrainedFPIntrinsic>(
I)) {
496 if (
Constant *
C = dyn_cast<Constant>(CI->getArgOperand(0)))
497 return C->isNullValue() || isa<UndefValue>(
C);
499 if (
auto *Call = dyn_cast<CallBase>(
I))
504 if (
auto *LI = dyn_cast<LoadInst>(
I))
505 if (
auto *GV = dyn_cast<GlobalVariable>(
506 LI->getPointerOperand()->stripPointerCasts()))
507 if (!LI->isVolatile() && GV->isConstant())
525 DeadInsts.push_back(
I);
527 AboutToDeleteCallback);
536 unsigned S = 0,
E = DeadInsts.size(), Alive = 0;
537 for (;
S !=
E; ++
S) {
538 auto *
I = dyn_cast<Instruction>(DeadInsts[
S]);
540 DeadInsts[
S] =
nullptr;
547 AboutToDeleteCallback);
556 while (!DeadInsts.empty()) {
562 "Live instruction found in dead worklist!");
563 assert(
I->use_empty() &&
"Instructions with uses are not dead.");
568 if (AboutToDeleteCallback)
569 AboutToDeleteCallback(
I);
573 for (
Use &OpU :
I->operands()) {
574 Value *OpV = OpU.get();
585 DeadInsts.push_back(OpI);
590 I->eraseFromParent();
597 for (
auto *DII : DbgUsers) {
599 DII->replaceVariableLocationOp(
I,
Undef);
601 return !DbgUsers.empty();
615 for (++UI; UI != UE; ++UI) {
632 I = cast<Instruction>(*
I->user_begin())) {
638 if (!Visited.
insert(
I).second) {
658 for (
unsigned i = 0,
e =
I->getNumOperands();
i !=
e; ++
i) {
660 I->setOperand(
i,
nullptr);
673 I->eraseFromParent();
681 for (
User *U :
I->users()) {
683 WorkList.
insert(cast<Instruction>(U));
688 bool Changed =
false;
689 if (!
I->use_empty()) {
690 I->replaceAllUsesWith(SimpleV);
694 I->eraseFromParent();
709 bool MadeChange =
false;
726 assert(!BI->isTerminator());
736 while (!WorkList.
empty()) {
751 while (
PHINode *PN = dyn_cast<PHINode>(DestBB->
begin())) {
752 Value *NewVal = PN->getIncomingValue(0);
755 PN->replaceAllUsesWith(NewVal);
756 PN->eraseFromParent();
760 assert(PredBB &&
"Block doesn't have a single predecessor!");
774 if (PredOfPredBB != PredBB)
775 if (SeenPreds.
insert(PredOfPredBB).second)
779 if (SeenPreds.
insert(PredOfPredBB).second)
811 "The successor list of PredBB isn't empty before "
812 "applying corresponding DTU updates.");
833 return First == Second || isa<UndefValue>(
First) || isa<UndefValue>(Second);
864 if (BBPreds.
count(IBB) &&
868 <<
"Can't fold, phi node " << PN->
getName() <<
" in "
869 << Succ->
getName() <<
" is conflicting with "
870 << BBPN->
getName() <<
" with regard to common predecessor "
882 if (BBPreds.
count(IBB) &&
886 <<
" is conflicting with regard to common "
887 <<
"predecessor " << IBB->
getName() <<
"\n");
914 if (!isa<UndefValue>(OldVal)) {
916 IncomingValues.
find(
BB)->second == OldVal) &&
917 "Expected OldVal to match incoming value from BB!");
919 IncomingValues.
insert(std::make_pair(
BB, OldVal));
924 if (It != IncomingValues.
end())
return It->second;
943 if (!isa<UndefValue>(V))
944 IncomingValues.
insert(std::make_pair(
BB, V));
959 if (!isa<UndefValue>(V))
continue;
968 if (It == IncomingValues.
end()) {
969 TrueUndefOps.push_back(
i);
981 unsigned PoisonCount =
count_if(TrueUndefOps, [&](
unsigned i) {
984 if (PoisonCount != 0 && PoisonCount != TrueUndefOps.size()) {
985 for (
unsigned i : TrueUndefOps)
1001 assert(OldVal &&
"No entry in PHI for Pred BB!");
1018 if (isa<PHINode>(OldVal) && cast<PHINode>(OldVal)->
getParent() ==
BB) {
1019 PHINode *OldValPN = cast<PHINode>(OldVal);
1036 for (
unsigned i = 0,
e = BBPreds.size();
i !=
e; ++
i) {
1054 assert(
BB != &
BB->getParent()->getEntryBlock() &&
1055 "TryToSimplifyUncondBranchFromEmptyBlock called on entry block!");
1058 BasicBlock *Succ = cast<BranchInst>(
BB->getTerminator())->getSuccessor(0);
1059 if (
BB == Succ)
return false;
1079 while (isa<PHINode>(*BBI)) {
1081 if (
PHINode* PN = dyn_cast<PHINode>(U.getUser())) {
1082 if (PN->getIncomingBlock(U) !=
BB)
1095 if (
auto *CBI = dyn_cast<CallBrInst>(PredBB->getTerminator())) {
1096 if (Succ == CBI->getDefaultDest())
1098 for (
unsigned i = 0,
e = CBI->getNumIndirectDests();
i !=
e; ++
i)
1099 if (Succ == CBI->getIndirectDest(
i))
1115 if (!PredsOfSucc.
contains(PredOfBB))
1116 if (SeenPreds.
insert(PredOfBB).second)
1120 if (SeenPreds.
insert(PredOfBB).second)
1125 if (isa<PHINode>(Succ->
begin())) {
1144 BB->getTerminator()->eraseFromParent();
1148 while (
PHINode *PN = dyn_cast<PHINode>(&
BB->front())) {
1150 assert(PN->use_empty() &&
"There shouldn't be any uses here!");
1151 PN->eraseFromParent();
1157 unsigned LoopMDKind =
BB->getContext().getMDKindID(
"llvm.loop");
1162 Pred->getTerminator()->setMetadata(LoopMDKind, LoopMD);
1165 BB->replaceAllUsesWith(Succ);
1169 if (
BB->getTerminator())
1170 BB->getInstList().pop_back();
1173 "applying corresponding DTU updates.");
1188 bool Changed =
false;
1193 for (
auto I =
BB->begin();
PHINode *PN = dyn_cast<PHINode>(
I);) {
1198 for (
auto J =
I;
PHINode *DuplicatePN = dyn_cast<PHINode>(J); ++J) {
1220 struct PHIDenseMapInfo {
1221 static PHINode *getEmptyKey() {
1225 static PHINode *getTombstoneKey() {
1230 return PN == getEmptyKey() || PN == getTombstoneKey();
1244 static unsigned getHashValue(
PHINode *PN) {
1259 return LHS->isIdenticalTo(
RHS);
1277 bool Changed =
false;
1278 for (
auto I =
BB->begin();
PHINode *PN = dyn_cast<PHINode>(
I++);) {
1279 auto Inserted = PHISet.
insert(PN);
1280 if (!Inserted.second) {
1283 PN->replaceAllUsesWith(*Inserted.first);
1284 PN->eraseFromParent();
1318 if (
AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
1324 Align CurrentAlign = AI->getAlign();
1325 if (PrefAlign <= CurrentAlign)
1326 return CurrentAlign;
1330 if (
DL.exceedsNaturalStackAlignment(PrefAlign))
1331 return CurrentAlign;
1332 AI->setAlignment(PrefAlign);
1336 if (
auto *GO = dyn_cast<GlobalObject>(V)) {
1338 Align CurrentAlign = GO->getPointerAlignment(
DL);
1339 if (PrefAlign <= CurrentAlign)
1340 return CurrentAlign;
1346 if (!GO->canIncreaseAlignment())
1347 return CurrentAlign;
1349 GO->setAlignment(PrefAlign);
1362 "getOrEnforceKnownAlignment expects a pointer!");
1374 if (PrefAlign && *PrefAlign > Alignment)
1394 for (
auto *DVI : DbgValues) {
1396 if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr))
1413 TypeSize ValueSize =
DL.getTypeAllocSizeInBits(ValTy);
1416 "Fragments don't work on scalable types.");
1425 "address of variable must have exactly 1 location operand.");
1456 assert(DIVar &&
"Missing variable");
1458 Value *DV =
SI->getValueOperand();
1465 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: "
1471 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
SI);
1475 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
SI);
1484 assert(DIVar &&
"Missing variable");
1490 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: "
1502 LI, DIVar, DIExpr, NewLoc, (
Instruction *)
nullptr);
1512 assert(DIVar &&
"Missing variable");
1521 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: "
1527 auto InsertionPt =
BB->getFirstInsertionPt();
1534 if (InsertionPt !=
BB->end())
1535 Builder.insertDbgValueIntrinsic(APN, DIVar, DIExpr, NewLoc, &*InsertionPt);
1552 bool Changed =
false;
1557 if (
auto DDI = dyn_cast<DbgDeclareInst>(&BI))
1558 Dbgs.push_back(DDI);
1563 for (
auto &
I : Dbgs) {
1577 if (LoadInst *LI = dyn_cast<LoadInst>(U))
1578 return LI->isVolatile();
1579 if (StoreInst *SI = dyn_cast<StoreInst>(U))
1580 return SI->isVolatile();
1586 WorkList.push_back(AI);
1587 while (!WorkList.empty()) {
1589 for (
auto &AIUse : V->
uses()) {
1590 User *U = AIUse.getUser();
1592 if (AIUse.getOperandNo() == 1)
1594 }
else if (
LoadInst *LI = dyn_cast<LoadInst>(U)) {
1596 }
else if (
CallInst *CI = dyn_cast<CallInst>(U)) {
1600 if (!CI->isLifetimeStartOrEnd()) {
1604 DIB.insertDbgValueIntrinsic(AI, DDI->
getVariable(), DerefExpr,
1607 }
else if (
BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
1608 if (BI->getType()->isPointerTy())
1609 WorkList.push_back(BI);
1627 assert(
BB &&
"No BasicBlock to clone dbg.value(s) from.");
1628 if (InsertedPHIs.size() == 0)
1633 for (
auto &
I : *
BB) {
1634 if (
auto DbgII = dyn_cast<DbgVariableIntrinsic>(&
I)) {
1635 for (
Value *V : DbgII->location_ops())
1636 if (
auto *Loc = dyn_cast_or_null<PHINode>(V))
1637 DbgValueMap.
insert({Loc, DbgII});
1640 if (DbgValueMap.
size() == 0)
1655 for (
auto PHI : InsertedPHIs) {
1660 for (
auto VI : PHI->operand_values()) {
1661 auto V = DbgValueMap.
find(
VI);
1662 if (V != DbgValueMap.
end()) {
1663 auto *DbgII = cast<DbgVariableIntrinsic>(V->second);
1664 auto NewDI = NewDbgValueMap.
find({Parent, DbgII});
1665 if (NewDI == NewDbgValueMap.
end()) {
1666 auto *NewDbgII = cast<DbgVariableIntrinsic>(DbgII->clone());
1667 NewDI = NewDbgValueMap.
insert({{Parent, DbgII}, NewDbgII}).first;
1678 for (
auto DI : NewDbgValueMap) {
1680 auto *NewDbgII = DI.second;
1682 assert(InsertionPt != Parent->
end() &&
"Ill-formed basic block");
1683 NewDbgII->insertBefore(&*InsertionPt);
1692 const DebugLoc &Loc = DII->getDebugLoc();
1693 auto *DIVar = DII->getVariable();
1694 auto *DIExpr = DII->getExpression();
1695 assert(DIVar &&
"Missing variable");
1699 Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, DII);
1700 DII->eraseFromParent();
1702 return !DbgAddrs.empty();
1710 assert(DIVar &&
"Missing variable");
1715 if (!DIExpr || DIExpr->getNumElements() < 1 ||
1716 DIExpr->getElement(0) != dwarf::DW_OP_deref)
1724 Builder.insertDbgValueIntrinsic(NewAddress, DIVar, DIExpr, Loc, DVI);
1733 if (
auto *DVI = dyn_cast<DbgValueInst>(U.getUser()))
1750 const unsigned MaxDebugArgs = 16;
1751 const unsigned MaxExpressionSize = 128;
1752 bool Salvaged =
false;
1754 for (
auto *DII : DbgUsers) {
1758 bool StackValue = isa<DbgValueInst>(DII);
1759 auto DIILocation = DII->location_ops();
1762 "DbgVariableIntrinsic must use salvaged instruction as its location");
1768 Value *Op0 =
nullptr;
1770 auto LocItr =
find(DIILocation, &
I);
1771 while (SalvagedExpr && LocItr != DIILocation.end()) {
1773 unsigned LocNo = std::distance(DIILocation.begin(), LocItr);
1780 LocItr =
std::find(++LocItr, DIILocation.end(), &
I);
1787 DII->replaceVariableLocationOp(&
I, Op0);
1788 bool IsValidSalvageExpr = SalvagedExpr->
getNumElements() <= MaxExpressionSize;
1789 if (AdditionalValues.empty() && IsValidSalvageExpr) {
1790 DII->setExpression(SalvagedExpr);
1791 }
else if (isa<DbgValueInst>(DII) && IsValidSalvageExpr &&
1792 DII->getNumVariableLocationOps() + AdditionalValues.size() <=
1794 DII->addVariableLocationOps(AdditionalValues, SalvagedExpr);
1801 DII->replaceVariableLocationOp(
I.getOperand(0),
Undef);
1810 for (
auto *DII : DbgUsers) {
1812 DII->replaceVariableLocationOp(&
I,
Undef);
1820 unsigned BitWidth =
DL.getIndexSizeInBits(
GEP->getPointerAddressSpace());
1824 if (!
GEP->collectOffset(
DL,
BitWidth, VariableOffsets, ConstantOffset))
1826 if (!VariableOffsets.
empty() && !CurrentLocOps) {
1827 Opcodes.
insert(Opcodes.begin(), {dwarf::DW_OP_LLVM_arg, 0});
1830 for (
auto Offset : VariableOffsets) {
1831 AdditionalValues.push_back(Offset.first);
1832 assert(Offset.second.isStrictlyPositive() &&
1833 "Expected strictly positive multiplier for offset.");
1835 Offset.second.getZExtValue(), dwarf::DW_OP_mul,
1836 dwarf::DW_OP_plus});
1839 return GEP->getOperand(0);
1845 return dwarf::DW_OP_plus;
1846 case Instruction::Sub:
1847 return dwarf::DW_OP_minus;
1849 return dwarf::DW_OP_mul;
1850 case Instruction::SDiv:
1851 return dwarf::DW_OP_div;
1852 case Instruction::SRem:
1853 return dwarf::DW_OP_mod;
1854 case Instruction::Or:
1855 return dwarf::DW_OP_or;
1856 case Instruction::And:
1857 return dwarf::DW_OP_and;
1858 case Instruction::Xor:
1859 return dwarf::DW_OP_xor;
1860 case Instruction::Shl:
1861 return dwarf::DW_OP_shl;
1862 case Instruction::LShr:
1863 return dwarf::DW_OP_shr;
1864 case Instruction::AShr:
1865 return dwarf::DW_OP_shra;
1876 auto *ConstInt = dyn_cast<ConstantInt>(BI->
getOperand(1));
1878 if (ConstInt && ConstInt->getBitWidth() > 64)
1884 uint64_t Val = ConstInt->getSExtValue();
1892 Opcodes.
append({dwarf::DW_OP_constu, Val});
1894 if (!CurrentLocOps) {
1899 AdditionalValues.push_back(BI->
getOperand(1));
1907 Opcodes.push_back(DwarfBinOp);
1914 auto &
M = *
I.getModule();
1915 auto &
DL =
M.getDataLayout();
1917 if (
auto *CI = dyn_cast<CastInst>(&
I)) {
1918 Value *FromValue = CI->getOperand(0);
1920 if (CI->isNoopCast(
DL)) {
1929 !(isa<TruncInst>(&
I) || isa<SExtInst>(&
I) || isa<ZExtInst>(&
I) ||
1930 isa<IntToPtrInst>(&
I) || isa<PtrToIntInst>(&
I)))
1937 unsigned FromTypeBitSize =
FromType->getScalarSizeInBits();
1942 Ops.
append(ExtOps.begin(), ExtOps.end());
1946 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(&
I))
1948 if (
auto *BI = dyn_cast<BinaryOperator>(&
I))
1973 bool Changed =
false;
1975 if (isa<Instruction>(&To)) {
1976 bool DomPointAfterFrom =
From.getNextNonDebugInstruction() == &DomPoint;
1978 for (
auto *DII :
Users) {
1988 }
else if (!DT.
dominates(&DomPoint, DII)) {
1989 UndefOrSalvage.
insert(DII);
1995 for (
auto *DII :
Users) {
1996 if (UndefOrSalvage.
count(DII))
2009 if (!UndefOrSalvage.
empty()) {
2033 bool SameSize =
DL.getTypeSizeInBits(FromTy) ==
DL.getTypeSizeInBits(ToTy);
2034 bool LosslessConversion = !
DL.isNonIntegralPointerType(FromTy) &&
2035 !
DL.isNonIntegralPointerType(ToTy);
2036 return SameSize && LosslessConversion;
2046 if (!
From.isUsedByMetadata())
2049 assert(&
From != &To &&
"Can't replace something with itself");
2055 return DII.getExpression();
2069 assert(FromBits != ToBits &&
"Unexpected no-op conversion");
2073 if (FromBits < ToBits)
2097 std::pair<unsigned, unsigned>
2099 unsigned NumDeadInst = 0;
2100 unsigned NumDeadDbgInst = 0;
2104 while (EndInst != &
BB->front()) {
2113 if (isa<DbgInfoIntrinsic>(Inst))
2119 return {NumDeadInst, NumDeadDbgInst};
2140 UI->setDebugLoc(
I->getDebugLoc());
2143 unsigned NumInstrsRemoved = 0;
2145 while (BBI != BBE) {
2146 if (!BBI->use_empty())
2148 BB->getInstList().erase(BBI++);
2154 for (
BasicBlock *UniqueSuccessor : UniqueSuccessors)
2158 return NumInstrsRemoved;
2177 auto NewWeights =
uint32_t(TotalWeight) != TotalWeight
2180 NewCall->
setMetadata(LLVMContext::MD_prof, NewWeights);
2218 BB->getInstList().pop_back();
2232 UnwindEdge, InvokeArgs, OpBundles, CI->
getName(),
BB);
2255 Worklist.push_back(
BB);
2257 bool Changed =
false;
2265 if (
auto *CI = dyn_cast<CallInst>(&
I)) {
2269 auto IntrinsicID =
F->getIntrinsicID();
2274 if (IntrinsicID == Intrinsic::assume) {
2281 }
else if (IntrinsicID == Intrinsic::experimental_guard) {
2292 if (!isa<UnreachableInst>(CI->getNextNode())) {
2298 }
else if ((isa<ConstantPointerNull>(
Callee) &&
2300 isa<UndefValue>(
Callee)) {
2305 if (CI->doesNotReturn() && !CI->isMustTailCall()) {
2309 if (!isa<UnreachableInst>(CI->getNextNode())) {
2316 }
else if (
auto *
SI = dyn_cast<StoreInst>(&
I)) {
2322 if (
SI->isVolatile())
continue;
2324 Value *Ptr =
SI->getOperand(1);
2326 if (isa<UndefValue>(Ptr) ||
2327 (isa<ConstantPointerNull>(Ptr) &&
2329 SI->getPointerAddressSpace()))) {
2338 if (
auto *II = dyn_cast<InvokeInst>(
Terminator)) {
2341 if ((isa<ConstantPointerNull>(
Callee) &&
2343 isa<UndefValue>(
Callee)) {
2347 if (II->doesNotReturn() &&
2348 !isa<UnreachableInst>(II->getNormalDest()->front())) {
2354 BasicBlock *OrigNormalDest = II->getNormalDest();
2358 Ctx, OrigNormalDest->
getName() +
".unreachable",
2359 II->getFunction(), OrigNormalDest);
2361 II->setNormalDest(UnreachableNormalDest);
2369 if (II->use_empty() && !II->mayHaveSideEffects()) {
2371 BasicBlock *NormalDestBB = II->getNormalDest();
2372 BasicBlock *UnwindDestBB = II->getUnwindDest();
2375 II->eraseFromParent();
2383 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(
Terminator)) {
2385 struct CatchPadDenseMapInfo {
2400 if (
LHS == getEmptyKey() ||
LHS == getTombstoneKey() ||
2401 RHS == getEmptyKey() ||
RHS == getTombstoneKey())
2403 return LHS->isIdenticalTo(
RHS);
2414 E = CatchSwitch->handler_end();
2418 ++NumPerSuccessorCases[HandlerBB];
2419 auto *CatchPad = cast<CatchPadInst>(HandlerBB->
getFirstNonPHI());
2420 if (!HandlerSet.insert({CatchPad, Empty}).second) {
2422 --NumPerSuccessorCases[HandlerBB];
2423 CatchSwitch->removeHandler(
I);
2430 std::vector<DominatorTree::UpdateType> Updates;
2431 for (
const std::pair<BasicBlock *, int> &
I : NumPerSuccessorCases)
2434 DTU->applyUpdates(Updates);
2442 }
while (!Worklist.empty());
2449 if (
auto *II = dyn_cast<InvokeInst>(TI)) {
2457 if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
2459 UnwindDest = CRI->getUnwindDest();
2460 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(TI)) {
2462 CatchSwitch->getParentPad(),
nullptr, CatchSwitch->getNumHandlers(),
2463 CatchSwitch->getName(), CatchSwitch);
2464 for (
BasicBlock *PadBB : CatchSwitch->handlers())
2465 NewCatchSwitch->addHandler(PadBB);
2467 NewTI = NewCatchSwitch;
2468 UnwindDest = CatchSwitch->getUnwindDest();
2491 if (Reachable.
size() ==
F.size())
2508 if (BlocksToRemove.
empty())
2512 NumRemoved += BlocksToRemove.
size();
2528 unsigned Kind = MD.first;
2536 case LLVMContext::MD_dbg:
2538 case LLVMContext::MD_tbaa:
2541 case LLVMContext::MD_alias_scope:
2544 case LLVMContext::MD_noalias:
2545 case LLVMContext::MD_mem_parallel_loop_access:
2548 case LLVMContext::MD_access_group:
2552 case LLVMContext::MD_range:
2563 case LLVMContext::MD_fpmath:
2566 case LLVMContext::MD_invariant_load:
2570 case LLVMContext::MD_nonnull:
2575 case LLVMContext::MD_invariant_group:
2578 case LLVMContext::MD_align:
2582 case LLVMContext::MD_dereferenceable:
2583 case LLVMContext::MD_dereferenceable_or_null:
2587 case LLVMContext::MD_preserve_access_index:
2598 if (
auto *JMD = J->
getMetadata(LLVMContext::MD_invariant_group))
2599 if (isa<LoadInst>(K) || isa<StoreInst>(K))
2600 K->
setMetadata(LLVMContext::MD_invariant_group, JMD);
2605 unsigned KnownIDs[] = {
2606 LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope,
2607 LLVMContext::MD_noalias, LLVMContext::MD_range,
2608 LLVMContext::MD_invariant_load, LLVMContext::MD_nonnull,
2609 LLVMContext::MD_invariant_group, LLVMContext::MD_align,
2610 LLVMContext::MD_dereferenceable,
2611 LLVMContext::MD_dereferenceable_or_null,
2612 LLVMContext::MD_access_group, LLVMContext::MD_preserve_access_index};
2618 Source.getAllMetadata(MD);
2622 for (
const auto &MDPair : MD) {
2623 unsigned ID = MDPair.first;
2633 case LLVMContext::MD_dbg:
2634 case LLVMContext::MD_tbaa:
2635 case LLVMContext::MD_prof:
2636 case LLVMContext::MD_fpmath:
2637 case LLVMContext::MD_tbaa_struct:
2638 case LLVMContext::MD_invariant_load:
2639 case LLVMContext::MD_alias_scope:
2640 case LLVMContext::MD_noalias:
2641 case LLVMContext::MD_nontemporal:
2642 case LLVMContext::MD_mem_parallel_loop_access:
2643 case LLVMContext::MD_access_group:
2648 case LLVMContext::MD_nonnull:
2652 case LLVMContext::MD_align:
2653 case LLVMContext::MD_dereferenceable:
2654 case LLVMContext::MD_dereferenceable_or_null:
2660 case LLVMContext::MD_range:
2668 auto *ReplInst = dyn_cast<Instruction>(Repl);
2678 if (!isa<LoadInst>(
I))
2679 ReplInst->andIRFlags(
I);
2690 static const unsigned KnownIDs[] = {
2691 LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope,
2692 LLVMContext::MD_noalias, LLVMContext::MD_range,
2693 LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load,
2694 LLVMContext::MD_invariant_group, LLVMContext::MD_nonnull,
2695 LLVMContext::MD_access_group, LLVMContext::MD_preserve_access_index};
2699 template <
typename RootType,
typename DominatesFn>
2701 const RootType &Root,
2702 const DominatesFn &Dominates) {
2707 if (!Dominates(Root, U))
2711 <<
"' as " << *To <<
" in " << *U <<
"\n");
2719 auto *
BB =
From->getParent();
2723 auto *
I = cast<Instruction>(U.getUser());
2724 if (
I->getParent() ==
BB)
2753 if (Call->hasFnAttr(
"gc-leaf-function"))
2755 if (
const Function *
F = Call->getCalledFunction()) {
2756 if (
F->hasFnAttribute(
"gc-leaf-function"))
2759 if (
auto IID =
F->getIntrinsicID()) {
2761 return IID != Intrinsic::experimental_gc_statepoint &&
2762 IID != Intrinsic::experimental_deoptimize &&
2763 IID != Intrinsic::memcpy_element_unordered_atomic &&
2764 IID != Intrinsic::memmove_element_unordered_atomic;
2781 auto *NewTy = NewLI.
getType();
2784 if (NewTy->isPointerTy()) {
2791 if (!NewTy->isIntegerTy())
2796 auto *ITy = cast<IntegerType>(NewTy);
2806 auto *NewTy = NewLI.
getType();
2812 if (!NewTy->isPointerTy())
2815 unsigned BitWidth =
DL.getPointerTypeSizeInBits(NewTy);
2825 for (
auto *DII : DbgUsers)
2826 DII->eraseFromParent();
2855 I->dropUndefImplyingAttrsAndUnknownMetadata();
2856 if (
I->isUsedByMetadata())
2858 if (
I->isDebugOrPseudoInst()) {
2860 II =
I->eraseFromParent();
2868 BB->getTerminator()->getIterator());
2876 BitPart(
Value *
P,
unsigned BW) : Provider(
P) {
2877 Provenance.resize(BW);
2887 enum { Unset = -1 };
2923 auto I = BPS.find(V);
2927 auto &Result = BPS[V] =
None;
2936 LLVM_DEBUG(
dbgs() <<
"collectBitParts max recursion depth reached.\n");
2940 if (
auto *
I = dyn_cast<Instruction>(V)) {
2948 Depth + 1, FoundRoot);
2949 if (!A || !A->Provider)
2953 Depth + 1, FoundRoot);
2954 if (!
B || A->Provider !=
B->Provider)
2958 Result = BitPart(A->Provider,
BitWidth);
2959 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx) {
2960 if (A->Provenance[BitIdx] != BitPart::Unset &&
2961 B->Provenance[BitIdx] != BitPart::Unset &&
2962 A->Provenance[BitIdx] !=
B->Provenance[BitIdx])
2963 return Result =
None;
2965 if (A->Provenance[BitIdx] == BitPart::Unset)
2966 Result->Provenance[BitIdx] =
B->Provenance[BitIdx];
2968 Result->Provenance[BitIdx] = A->Provenance[BitIdx];
2976 const APInt &BitShift = *
C;
2983 if (!MatchBitReversals && (BitShift.
getZExtValue() % 8) != 0)
2987 Depth + 1, FoundRoot);
2993 auto &
P = Result->Provenance;
2994 if (
I->getOpcode() == Instruction::Shl) {
3008 const APInt &AndMask = *
C;
3013 if (!MatchBitReversals && (NumMaskedBits % 8) != 0)
3017 Depth + 1, FoundRoot);
3022 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3024 if (AndMask[BitIdx] == 0)
3025 Result->Provenance[BitIdx] = BitPart::Unset;
3032 Depth + 1, FoundRoot);
3036 Result = BitPart(Res->Provider,
BitWidth);
3037 auto NarrowBitWidth =
X->getType()->getScalarSizeInBits();
3038 for (
unsigned BitIdx = 0; BitIdx < NarrowBitWidth; ++BitIdx)
3039 Result->Provenance[BitIdx] = Res->Provenance[BitIdx];
3040 for (
unsigned BitIdx = NarrowBitWidth; BitIdx <
BitWidth; ++BitIdx)
3041 Result->Provenance[BitIdx] = BitPart::Unset;
3048 Depth + 1, FoundRoot);
3052 Result = BitPart(Res->Provider,
BitWidth);
3053 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3054 Result->Provenance[BitIdx] = Res->Provenance[BitIdx];
3062 Depth + 1, FoundRoot);
3066 Result = BitPart(Res->Provider,
BitWidth);
3067 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3068 Result->Provenance[(
BitWidth - 1) - BitIdx] = Res->Provenance[BitIdx];
3075 Depth + 1, FoundRoot);
3080 Result = BitPart(Res->Provider,
BitWidth);
3081 for (
unsigned ByteIdx = 0; ByteIdx < ByteWidth; ++ByteIdx) {
3082 unsigned ByteBitOfs = ByteIdx * 8;
3083 for (
unsigned BitIdx = 0; BitIdx < 8; ++BitIdx)
3084 Result->Provenance[(
BitWidth - 8 - ByteBitOfs) + BitIdx] =
3085 Res->Provenance[ByteBitOfs + BitIdx];
3102 if (!MatchBitReversals && (ModAmt % 8) != 0)
3107 Depth + 1, FoundRoot);
3108 if (!
LHS || !
LHS->Provider)
3112 Depth + 1, FoundRoot);
3113 if (!
RHS ||
LHS->Provider !=
RHS->Provider)
3116 unsigned StartBitRHS =
BitWidth - ModAmt;
3118 for (
unsigned BitIdx = 0; BitIdx < StartBitRHS; ++BitIdx)
3119 Result->Provenance[BitIdx + ModAmt] =
LHS->Provenance[BitIdx];
3120 for (
unsigned BitIdx = 0; BitIdx < ModAmt; ++BitIdx)
3121 Result->Provenance[BitIdx] =
RHS->Provenance[BitIdx + StartBitRHS];
3135 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3136 Result->Provenance[BitIdx] = BitIdx;
3142 if (
From % 8 != To % 8)
3157 Instruction *
I,
bool MatchBSwaps,
bool MatchBitReversals,
3163 if (!MatchBSwaps && !MatchBitReversals)
3165 Type *ITy =
I->getType();
3170 bool FoundRoot =
false;
3171 std::map<Value *, Optional<BitPart>> BPS;
3178 [](int8_t
I) {
return I == BitPart::Unset || 0 <=
I; }) &&
3179 "Illegal bit provenance index");
3182 Type *DemandedTy = ITy;
3183 if (BitProvenance.
back() == BitPart::Unset) {
3184 while (!BitProvenance.
empty() && BitProvenance.
back() == BitPart::Unset)
3185 BitProvenance = BitProvenance.
drop_back();
3186 if (BitProvenance.
empty())
3189 if (
auto *IVecTy = dyn_cast<VectorType>(ITy))
3201 bool OKForBSwap = MatchBSwaps && (DemandedBW % 16) == 0;
3202 bool OKForBitReverse = MatchBitReversals;
3203 for (
unsigned BitIdx = 0;
3204 (BitIdx < DemandedBW) && (OKForBSwap || OKForBitReverse); ++BitIdx) {
3205 if (BitProvenance[BitIdx] == BitPart::Unset) {
3212 BitIdx, DemandedBW);
3217 Intrin = Intrinsic::bswap;
3218 else if (OKForBitReverse)
3219 Intrin = Intrinsic::bitreverse;
3224 Value *Provider = Res->Provider;
3227 if (DemandedTy != Provider->
getType()) {
3230 InsertedInsts.push_back(Trunc);
3235 InsertedInsts.push_back(Result);
3240 InsertedInsts.push_back(Result);
3244 if (ITy != Result->getType()) {
3246 InsertedInsts.push_back(ExtInst);
3261 if (
F && !
F->hasLocalLinkage() &&
F->hasName() &&
3263 !
F->doesNotAccessMemory())
3269 if (
I->getOperand(OpIdx)->getType()->isMetadataTy())
3273 if (!isa<Constant>(
I->getOperand(OpIdx)))
3276 switch (
I->getOpcode()) {
3280 case Instruction::Invoke: {
3281 const auto &CB = cast<CallBase>(*
I);
3284 if (CB.isInlineAsm())
3289 if (CB.isBundleOperand(OpIdx))
3292 if (OpIdx < CB.arg_size()) {
3295 if (isa<IntrinsicInst>(CB) &&
3296 OpIdx >= CB.getFunctionType()->getNumParams()) {
3298 return CB.getIntrinsicID() == Intrinsic::experimental_stackmap;
3303 if (CB.getIntrinsicID() == Intrinsic::gcroot)
3307 return !CB.paramHasAttr(OpIdx, Attribute::ImmArg);
3312 return !isa<IntrinsicInst>(CB);
3314 case Instruction::ShuffleVector:
3317 case Instruction::Switch:
3318 case Instruction::ExtractValue:
3321 case Instruction::InsertValue:
3324 case Instruction::Alloca:
3328 return !cast<AllocaInst>(
I)->isStaticAlloca();
3329 case Instruction::GetElementPtr:
3333 for (
auto E = std::next(It, OpIdx); It !=
E; ++It)
3342 if (
Constant *
C = dyn_cast<Constant>(Condition))
3346 Value *NotCondition;
3348 return NotCondition;
3351 Instruction *Inst = dyn_cast<Instruction>(Condition);
3354 else if (
Argument *
Arg = dyn_cast<Argument>(Condition))
3355 Parent = &
Arg->getParent()->getEntryBlock();
3356 assert(Parent &&
"Unsupported condition to invert");
3367 if (Inst && !isa<PHINode>(Inst))
3368 Inverted->insertAfter(Inst);
3378 bool Changed =
false;
3380 if (!
F.hasFnAttribute(Attribute::NoSync) &&
3381 F.doesNotAccessMemory() && !
F.isConvergent()) {
3387 if (!
F.hasFnAttribute(Attribute::NoFree) &&
F.onlyReadsMemory()) {
3388 F.setDoesNotFreeMemory();
3393 if (!
F.hasFnAttribute(Attribute::MustProgress) &&
F.willReturn()) {
3394 F.setMustProgress();
static DIExpression * prepend(const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an ...
BasicBlock * getNormalDest() const
bool hasNItemsOrLess(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;})
Returns true if the sequence [Begin, End) has N or less items.
Value * invertCondition(Value *Condition)
Invert the given true/false value, possibly reusing an existing copy.
DIExpression * getExpression() const
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
This class represents an incoming formal argument to a Function.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
static Value * selectIncomingValueForBlock(Value *OldVal, BasicBlock *BB, IncomingValueMap &IncomingValues)
Determines the value to use as the phi node input for a block.
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
This is an optimization pass for GlobalISel generic memory operations.
Value * getAddress() const
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===------------------------------------------------------------------—===// Dbg Intrinsic utilities
uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
void reserve(size_t Size)
Grow the DenseSet so that it can contain at least NumEntries items before resizing again.
void deleteBB(BasicBlock *DelBB)
Delete DelBB.
static Constant * getNot(Constant *C)
A parsed version of the target data layout string in and methods for querying it.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static void replaceOneDbgValueForAlloca(DbgValueInst *DVI, Value *NewAddress, DIBuilder &Builder, int Offset)
InstListType::iterator iterator
Instruction iterators...
const Function * getParent() const
Return the enclosing method, or null if none.
bool isPointerTy() const
True if this is an instance of PointerType.
static unsigned getHashValueImpl(SimpleValue Val)
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
ScalarTy getFixedSize() const
bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI)
Return true if this call calls a gc leaf function.
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
static Align tryEnforceAlignment(Value *V, Align PrefAlign, const DataLayout &DL)
If the specified pointer points to an object that we control, try to modify the object's alignment to...
size_type size() const
Determine the number of elements in the SetVector.
This class represents a no-op cast from one type to another.
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
const APInt & getValue() const
Return the constant as an APInt value reference.
unsigned pred_size(MachineBasicBlock *BB)
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
static bool areAllUsesEqual(Instruction *I)
areAllUsesEqual - Check whether the uses of a value are all the same.
int64_t getSExtValue() const
Get sign extended value.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
static void gatherIncomingValuesToPhi(PHINode *PN, IncomingValueMap &IncomingValues)
Create a map from block to value for the operands of a given phi.
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
static unsigned getIntrinsicID(const SDNode *N)
void dropDebugUsers(Instruction &I)
Remove the debug intrinsic instructions for the given instruction.
void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified blocks from BB.
bool isAssumeWithEmptyBundle(AssumeInst &Assume)
Return true iff the operand bundles of the provided llvm.assume doesn't contain any valuable informat...
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
void removeBlocks(const SmallSetVector< BasicBlock *, 8 > &DeadBlocks)
Remove all MemoryAcceses in a set of BasicBlocks about to be deleted.
void replaceVariableLocationOp(Value *OldValue, Value *NewValue)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
The instances of the Type class are immutable: once they are created, they are never changed.
bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function's entry.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
DILocation * getInlinedAt() const
Align getOrEnforceKnownAlignment(Value *V, MaybeAlign PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
AttributeList getAttributes() const
Return the parameter attributes for this call.
uint64_t getDwarfOpForBinOp(Instruction::BinaryOps Opcode)
FunctionType * getFunctionType() const
value_op_iterator value_op_begin()
static constexpr UpdateKind Insert
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
DILocalVariable * getVariable() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
This class implements a map that also provides access to all stored values in a deterministic order.
TinyPtrVector< DbgVariableIntrinsic * > FindDbgAddrUses(Value *V)
Finds all intrinsics declaring local variables as living in the memory that 'V' points to.
auto successors(MachineBasicBlock *BB)
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", Instruction *InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
static const unsigned BitPartRecursionMaxDepth
CallInst * changeToCall(InvokeInst *II, DomTreeUpdater *DTU=nullptr)
This function converts the specified invoek into a normall call.
LLVM_NODISCARD T pop_back_val()
Value * getPointerOperand()
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
gep_type_iterator gep_type_begin(const User *GEP)
BinaryOp_match< ValTy, cst_pred_ty< is_all_ones >, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
bool succ_empty(const Instruction *I)
static bool isSentinel(const DWARFDebugNames::AttributeEncoding &AE)
std::pair< iterator, bool > insert(const ValueT &V)
void setIncomingValue(unsigned i, Value *V)
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
bool isScalable() const
Returns whether the size is scaled by a runtime quantity (vscale).
void combineMetadataForCSE(Instruction *K, const Instruction *J, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
__FakeVCSRevision h endif() endif() set(generated_files "$
static IntegerType * getInt32Ty(LLVMContext &C)
bool isEqual(const GCNRPTracker::LiveRegSet &S1, const GCNRPTracker::LiveRegSet &S2)
Value * getVariableLocationOp(unsigned OpIdx) const
bool empty() const
empty - Check if the array is empty.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned countPopulation() const
Count the number of bits set.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
LLVM Basic Block Representation.
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
unsigned getNumOperands() const
Return number of MDNode operands.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
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.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
This is the shared class of boolean and integer constants.
bool isArrayTy() const
True if this is an instance of ArrayType.
static bool rewriteDebugUsers(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT, function_ref< DbgValReplacement(DbgVariableIntrinsic &DII)> RewriteExpr)
Point debug users of From to To using exprs given by RewriteExpr, possibly moving/undefing users to p...
static bool valueCoversEntireFragment(Type *ValTy, DbgVariableIntrinsic *DII)
Check if the alloc size of ValTy is large enough to cover the variable (or fragment of the variable) ...
An information struct used to provide DenseMap with the various necessary components for a given valu...
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 DIExpression * appendOpsToArg(const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_a...
const T & back() const
back - Get the last element.
bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
static void replaceUndefValuesInPhi(PHINode *PN, const IncomingValueMap &IncomingValues)
Replace the incoming undef values to a phi with the values from a block-to-value map.
bool match(Val *V, const Pattern &P)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
bool isBBPendingDeletion(BasicBlock *DelBB) const
Returns true if DelBB is awaiting deletion.
This represents the llvm.dbg.value instruction.
Optional< DIExpression * > DbgValReplacement
A replacement for a dbg.value expression.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool isAddressOfVariable() const
Does this describe the address of a local variable.
static bool CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ)
Return true if we can fold BB, an almost-empty BB ending in an unconditional branch to Succ,...
(vector float) vec_cmpeq(*A, *B) C
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
iterator begin()
Instruction iterator methods.
bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx)
Given an instruction, is it legal to set operand OpIdx to a non-constant value?
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
bool isIdenticalToWhenDefined(const Instruction *I) const
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
void recalculate(Function &F)
Notify DTU that the entry block was replaced.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
bool isVectorTy() const
True if this is an instance of VectorType.
iterator_range< use_iterator > uses()
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
bool inferAttributesFromOthers(Function &F)
If we can infer one attribute from another on the declaration of a function, explicitly materialize t...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
into llvm powi allowing the code generator to produce balanced multiplication trees First
void setExpression(DIExpression *NewExpr)
std::pair< unsigned, unsigned > removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB)
Remove all instructions from a basic block other than its terminator and any present EH pad instructi...
Value * getIncomingValueForBlock(const BasicBlock *BB) const
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
BinaryOps getOpcode() const
bool isTokenTy() const
Return true if this is 'token'.
static unsigned replaceDominatedUsesWith(Value *From, Value *To, const RootType &Root, const DominatesFn &Dominates)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
static bool bitTransformIsCorrectForBSwap(unsigned From, unsigned To, unsigned BitWidth)
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
static bool isStructure(AllocaInst *AI)
Determine whether this alloca is a structure.
uint64_t getZExtValue() const
Get zero extended value.
STATISTIC(NumFunctions, "Total number of functions")
void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a range metadata node to a new load instruction.
auto predecessors(MachineBasicBlock *BB)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
static bool bitTransformIsCorrectForBitReverse(unsigned From, unsigned To, unsigned BitWidth)
bool RemoveRedundantDbgInstrs(BasicBlock *BB)
Try to remove redundant dbg.value instructions from given basic block.
This struct is a compact representation of a valid (non-zero power of two) alignment.
CallingConv::ID getCallingConv() const
bool empty() const
Determine if the SetVector is empty or not.
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
unsigned getNumVariableLocationOps() const
bool hasDomTree() const
Returns true if it holds a DominatorTree.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
static DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
bool isIntegerTy() const
True if this is an instance of IntegerType.
An efficient, type-erasing, non-owning reference to a callable.
const MDOperand & getOperand(unsigned I) const
bool isMathLibCallNoop(const CallBase *Call, const TargetLibraryInfo *TLI)
Check whether the given call has no side-effects.
Implements a dense probed hash-table based set.
bool wouldInstructionBeTriviallyDead(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.
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
void copyMetadataForLoad(LoadInst &Dest, const LoadInst &Source)
Copy the metadata from the source instruction to the destination (the replacement for the source inst...
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
void removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
Replace 'BB's terminator with one that does not have an unwind successor block.
This is the common base class for debug info intrinsics for variables.
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes,...
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
An instruction for storing to memory.
This is an important base class in LLVM.
Class recording the (high level) value of a variable.
static MDNode * intersect(MDNode *A, MDNode *B)
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
iterator find(const KeyT &Key)
This represents the llvm.dbg.declare instruction.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
void changeToUnreachable(const Instruction *I)
Instruction I will be changed to an unreachable.
This represents the llvm.dbg.label instruction.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
bool canSimplifyInvokeNoUnwind(const Function *F)
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
This is an important class for using LLVM in a threaded context.
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
initializer< Ty > init(const Ty &Val)
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...
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
void insertDebugValuesForPHIs(BasicBlock *BB, SmallVectorImpl< PHINode * > &InsertedPHIs)
Propagate dbg.value intrinsics through the newly inserted PHIs.
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.
void findDbgValues(SmallVectorImpl< DbgValueInst * > &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
void hoistAllInstructionsInto(BasicBlock *DomBlock, Instruction *InsertPt, BasicBlock *BB)
Hoist all of the instructions in the IfBlock to the dominant block DomBlock, by moving its instructio...
iterator find(const_arg_type_t< KeyT > Val)
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
static MDNode * getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static cl::opt< unsigned > PHICSENumPHISmallSize("phicse-num-phi-smallsize", cl::init(32), cl::Hidden, cl::desc("When the basic block contains not more than this number of PHI nodes, " "perform a (faster!) exhaustive search instead of set-driven one."))
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
void salvageDebugInfoForDbgValues(Instruction &I, ArrayRef< DbgVariableIntrinsic * > Insns)
Implementation of salvageDebugInfo, applying only to instructions in Insns, rather than all debug use...
StandardInstrumentations SI(Debug, VerifyEach)
bool wouldInstructionBeTriviallyDeadOnUnusedPaths(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction has no side effects on any paths other than whe...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
static bool isKnownGE(const LinearPolySize &LHS, const LinearPolySize &RHS)
bool has(LibFunc F) const
Tests whether a library function is available.
print Print MemDeps of function
A Module instance is used to store all the information related to an LLVM module.
unsigned replaceDominatedUsesWith(Value *From, Value *To, DominatorTree &DT, const BasicBlockEdge &Edge)
Replace each use of 'From' with 'To' if that use is dominated by the given edge.
bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT)
Point debug users of From to To or salvage them.
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge, DomTreeUpdater *DTU=nullptr)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
block_iterator block_begin()
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or None if this type is neither signed nor unsigned.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
Class for arbitrary precision integers.
bool insert(const value_type &X)
Insert a new element into the SetVector.
Value * getSalvageOpsForGEP(GetElementPtrInst *GEP, const DataLayout &DL, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Opcodes, SmallVectorImpl< Value * > &AdditionalValues)
MDNode * intersectAccessGroups(const Instruction *Inst1, const Instruction *Inst2)
Compute the access-group list of access groups that Inst1 and Inst2 are both in.
The address of a basic block.
@ DW_OP_LLVM_arg
Only used in LLVM metadata.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction will return.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
SmallVector< MachineOperand, 4 > Cond
auto m_Undef()
Match an arbitrary undef constant.
A cache of @llvm.assume calls within a function.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static const Function * getParent(const Value *V)
LLVMContext & getContext() const
All values hold a context through their type.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
static bool PhiHasDebugValue(DILocalVariable *DIVar, DIExpression *DIExpr, PHINode *APN)
===------------------------------------------------------------------—===// Dbg Intrinsic utilities
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
self_iterator getIterator()
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction * > &InsertedInsts)
Try to match a bswap or bitreverse idiom.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
static bool isEqualImpl(SimpleValue LHS, SimpleValue RHS)
Optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
void maybeMarkSanitizerLibraryCallNoBuiltin(CallInst *CI, const TargetLibraryInfo *TLI)
Given a CallInst, check if it calls a string function known to CodeGen, and mark it with NoBuiltin if...
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
StringRef getName() const
Return a constant reference to the value's name.
this could be done in SelectionDAGISel along with other special for
An instruction for reading from memory.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
static bool isBitCastSemanticsPreserving(const DataLayout &DL, Type *FromTy, Type *ToTy)
Check if a bitcast between a value of type FromTy to type ToTy would losslessly preserve the bits and...
static bool isArray(AllocaInst *AI)
Determine whether this alloca is either a VLA or an array.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
void replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, int Offset=0)
Replaces multiple llvm.dbg.value instructions when the alloca it describes is replaced with a new val...
block_iterator block_end()
amdgpu Simplify well known AMD library false FunctionCallee Callee
LLVMContext & getContext() const
Get the context in which this basic block lives.
bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
value_op_iterator value_op_end()
static void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DomTreeUpdater *DTU=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs)
Drop all unknown metadata except for debug locations.
static DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
user_iterator_impl< User > user_iterator
static void redirectValuesFromPredecessorsToPhi(BasicBlock *BB, const PredBlockVector &BBPreds, PHINode *PN)
Replace a value flowing from a block to a phi with potentially multiple instances of that value flowi...
static bool CanMergeValues(Value *First, Value *Second)
Return true if we can choose one of these values to use in place of the other.
static const Optional< BitPart > & collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals, std::map< Value *, Optional< BitPart >> &BPS, int Depth, bool &FoundRoot)
Analyze the specified subexpression and see if it is capable of providing pieces of a bswap or bitrev...
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
Interval::pred_iterator pred_end(Interval *I)
Value * salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Ops, SmallVectorImpl< Value * > &AdditionalValues)
static bool markAliveBlocks(Function &F, SmallPtrSetImpl< BasicBlock * > &Reachable, DomTreeUpdater *DTU=nullptr)
constexpr unsigned BitWidth
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
void salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage debug users of I by writing the...
Provides information about what library functions are available for the current target.
iterator find(const KeyT &Val)
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
static ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
Value * getCalledOperand() const
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
bool replaceDbgUsesWithUndef(Instruction *I)
Replace all the uses of an SSA value in @llvm.dbg intrinsics with undef.
static bool EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB)
A wrapper class for inspecting calls to intrinsic functions.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
Value * getSalvageOpsForBinOp(BinaryOperator *BI, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Opcodes, SmallVectorImpl< Value * > &AdditionalValues)
Interval::pred_iterator pred_begin(Interval *I)
pred_begin/pred_end - define methods so that Intervals may be used just like BasicBlocks can with the...
unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
const InstListType & getInstList() const
Return the underlying instruction list container.
static MDNode * getMostGenericRange(MDNode *A, MDNode *B)
bool isStructTy() const
True if this is an instance of StructType.
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
MDNode * createRange(const APInt &Lo, const APInt &Hi)
Return metadata describing the range [Lo, Hi).
LLVM_NODISCARD bool empty() const
Value handle that asserts if the Value is deleted.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
const BasicBlock * getParent() const
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
size_t size() const
size - Get the array size.
iv Induction Variable Users
const Instruction * getFirstNonPHIOrDbg(bool SkipPseudoOp=true) const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic,...
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...
unsigned getNumElements() const
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified block, which must have no predecessors.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
A SetVector that performs no allocations if smaller than a certain size.
This class represents a function call, abstracting a target machine's calling convention.
static bool EliminateDuplicatePHINodesNaiveImpl(BasicBlock *BB)
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
This function has undefined behavior.
bool hasOptimizedCodeGen(LibFunc F) const
Tests if the function is both available and a candidate for optimized code generation.
CallInst * createCallMatchingInvoke(InvokeInst *II)
Create a call that matches the invoke II in terms of arguments, attributes, debug information,...
SmallVector< T, N > takeVector()
Clear the SetVector and return the underlying vector.
void patchReplacementInstruction(Instruction *I, Value *Repl)
Patch the replacement so that it is not more restrictive than the value being replaced.
unsigned getBitWidth() const
Get the bit width of this value.
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!...
@ ebStrict
This corresponds to "fpexcept.strict".
BlockVerifier::State From
void takeName(Value *V)
Transfer the name from V to this value.
bool isAllocRemovable(const CallBase *V, const TargetLibraryInfo *TLI)
Return false if the allocation can have side effects on the program state we are required to preserve...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
an instruction to allocate memory on the stack
MDNode * getScope() const
Value * getOperand(unsigned i) const
static bool simplifyAndDCEInstruction(Instruction *I, SmallSetVector< Instruction *, 16 > &WorkList, const DataLayout &DL, const TargetLibraryInfo *TLI)
Conditional or Unconditional Branch instruction.
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
bool contains(ConstPtrType Ptr) const
void reserve(size_type N)
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
bool replaceDbgDeclare(Value *Address, Value *NewAddress, DIBuilder &Builder, uint8_t DIExprFlags, int Offset)
Replaces llvm.dbg.declare instruction when the address it describes is replaced with a new value.
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
BasicBlock * getUnwindDest() const
void applyUpdatesPermissive(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
LLVM_NODISCARD T pop_back_val()
bool RecursivelyDeleteTriviallyDeadInstructionsPermissive(SmallVectorImpl< WeakTrackingVH > &DeadInsts, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
Same functionality as RecursivelyDeleteTriviallyDeadInstructions, but allow instructions that are not...
LLVM Value Representation.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
iterator_range< user_iterator > users()
static cl::opt< bool > PHICSEDebugHash("phicse-debug-hash", cl::init(false), cl::Hidden, cl::desc("Perform extra assertion checking to verify that PHINodes's hash " "function is well-behaved w.r.t. its isEqual predicate"))
static DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII, Instruction *Src)
Produce a DebugLoc to use for each dbg.declare/inst pair that are promoted to a dbg....
void destroyConstant()
Called if some element of this constant is no longer valid.
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
void removeMemoryAccess(MemoryAccess *, bool OptimizePhis=false)
Remove a MemoryAccess from MemorySSA, including updating all definitions and uses.
static constexpr UpdateKind Delete
void setCallingConv(CallingConv::ID CC)
A Use represents the edge between a Value definition and its users.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
iterator insert(iterator I, T &&Elt)
@ Undef
Value of the register doesn't matter.