59#include "llvm/IR/IntrinsicsWebAssembly.h"
89#define DEBUG_TYPE "local"
91STATISTIC(NumRemoved,
"Number of unreachable basic blocks removed");
92STATISTIC(NumPHICSEs,
"Number of PHI's that got CSE'd");
96#ifdef EXPENSIVE_CHECKS
102 cl::desc(
"Perform extra assertion checking to verify that PHINodes's hash "
103 "function is well-behaved w.r.t. its isEqual predicate"));
108 "When the basic block contains not more than this number of PHI nodes, "
109 "perform a (faster!) exhaustive search instead of set-driven one."));
133 if (
auto *BI = dyn_cast<BranchInst>(
T)) {
134 if (BI->isUnconditional())
return false;
139 if (Dest2 == Dest1) {
145 assert(BI->getParent() &&
"Terminator not inserted in block!");
152 NewBI->
copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
153 LLVMContext::MD_annotation});
156 BI->eraseFromParent();
157 if (DeleteDeadConditions)
162 if (
auto *
Cond = dyn_cast<ConstantInt>(BI->getCondition())) {
176 NewBI->
copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
177 LLVMContext::MD_annotation});
179 BI->eraseFromParent();
181 DTU->
applyUpdates({{DominatorTree::Delete, BB, OldDest}});
188 if (
auto *
SI = dyn_cast<SwitchInst>(
T)) {
191 auto *CI = dyn_cast<ConstantInt>(
SI->getCondition());
197 SI->getNumCases() > 0) {
198 TheOnlyDest =
SI->case_begin()->getCaseSuccessor();
201 bool Changed =
false;
204 for (
auto It =
SI->case_begin(), End =
SI->case_end(); It != End;) {
206 if (It->getCaseValue() == CI) {
207 TheOnlyDest = It->getCaseSuccessor();
213 if (It->getCaseSuccessor() == DefaultDest) {
215 unsigned NCases =
SI->getNumCases();
218 if (NCases > 1 && MD) {
224 unsigned Idx = It->getCaseIndex();
226 Weights[0] += Weights[
Idx + 1];
230 SI->setMetadata(LLVMContext::MD_prof,
232 createBranchWeights(Weights));
237 It =
SI->removeCase(It);
238 End =
SI->case_end();
242 if (
auto *NewCI = dyn_cast<ConstantInt>(
SI->getCondition())) {
244 It =
SI->case_begin();
254 if (It->getCaseSuccessor() != TheOnlyDest)
255 TheOnlyDest =
nullptr;
261 if (CI && !TheOnlyDest) {
264 TheOnlyDest =
SI->getDefaultDest();
279 if (DTU && Succ != TheOnlyDest)
280 RemovedSuccessors.
insert(Succ);
282 if (Succ == SuccToKeep) {
283 SuccToKeep =
nullptr;
291 SI->eraseFromParent();
292 if (DeleteDeadConditions)
295 std::vector<DominatorTree::UpdateType> Updates;
296 Updates.reserve(RemovedSuccessors.
size());
297 for (
auto *RemovedSuccessor : RemovedSuccessors)
298 Updates.push_back({DominatorTree::Delete, BB, RemovedSuccessor});
304 if (
SI->getNumCases() == 1) {
307 auto FirstCase = *
SI->case_begin();
309 FirstCase.getCaseValue(),
"cond");
313 FirstCase.getCaseSuccessor(),
314 SI->getDefaultDest());
326 MDNode *MakeImplicitMD =
SI->getMetadata(LLVMContext::MD_make_implicit);
328 NewBr->
setMetadata(LLVMContext::MD_make_implicit, MakeImplicitMD);
331 SI->eraseFromParent();
337 if (
auto *IBI = dyn_cast<IndirectBrInst>(
T)) {
340 dyn_cast<BlockAddress>(IBI->getAddress()->stripPointerCasts())) {
341 BasicBlock *TheOnlyDest = BA->getBasicBlock();
348 for (
unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
350 if (DTU && DestBB != TheOnlyDest)
351 RemovedSuccessors.
insert(DestBB);
352 if (IBI->getDestination(i) == SuccToKeep) {
353 SuccToKeep =
nullptr;
358 Value *Address = IBI->getAddress();
359 IBI->eraseFromParent();
360 if (DeleteDeadConditions)
367 BA->destroyConstant();
378 std::vector<DominatorTree::UpdateType> Updates;
379 Updates.reserve(RemovedSuccessors.
size());
380 for (
auto *RemovedSuccessor : RemovedSuccessors)
381 Updates.push_back({DominatorTree::Delete, BB, RemovedSuccessor});
410 if (II->getIntrinsicID() == Intrinsic::stacksave ||
411 II->getIntrinsicID() == Intrinsic::launder_invariant_group ||
412 II->isLifetimeStartOrEnd())
419 if (
I->isTerminator())
430 if (DDI->getAddress())
435 if (DVI->hasArgList() || DVI->getValue(0))
445 if (
auto *CB = dyn_cast<CallBase>(
I))
449 if (!
I->willReturn()) {
450 auto *II = dyn_cast<IntrinsicInst>(
I);
456 switch (II->getIntrinsicID()) {
457 case Intrinsic::wasm_trunc_signed:
458 case Intrinsic::wasm_trunc_unsigned:
459 case Intrinsic::ptrauth_auth:
460 case Intrinsic::ptrauth_resign:
467 if (!
I->mayHaveSideEffects())
474 if (II->getIntrinsicID() == Intrinsic::stacksave ||
475 II->getIntrinsicID() == Intrinsic::launder_invariant_group)
478 if (II->isLifetimeStartOrEnd()) {
479 auto *
Arg = II->getArgOperand(1);
481 if (isa<UndefValue>(
Arg))
485 if (isa<AllocaInst>(
Arg) || isa<GlobalValue>(
Arg) || isa<Argument>(
Arg))
487 if (IntrinsicInst *IntrinsicUse =
488 dyn_cast<IntrinsicInst>(Use.getUser()))
489 return IntrinsicUse->isLifetimeStartOrEnd();
499 if ((II->getIntrinsicID() == Intrinsic::assume &&
501 II->getIntrinsicID() == Intrinsic::experimental_guard) {
503 return !
Cond->isZero();
508 if (
auto *FPI = dyn_cast<ConstrainedFPIntrinsic>(
I)) {
509 std::optional<fp::ExceptionBehavior> ExBehavior =
510 FPI->getExceptionBehavior();
515 if (
auto *Call = dyn_cast<CallBase>(
I)) {
517 if (
Constant *
C = dyn_cast<Constant>(FreedOp))
518 return C->isNullValue() || isa<UndefValue>(
C);
524 if (
auto *LI = dyn_cast<LoadInst>(
I))
525 if (
auto *GV = dyn_cast<GlobalVariable>(
526 LI->getPointerOperand()->stripPointerCasts()))
527 if (!LI->isVolatile() && GV->isConstant())
539 std::function<
void(
Value *)> AboutToDeleteCallback) {
547 AboutToDeleteCallback);
555 std::function<
void(
Value *)> AboutToDeleteCallback) {
556 unsigned S = 0,
E = DeadInsts.
size(), Alive = 0;
557 for (; S !=
E; ++S) {
558 auto *
I = dyn_cast_or_null<Instruction>(DeadInsts[S]);
560 DeadInsts[S] =
nullptr;
567 AboutToDeleteCallback);
574 std::function<
void(
Value *)> AboutToDeleteCallback) {
576 while (!DeadInsts.
empty()) {
582 "Live instruction found in dead worklist!");
583 assert(
I->use_empty() &&
"Instructions with uses are not dead.");
588 if (AboutToDeleteCallback)
589 AboutToDeleteCallback(
I);
593 for (
Use &OpU :
I->operands()) {
594 Value *OpV = OpU.get();
610 I->eraseFromParent();
617 for (
auto *DII : DbgUsers)
618 DII->setKillLocation();
619 return !DbgUsers.
empty();
633 for (++UI; UI != UE; ++UI) {
650 I = cast<Instruction>(*
I->user_begin())) {
656 if (!Visited.
insert(
I).second) {
676 for (
unsigned i = 0, e =
I->getNumOperands(); i != e; ++i) {
677 Value *OpV =
I->getOperand(i);
678 I->setOperand(i,
nullptr);
691 I->eraseFromParent();
699 for (
User *U :
I->users()) {
701 WorkList.
insert(cast<Instruction>(U));
706 bool Changed =
false;
707 if (!
I->use_empty()) {
708 I->replaceAllUsesWith(SimpleV);
712 I->eraseFromParent();
727 bool MadeChange =
false;
744 assert(!BI->isTerminator());
754 while (!WorkList.
empty()) {
769 while (
PHINode *PN = dyn_cast<PHINode>(DestBB->
begin())) {
770 Value *NewVal = PN->getIncomingValue(0);
773 PN->replaceAllUsesWith(NewVal);
774 PN->eraseFromParent();
778 assert(PredBB &&
"Block doesn't have a single predecessor!");
792 if (PredOfPredBB != PredBB)
793 if (SeenPreds.
insert(PredOfPredBB).second)
794 Updates.
push_back({DominatorTree::Insert, PredOfPredBB, DestBB});
797 if (SeenPreds.
insert(PredOfPredBB).second)
798 Updates.
push_back({DominatorTree::Delete, PredOfPredBB, PredBB});
799 Updates.
push_back({DominatorTree::Delete, PredBB, DestBB});
829 "The successor list of PredBB isn't empty before "
830 "applying corresponding DTU updates.");
851 return First == Second || isa<UndefValue>(First) || isa<UndefValue>(Second);
882 if (BBPreds.
count(IBB) &&
886 <<
"Can't fold, phi node " << PN->
getName() <<
" in "
887 << Succ->
getName() <<
" is conflicting with "
888 << BBPN->
getName() <<
" with regard to common predecessor "
900 if (BBPreds.
count(IBB) &&
904 <<
" is conflicting with regard to common "
905 <<
"predecessor " << IBB->
getName() <<
"\n");
932 if (!isa<UndefValue>(OldVal)) {
934 IncomingValues.
find(BB)->second == OldVal) &&
935 "Expected OldVal to match incoming value from BB!");
937 IncomingValues.
insert(std::make_pair(BB, OldVal));
942 if (It != IncomingValues.
end())
return It->second;
961 if (!isa<UndefValue>(V))
962 IncomingValues.
insert(std::make_pair(BB, V));
977 if (!isa<UndefValue>(V))
continue;
986 if (It == IncomingValues.
end()) {
999 unsigned PoisonCount =
count_if(TrueUndefOps, [&](
unsigned i) {
1002 if (PoisonCount != 0 && PoisonCount != TrueUndefOps.
size()) {
1003 for (
unsigned i : TrueUndefOps)
1019 assert(OldVal &&
"No entry in PHI for Pred BB!");
1036 if (isa<PHINode>(OldVal) && cast<PHINode>(OldVal)->
getParent() == BB) {
1037 PHINode *OldValPN = cast<PHINode>(OldVal);
1054 for (
unsigned i = 0, e = BBPreds.
size(); i != e; ++i) {
1073 "TryToSimplifyUncondBranchFromEmptyBlock called on entry block!");
1077 if (BB == Succ)
return false;
1097 while (isa<PHINode>(*BBI)) {
1098 for (
Use &U : BBI->uses()) {
1099 if (
PHINode* PN = dyn_cast<PHINode>(U.getUser())) {
1100 if (PN->getIncomingBlock(U) != BB)
1176 if (TI->hasMetadata(LLVMContext::MD_loop))
1179 if (PredTI->hasMetadata(LLVMContext::MD_loop))
1193 if (!PredsOfSucc.
contains(PredOfBB))
1194 if (SeenPreds.
insert(PredOfBB).second)
1195 Updates.
push_back({DominatorTree::Insert, PredOfBB, Succ});
1198 if (SeenPreds.
insert(PredOfBB).second)
1199 Updates.
push_back({DominatorTree::Delete, PredOfBB, BB});
1200 Updates.
push_back({DominatorTree::Delete, BB, Succ});
1203 if (isa<PHINode>(Succ->
begin())) {
1225 while (
PHINode *PN = dyn_cast<PHINode>(&BB->
front())) {
1227 assert(PN->use_empty() &&
"There shouldn't be any uses here!");
1228 PN->eraseFromParent();
1239 Pred->getTerminator()->
setMetadata(LoopMDKind, LoopMD);
1250 "applying corresponding DTU updates.");
1265 bool Changed =
false;
1270 for (
auto I = BB->
begin();
PHINode *PN = dyn_cast<PHINode>(
I);) {
1275 for (
auto J =
I;
PHINode *DuplicatePN = dyn_cast<PHINode>(J); ++J) {
1297 struct PHIDenseMapInfo {
1298 static PHINode *getEmptyKey() {
1302 static PHINode *getTombstoneKey() {
1307 return PN == getEmptyKey() || PN == getTombstoneKey();
1321 static unsigned getHashValue(
PHINode *PN) {
1336 return LHS->isIdenticalTo(
RHS);
1354 bool Changed =
false;
1355 for (
auto I = BB->
begin();
PHINode *PN = dyn_cast<PHINode>(
I++);) {
1356 auto Inserted = PHISet.
insert(PN);
1357 if (!Inserted.second) {
1360 PN->replaceAllUsesWith(*Inserted.first);
1361 PN->eraseFromParent();
1393 V = V->stripPointerCasts();
1395 if (
AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
1401 Align CurrentAlign = AI->getAlign();
1402 if (PrefAlign <= CurrentAlign)
1403 return CurrentAlign;
1407 if (
DL.exceedsNaturalStackAlignment(PrefAlign))
1408 return CurrentAlign;
1409 AI->setAlignment(PrefAlign);
1413 if (
auto *GO = dyn_cast<GlobalObject>(V)) {
1415 Align CurrentAlign = GO->getPointerAlignment(
DL);
1416 if (PrefAlign <= CurrentAlign)
1417 return CurrentAlign;
1423 if (!GO->canIncreaseAlignment())
1424 return CurrentAlign;
1426 if (GO->isThreadLocal()) {
1427 unsigned MaxTLSAlign = GO->getParent()->getMaxTLSAlignment() / CHAR_BIT;
1428 if (MaxTLSAlign && PrefAlign >
Align(MaxTLSAlign))
1429 PrefAlign =
Align(MaxTLSAlign);
1432 GO->setAlignment(PrefAlign);
1444 assert(V->getType()->isPointerTy() &&
1445 "getOrEnforceKnownAlignment expects a pointer!");
1457 if (PrefAlign && *PrefAlign > Alignment)
1477 for (
auto *DVI : DbgValues) {
1479 if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr))
1495 TypeSize ValueSize =
DL.getTypeAllocSizeInBits(ValTy);
1505 "address of variable must have exactly 1 location operand.");
1508 if (std::optional<TypeSize> FragmentSize =
1509 AI->getAllocationSizeInBits(
DL)) {
1510 return TypeSize::isKnownGE(ValueSize, *FragmentSize);
1524 assert(DIVar &&
"Missing variable");
1526 Value *DV =
SI->getValueOperand();
1543 DIExpr->isDeref() || (!DIExpr->startsWithDeref() &&
1546 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
SI);
1552 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: " << *DII
1558 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
SI);
1567 assert(DIVar &&
"Missing variable");
1573 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: "
1585 LI, DIVar, DIExpr, NewLoc, (
Instruction *)
nullptr);
1595 assert(DIVar &&
"Missing variable");
1604 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: "
1617 if (InsertionPt != BB->
end())
1618 Builder.insertDbgValueIntrinsic(APN, DIVar, DIExpr, NewLoc, &*InsertionPt);
1635 bool Changed =
false;
1640 if (
auto DDI = dyn_cast<DbgDeclareInst>(&BI))
1646 for (
auto &
I : Dbgs) {
1660 if (LoadInst *LI = dyn_cast<LoadInst>(U))
1661 return LI->isVolatile();
1662 if (StoreInst *SI = dyn_cast<StoreInst>(U))
1663 return SI->isVolatile();
1670 while (!WorkList.
empty()) {
1672 for (
const auto &AIUse : V->uses()) {
1673 User *U = AIUse.getUser();
1675 if (AIUse.getOperandNo() == 1)
1677 }
else if (
LoadInst *LI = dyn_cast<LoadInst>(U)) {
1679 }
else if (
CallInst *CI = dyn_cast<CallInst>(U)) {
1683 if (!CI->isLifetimeStartOrEnd()) {
1687 DIB.insertDbgValueIntrinsic(AI, DDI->
getVariable(), DerefExpr,
1690 }
else if (
BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
1691 if (BI->getType()->isPointerTy())
1710 assert(BB &&
"No BasicBlock to clone dbg.value(s) from.");
1711 if (InsertedPHIs.
size() == 0)
1716 for (
auto &
I : *BB) {
1717 if (
auto DbgII = dyn_cast<DbgVariableIntrinsic>(&
I)) {
1718 for (
Value *V : DbgII->location_ops())
1719 if (
auto *Loc = dyn_cast_or_null<PHINode>(V))
1720 DbgValueMap.
insert({Loc, DbgII});
1723 if (DbgValueMap.
size() == 0)
1738 for (
auto *
PHI : InsertedPHIs) {
1743 for (
auto *
VI :
PHI->operand_values()) {
1744 auto V = DbgValueMap.
find(
VI);
1745 if (V != DbgValueMap.
end()) {
1746 auto *DbgII = cast<DbgVariableIntrinsic>(V->second);
1747 auto NewDI = NewDbgValueMap.
find({Parent, DbgII});
1748 if (NewDI == NewDbgValueMap.
end()) {
1749 auto *NewDbgII = cast<DbgVariableIntrinsic>(DbgII->clone());
1750 NewDI = NewDbgValueMap.
insert({{Parent, DbgII}, NewDbgII}).first;
1761 for (
auto DI : NewDbgValueMap) {
1763 auto *NewDbgII = DI.second;
1765 assert(InsertionPt != Parent->
end() &&
"Ill-formed basic block");
1766 NewDbgII->insertBefore(&*InsertionPt);
1771 DIBuilder &Builder, uint8_t DIExprFlags,
1775 const DebugLoc &Loc = DII->getDebugLoc();
1776 auto *DIVar = DII->getVariable();
1777 auto *DIExpr = DII->getExpression();
1778 assert(DIVar &&
"Missing variable");
1782 Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, DII);
1783 DII->eraseFromParent();
1785 return !DbgDeclares.empty();
1793 assert(DIVar &&
"Missing variable");
1798 if (!DIExpr || DIExpr->getNumElements() < 1 ||
1799 DIExpr->getElement(0) != dwarf::DW_OP_deref)
1807 Builder.insertDbgValueIntrinsic(NewAddress, DIVar, DIExpr, Loc, DVI);
1816 if (
auto *DVI = dyn_cast<DbgValueInst>(U.getUser()))
1836 "address-expression shouldn't have fragment info");
1851 "address-expression shouldn't have fragment info");
1854 if (AdditionalValues.
empty()) {
1867 const unsigned MaxDebugArgs = 16;
1868 const unsigned MaxExpressionSize = 128;
1869 bool Salvaged =
false;
1871 for (
auto *DII : DbgUsers) {
1872 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(DII)) {
1873 if (DAI->getAddress() == &
I) {
1877 if (DAI->getValue() != &
I)
1883 bool StackValue = isa<DbgValueInst>(DII);
1884 auto DIILocation = DII->location_ops();
1887 "DbgVariableIntrinsic must use salvaged instruction as its location");
1893 Value *Op0 =
nullptr;
1895 auto LocItr =
find(DIILocation, &
I);
1896 while (SalvagedExpr && LocItr != DIILocation.end()) {
1898 unsigned LocNo = std::distance(DIILocation.begin(), LocItr);
1905 LocItr = std::find(++LocItr, DIILocation.end(), &
I);
1912 DII->replaceVariableLocationOp(&
I, Op0);
1913 bool IsValidSalvageExpr = SalvagedExpr->
getNumElements() <= MaxExpressionSize;
1914 if (AdditionalValues.
empty() && IsValidSalvageExpr) {
1915 DII->setExpression(SalvagedExpr);
1916 }
else if (isa<DbgValueInst>(DII) && IsValidSalvageExpr &&
1917 DII->getNumVariableLocationOps() + AdditionalValues.
size() <=
1919 DII->addVariableLocationOps(AdditionalValues, SalvagedExpr);
1924 DII->setKillLocation();
1933 for (
auto *DII : DbgUsers)
1934 DII->setKillLocation();
1941 unsigned BitWidth =
DL.getIndexSizeInBits(
GEP->getPointerAddressSpace());
1945 if (!
GEP->collectOffset(
DL,
BitWidth, VariableOffsets, ConstantOffset))
1947 if (!VariableOffsets.
empty() && !CurrentLocOps) {
1948 Opcodes.
insert(Opcodes.
begin(), {dwarf::DW_OP_LLVM_arg, 0});
1951 for (
auto Offset : VariableOffsets) {
1954 "Expected strictly positive multiplier for offset.");
1956 Offset.second.getZExtValue(), dwarf::DW_OP_mul,
1957 dwarf::DW_OP_plus});
1960 return GEP->getOperand(0);
1965 case Instruction::Add:
1966 return dwarf::DW_OP_plus;
1967 case Instruction::Sub:
1968 return dwarf::DW_OP_minus;
1969 case Instruction::Mul:
1970 return dwarf::DW_OP_mul;
1971 case Instruction::SDiv:
1972 return dwarf::DW_OP_div;
1973 case Instruction::SRem:
1974 return dwarf::DW_OP_mod;
1975 case Instruction::Or:
1976 return dwarf::DW_OP_or;
1977 case Instruction::And:
1978 return dwarf::DW_OP_and;
1979 case Instruction::Xor:
1980 return dwarf::DW_OP_xor;
1981 case Instruction::Shl:
1982 return dwarf::DW_OP_shl;
1983 case Instruction::LShr:
1984 return dwarf::DW_OP_shr;
1985 case Instruction::AShr:
1986 return dwarf::DW_OP_shra;
1997 auto *ConstInt = dyn_cast<ConstantInt>(BI->
getOperand(1));
1999 if (ConstInt && ConstInt->getBitWidth() > 64)
2005 uint64_t Val = ConstInt->getSExtValue();
2008 if (BinOpcode == Instruction::Add || BinOpcode == Instruction::Sub) {
2009 uint64_t Offset = BinOpcode == Instruction::Add ? Val : -int64_t(Val);
2013 Opcodes.
append({dwarf::DW_OP_constu, Val});
2015 if (!CurrentLocOps) {
2035 auto &M = *
I.getModule();
2036 auto &
DL = M.getDataLayout();
2038 if (
auto *CI = dyn_cast<CastInst>(&
I)) {
2039 Value *FromValue = CI->getOperand(0);
2041 if (CI->isNoopCast(
DL)) {
2050 !(isa<TruncInst>(&
I) || isa<SExtInst>(&
I) || isa<ZExtInst>(&
I) ||
2051 isa<IntToPtrInst>(&
I) || isa<PtrToIntInst>(&
I)))
2055 if (FromType->isPointerTy())
2056 FromType =
DL.getIntPtrType(FromType);
2058 unsigned FromTypeBitSize = FromType->getScalarSizeInBits();
2063 Ops.
append(ExtOps.begin(), ExtOps.end());
2067 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(&
I))
2069 if (
auto *BI = dyn_cast<BinaryOperator>(&
I))
2094 bool Changed =
false;
2096 if (isa<Instruction>(&To)) {
2097 bool DomPointAfterFrom =
From.getNextNonDebugInstruction() == &DomPoint;
2099 for (
auto *DII :
Users) {
2109 }
else if (!DT.
dominates(&DomPoint, DII)) {
2110 UndefOrSalvage.
insert(DII);
2116 for (
auto *DII :
Users) {
2117 if (UndefOrSalvage.
count(DII))
2130 if (!UndefOrSalvage.
empty()) {
2154 bool SameSize =
DL.getTypeSizeInBits(FromTy) ==
DL.getTypeSizeInBits(ToTy);
2155 bool LosslessConversion = !
DL.isNonIntegralPointerType(FromTy) &&
2156 !
DL.isNonIntegralPointerType(ToTy);
2157 return SameSize && LosslessConversion;
2167 if (!
From.isUsedByMetadata())
2170 assert(&
From != &To &&
"Can't replace something with itself");
2176 return DII.getExpression();
2190 assert(FromBits != ToBits &&
"Unexpected no-op conversion");
2194 if (FromBits < ToBits)
2205 return std::nullopt;
2207 bool Signed = *Signedness == DIBasicType::Signedness::Signed;
2218std::pair<unsigned, unsigned>
2220 unsigned NumDeadInst = 0;
2221 unsigned NumDeadDbgInst = 0;
2225 while (EndInst != &BB->
front()) {
2234 if (isa<DbgInfoIntrinsic>(Inst))
2240 return {NumDeadInst, NumDeadDbgInst};
2256 Successor->removePredecessor(BB, PreserveLCSSA);
2261 UI->setDebugLoc(
I->getDebugLoc());
2264 unsigned NumInstrsRemoved = 0;
2266 while (BBI != BBE) {
2267 if (!BBI->use_empty())
2269 BBI++->eraseFromParent();
2275 for (
BasicBlock *UniqueSuccessor : UniqueSuccessors)
2276 Updates.
push_back({DominatorTree::Delete, BB, UniqueSuccessor});
2279 return NumInstrsRemoved;
2298 auto NewWeights =
uint32_t(TotalWeight) != TotalWeight
2301 NewCall->
setMetadata(LLVMContext::MD_prof, NewWeights);
2324 DTU->
applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}});
2353 UnwindEdge, InvokeArgs, OpBundles, CI->
getName(), BB);
2360 DTU->
applyUpdates({{DominatorTree::Insert, BB, UnwindEdge}});
2367 Split->front().eraseFromParent();
2378 bool Changed =
false;
2386 if (
auto *CI = dyn_cast<CallInst>(&
I)) {
2390 auto IntrinsicID =
F->getIntrinsicID();
2395 if (IntrinsicID == Intrinsic::assume) {
2402 }
else if (IntrinsicID == Intrinsic::experimental_guard) {
2413 if (!isa<UnreachableInst>(CI->getNextNode())) {
2419 }
else if ((isa<ConstantPointerNull>(
Callee) &&
2421 cast<PointerType>(
Callee->getType())
2422 ->getAddressSpace())) ||
2423 isa<UndefValue>(
Callee)) {
2428 if (CI->doesNotReturn() && !CI->isMustTailCall()) {
2432 if (!isa<UnreachableInst>(CI->getNextNode())) {
2439 }
else if (
auto *
SI = dyn_cast<StoreInst>(&
I)) {
2445 if (
SI->isVolatile())
continue;
2449 if (isa<UndefValue>(
Ptr) ||
2450 (isa<ConstantPointerNull>(
Ptr) &&
2452 SI->getPointerAddressSpace()))) {
2461 if (
auto *II = dyn_cast<InvokeInst>(Terminator)) {
2464 if ((isa<ConstantPointerNull>(
Callee) &&
2466 isa<UndefValue>(
Callee)) {
2470 if (II->doesNotReturn() &&
2471 !isa<UnreachableInst>(II->getNormalDest()->front())) {
2477 BasicBlock *OrigNormalDest = II->getNormalDest();
2481 Ctx, OrigNormalDest->
getName() +
".unreachable",
2482 II->getFunction(), OrigNormalDest);
2484 II->setNormalDest(UnreachableNormalDest);
2487 {{DominatorTree::Delete, BB, OrigNormalDest},
2488 {DominatorTree::Insert, BB, UnreachableNormalDest}});
2492 if (II->use_empty() && !II->mayHaveSideEffects()) {
2494 BasicBlock *NormalDestBB = II->getNormalDest();
2495 BasicBlock *UnwindDestBB = II->getUnwindDest();
2498 II->eraseFromParent();
2500 DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}});
2506 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) {
2508 struct CatchPadDenseMapInfo {
2523 if (
LHS == getEmptyKey() ||
LHS == getTombstoneKey() ||
2524 RHS == getEmptyKey() ||
RHS == getTombstoneKey())
2526 return LHS->isIdenticalTo(
RHS);
2537 E = CatchSwitch->handler_end();
2541 ++NumPerSuccessorCases[HandlerBB];
2542 auto *CatchPad = cast<CatchPadInst>(HandlerBB->
getFirstNonPHI());
2543 if (!HandlerSet.insert({CatchPad, Empty}).second) {
2545 --NumPerSuccessorCases[HandlerBB];
2546 CatchSwitch->removeHandler(
I);
2553 std::vector<DominatorTree::UpdateType> Updates;
2554 for (
const std::pair<BasicBlock *, int> &
I : NumPerSuccessorCases)
2556 Updates.push_back({DominatorTree::Delete, BB,
I.first});
2557 DTU->applyUpdates(Updates);
2565 }
while (!Worklist.
empty());
2572 if (
auto *II = dyn_cast<InvokeInst>(TI))
2578 if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
2580 UnwindDest = CRI->getUnwindDest();
2581 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(TI)) {
2583 CatchSwitch->getParentPad(),
nullptr, CatchSwitch->getNumHandlers(),
2584 CatchSwitch->getName(), CatchSwitch);
2585 for (
BasicBlock *PadBB : CatchSwitch->handlers())
2586 NewCatchSwitch->addHandler(PadBB);
2588 NewTI = NewCatchSwitch;
2589 UnwindDest = CatchSwitch->getUnwindDest();
2600 DTU->
applyUpdates({{DominatorTree::Delete, BB, UnwindDest}});
2613 if (Reachable.
size() ==
F.size())
2622 if (Reachable.
count(&BB))
2627 BlocksToRemove.
insert(&BB);
2630 if (BlocksToRemove.
empty())
2634 NumRemoved += BlocksToRemove.
size();
2647 K->dropUnknownNonDebugMetadata(KnownIDs);
2648 K->getAllMetadataOtherThanDebugLoc(
Metadata);
2650 unsigned Kind = MD.first;
2656 K->setMetadata(Kind,
nullptr);
2658 case LLVMContext::MD_dbg:
2660 case LLVMContext::MD_DIAssignID:
2661 K->mergeDIAssignID(J);
2663 case LLVMContext::MD_tbaa:
2666 case LLVMContext::MD_alias_scope:
2669 case LLVMContext::MD_noalias:
2670 case LLVMContext::MD_mem_parallel_loop_access:
2673 case LLVMContext::MD_access_group:
2674 K->setMetadata(LLVMContext::MD_access_group,
2677 case LLVMContext::MD_range:
2678 if (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef))
2681 case LLVMContext::MD_fpmath:
2684 case LLVMContext::MD_invariant_load:
2686 K->setMetadata(Kind, JMD);
2688 case LLVMContext::MD_nonnull:
2689 if (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef))
2690 K->setMetadata(Kind, JMD);
2692 case LLVMContext::MD_invariant_group:
2695 case LLVMContext::MD_align:
2696 if (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef))
2700 case LLVMContext::MD_dereferenceable:
2701 case LLVMContext::MD_dereferenceable_or_null:
2702 K->setMetadata(Kind,
2705 case LLVMContext::MD_preserve_access_index:
2708 case LLVMContext::MD_noundef:
2711 K->setMetadata(Kind, JMD);
2713 case LLVMContext::MD_nontemporal:
2715 K->setMetadata(Kind, JMD);
2725 if (
auto *JMD = J->
getMetadata(LLVMContext::MD_invariant_group))
2726 if (isa<LoadInst>(K) || isa<StoreInst>(K))
2727 K->setMetadata(LLVMContext::MD_invariant_group, JMD);
2732 unsigned KnownIDs[] = {
2733 LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope,
2734 LLVMContext::MD_noalias, LLVMContext::MD_range,
2735 LLVMContext::MD_invariant_load, LLVMContext::MD_nonnull,
2736 LLVMContext::MD_invariant_group, LLVMContext::MD_align,
2737 LLVMContext::MD_dereferenceable,
2738 LLVMContext::MD_dereferenceable_or_null,
2739 LLVMContext::MD_access_group, LLVMContext::MD_preserve_access_index,
2740 LLVMContext::MD_nontemporal, LLVMContext::MD_noundef};
2746 Source.getAllMetadata(MD);
2749 const DataLayout &
DL = Source.getModule()->getDataLayout();
2750 for (
const auto &MDPair : MD) {
2751 unsigned ID = MDPair.first;
2761 case LLVMContext::MD_dbg:
2762 case LLVMContext::MD_tbaa:
2763 case LLVMContext::MD_prof:
2764 case LLVMContext::MD_fpmath:
2765 case LLVMContext::MD_tbaa_struct:
2766 case LLVMContext::MD_invariant_load:
2767 case LLVMContext::MD_alias_scope:
2768 case LLVMContext::MD_noalias:
2769 case LLVMContext::MD_nontemporal:
2770 case LLVMContext::MD_mem_parallel_loop_access:
2771 case LLVMContext::MD_access_group:
2772 case LLVMContext::MD_noundef:
2777 case LLVMContext::MD_nonnull:
2781 case LLVMContext::MD_align:
2782 case LLVMContext::MD_dereferenceable:
2783 case LLVMContext::MD_dereferenceable_or_null:
2789 case LLVMContext::MD_range:
2797 auto *ReplInst = dyn_cast<Instruction>(Repl);
2807 if (!isa<LoadInst>(
I))
2808 ReplInst->andIRFlags(
I);
2819 static const unsigned KnownIDs[] = {
2820 LLVMContext::MD_tbaa, LLVMContext::MD_alias_scope,
2821 LLVMContext::MD_noalias, LLVMContext::MD_range,
2822 LLVMContext::MD_fpmath, LLVMContext::MD_invariant_load,
2823 LLVMContext::MD_invariant_group, LLVMContext::MD_nonnull,
2824 LLVMContext::MD_access_group, LLVMContext::MD_preserve_access_index,
2825 LLVMContext::MD_noundef, LLVMContext::MD_nontemporal};
2829template <
typename RootType,
typename DominatesFn>
2831 const RootType &Root,
2832 const DominatesFn &Dominates) {
2837 if (!Dominates(Root, U))
2841 <<
"' as " << *To <<
" in " << *U <<
"\n");
2849 auto *BB =
From->getParent();
2853 auto *
I = cast<Instruction>(U.getUser());
2854 if (
I->getParent() == BB)
2868 return ::replaceDominatedUsesWith(
From, To, Root, Dominates);
2874 auto Dominates = [&DT](
const BasicBlock *BB,
const Use &U) {
2877 return ::replaceDominatedUsesWith(
From, To, BB, Dominates);
2883 if (Call->hasFnAttr(
"gc-leaf-function"))
2885 if (
const Function *
F = Call->getCalledFunction()) {
2886 if (
F->hasFnAttribute(
"gc-leaf-function"))
2889 if (
auto IID =
F->getIntrinsicID()) {
2891 return IID != Intrinsic::experimental_gc_statepoint &&
2892 IID != Intrinsic::experimental_deoptimize &&
2893 IID != Intrinsic::memcpy_element_unordered_atomic &&
2894 IID != Intrinsic::memmove_element_unordered_atomic;
2911 auto *NewTy = NewLI.
getType();
2914 if (NewTy->isPointerTy()) {
2921 if (!NewTy->isIntegerTy())
2926 auto *ITy = cast<IntegerType>(NewTy);
2936 auto *NewTy = NewLI.
getType();
2938 if (NewTy == OldLI.
getType()) {
2947 if (!NewTy->isPointerTy())
2950 unsigned BitWidth =
DL.getPointerTypeSizeInBits(NewTy);
2960 for (
auto *DII : DbgUsers)
2961 DII->eraseFromParent();
2990 I->dropUBImplyingAttrsAndUnknownMetadata();
2991 if (
I->isUsedByMetadata())
2993 if (
I->isDebugOrPseudoInst()) {
2995 II =
I->eraseFromParent();
3010 BitPart(
Value *
P,
unsigned BW) : Provider(
P) {
3011 Provenance.resize(BW);
3021 enum { Unset = -1 };
3053static const std::optional<BitPart> &
3055 std::map<
Value *, std::optional<BitPart>> &BPS,
int Depth,
3057 auto I = BPS.find(V);
3061 auto &Result = BPS[V] = std::nullopt;
3062 auto BitWidth = V->getType()->getScalarSizeInBits();
3070 LLVM_DEBUG(
dbgs() <<
"collectBitParts max recursion depth reached.\n");
3074 if (
auto *
I = dyn_cast<Instruction>(V)) {
3082 Depth + 1, FoundRoot);
3083 if (!
A || !
A->Provider)
3087 Depth + 1, FoundRoot);
3088 if (!
B ||
A->Provider !=
B->Provider)
3092 Result = BitPart(
A->Provider,
BitWidth);
3093 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx) {
3094 if (
A->Provenance[BitIdx] != BitPart::Unset &&
3095 B->Provenance[BitIdx] != BitPart::Unset &&
3096 A->Provenance[BitIdx] !=
B->Provenance[BitIdx])
3097 return Result = std::nullopt;
3099 if (
A->Provenance[BitIdx] == BitPart::Unset)
3100 Result->Provenance[BitIdx] =
B->Provenance[BitIdx];
3102 Result->Provenance[BitIdx] =
A->Provenance[BitIdx];
3110 const APInt &BitShift = *
C;
3117 if (!MatchBitReversals && (BitShift.
getZExtValue() % 8) != 0)
3121 Depth + 1, FoundRoot);
3127 auto &
P = Result->Provenance;
3128 if (
I->getOpcode() == Instruction::Shl) {
3142 const APInt &AndMask = *
C;
3146 unsigned NumMaskedBits = AndMask.
popcount();
3147 if (!MatchBitReversals && (NumMaskedBits % 8) != 0)
3151 Depth + 1, FoundRoot);
3156 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3158 if (AndMask[BitIdx] == 0)
3159 Result->Provenance[BitIdx] = BitPart::Unset;
3166 Depth + 1, FoundRoot);
3170 Result = BitPart(Res->Provider,
BitWidth);
3171 auto NarrowBitWidth =
X->getType()->getScalarSizeInBits();
3172 for (
unsigned BitIdx = 0; BitIdx < NarrowBitWidth; ++BitIdx)
3173 Result->Provenance[BitIdx] = Res->Provenance[BitIdx];
3174 for (
unsigned BitIdx = NarrowBitWidth; BitIdx <
BitWidth; ++BitIdx)
3175 Result->Provenance[BitIdx] = BitPart::Unset;
3182 Depth + 1, FoundRoot);
3186 Result = BitPart(Res->Provider,
BitWidth);
3187 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3188 Result->Provenance[BitIdx] = Res->Provenance[BitIdx];
3196 Depth + 1, FoundRoot);
3200 Result = BitPart(Res->Provider,
BitWidth);
3201 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3202 Result->Provenance[(
BitWidth - 1) - BitIdx] = Res->Provenance[BitIdx];
3209 Depth + 1, FoundRoot);
3214 Result = BitPart(Res->Provider,
BitWidth);
3215 for (
unsigned ByteIdx = 0; ByteIdx < ByteWidth; ++ByteIdx) {
3216 unsigned ByteBitOfs = ByteIdx * 8;
3217 for (
unsigned BitIdx = 0; BitIdx < 8; ++BitIdx)
3218 Result->Provenance[(
BitWidth - 8 - ByteBitOfs) + BitIdx] =
3219 Res->Provenance[ByteBitOfs + BitIdx];
3236 if (!MatchBitReversals && (ModAmt % 8) != 0)
3241 Depth + 1, FoundRoot);
3242 if (!
LHS || !
LHS->Provider)
3246 Depth + 1, FoundRoot);
3247 if (!
RHS ||
LHS->Provider !=
RHS->Provider)
3250 unsigned StartBitRHS =
BitWidth - ModAmt;
3252 for (
unsigned BitIdx = 0; BitIdx < StartBitRHS; ++BitIdx)
3253 Result->Provenance[BitIdx + ModAmt] =
LHS->Provenance[BitIdx];
3254 for (
unsigned BitIdx = 0; BitIdx < ModAmt; ++BitIdx)
3255 Result->Provenance[BitIdx] =
RHS->Provenance[BitIdx + StartBitRHS];
3269 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3270 Result->Provenance[BitIdx] = BitIdx;
3276 if (
From % 8 != To % 8)
3291 Instruction *
I,
bool MatchBSwaps,
bool MatchBitReversals,
3297 if (!MatchBSwaps && !MatchBitReversals)
3299 Type *ITy =
I->getType();
3304 bool FoundRoot =
false;
3305 std::map<Value *, std::optional<BitPart>> BPS;
3312 [](int8_t
I) {
return I == BitPart::Unset || 0 <=
I; }) &&
3313 "Illegal bit provenance index");
3316 Type *DemandedTy = ITy;
3317 if (BitProvenance.
back() == BitPart::Unset) {
3318 while (!BitProvenance.
empty() && BitProvenance.
back() == BitPart::Unset)
3319 BitProvenance = BitProvenance.
drop_back();
3320 if (BitProvenance.
empty())
3323 if (
auto *IVecTy = dyn_cast<VectorType>(ITy))
3324 DemandedTy = VectorType::get(DemandedTy, IVecTy);
3335 bool OKForBSwap = MatchBSwaps && (DemandedBW % 16) == 0;
3336 bool OKForBitReverse = MatchBitReversals;
3337 for (
unsigned BitIdx = 0;
3338 (BitIdx < DemandedBW) && (OKForBSwap || OKForBitReverse); ++BitIdx) {
3339 if (BitProvenance[BitIdx] == BitPart::Unset) {
3346 BitIdx, DemandedBW);
3351 Intrin = Intrinsic::bswap;
3352 else if (OKForBitReverse)
3353 Intrin = Intrinsic::bitreverse;
3358 Value *Provider = Res->Provider;
3361 if (DemandedTy != Provider->
getType()) {
3378 if (ITy != Result->getType()) {
3395 if (
F && !
F->hasLocalLinkage() &&
F->hasName() &&
3397 !
F->doesNotAccessMemory())
3403 if (
I->getOperand(OpIdx)->getType()->isMetadataTy())
3407 if (!isa<Constant>(
I->getOperand(OpIdx)))
3410 switch (
I->getOpcode()) {
3413 case Instruction::Call:
3414 case Instruction::Invoke: {
3415 const auto &CB = cast<CallBase>(*
I);
3418 if (CB.isInlineAsm())
3423 if (CB.isBundleOperand(OpIdx))
3426 if (OpIdx < CB.arg_size()) {
3429 if (isa<IntrinsicInst>(CB) &&
3430 OpIdx >= CB.getFunctionType()->getNumParams()) {
3432 return CB.getIntrinsicID() == Intrinsic::experimental_stackmap;
3437 if (CB.getIntrinsicID() == Intrinsic::gcroot)
3441 return !CB.paramHasAttr(OpIdx, Attribute::ImmArg);
3446 return !isa<IntrinsicInst>(CB);
3448 case Instruction::ShuffleVector:
3451 case Instruction::Switch:
3452 case Instruction::ExtractValue:
3455 case Instruction::InsertValue:
3458 case Instruction::Alloca:
3462 return !cast<AllocaInst>(
I)->isStaticAlloca();
3463 case Instruction::GetElementPtr:
3467 for (
auto E = std::next(It, OpIdx); It !=
E; ++It)
3476 if (
Constant *
C = dyn_cast<Constant>(Condition))
3480 Value *NotCondition;
3482 return NotCondition;
3485 Instruction *Inst = dyn_cast<Instruction>(Condition);
3488 else if (
Argument *
Arg = dyn_cast<Argument>(Condition))
3489 Parent = &
Arg->getParent()->getEntryBlock();
3490 assert(Parent &&
"Unsupported condition to invert");
3501 if (Inst && !isa<PHINode>(Inst))
3502 Inverted->insertAfter(Inst);
3512 bool Changed =
false;
3514 if (!
F.hasFnAttribute(Attribute::NoSync) &&
3515 F.doesNotAccessMemory() && !
F.isConvergent()) {
3521 if (!
F.hasFnAttribute(Attribute::NoFree) &&
F.onlyReadsMemory()) {
3522 F.setDoesNotFreeMemory();
3527 if (!
F.hasFnAttribute(Attribute::MustProgress) &&
F.willReturn()) {
3528 F.setMustProgress();
static unsigned getIntrinsicID(const SDNode *N)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
amdgpu Simplify well known AMD library false FunctionCallee Callee
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
This file implements a class to represent arbitrary precision integral constant values and operations...
static bool isEqual(const Function &Caller, const Function &Callee)
This file contains the simple types necessary to represent the attributes associated with functions a...
static const Function * getParent(const Value *V)
SmallVector< MachineOperand, 4 > Cond
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")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isSentinel(const DWARFDebugNames::AttributeEncoding &AE)
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
This file defines DenseMapInfo traits for DenseMap.
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
This file contains constants used for implementing Dwarf debug support.
static unsigned getHashValueImpl(SimpleValue Val)
static bool isEqualImpl(SimpleValue LHS, SimpleValue RHS)
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
iv Induction Variable Users
Module.h This file contains the declarations for the Module class.
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
This file contains the declarations for profiling metadata utility functions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
This defines the Use class.
Class recording the (high level) value of a variable.
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
void clearBit(unsigned BitPosition)
Set a given bit to 0.
uint64_t getZExtValue() const
Get zero extended value.
unsigned popcount() const
Count the number of bits set.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
int64_t getSExtValue() const
Get sign extended value.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
an instruction to allocate memory on the stack
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
const T & back() const
back - Get the last element.
size_t size() const
size - Get the array size.
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
bool empty() const
empty - Check if the array is empty.
Value handle that asserts if the Value is deleted.
A cache of @llvm.assume calls within a function.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
const Instruction & front() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
bool isEntryBlock() const
Return true if this is the entry block of the containing function.
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
const Function * getParent() const
Return the enclosing method, or null if none.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
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,...
InstListType::iterator iterator
Instruction iterators...
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...
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
const Instruction & back() const
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
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.
BinaryOps getOpcode() const
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", Instruction *InsertBefore=nullptr)
This class represents a no-op cast from one type to another.
The address of a basic block.
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void setCallingConv(CallingConv::ID CC)
void addFnAttr(Attribute::AttrKind Kind)
Adds the attribute to the function.
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
CallingConv::ID getCallingConv() const
Value * getCalledOperand() const
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
FunctionType * getFunctionType() const
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
AttributeList getAttributes() const
Return the parameter attributes for this call.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
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 CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getNot(Constant *C)
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
This is the shared class of boolean and integer constants.
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.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
This is an important base class in LLVM.
void destroyConstant()
Called if some element of this constant is no longer valid.
static DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
unsigned getNumElements() const
static ExtOps getExtOps(unsigned FromSize, unsigned ToSize, bool Signed)
Returns the ops for a zero- or sign-extension in a DIExpression.
static void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
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...
static std::optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
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 ...
static DIExpression * appendExt(const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
Append a zero- or sign-extension to Expr.
std::optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or std::nullopt if this type is neither signed nor uns...
A parsed version of the target data layout string in and methods for querying it.
This represents the llvm.dbg.assign instruction.
void setKillAddress()
Kill the address component.
DIExpression * getAddressExpression() const
Value * getAddress() const
void setAddress(Value *V)
void setAddressExpression(DIExpression *NewExpr)
This represents the llvm.dbg.declare instruction.
Value * getAddress() const
This represents the llvm.dbg.label instruction.
This represents the llvm.dbg.value instruction.
This is the common base class for debug info intrinsics for variables.
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
void replaceVariableLocationOp(Value *OldValue, Value *NewValue)
Value * getVariableLocationOp(unsigned OpIdx) const
void setExpression(DIExpression *NewExpr)
DILocalVariable * getVariable() const
unsigned getNumVariableLocationOps() const
bool isAddressOfVariable() const
Does this describe the address of a local variable.
std::optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
DIExpression * getExpression() const
iterator find(const_arg_type_t< KeyT > Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
void recalculate(Function &F)
Notify DTU that the entry block was replaced.
bool hasDomTree() const
Returns true if it holds a DominatorTree.
bool isBBPendingDeletion(BasicBlock *DelBB) const
Returns true if DelBB is awaiting deletion.
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
void deleteBB(BasicBlock *DelBB)
Delete DelBB.
void applyUpdatesPermissive(ArrayRef< DominatorTree::UpdateType > Updates)
Submit updates to all available trees.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
bool dominates(const BasicBlock *BB, const Use &U) const
Return true if the (end of the) basic block BB dominates the use U.
const BasicBlock & getEntryBlock() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
const BasicBlock * getParent() const
bool isIdenticalToWhenDefined(const Instruction *I) const LLVM_READONLY
This is like isIdenticalTo, except that it ignores the SubclassOptionalData flags,...
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
const Instruction * getNextNonDebugInstruction(bool SkipPseudoOp=false) const
Return a pointer to the next non-debug instruction in the same basic block as 'this',...
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
A wrapper class for inspecting calls to intrinsic functions.
BasicBlock * getUnwindDest() const
BasicBlock * getNormalDest() const
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
An instruction for reading from memory.
Value * getPointerOperand()
MDNode * createRange(const APInt &Lo, const APInt &Hi)
Return metadata describing the range [Lo, Hi).
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
static MDNode * getMostGenericRange(MDNode *A, MDNode *B)
static MDNode * intersect(MDNode *A, MDNode *B)
static MDNode * getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B)
This class implements a map that also provides access to all stored values in a deterministic order.
iterator find(const KeyT &Key)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
void changeToUnreachable(const Instruction *I)
Instruction I will be changed to an unreachable.
void removeBlocks(const SmallSetVector< BasicBlock *, 8 > &DeadBlocks)
Remove all MemoryAcceses in a set of BasicBlocks about to be deleted.
void removeMemoryAccess(MemoryAccess *, bool OptimizePhis=false)
Remove a MemoryAccess from MemorySSA, including updating all definitions and uses.
A Module instance is used to store all the information related to an LLVM module.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
const_block_iterator block_begin() const
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
void setIncomingValue(unsigned i, Value *V)
const_block_iterator block_end() const
Value * getIncomingValueForBlock(const BasicBlock *BB) const
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.
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
size_type size() const
Determine the number of elements in the SetVector.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
Vector takeVector()
Clear the SetVector and return the underlying vector.
value_type pop_back_val()
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.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
iterator insert(iterator I, T &&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.
Provides information about what library functions are available for the current target.
bool hasOptimizedCodeGen(LibFunc F) const
Tests if the function is both available and a candidate for optimized code generation.
bool has(LibFunc F) const
Tests whether a library function is available.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isStructTy() const
True if this is an instance of StructType.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
static IntegerType * getInt32Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isTokenTy() const
Return true if this is 'token'.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
static 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_op_iterator value_op_end()
Value * getOperand(unsigned i) const
value_op_iterator value_op_begin()
iterator find(const KeyT &Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
LLVM Value Representation.
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.
iterator_range< user_iterator > users()
LLVMContext & getContext() const
All values hold a context through their type.
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
user_iterator_impl< User > user_iterator
StringRef getName() const
Return a constant reference to the value's name.
void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
void reserve(size_t Size)
Grow the DenseSet so that it can contain at least NumEntries items before resizing again.
An efficient, type-erasing, non-owning reference to a callable.
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.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=std::nullopt)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_BitReverse(const Opnd0 &Op0)
CastClass_match< OpTy, Instruction::ZExt > m_ZExt(const OpTy &Op)
Matches ZExt.
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
BinOpPred_match< LHS, RHS, is_logical_shift_op > m_LogicalShift(const LHS &L, const RHS &R)
Matches logical shift operations.
CastClass_match< OpTy, Instruction::Trunc > m_Trunc(const OpTy &Op)
Matches Trunc.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShl(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
m_Intrinsic_Ty< Opnd0, Opnd1, Opnd2 >::Ty m_FShr(const Opnd0 &Op0, const Opnd1 &Op1, const Opnd2 &Op2)
auto m_Undef()
Match an arbitrary undef constant.
BinaryOp_match< cst_pred_ty< is_all_ones >, ValTy, Instruction::Xor, true > m_Not(const ValTy &V)
Matches a 'Not' as 'xor V, -1' or 'xor -1, V'.
BinaryOp_match< LHS, RHS, Instruction::Or > m_Or(const LHS &L, const RHS &R)
m_Intrinsic_Ty< Opnd0 >::Ty m_BSwap(const Opnd0 &Op0)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
initializer< Ty > init(const Ty &Val)
@ DW_OP_LLVM_arg
Only used in LLVM metadata.
@ ebStrict
This corresponds to "fpexcept.strict".
This is an optimization pass for GlobalISel generic memory operations.
TinyPtrVector< DbgDeclareInst * > FindDbgDeclareUses(Value *V)
Finds dbg.declare intrinsics declaring local variables as living in the memory that 'V' points to.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
bool RemoveRedundantDbgInstrs(BasicBlock *BB)
Try to remove redundant dbg.value instructions from given basic block.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
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.
bool succ_empty(const Instruction *I)
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge, DomTreeUpdater *DTU=nullptr)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
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...
std::pair< unsigned, unsigned > removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB)
Remove all instructions from a basic block other than its terminator and any present EH pad instructi...
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
void salvageDebugInfoForDbgValues(Instruction &I, ArrayRef< DbgVariableIntrinsic * > Insns)
Implementation of salvageDebugInfo, applying only to instructions in Insns, rather than all debug use...
void salvageDebugInfo(const MachineRegisterInfo &MRI, MachineInstr &MI)
Assuming the instruction MI is going to be deleted, attempt to salvage debug users of MI by writing t...
auto successors(const MachineBasicBlock *BB)
bool isRemovableAlloc(const CallBase *V, const TargetLibraryInfo *TLI)
Return true if this is a call to an allocation function that does not have side effects that we are r...
CallInst * changeToCall(InvokeInst *II, DomTreeUpdater *DTU=nullptr)
This function converts the specified invoke into a normal call.
bool isMathLibCallNoop(const CallBase *Call, const TargetLibraryInfo *TLI)
Check whether the given call has no side-effects.
void copyMetadataForLoad(LoadInst &Dest, const LoadInst &Source)
Copy the metadata from the source instruction to the destination (the replacement for the source inst...
Interval::succ_iterator succ_begin(Interval *I)
succ_begin/succ_end - define methods so that Intervals may be used just like BasicBlocks can with the...
bool 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.
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...
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...
void DeleteDeadBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified block, which must have no predecessors.
void insertDebugValuesForPHIs(BasicBlock *BB, SmallVectorImpl< PHINode * > &InsertedPHIs)
Propagate dbg.value intrinsics through the newly inserted PHIs.
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
MDNode * intersectAccessGroups(const Instruction *Inst1, const Instruction *Inst2)
Compute the access-group list of access groups that Inst1 and Inst2 are both in.
bool canSimplifyInvokeNoUnwind(const Function *F)
Interval::pred_iterator pred_end(Interval *I)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
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.
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.
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes,...
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction * > &InsertedInsts)
Try to match a bswap or bitreverse idiom.
MDNode * getValidBranchWeightMDNode(const Instruction &I)
Get the valid branch weights metadata node.
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.
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...
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
CallInst * createCallMatchingInvoke(InvokeInst *II)
Create a call that matches the invoke II in terms of arguments, attributes, debug information,...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
Instruction * removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
Replace 'BB's terminator with one that does not have an unwind successor block.
void patchReplacementInstruction(Instruction *I, Value *Repl)
Patch the replacement so that it is not more restrictive than the value being replaced.
DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII)
Produce a DebugLoc to use for each dbg.declare that is promoted to a dbg.value.
void findDbgValues(SmallVectorImpl< DbgValueInst * > &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===------------------------------------------------------------------—===// Dbg Intrinsic utilities
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.
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
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...
bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT)
Point debug users of From to To or salvage them.
Value * salvageDebugInfoImpl(Instruction &I, uint64_t CurrentLocOps, SmallVectorImpl< uint64_t > &Ops, SmallVectorImpl< Value * > &AdditionalValues)
void combineMetadataForCSE(Instruction *K, const Instruction *J, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
void dropDebugUsers(Instruction &I)
Remove the debug intrinsic instructions for the given instruction.
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!...
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...
bool replaceDbgUsesWithUndef(Instruction *I)
Replace all the uses of an SSA value in @llvm.dbg intrinsics with undef.
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
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...
void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a range metadata node to a new load instruction.
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx)
Given an instruction, is it legal to set operand OpIdx to a non-constant value?
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...
Value * getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI)
If this if a call to a free function, return the freed operand.
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...
constexpr unsigned BitWidth
bool extractBranchWeights(const MDNode *ProfileData, SmallVectorImpl< uint32_t > &Weights)
Extract branch weights from MD_prof metadata.
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...
gep_type_iterator gep_type_begin(const User *GEP)
auto predecessors(const MachineBasicBlock *BB)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
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.
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...
bool inferAttributesFromOthers(Function &F)
If we can infer one attribute from another on the declaration of a function, explicitly materialize t...
Value * invertCondition(Value *Condition)
Invert the given true/false value, possibly reusing an existing copy.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
void DeleteDeadBlocks(ArrayRef< BasicBlock * > BBs, DomTreeUpdater *DTU=nullptr, bool KeepOneInputPHIs=false)
Delete the specified blocks from BB.
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...
unsigned pred_size(const MachineBasicBlock *BB)
bool removeUnreachableBlocks(Function &F, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function's entry.
bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
bool isAssumeWithEmptyBundle(AssumeInst &Assume)
Return true iff the operand bundles of the provided llvm.assume doesn't contain any valuable informat...
bool callsGCLeafFunction(const CallBase *Call, const TargetLibraryInfo &TLI)
Return true if this call calls a gc leaf function.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
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.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
An information struct used to provide DenseMap with the various necessary components for a given valu...
unsigned countMinTrailingZeros() const
Returns the minimum number of trailing zero bits.
unsigned getBitWidth() const
Get the bit width of this value.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.