59#include "llvm/IR/IntrinsicsWebAssembly.h"
93#define DEBUG_TYPE "local"
95STATISTIC(NumRemoved,
"Number of unreachable basic blocks removed");
96STATISTIC(NumPHICSEs,
"Number of PHI's that got CSE'd");
100#ifdef EXPENSIVE_CHECKS
106 cl::desc(
"Perform extra assertion checking to verify that PHINodes's hash "
107 "function is well-behaved w.r.t. its isEqual predicate"));
112 "When the basic block contains not more than this number of PHI nodes, "
113 "perform a (faster!) exhaustive search instead of set-driven one."));
137 if (
auto *BI = dyn_cast<BranchInst>(
T)) {
138 if (BI->isUnconditional())
return false;
143 if (Dest2 == Dest1) {
149 assert(BI->getParent() &&
"Terminator not inserted in block!");
156 NewBI->
copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
157 LLVMContext::MD_annotation});
160 BI->eraseFromParent();
161 if (DeleteDeadConditions)
166 if (
auto *
Cond = dyn_cast<ConstantInt>(BI->getCondition())) {
180 NewBI->
copyMetadata(*BI, {LLVMContext::MD_loop, LLVMContext::MD_dbg,
181 LLVMContext::MD_annotation});
183 BI->eraseFromParent();
185 DTU->
applyUpdates({{DominatorTree::Delete, BB, OldDest}});
192 if (
auto *SI = dyn_cast<SwitchInst>(
T)) {
195 auto *CI = dyn_cast<ConstantInt>(SI->getCondition());
196 BasicBlock *DefaultDest = SI->getDefaultDest();
201 SI->getNumCases() > 0) {
202 TheOnlyDest = SI->case_begin()->getCaseSuccessor();
205 bool Changed =
false;
208 for (
auto It = SI->case_begin(),
End = SI->case_end(); It !=
End;) {
210 if (It->getCaseValue() == CI) {
211 TheOnlyDest = It->getCaseSuccessor();
217 if (It->getCaseSuccessor() == DefaultDest) {
219 unsigned NCases = SI->getNumCases();
222 if (NCases > 1 && MD) {
228 unsigned Idx = It->getCaseIndex();
230 Weights[0] += Weights[
Idx + 1];
239 It = SI->removeCase(It);
240 End = SI->case_end();
244 if (
auto *NewCI = dyn_cast<ConstantInt>(SI->getCondition())) {
246 It = SI->case_begin();
256 if (It->getCaseSuccessor() != TheOnlyDest)
257 TheOnlyDest =
nullptr;
263 if (CI && !TheOnlyDest) {
266 TheOnlyDest = SI->getDefaultDest();
281 if (DTU && Succ != TheOnlyDest)
282 RemovedSuccessors.
insert(Succ);
284 if (Succ == SuccToKeep) {
285 SuccToKeep =
nullptr;
293 SI->eraseFromParent();
294 if (DeleteDeadConditions)
297 std::vector<DominatorTree::UpdateType> Updates;
298 Updates.reserve(RemovedSuccessors.
size());
299 for (
auto *RemovedSuccessor : RemovedSuccessors)
300 Updates.push_back({DominatorTree::Delete, BB, RemovedSuccessor});
306 if (SI->getNumCases() == 1) {
309 auto FirstCase = *SI->case_begin();
311 FirstCase.getCaseValue(),
"cond");
315 FirstCase.getCaseSuccessor(),
316 SI->getDefaultDest());
328 MDNode *MakeImplicitMD = SI->getMetadata(LLVMContext::MD_make_implicit);
330 NewBr->
setMetadata(LLVMContext::MD_make_implicit, MakeImplicitMD);
333 SI->eraseFromParent();
339 if (
auto *IBI = dyn_cast<IndirectBrInst>(
T)) {
342 dyn_cast<BlockAddress>(IBI->getAddress()->stripPointerCasts())) {
343 BasicBlock *TheOnlyDest = BA->getBasicBlock();
350 for (
unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
352 if (DTU && DestBB != TheOnlyDest)
353 RemovedSuccessors.
insert(DestBB);
354 if (IBI->getDestination(i) == SuccToKeep) {
355 SuccToKeep =
nullptr;
360 Value *Address = IBI->getAddress();
361 IBI->eraseFromParent();
362 if (DeleteDeadConditions)
369 BA->destroyConstant();
380 std::vector<DominatorTree::UpdateType> Updates;
381 Updates.reserve(RemovedSuccessors.
size());
382 for (
auto *RemovedSuccessor : RemovedSuccessors)
383 Updates.push_back({DominatorTree::Delete, BB, RemovedSuccessor});
412 if (
II->getIntrinsicID() == Intrinsic::stacksave ||
413 II->getIntrinsicID() == Intrinsic::launder_invariant_group ||
414 II->isLifetimeStartOrEnd())
421 if (
I->isTerminator())
430 if (isa<DbgVariableIntrinsic>(
I))
439 if (
auto *CB = dyn_cast<CallBase>(
I))
443 if (!
I->willReturn()) {
444 auto *
II = dyn_cast<IntrinsicInst>(
I);
448 switch (
II->getIntrinsicID()) {
449 case Intrinsic::experimental_guard: {
453 auto *
Cond = dyn_cast<ConstantInt>(
II->getArgOperand(0));
458 case Intrinsic::wasm_trunc_signed:
459 case Intrinsic::wasm_trunc_unsigned:
460 case Intrinsic::ptrauth_auth:
461 case Intrinsic::ptrauth_resign:
468 if (!
I->mayHaveSideEffects())
475 if (
II->getIntrinsicID() == Intrinsic::stacksave ||
476 II->getIntrinsicID() == Intrinsic::launder_invariant_group)
481 if (
II->getIntrinsicID() == Intrinsic::allow_runtime_check ||
482 II->getIntrinsicID() == Intrinsic::allow_ubsan_check)
485 if (
II->isLifetimeStartOrEnd()) {
486 auto *Arg =
II->getArgOperand(1);
488 if (isa<UndefValue>(Arg))
492 if (isa<AllocaInst>(Arg) || isa<GlobalValue>(Arg) || isa<Argument>(Arg))
494 if (IntrinsicInst *IntrinsicUse =
495 dyn_cast<IntrinsicInst>(Use.getUser()))
496 return IntrinsicUse->isLifetimeStartOrEnd();
503 if (
II->getIntrinsicID() == Intrinsic::assume &&
506 return !
Cond->isZero();
511 if (
auto *FPI = dyn_cast<ConstrainedFPIntrinsic>(
I)) {
512 std::optional<fp::ExceptionBehavior> ExBehavior =
513 FPI->getExceptionBehavior();
518 if (
auto *Call = dyn_cast<CallBase>(
I)) {
520 if (
Constant *
C = dyn_cast<Constant>(FreedOp))
521 return C->isNullValue() || isa<UndefValue>(
C);
527 if (
auto *LI = dyn_cast<LoadInst>(
I))
528 if (
auto *GV = dyn_cast<GlobalVariable>(
529 LI->getPointerOperand()->stripPointerCasts()))
530 if (!LI->isVolatile() && GV->isConstant())
542 std::function<
void(
Value *)> AboutToDeleteCallback) {
550 AboutToDeleteCallback);
558 std::function<
void(
Value *)> AboutToDeleteCallback) {
559 unsigned S = 0, E = DeadInsts.
size(), Alive = 0;
560 for (; S != E; ++S) {
561 auto *
I = dyn_cast_or_null<Instruction>(DeadInsts[S]);
563 DeadInsts[S] =
nullptr;
570 AboutToDeleteCallback);
577 std::function<
void(
Value *)> AboutToDeleteCallback) {
579 while (!DeadInsts.
empty()) {
585 "Live instruction found in dead worklist!");
586 assert(
I->use_empty() &&
"Instructions with uses are not dead.");
591 if (AboutToDeleteCallback)
592 AboutToDeleteCallback(
I);
596 for (
Use &OpU :
I->operands()) {
597 Value *OpV = OpU.get();
613 I->eraseFromParent();
621 for (
auto *DII : DbgUsers)
622 DII->setKillLocation();
623 for (
auto *DVR : DPUsers)
624 DVR->setKillLocation();
639 for (++UI; UI != UE; ++UI) {
656 I = cast<Instruction>(*
I->user_begin())) {
662 if (!Visited.
insert(
I).second) {
682 for (
unsigned i = 0, e =
I->getNumOperands(); i != e; ++i) {
683 Value *OpV =
I->getOperand(i);
684 I->setOperand(i,
nullptr);
697 I->eraseFromParent();
705 for (
User *U :
I->users()) {
707 WorkList.
insert(cast<Instruction>(U));
712 bool Changed =
false;
713 if (!
I->use_empty()) {
714 I->replaceAllUsesWith(SimpleV);
718 I->eraseFromParent();
733 bool MadeChange =
false;
750 assert(!BI->isTerminator());
760 while (!WorkList.
empty()) {
775 while (
PHINode *PN = dyn_cast<PHINode>(DestBB->
begin())) {
776 Value *NewVal = PN->getIncomingValue(0);
779 PN->replaceAllUsesWith(NewVal);
780 PN->eraseFromParent();
784 assert(PredBB &&
"Block doesn't have a single predecessor!");
798 if (PredOfPredBB != PredBB)
799 if (SeenPreds.
insert(PredOfPredBB).second)
800 Updates.
push_back({DominatorTree::Insert, PredOfPredBB, DestBB});
803 if (SeenPreds.
insert(PredOfPredBB).second)
804 Updates.
push_back({DominatorTree::Delete, PredOfPredBB, PredBB});
805 Updates.
push_back({DominatorTree::Delete, PredBB, DestBB});
835 "The successor list of PredBB isn't empty before "
836 "applying corresponding DTU updates.");
857 return First == Second || isa<UndefValue>(
First) || isa<UndefValue>(Second);
888 if (BBPreds.
count(IBB) &&
892 <<
"Can't fold, phi node " << PN->
getName() <<
" in "
893 << Succ->
getName() <<
" is conflicting with "
894 << BBPN->
getName() <<
" with regard to common predecessor "
906 if (BBPreds.
count(IBB) &&
910 <<
" is conflicting with regard to common "
911 <<
"predecessor " << IBB->
getName() <<
"\n");
938 if (!isa<UndefValue>(OldVal)) {
940 IncomingValues.
find(BB)->second == OldVal) &&
941 "Expected OldVal to match incoming value from BB!");
943 IncomingValues.
insert(std::make_pair(BB, OldVal));
948 if (It != IncomingValues.
end())
return It->second;
967 if (!isa<UndefValue>(V))
968 IncomingValues.
insert(std::make_pair(BB, V));
983 if (!isa<UndefValue>(V))
continue;
992 if (It == IncomingValues.
end()) {
1005 unsigned PoisonCount =
count_if(TrueUndefOps, [&](
unsigned i) {
1008 if (PoisonCount != 0 && PoisonCount != TrueUndefOps.
size()) {
1009 for (
unsigned i : TrueUndefOps)
1024 if (BB->
phis().empty() || Succ->
phis().empty())
1033 if (BBPreds.
count(SuccPred)) {
1036 CommonPred = SuccPred;
1056 assert(OldVal &&
"No entry in PHI for Pred BB!");
1073 if (isa<PHINode>(OldVal) && cast<PHINode>(OldVal)->
getParent() == BB) {
1074 PHINode *OldValPN = cast<PHINode>(OldVal);
1083 if (PredBB == CommonPred)
1101 if (PredBB == CommonPred)
1121 "TryToSimplifyUncondBranchFromEmptyBlock called on entry block!");
1138 bool BBPhisMergeable =
1142 if (!BBKillable && !BBPhisMergeable)
1162 while (isa<PHINode>(*BBI)) {
1163 for (
Use &U : BBI->uses()) {
1164 if (
PHINode* PN = dyn_cast<PHINode>(U.getUser())) {
1165 if (PN->getIncomingBlock(U) != BB)
1175 if (BBPhisMergeable && CommonPred)
1177 <<
" and " << Succ->
getName() <<
" : "
1178 << CommonPred->
getName() <<
"\n");
1246 if (TI->hasMetadata(LLVMContext::MD_loop))
1249 if (PredTI->hasMetadata(LLVMContext::MD_loop))
1254 else if (BBPhisMergeable)
1269 if (SeenPreds.
insert(PredOfBB).second)
1270 Updates.
push_back({DominatorTree::Insert, PredOfBB, Succ});
1278 if (SeenPreds.
insert(PredOfBB).second && PredOfBB != CommonPred)
1279 Updates.
push_back({DominatorTree::Delete, PredOfBB, BB});
1282 Updates.
push_back({DominatorTree::Delete, BB, Succ});
1285 if (isa<PHINode>(Succ->
begin())) {
1305 while (
PHINode *PN = dyn_cast<PHINode>(&BB->
front())) {
1307 assert(PN->use_empty() &&
"There shouldn't be any uses here!");
1308 PN->eraseFromParent();
1315 if (
MDNode *LoopMD = TI->getMetadata(LLVMContext::MD_loop))
1317 Pred->getTerminator()->setMetadata(LLVMContext::MD_loop, LoopMD);
1332 "applying corresponding DTU updates.");
1333 }
else if (BBPhisMergeable) {
1336 if (
Instruction *UseInst = dyn_cast<Instruction>(U.getUser()))
1337 return UseInst->
getParent() != CommonPred &&
1338 BBPreds.
contains(UseInst->getParent());
1359 bool Changed =
false;
1364 for (
auto I = BB->
begin();
PHINode *PN = dyn_cast<PHINode>(
I);) {
1369 for (
auto J =
I;
PHINode *DuplicatePN = dyn_cast<PHINode>(J); ++J) {
1370 if (
ToRemove.contains(DuplicatePN))
1395 struct PHIDenseMapInfo {
1396 static PHINode *getEmptyKey() {
1400 static PHINode *getTombstoneKey() {
1405 return PN == getEmptyKey() || PN == getTombstoneKey();
1419 static unsigned getHashValue(
PHINode *PN) {
1434 return LHS->isIdenticalTo(
RHS);
1452 bool Changed =
false;
1453 for (
auto I = BB->
begin();
PHINode *PN = dyn_cast<PHINode>(
I++);) {
1456 auto Inserted = PHISet.
insert(PN);
1457 if (!Inserted.second) {
1460 PN->replaceAllUsesWith(*Inserted.first);
1489 PN->eraseFromParent();
1495 V = V->stripPointerCasts();
1497 if (
AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
1503 Align CurrentAlign = AI->getAlign();
1504 if (PrefAlign <= CurrentAlign)
1505 return CurrentAlign;
1509 if (
DL.exceedsNaturalStackAlignment(PrefAlign))
1510 return CurrentAlign;
1511 AI->setAlignment(PrefAlign);
1515 if (
auto *GO = dyn_cast<GlobalObject>(V)) {
1517 Align CurrentAlign = GO->getPointerAlignment(
DL);
1518 if (PrefAlign <= CurrentAlign)
1519 return CurrentAlign;
1525 if (!GO->canIncreaseAlignment())
1526 return CurrentAlign;
1528 if (GO->isThreadLocal()) {
1529 unsigned MaxTLSAlign = GO->getParent()->getMaxTLSAlignment() / CHAR_BIT;
1530 if (MaxTLSAlign && PrefAlign >
Align(MaxTLSAlign))
1531 PrefAlign =
Align(MaxTLSAlign);
1534 GO->setAlignment(PrefAlign);
1546 assert(V->getType()->isPointerTy() &&
1547 "getOrEnforceKnownAlignment expects a pointer!");
1559 if (PrefAlign && *PrefAlign > Alignment)
1580 for (
auto *DVI : DbgValues) {
1582 if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr))
1585 for (
auto *DVR : DbgVariableRecords) {
1587 if ((DVR->getVariable() == DIVar) && (DVR->getExpression() == DIExpr))
1603 TypeSize ValueSize =
DL.getTypeAllocSizeInBits(ValTy);
1604 if (std::optional<uint64_t> FragmentSize =
1614 "address of variable must have exactly 1 location operand.");
1617 if (std::optional<TypeSize> FragmentSize =
1618 AI->getAllocationSizeInBits(
DL)) {
1619 return TypeSize::isKnownGE(ValueSize, *FragmentSize);
1630 TypeSize ValueSize =
DL.getTypeAllocSizeInBits(ValTy);
1631 if (std::optional<uint64_t> FragmentSize =
1641 "address of variable must have exactly 1 location operand.");
1644 if (std::optional<TypeSize> FragmentSize = AI->getAllocationSizeInBits(
DL)) {
1645 return TypeSize::isKnownGE(ValueSize, *FragmentSize);
1659 auto DbgVal = Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
1668 Instr->getParent()->insertDbgRecordBefore(DV, Instr);
1676 auto DbgVal = Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
1685 Instr->getParent()->insertDbgRecordAfter(DV, &*Instr);
1695 assert(DIVar &&
"Missing variable");
1697 Value *DV = SI->getValueOperand();
1714 DIExpr->isDeref() || (!DIExpr->startsWithDeref() &&
1724 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: " << *DII
1736 return DIExpression::get(DIExpr->
getContext(),
1743 assert(DIVar &&
"Missing variable");
1746 Value *DV = SI->getValueOperand();
1760 assert(DIVar &&
"Missing variable");
1766 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: "
1785 assert(DIVar &&
"Missing variable");
1787 Value *DV = SI->getValueOperand();
1804 DIExpr->isDeref() || (!DIExpr->startsWithDeref() &&
1814 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: " << *DVR
1825 SI->getParent()->insertDbgRecordBefore(NewDVR, SI->getIterator());
1831 assert(DIVar &&
"Missing variable");
1834 Value *DV = SI->getValueOperand();
1848 assert(DIVar &&
"Missing variable");
1857 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: "
1870 if (InsertionPt != BB->
end()) {
1880 assert(DIVar &&
"Missing variable");
1886 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to DbgVariableRecord: "
1903 LI->
getParent()->insertDbgRecordAfter(DV, LI);
1920 assert(DIVar &&
"Missing variable");
1929 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to DbgVariableRecord: "
1942 if (InsertionPt != BB->
end()) {
1951 bool Changed =
false;
1955 for (
auto &FI :
F) {
1957 if (
auto *DDI = dyn_cast<DbgDeclareInst>(&BI))
1960 if (DVR.getType() == DbgVariableRecord::LocationType::Declare)
1969 auto LowerOne = [&](
auto *DDI) {
1971 dyn_cast_or_null<AllocaInst>(DDI->getVariableLocationOp(0));
1983 if (LoadInst *LI = dyn_cast<LoadInst>(U))
1984 return LI->isVolatile();
1985 if (StoreInst *SI = dyn_cast<StoreInst>(U))
1986 return SI->isVolatile();
1993 while (!WorkList.
empty()) {
1995 for (
const auto &AIUse : V->uses()) {
1996 User *U = AIUse.getUser();
1997 if (
StoreInst *SI = dyn_cast<StoreInst>(U)) {
1998 if (AIUse.getOperandNo() == 1)
2000 }
else if (
LoadInst *LI = dyn_cast<LoadInst>(U)) {
2002 }
else if (
CallInst *CI = dyn_cast<CallInst>(U)) {
2006 if (!CI->isLifetimeStartOrEnd()) {
2014 }
else if (
BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
2015 if (BI->getType()->isPointerTy())
2020 DDI->eraseFromParent();
2040 assert(BB &&
"No BasicBlock to clone DbgVariableRecord(s) from.");
2041 if (InsertedPHIs.
size() == 0)
2046 for (
auto &
I : *BB) {
2048 for (
Value *V : DVR.location_ops())
2049 if (
auto *Loc = dyn_cast_or_null<PHINode>(V))
2050 DbgValueMap.
insert({Loc, &DVR});
2053 if (DbgValueMap.
size() == 0)
2068 for (
auto PHI : InsertedPHIs) {
2073 for (
auto VI :
PHI->operand_values()) {
2074 auto V = DbgValueMap.
find(VI);
2075 if (V != DbgValueMap.
end()) {
2077 auto NewDI = NewDbgValueMap.
find({Parent, DbgII});
2078 if (NewDI == NewDbgValueMap.
end()) {
2080 NewDI = NewDbgValueMap.
insert({{Parent, DbgII}, NewDbgII}).first;
2091 for (
auto DI : NewDbgValueMap) {
2095 assert(InsertionPt != Parent->
end() &&
"Ill-formed basic block");
2104 assert(BB &&
"No BasicBlock to clone dbg.value(s) from.");
2105 if (InsertedPHIs.
size() == 0)
2112 for (
auto &
I : *BB) {
2113 if (
auto DbgII = dyn_cast<DbgVariableIntrinsic>(&
I)) {
2114 for (
Value *V : DbgII->location_ops())
2115 if (
auto *Loc = dyn_cast_or_null<PHINode>(V))
2116 DbgValueMap.
insert({Loc, DbgII});
2119 if (DbgValueMap.
size() == 0)
2134 for (
auto *
PHI : InsertedPHIs) {
2139 for (
auto *VI :
PHI->operand_values()) {
2140 auto V = DbgValueMap.
find(VI);
2141 if (V != DbgValueMap.
end()) {
2142 auto *DbgII = cast<DbgVariableIntrinsic>(V->second);
2143 auto NewDI = NewDbgValueMap.
find({Parent, DbgII});
2144 if (NewDI == NewDbgValueMap.
end()) {
2145 auto *NewDbgII = cast<DbgVariableIntrinsic>(DbgII->clone());
2146 NewDI = NewDbgValueMap.
insert({{Parent, DbgII}, NewDbgII}).first;
2157 for (
auto DI : NewDbgValueMap) {
2159 auto *NewDbgII = DI.second;
2161 assert(InsertionPt != Parent->
end() &&
"Ill-formed basic block");
2162 NewDbgII->insertBefore(&*InsertionPt);
2167 DIBuilder &Builder, uint8_t DIExprFlags,
2172 auto ReplaceOne = [&](
auto *DII) {
2173 assert(DII->getVariable() &&
"Missing variable");
2174 auto *DIExpr = DII->getExpression();
2176 DII->setExpression(DIExpr);
2177 DII->replaceVariableLocationOp(Address, NewAddress);
2183 return !DbgDeclares.
empty() || !DVRDeclares.
empty();
2192 assert(DIVar &&
"Missing variable");
2222 for (
auto *DVI : DbgUsers)
2224 DVI->getExpression(), NewAllocaAddress, DVI,
2225 nullptr, Builder,
Offset);
2230 DVR->getExpression(), NewAllocaAddress,
nullptr,
2244 Instruction *
I = dyn_cast<Instruction>(Assign->getAddress());
2249 assert(!Assign->getAddressExpression()->getFragmentInfo().has_value() &&
2250 "address-expression shouldn't have fragment info");
2263 Assign->getAddressExpression(), Ops, 0,
false);
2265 "address-expression shouldn't have fragment info");
2270 if (AdditionalValues.
empty()) {
2271 Assign->setAddress(NewV);
2272 Assign->setAddressExpression(SalvagedExpr);
2274 Assign->setKillAddress();
2284 const unsigned MaxDebugArgs = 16;
2285 const unsigned MaxExpressionSize = 128;
2286 bool Salvaged =
false;
2288 for (
auto *DII : DbgUsers) {
2289 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(DII)) {
2290 if (DAI->getAddress() == &
I) {
2294 if (DAI->getValue() != &
I)
2300 bool StackValue = isa<DbgValueInst>(DII);
2301 auto DIILocation = DII->location_ops();
2304 "DbgVariableIntrinsic must use salvaged instruction as its location");
2310 Value *Op0 =
nullptr;
2312 auto LocItr =
find(DIILocation, &
I);
2313 while (SalvagedExpr && LocItr != DIILocation.end()) {
2315 unsigned LocNo = std::distance(DIILocation.begin(), LocItr);
2322 LocItr = std::find(++LocItr, DIILocation.end(), &
I);
2330 DII->replaceVariableLocationOp(&
I, Op0);
2331 bool IsValidSalvageExpr = SalvagedExpr->
getNumElements() <= MaxExpressionSize;
2332 if (AdditionalValues.
empty() && IsValidSalvageExpr) {
2333 DII->setExpression(SalvagedExpr);
2334 }
else if (isa<DbgValueInst>(DII) && IsValidSalvageExpr &&
2335 DII->getNumVariableLocationOps() + AdditionalValues.
size() <=
2337 DII->addVariableLocationOps(AdditionalValues, SalvagedExpr);
2342 DII->setKillLocation();
2348 for (
auto *DVR : DPUsers) {
2349 if (DVR->isDbgAssign()) {
2350 if (DVR->getAddress() == &
I) {
2354 if (DVR->getValue() != &
I)
2362 DVR->getType() != DbgVariableRecord::LocationType::Declare;
2363 auto DVRLocation = DVR->location_ops();
2366 "DbgVariableIntrinsic must use salvaged instruction as its location");
2372 Value *Op0 =
nullptr;
2374 auto LocItr =
find(DVRLocation, &
I);
2375 while (SalvagedExpr && LocItr != DVRLocation.end()) {
2377 unsigned LocNo = std::distance(DVRLocation.begin(), LocItr);
2384 LocItr = std::find(++LocItr, DVRLocation.end(), &
I);
2392 DVR->replaceVariableLocationOp(&
I, Op0);
2393 bool IsValidSalvageExpr =
2395 if (AdditionalValues.
empty() && IsValidSalvageExpr) {
2396 DVR->setExpression(SalvagedExpr);
2397 }
else if (DVR->getType() != DbgVariableRecord::LocationType::Declare &&
2398 IsValidSalvageExpr &&
2399 DVR->getNumVariableLocationOps() + AdditionalValues.
size() <=
2401 DVR->addVariableLocationOps(AdditionalValues, SalvagedExpr);
2407 DVR->setKillLocation();
2416 for (
auto *DII : DbgUsers)
2417 DII->setKillLocation();
2419 for (
auto *DVR : DPUsers)
2420 DVR->setKillLocation();
2427 unsigned BitWidth =
DL.getIndexSizeInBits(
GEP->getPointerAddressSpace());
2431 if (!
GEP->collectOffset(
DL,
BitWidth, VariableOffsets, ConstantOffset))
2433 if (!VariableOffsets.
empty() && !CurrentLocOps) {
2434 Opcodes.
insert(Opcodes.
begin(), {dwarf::DW_OP_LLVM_arg, 0});
2437 for (
const auto &
Offset : VariableOffsets) {
2440 "Expected strictly positive multiplier for offset.");
2442 Offset.second.getZExtValue(), dwarf::DW_OP_mul,
2443 dwarf::DW_OP_plus});
2446 return GEP->getOperand(0);
2451 case Instruction::Add:
2452 return dwarf::DW_OP_plus;
2453 case Instruction::Sub:
2454 return dwarf::DW_OP_minus;
2455 case Instruction::Mul:
2456 return dwarf::DW_OP_mul;
2457 case Instruction::SDiv:
2458 return dwarf::DW_OP_div;
2459 case Instruction::SRem:
2460 return dwarf::DW_OP_mod;
2461 case Instruction::Or:
2462 return dwarf::DW_OP_or;
2463 case Instruction::And:
2464 return dwarf::DW_OP_and;
2465 case Instruction::Xor:
2466 return dwarf::DW_OP_xor;
2467 case Instruction::Shl:
2468 return dwarf::DW_OP_shl;
2469 case Instruction::LShr:
2470 return dwarf::DW_OP_shr;
2471 case Instruction::AShr:
2472 return dwarf::DW_OP_shra;
2483 if (!CurrentLocOps) {
2488 AdditionalValues.
push_back(
I->getOperand(1));
2495 auto *ConstInt = dyn_cast<ConstantInt>(BI->
getOperand(1));
2497 if (ConstInt && ConstInt->getBitWidth() > 64)
2503 uint64_t Val = ConstInt->getSExtValue();
2506 if (BinOpcode == Instruction::Add || BinOpcode == Instruction::Sub) {
2507 uint64_t Offset = BinOpcode == Instruction::Add ? Val : -int64_t(Val);
2511 Opcodes.
append({dwarf::DW_OP_constu, Val});
2530 return dwarf::DW_OP_eq;
2532 return dwarf::DW_OP_ne;
2535 return dwarf::DW_OP_gt;
2538 return dwarf::DW_OP_ge;
2541 return dwarf::DW_OP_lt;
2544 return dwarf::DW_OP_le;
2554 auto *ConstInt = dyn_cast<ConstantInt>(Icmp->
getOperand(1));
2556 if (ConstInt && ConstInt->getBitWidth() > 64)
2564 uint64_t Val = ConstInt->getSExtValue();
2582 auto &M = *
I.getModule();
2583 auto &
DL = M.getDataLayout();
2585 if (
auto *CI = dyn_cast<CastInst>(&
I)) {
2586 Value *FromValue = CI->getOperand(0);
2588 if (CI->isNoopCast(
DL)) {
2597 !(isa<TruncInst>(&
I) || isa<SExtInst>(&
I) || isa<ZExtInst>(&
I) ||
2598 isa<IntToPtrInst>(&
I) || isa<PtrToIntInst>(&
I)))
2602 if (FromType->isPointerTy())
2603 FromType =
DL.getIntPtrType(FromType);
2605 unsigned FromTypeBitSize = FromType->getScalarSizeInBits();
2610 Ops.
append(ExtOps.begin(), ExtOps.end());
2614 if (
auto *
GEP = dyn_cast<GetElementPtrInst>(&
I))
2616 if (
auto *BI = dyn_cast<BinaryOperator>(&
I))
2618 if (
auto *IC = dyn_cast<ICmpInst>(&
I))
2645 bool Changed =
false;
2649 if (isa<Instruction>(&To)) {
2650 bool DomPointAfterFrom =
From.getNextNonDebugInstruction() == &DomPoint;
2652 for (
auto *DII :
Users) {
2662 }
else if (!DT.
dominates(&DomPoint, DII)) {
2663 UndefOrSalvage.
insert(DII);
2668 for (
auto *DVR : DPUsers) {
2672 if (isa<DbgVariableIntrinsic>(NextNonDebug))
2675 if (DomPointAfterFrom && NextNonDebug == &DomPoint) {
2679 DomPoint.
getParent()->insertDbgRecordAfter(DVR, &DomPoint);
2681 }
else if (!DT.
dominates(&DomPoint, MarkedInstr)) {
2682 UndefOrSalvageDVR.
insert(DVR);
2688 for (
auto *DII :
Users) {
2689 if (UndefOrSalvage.
count(DII))
2701 for (
auto *DVR : DPUsers) {
2702 if (UndefOrSalvageDVR.
count(DVR))
2715 if (!UndefOrSalvage.
empty() || !UndefOrSalvageDVR.
empty()) {
2739 bool SameSize =
DL.getTypeSizeInBits(FromTy) ==
DL.getTypeSizeInBits(ToTy);
2740 bool LosslessConversion = !
DL.isNonIntegralPointerType(FromTy) &&
2741 !
DL.isNonIntegralPointerType(ToTy);
2742 return SameSize && LosslessConversion;
2752 if (!
From.isUsedByMetadata())
2755 assert(&
From != &To &&
"Can't replace something with itself");
2764 return DVR.getExpression();
2778 assert(FromBits != ToBits &&
"Unexpected no-op conversion");
2782 if (FromBits < ToBits)
2793 return std::nullopt;
2795 bool Signed = *Signedness == DIBasicType::Signedness::Signed;
2807 return std::nullopt;
2809 bool Signed = *Signedness == DIBasicType::Signedness::Signed;
2823 bool Changed =
false;
2825 I->dropDbgRecords();
2826 for (
Use &U :
I->operands()) {
2828 if (isa<Instruction>(
Op) && !
Op->getType()->isTokenTy()) {
2838std::pair<unsigned, unsigned>
2840 unsigned NumDeadInst = 0;
2841 unsigned NumDeadDbgInst = 0;
2848 while (EndInst != &BB->
front()) {
2860 if (isa<DbgInfoIntrinsic>(Inst))
2868 return {NumDeadInst, NumDeadDbgInst};
2884 Successor->removePredecessor(BB, PreserveLCSSA);
2889 UI->setDebugLoc(
I->getDebugLoc());
2892 unsigned NumInstrsRemoved = 0;
2894 while (BBI != BBE) {
2895 if (!BBI->use_empty())
2897 BBI++->eraseFromParent();
2903 for (
BasicBlock *UniqueSuccessor : UniqueSuccessors)
2904 Updates.
push_back({DominatorTree::Delete, BB, UniqueSuccessor});
2908 return NumInstrsRemoved;
2914 II->getOperandBundlesAsDefs(OpBundles);
2916 II->getCalledOperand(), Args, OpBundles);
2927 auto NewWeights =
uint32_t(TotalWeight) != TotalWeight
2930 NewCall->
setMetadata(LLVMContext::MD_prof, NewWeights);
2941 II->replaceAllUsesWith(NewCall);
2951 II->eraseFromParent();
2953 DTU->
applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}});
2982 UnwindEdge, InvokeArgs, OpBundles, CI->
getName(), BB);
2986 II->setMetadata(LLVMContext::MD_prof, CI->
getMetadata(LLVMContext::MD_prof));
2989 DTU->
applyUpdates({{DominatorTree::Insert, BB, UnwindEdge}});
2996 Split->front().eraseFromParent();
3007 bool Changed =
false;
3015 if (
auto *CI = dyn_cast<CallInst>(&
I)) {
3016 Value *Callee = CI->getCalledOperand();
3018 if (
Function *
F = dyn_cast<Function>(Callee)) {
3019 auto IntrinsicID =
F->getIntrinsicID();
3024 if (IntrinsicID == Intrinsic::assume) {
3031 }
else if (IntrinsicID == Intrinsic::experimental_guard) {
3042 if (!isa<UnreachableInst>(CI->getNextNode())) {
3048 }
else if ((isa<ConstantPointerNull>(Callee) &&
3050 cast<PointerType>(Callee->getType())
3051 ->getAddressSpace())) ||
3052 isa<UndefValue>(Callee)) {
3057 if (CI->doesNotReturn() && !CI->isMustTailCall()) {
3061 if (!isa<UnreachableInst>(CI->getNextNonDebugInstruction())) {
3068 }
else if (
auto *SI = dyn_cast<StoreInst>(&
I)) {
3074 if (SI->isVolatile())
continue;
3078 if (isa<UndefValue>(
Ptr) ||
3079 (isa<ConstantPointerNull>(
Ptr) &&
3081 SI->getPointerAddressSpace()))) {
3090 if (
auto *
II = dyn_cast<InvokeInst>(Terminator)) {
3092 Value *Callee =
II->getCalledOperand();
3093 if ((isa<ConstantPointerNull>(Callee) &&
3095 isa<UndefValue>(Callee)) {
3099 if (
II->doesNotReturn() &&
3100 !isa<UnreachableInst>(
II->getNormalDest()->front())) {
3110 Ctx, OrigNormalDest->
getName() +
".unreachable",
3111 II->getFunction(), OrigNormalDest);
3113 II->setNormalDest(UnreachableNormalDest);
3116 {{DominatorTree::Delete, BB, OrigNormalDest},
3117 {DominatorTree::Insert, BB, UnreachableNormalDest}});
3121 if (
II->use_empty() && !
II->mayHaveSideEffects()) {
3127 II->eraseFromParent();
3129 DTU->applyUpdates({{DominatorTree::Delete, BB, UnwindDestBB}});
3135 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) {
3137 struct CatchPadDenseMapInfo {
3152 if (
LHS == getEmptyKey() ||
LHS == getTombstoneKey() ||
3153 RHS == getEmptyKey() ||
RHS == getTombstoneKey())
3155 return LHS->isIdenticalTo(
RHS);
3166 E = CatchSwitch->handler_end();
3170 ++NumPerSuccessorCases[HandlerBB];
3171 auto *CatchPad = cast<CatchPadInst>(HandlerBB->
getFirstNonPHI());
3172 if (!HandlerSet.insert({CatchPad, Empty}).second) {
3174 --NumPerSuccessorCases[HandlerBB];
3175 CatchSwitch->removeHandler(
I);
3182 std::vector<DominatorTree::UpdateType> Updates;
3183 for (
const std::pair<BasicBlock *, int> &
I : NumPerSuccessorCases)
3185 Updates.push_back({DominatorTree::Delete, BB,
I.first});
3186 DTU->applyUpdates(Updates);
3194 }
while (!Worklist.
empty());
3201 if (
auto *
II = dyn_cast<InvokeInst>(TI))
3207 if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
3209 UnwindDest = CRI->getUnwindDest();
3210 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(TI)) {
3212 CatchSwitch->getParentPad(),
nullptr, CatchSwitch->getNumHandlers(),
3213 CatchSwitch->getName(), CatchSwitch->getIterator());
3214 for (
BasicBlock *PadBB : CatchSwitch->handlers())
3215 NewCatchSwitch->addHandler(PadBB);
3217 NewTI = NewCatchSwitch;
3218 UnwindDest = CatchSwitch->getUnwindDest();
3229 DTU->
applyUpdates({{DominatorTree::Delete, BB, UnwindDest}});
3242 if (Reachable.
size() ==
F.size())
3251 if (Reachable.
count(&BB))
3256 BlocksToRemove.
insert(&BB);
3259 if (BlocksToRemove.
empty())
3263 NumRemoved += BlocksToRemove.
size();
3276 K->dropUnknownNonDebugMetadata(KnownIDs);
3277 K->getAllMetadataOtherThanDebugLoc(
Metadata);
3279 unsigned Kind = MD.first;
3285 K->setMetadata(Kind,
nullptr);
3287 case LLVMContext::MD_dbg:
3289 case LLVMContext::MD_DIAssignID:
3290 K->mergeDIAssignID(J);
3292 case LLVMContext::MD_tbaa:
3295 case LLVMContext::MD_alias_scope:
3298 case LLVMContext::MD_noalias:
3299 case LLVMContext::MD_mem_parallel_loop_access:
3302 case LLVMContext::MD_access_group:
3303 K->setMetadata(LLVMContext::MD_access_group,
3306 case LLVMContext::MD_range:
3307 if (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef))
3310 case LLVMContext::MD_fpmath:
3313 case LLVMContext::MD_invariant_load:
3317 K->setMetadata(Kind, JMD);
3319 case LLVMContext::MD_nonnull:
3320 if (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef))
3321 K->setMetadata(Kind, JMD);
3323 case LLVMContext::MD_invariant_group:
3326 case LLVMContext::MD_mmra:
3329 case LLVMContext::MD_align:
3330 if (DoesKMove || !K->hasMetadata(LLVMContext::MD_noundef))
3334 case LLVMContext::MD_dereferenceable:
3335 case LLVMContext::MD_dereferenceable_or_null:
3337 K->setMetadata(Kind,
3340 case LLVMContext::MD_preserve_access_index:
3343 case LLVMContext::MD_noundef:
3346 K->setMetadata(Kind, JMD);
3348 case LLVMContext::MD_nontemporal:
3350 K->setMetadata(Kind, JMD);
3352 case LLVMContext::MD_prof:
3364 if (
auto *JMD = J->
getMetadata(LLVMContext::MD_invariant_group))
3365 if (isa<LoadInst>(K) || isa<StoreInst>(K))
3366 K->setMetadata(LLVMContext::MD_invariant_group, JMD);
3371 auto JMMRA = J->
getMetadata(LLVMContext::MD_mmra);
3372 auto KMMRA = K->getMetadata(LLVMContext::MD_mmra);
3373 if (JMMRA || KMMRA) {
3374 K->setMetadata(LLVMContext::MD_mmra,
3381 unsigned KnownIDs[] = {LLVMContext::MD_tbaa,
3382 LLVMContext::MD_alias_scope,
3383 LLVMContext::MD_noalias,
3384 LLVMContext::MD_range,
3385 LLVMContext::MD_fpmath,
3386 LLVMContext::MD_invariant_load,
3387 LLVMContext::MD_nonnull,
3388 LLVMContext::MD_invariant_group,
3389 LLVMContext::MD_align,
3390 LLVMContext::MD_dereferenceable,
3391 LLVMContext::MD_dereferenceable_or_null,
3392 LLVMContext::MD_access_group,
3393 LLVMContext::MD_preserve_access_index,
3394 LLVMContext::MD_prof,
3395 LLVMContext::MD_nontemporal,
3396 LLVMContext::MD_noundef,
3397 LLVMContext::MD_mmra};
3403 Source.getAllMetadata(MD);
3407 for (
const auto &MDPair : MD) {
3408 unsigned ID = MDPair.first;
3418 case LLVMContext::MD_dbg:
3419 case LLVMContext::MD_tbaa:
3420 case LLVMContext::MD_prof:
3421 case LLVMContext::MD_fpmath:
3422 case LLVMContext::MD_tbaa_struct:
3423 case LLVMContext::MD_invariant_load:
3424 case LLVMContext::MD_alias_scope:
3425 case LLVMContext::MD_noalias:
3426 case LLVMContext::MD_nontemporal:
3427 case LLVMContext::MD_mem_parallel_loop_access:
3428 case LLVMContext::MD_access_group:
3429 case LLVMContext::MD_noundef:
3434 case LLVMContext::MD_nonnull:
3438 case LLVMContext::MD_align:
3439 case LLVMContext::MD_dereferenceable:
3440 case LLVMContext::MD_dereferenceable_or_null:
3446 case LLVMContext::MD_range:
3454 auto *ReplInst = dyn_cast<Instruction>(Repl);
3463 if (isa<OverflowingBinaryOperator>(ReplInst) &&
3470 else if (!isa<LoadInst>(
I))
3471 ReplInst->andIRFlags(
I);
3485template <
typename RootType,
typename ShouldReplaceFn>
3487 const RootType &Root,
3488 const ShouldReplaceFn &ShouldReplace) {
3493 if (!ShouldReplace(Root, U))
3497 dbgs() <<
"' with " << *To <<
" in " << *U.getUser() <<
"\n");
3506 auto *BB =
From->getParent();
3510 auto *
I = cast<Instruction>(U.getUser());
3511 if (
I->getParent() == BB)
3525 return ::replaceDominatedUsesWith(
From, To, Root, Dominates);
3531 auto Dominates = [&DT](
const BasicBlock *BB,
const Use &U) {
3534 return ::replaceDominatedUsesWith(
From, To, BB, Dominates);
3540 auto DominatesAndShouldReplace =
3542 return DT.
dominates(Root, U) && ShouldReplace(U, To);
3544 return ::replaceDominatedUsesWith(
From, To, Root, DominatesAndShouldReplace);
3550 auto DominatesAndShouldReplace = [&DT, &ShouldReplace,
3552 return DT.
dominates(BB, U) && ShouldReplace(U, To);
3554 return ::replaceDominatedUsesWith(
From, To, BB, DominatesAndShouldReplace);
3560 if (Call->hasFnAttr(
"gc-leaf-function"))
3562 if (
const Function *
F = Call->getCalledFunction()) {
3563 if (
F->hasFnAttribute(
"gc-leaf-function"))
3566 if (
auto IID =
F->getIntrinsicID()) {
3568 return IID != Intrinsic::experimental_gc_statepoint &&
3569 IID != Intrinsic::experimental_deoptimize &&
3570 IID != Intrinsic::memcpy_element_unordered_atomic &&
3571 IID != Intrinsic::memmove_element_unordered_atomic;
3588 auto *NewTy = NewLI.
getType();
3591 if (NewTy->isPointerTy()) {
3598 if (!NewTy->isIntegerTy())
3603 auto *ITy = cast<IntegerType>(NewTy);
3613 auto *NewTy = NewLI.
getType();
3615 if (NewTy == OldLI.
getType()) {
3624 if (!NewTy->isPointerTy())
3627 unsigned BitWidth =
DL.getPointerTypeSizeInBits(NewTy);
3639 for (
auto *DII : DbgUsers)
3641 for (
auto *DVR : DPUsers)
3642 DVR->eraseFromParent();
3671 I->dropUBImplyingAttrsAndMetadata();
3672 if (
I->isUsedByMetadata())
3675 I->dropDbgRecords();
3676 if (
I->isDebugOrPseudoInst()) {
3678 II =
I->eraseFromParent();
3692 const APInt &API = cast<ConstantInt>(&CV)->getValue();
3693 std::optional<int64_t> InitIntOpt = API.
trySExtValue();
3695 static_cast<uint64_t>(*InitIntOpt))
3699 if (isa<ConstantInt>(
C))
3700 return createIntegerExpression(
C);
3702 auto *
FP = dyn_cast<ConstantFP>(&
C);
3714 if (isa<ConstantPointerNull>(
C))
3718 if (CE->getOpcode() == Instruction::IntToPtr) {
3719 const Value *V = CE->getOperand(0);
3720 if (
auto CI = dyn_cast_or_null<ConstantInt>(V))
3721 return createIntegerExpression(*CI);
3727 auto RemapDebugOperands = [&Mapping](
auto *DV,
auto Set) {
3728 for (
auto *
Op : Set) {
3730 if (
I != Mapping.
end())
3731 DV->replaceVariableLocationOp(
Op,
I->second,
true);
3734 auto RemapAssignAddress = [&Mapping](
auto *DA) {
3735 auto I = Mapping.
find(DA->getAddress());
3736 if (
I != Mapping.
end())
3737 DA->setAddress(
I->second);
3739 if (
auto DVI = dyn_cast<DbgVariableIntrinsic>(Inst))
3740 RemapDebugOperands(DVI, DVI->location_ops());
3741 if (
auto DAI = dyn_cast<DbgAssignIntrinsic>(Inst))
3742 RemapAssignAddress(DAI);
3744 RemapDebugOperands(&DVR, DVR.location_ops());
3745 if (DVR.isDbgAssign())
3746 RemapAssignAddress(&DVR);
3755 BitPart(
Value *
P,
unsigned BW) : Provider(
P) {
3756 Provenance.resize(BW);
3766 enum { Unset = -1 };
3798static const std::optional<BitPart> &
3800 std::map<
Value *, std::optional<BitPart>> &BPS,
int Depth,
3802 auto I = BPS.find(V);
3806 auto &Result = BPS[V] = std::nullopt;
3807 auto BitWidth = V->getType()->getScalarSizeInBits();
3815 LLVM_DEBUG(
dbgs() <<
"collectBitParts max recursion depth reached.\n");
3819 if (
auto *
I = dyn_cast<Instruction>(V)) {
3827 Depth + 1, FoundRoot);
3828 if (!
A || !
A->Provider)
3832 Depth + 1, FoundRoot);
3833 if (!
B ||
A->Provider !=
B->Provider)
3837 Result = BitPart(
A->Provider,
BitWidth);
3838 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx) {
3839 if (
A->Provenance[BitIdx] != BitPart::Unset &&
3840 B->Provenance[BitIdx] != BitPart::Unset &&
3841 A->Provenance[BitIdx] !=
B->Provenance[BitIdx])
3842 return Result = std::nullopt;
3844 if (
A->Provenance[BitIdx] == BitPart::Unset)
3845 Result->Provenance[BitIdx] =
B->Provenance[BitIdx];
3847 Result->Provenance[BitIdx] =
A->Provenance[BitIdx];
3855 const APInt &BitShift = *
C;
3862 if (!MatchBitReversals && (BitShift.
getZExtValue() % 8) != 0)
3866 Depth + 1, FoundRoot);
3872 auto &
P = Result->Provenance;
3873 if (
I->getOpcode() == Instruction::Shl) {
3887 const APInt &AndMask = *
C;
3891 unsigned NumMaskedBits = AndMask.
popcount();
3892 if (!MatchBitReversals && (NumMaskedBits % 8) != 0)
3896 Depth + 1, FoundRoot);
3901 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3903 if (AndMask[BitIdx] == 0)
3904 Result->Provenance[BitIdx] = BitPart::Unset;
3911 Depth + 1, FoundRoot);
3915 Result = BitPart(Res->Provider,
BitWidth);
3916 auto NarrowBitWidth =
X->getType()->getScalarSizeInBits();
3917 for (
unsigned BitIdx = 0; BitIdx < NarrowBitWidth; ++BitIdx)
3918 Result->Provenance[BitIdx] = Res->Provenance[BitIdx];
3919 for (
unsigned BitIdx = NarrowBitWidth; BitIdx <
BitWidth; ++BitIdx)
3920 Result->Provenance[BitIdx] = BitPart::Unset;
3927 Depth + 1, FoundRoot);
3931 Result = BitPart(Res->Provider,
BitWidth);
3932 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3933 Result->Provenance[BitIdx] = Res->Provenance[BitIdx];
3941 Depth + 1, FoundRoot);
3945 Result = BitPart(Res->Provider,
BitWidth);
3946 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
3947 Result->Provenance[(
BitWidth - 1) - BitIdx] = Res->Provenance[BitIdx];
3954 Depth + 1, FoundRoot);
3959 Result = BitPart(Res->Provider,
BitWidth);
3960 for (
unsigned ByteIdx = 0; ByteIdx < ByteWidth; ++ByteIdx) {
3961 unsigned ByteBitOfs = ByteIdx * 8;
3962 for (
unsigned BitIdx = 0; BitIdx < 8; ++BitIdx)
3963 Result->Provenance[(
BitWidth - 8 - ByteBitOfs) + BitIdx] =
3964 Res->Provenance[ByteBitOfs + BitIdx];
3981 if (!MatchBitReversals && (ModAmt % 8) != 0)
3986 Depth + 1, FoundRoot);
3987 if (!
LHS || !
LHS->Provider)
3991 Depth + 1, FoundRoot);
3992 if (!
RHS ||
LHS->Provider !=
RHS->Provider)
3995 unsigned StartBitRHS =
BitWidth - ModAmt;
3997 for (
unsigned BitIdx = 0; BitIdx < StartBitRHS; ++BitIdx)
3998 Result->Provenance[BitIdx + ModAmt] =
LHS->Provenance[BitIdx];
3999 for (
unsigned BitIdx = 0; BitIdx < ModAmt; ++BitIdx)
4000 Result->Provenance[BitIdx] =
RHS->Provenance[BitIdx + StartBitRHS];
4014 for (
unsigned BitIdx = 0; BitIdx <
BitWidth; ++BitIdx)
4015 Result->Provenance[BitIdx] = BitIdx;
4021 if (
From % 8 != To % 8)
4036 Instruction *
I,
bool MatchBSwaps,
bool MatchBitReversals,
4043 if (!MatchBSwaps && !MatchBitReversals)
4045 Type *ITy =
I->getType();
4050 bool FoundRoot =
false;
4051 std::map<Value *, std::optional<BitPart>> BPS;
4058 [](int8_t
I) {
return I == BitPart::Unset || 0 <=
I; }) &&
4059 "Illegal bit provenance index");
4062 Type *DemandedTy = ITy;
4063 if (BitProvenance.
back() == BitPart::Unset) {
4064 while (!BitProvenance.
empty() && BitProvenance.
back() == BitPart::Unset)
4065 BitProvenance = BitProvenance.
drop_back();
4066 if (BitProvenance.
empty())
4069 if (
auto *IVecTy = dyn_cast<VectorType>(ITy))
4070 DemandedTy = VectorType::get(DemandedTy, IVecTy);
4081 bool OKForBSwap = MatchBSwaps && (DemandedBW % 16) == 0;
4082 bool OKForBitReverse = MatchBitReversals;
4083 for (
unsigned BitIdx = 0;
4084 (BitIdx < DemandedBW) && (OKForBSwap || OKForBitReverse); ++BitIdx) {
4085 if (BitProvenance[BitIdx] == BitPart::Unset) {
4092 BitIdx, DemandedBW);
4097 Intrin = Intrinsic::bswap;
4098 else if (OKForBitReverse)
4099 Intrin = Intrinsic::bitreverse;
4104 Value *Provider = Res->Provider;
4107 if (DemandedTy != Provider->
getType()) {
4118 auto *Mask = ConstantInt::get(DemandedTy, DemandedMask);
4124 if (ITy != Result->getType()) {
4141 if (
F && !
F->hasLocalLinkage() &&
F->hasName() &&
4143 !
F->doesNotAccessMemory())
4149 if (
I->getOperand(OpIdx)->getType()->isMetadataTy())
4153 if (!isa<Constant>(
I->getOperand(OpIdx)))
4156 switch (
I->getOpcode()) {
4159 case Instruction::Call:
4160 case Instruction::Invoke: {
4161 const auto &CB = cast<CallBase>(*
I);
4164 if (CB.isInlineAsm())
4169 if (CB.isBundleOperand(OpIdx))
4172 if (OpIdx < CB.arg_size()) {
4175 if (isa<IntrinsicInst>(CB) &&
4176 OpIdx >= CB.getFunctionType()->getNumParams()) {
4178 return CB.getIntrinsicID() == Intrinsic::experimental_stackmap;
4183 if (CB.getIntrinsicID() == Intrinsic::gcroot)
4187 return !CB.paramHasAttr(OpIdx, Attribute::ImmArg);
4192 return !isa<IntrinsicInst>(CB);
4194 case Instruction::ShuffleVector:
4197 case Instruction::Switch:
4198 case Instruction::ExtractValue:
4201 case Instruction::InsertValue:
4204 case Instruction::Alloca:
4208 return !cast<AllocaInst>(
I)->isStaticAlloca();
4209 case Instruction::GetElementPtr:
4213 for (
auto E = std::next(It, OpIdx); It != E; ++It)
4222 if (
Constant *
C = dyn_cast<Constant>(Condition))
4226 Value *NotCondition;
4228 return NotCondition;
4231 Instruction *Inst = dyn_cast<Instruction>(Condition);
4234 else if (
Argument *Arg = dyn_cast<Argument>(Condition))
4236 assert(Parent &&
"Unsupported condition to invert");
4247 if (Inst && !isa<PHINode>(Inst))
4248 Inverted->insertAfter(Inst);
4258 bool Changed =
false;
4260 if (!
F.hasFnAttribute(Attribute::NoSync) &&
4261 F.doesNotAccessMemory() && !
F.isConvergent()) {
4267 if (!
F.hasFnAttribute(Attribute::NoFree) &&
F.onlyReadsMemory()) {
4268 F.setDoesNotFreeMemory();
4273 if (!
F.hasFnAttribute(Attribute::MustProgress) &&
F.willReturn()) {
4274 F.setMustProgress();
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
static unsigned getIntrinsicID(const SDNode *N)
This file implements a class to represent arbitrary precision integral constant values and operations...
ReachingDefAnalysis InstSet & ToRemove
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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)
BlockVerifier::State From
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
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")
Rewrite Partial Register Uses
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
This defines the Use class.
iv Induction Variable Users
This file provides utility for Memory Model Relaxation Annotations (MMRAs).
Module.h This file contains the declarations for the Module class.
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
This file contains the declarations for profiling metadata utility functions.
const SmallVectorImpl< MachineOperand > & Cond
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)
APInt bitcastToAPInt() const
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.
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
std::optional< int64_t > trySExtValue() const
Get sign extended value if possible.
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.
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
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,...
InstListType::const_iterator getFirstNonPHIIt() const
Iterator returning form of getFirstNonPHI.
void insertDbgRecordBefore(DbgRecord *DR, InstListType::iterator Here)
Insert a DbgRecord into a block at the position given by Here.
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.
void flushTerminatorDbgRecords()
Eject any debug-info trailing at the end of a block.
const Function * getParent() const
Return the enclosing method, or null if none.
const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
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...
bool hasNPredecessorsOrMore(unsigned N) const
Return true if this block has N predecessors or more.
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
const Instruction & back() const
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
BinaryOps getOpcode() const
static BinaryOperator * CreateNot(Value *Op, const Twine &Name="", InsertPosition InsertBefore=nullptr)
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
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, InsertPosition 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="", InsertPosition InsertBefore=nullptr)
static CastInst * CreateIntegerCast(Value *S, Type *Ty, bool isSigned, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a ZExt, BitCast, or Trunc for int -> int casts.
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ ICMP_ULT
unsigned less than
@ ICMP_SGE
signed greater or equal
@ ICMP_ULE
unsigned less or equal
Predicate getPredicate() const
Return the predicate for this instruction.
A constant value that is initialized with an expression using other constant values.
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 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.
DIExpression * createConstantValueExpression(uint64_t Val)
Create an expression for a variable that does not have an address, but does have a constant value.
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.
DIExpression * foldConstantMath()
Try to shorten an expression with constant math operations that can be evaluated at compile time.
uint64_t getNumLocationOperands() const
Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; th...
ArrayRef< uint64_t > getElements() const
std::optional< uint64_t > getActiveBits(DIVariable *Var)
Return the number of bits that have an active value, i.e.
uint64_t getElement(unsigned I) const
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...
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
This represents the llvm.dbg.label instruction.
Instruction * MarkedInstr
Link back to the Instruction that owns this marker.
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, bool AllowEmpty=false)
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.
DIExpression * getExpression() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
bool isAddressOfVariable() const
Does this describe the address of a local variable.
DbgVariableRecord * clone() const
void setExpression(DIExpression *NewExpr)
DIExpression * getExpression() const
Value * getVariableLocationOp(unsigned OpIdx) const
DILocalVariable * getVariable() const
unsigned getNumVariableLocationOps() const
void replaceVariableLocationOp(Value *OldValue, Value *NewValue, bool AllowEmpty=false)
iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
DILocation * get() const
Get the underlying DILocation.
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 deleteBB(BasicBlock *DelBB)
Delete DelBB.
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
void applyUpdatesPermissive(ArrayRef< typename DomTreeT::UpdateType > Updates)
Submit updates to all available trees.
void applyUpdates(ArrayRef< typename DomTreeT::UpdateType > Updates)
Submit updates to all available trees.
bool hasDomTree() const
Returns true if it holds a DomTreeT.
bool isBBPendingDeletion(BasicBlockT *DelBB) const
Returns true if DelBB is awaiting deletion.
void recalculate(FuncT &F)
Notify DTU that the entry block was replaced.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
This instruction compares its operands according to the predicate given to the constructor.
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
iterator_range< simple_ilist< DbgRecord >::iterator > getDbgRecordRange() const
Return a range over the DbgRecords attached to this instruction.
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.
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.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
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.
void dropPoisonGeneratingFlags()
Drops flags that may cause this instruction to evaluate to poison despite having non-poison inputs.
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.
void dropDbgRecords()
Erase any DbgRecords attached to this instruction.
const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
A wrapper class for inspecting calls to intrinsic functions.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value * > Args, const Twine &NameStr, InsertPosition InsertBefore=nullptr)
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
Value * getPointerOperand()
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
MDNode * createRange(const APInt &Lo, const APInt &Hi)
Return metadata describing the range [Lo, Hi).
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDNode * getMergedProfMetadata(MDNode *A, MDNode *B, const Instruction *AInstr, const Instruction *BInstr)
Merge !prof metadata from two instructions.
static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
static MDNode * getMostGenericRange(MDNode *A, MDNode *B)
static MDNode * intersect(MDNode *A, MDNode *B)
LLVMContext & getContext() const
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.
T get() const
Returns the value of the specified pointer type.
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.
Vector takeVector()
Clear the SetVector and return the underlying vector.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
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.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
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.