91 #define DEBUG_TYPE "local" 93 STATISTIC(NumRemoved,
"Number of unreachable basic blocks removed");
113 if (
auto *BI = dyn_cast<BranchInst>(T)) {
114 if (BI->isUnconditional())
return false;
118 if (
auto *Cond = dyn_cast<ConstantInt>(BI->getCondition())) {
121 BasicBlock *Destination = Cond->getZExtValue() ? Dest1 : Dest2;
122 BasicBlock *OldDest = Cond->getZExtValue() ? Dest2 : Dest1;
136 if (Dest2 == Dest1) {
142 assert(BI->getParent() &&
"Terminator not inserted in block!");
147 Value *Cond = BI->getCondition();
148 BI->eraseFromParent();
149 if (DeleteDeadConditions)
156 if (
auto *
SI = dyn_cast<SwitchInst>(T)) {
164 if (isa<UnreachableInst>(DefaultDest->getFirstNonPHIOrDbg()) &&
165 SI->getNumCases() > 0) {
166 TheOnlyDest =
SI->case_begin()->getCaseSuccessor();
170 for (
auto i =
SI->case_begin(), e =
SI->case_end(); i != e;) {
172 if (i->getCaseValue() == CI) {
173 TheOnlyDest = i->getCaseSuccessor();
179 if (i->getCaseSuccessor() == DefaultDest) {
181 unsigned NCases =
SI->getNumCases();
189 auto *CI = mdconst::extract<ConstantInt>(MD->
getOperand(MD_i));
190 Weights.
push_back(CI->getValue().getZExtValue());
193 unsigned idx = i->getCaseIndex();
194 Weights[0] += Weights[idx+1];
200 createBranchWeights(Weights));
204 DefaultDest->removePredecessor(ParentBB);
205 i =
SI->removeCase(i);
215 if (i->getCaseSuccessor() != TheOnlyDest)
216 TheOnlyDest =
nullptr;
222 if (CI && !TheOnlyDest) {
225 TheOnlyDest =
SI->getDefaultDest();
234 std::vector <DominatorTree::UpdateType> Updates;
236 Updates.reserve(
SI->getNumSuccessors() - 1);
241 if (Succ == TheOnlyDest) {
242 TheOnlyDest =
nullptr;
251 Value *Cond =
SI->getCondition();
252 SI->eraseFromParent();
253 if (DeleteDeadConditions)
260 if (
SI->getNumCases() == 1) {
263 auto FirstCase = *
SI->case_begin();
265 FirstCase.getCaseValue(),
"cond");
269 FirstCase.getCaseSuccessor(),
270 SI->getDefaultDest());
274 mdconst::dyn_extract<ConstantInt>(MD->
getOperand(2));
276 mdconst::dyn_extract<ConstantInt>(MD->
getOperand(1));
282 SIDef->getValue().getZExtValue()));
291 SI->eraseFromParent();
297 if (
auto *IBI = dyn_cast<IndirectBrInst>(T)) {
300 dyn_cast<BlockAddress>(IBI->getAddress()->stripPointerCasts())) {
301 BasicBlock *TheOnlyDest = BA->getBasicBlock();
302 std::vector <DominatorTree::UpdateType> Updates;
304 Updates.reserve(IBI->getNumDestinations() - 1);
309 for (
unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
310 if (IBI->getDestination(i) == TheOnlyDest) {
311 TheOnlyDest =
nullptr;
321 IBI->eraseFromParent();
322 if (DeleteDeadConditions)
369 if (DDI->getAddress())
396 if (II->isLifetimeStartOrEnd())
397 return isa<UndefValue>(II->getArgOperand(1));
405 if (
ConstantInt *Cond = dyn_cast<ConstantInt>(II->getArgOperand(0)))
406 return !Cond->isZero();
416 if (
Constant *
C = dyn_cast<Constant>(CI->getArgOperand(0)))
417 return C->isNullValue() || isa<UndefValue>(
C);
447 while (!DeadInsts.
empty()) {
451 "Live instruction found in dead worklist!");
459 Value *OpV = OpU.get();
482 for (
auto *DII : DbgUsers) {
487 return !DbgUsers.empty();
501 for (++UI; UI != UE; ++UI) {
517 I = cast<Instruction>(*
I->user_begin())) {
523 if (!Visited.
insert(
I).second) {
568 WorkList.
insert(cast<Instruction>(U));
573 bool Changed =
false;
594 bool MadeChange =
false;
611 assert(!BI->isTerminator());
617 if (!WorkList.count(I))
621 while (!WorkList.empty()) {
646 if (!isa<PHINode>(BB->
begin()))
655 while (
PHINode *PN = dyn_cast<PHINode>(PhiIt)) {
657 Value *OldPhiIt = PhiIt;
665 if (PhiIt != OldPhiIt) PhiIt = &BB->
front();
679 while (
PHINode *PN = dyn_cast<PHINode>(DestBB->
begin())) {
680 Value *NewVal = PN->getIncomingValue(0);
684 PN->eraseFromParent();
688 assert(PredBB &&
"Block doesn't have a single predecessor!");
690 bool ReplaceEntryBB =
false;
692 ReplaceEntryBB =
true;
735 "The successor list of PredBB isn't empty before " 736 "applying corresponding DTU updates.");
758 return First == Second || isa<UndefValue>(First) || isa<UndefValue>(Second);
786 if (BBPN && BBPN->getParent() == BB) {
789 if (BBPreds.
count(IBB) &&
793 <<
"Can't fold, phi node " << PN->
getName() <<
" in " 794 << Succ->
getName() <<
" is conflicting with " 795 << BBPN->getName() <<
" with regard to common predecessor " 807 if (BBPreds.
count(IBB) &&
811 <<
" is conflicting with regard to common " 812 <<
"predecessor " << IBB->
getName() <<
"\n");
839 if (!isa<UndefValue>(OldVal)) {
841 IncomingValues.
find(BB)->second == OldVal) &&
842 "Expected OldVal to match incoming value from BB!");
844 IncomingValues.
insert(std::make_pair(BB, OldVal));
849 if (It != IncomingValues.
end())
return It->second;
868 if (!isa<UndefValue>(V))
869 IncomingValues.
insert(std::make_pair(BB, V));
883 if (!isa<UndefValue>(V))
continue;
887 if (It == IncomingValues.
end())
continue;
904 assert(OldVal &&
"No entry in PHI for Pred BB!");
921 if (isa<PHINode>(OldVal) && cast<PHINode>(OldVal)->
getParent() == BB) {
922 PHINode *OldValPN = cast<PHINode>(OldVal);
939 for (
unsigned i = 0, e = BBPreds.
size(); i != e; ++i) {
963 "TryToSimplifyUncondBranchFromEmptyBlock called on entry block!");
967 if (BB == Succ)
return false;
985 if (!Succ->getSinglePredecessor()) {
987 while (isa<PHINode>(*BBI)) {
988 for (
Use &U : BBI->uses()) {
989 if (
PHINode* PN = dyn_cast<PHINode>(U.getUser())) {
990 if (PN->getIncomingBlock(U) != BB)
1014 if (isa<PHINode>(Succ->begin())) {
1028 if (Succ->getSinglePredecessor()) {
1034 Succ->getInstList().
splice(Succ->getFirstNonPHI()->getIterator(),
1037 while (
PHINode *PN = dyn_cast<PHINode>(&BB->
front())) {
1039 assert(PN->use_empty() &&
"There shouldn't be any uses here!");
1040 PN->eraseFromParent();
1057 if (!Succ->hasName()) Succ->takeName(BB);
1064 "applying corresponding DTU updates.");
1084 struct PHIDenseMapInfo {
1085 static PHINode *getEmptyKey() {
1089 static PHINode *getTombstoneKey() {
1093 static unsigned getHashValue(
PHINode *PN) {
1103 if (LHS == getEmptyKey() || LHS == getTombstoneKey() ||
1104 RHS == getEmptyKey() || RHS == getTombstoneKey())
1114 bool Changed =
false;
1116 auto Inserted = PHISet.
insert(PN);
1117 if (!Inserted.second) {
1141 assert(PrefAlign > Align);
1145 if (
AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
1153 if (PrefAlign <= Align)
1160 AI->setAlignment(PrefAlign);
1164 if (
auto *GO = dyn_cast<GlobalObject>(V)) {
1167 if (PrefAlign <= Align)
1174 if (!GO->canIncreaseAlignment())
1177 GO->setAlignment(PrefAlign);
1190 "getOrEnforceKnownAlignment expects a pointer!");
1193 unsigned TrailZ = Known.countMinTrailingZeros();
1197 TrailZ = std::min(TrailZ,
unsigned(
sizeof(
unsigned) * CHAR_BIT - 1));
1199 unsigned Align = 1u << std::min(Known.getBitWidth() - 1, TrailZ);
1204 if (PrefAlign > Align)
1226 DVI->getVariable() == DIVar &&
1227 DVI->getExpression() == DIExpr)
1242 for (
auto *DVI : DbgValues) {
1243 assert(DVI->getValue() == APN);
1244 if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr))
1263 return ValueSize >= *FragmentSize;
1269 if (
auto FragmentSize = AI->getAllocationSizeInBits(DL))
1270 return ValueSize >= *FragmentSize;
1281 assert(DIVar &&
"Missing variable");
1288 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: " 1295 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, DII->
getDebugLoc(),
1301 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, DII->
getDebugLoc(),
1311 assert(DIVar &&
"Missing variable");
1320 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: " 1329 Instruction *DbgValue = Builder.insertDbgValueIntrinsic(
1340 assert(DIVar &&
"Missing variable");
1349 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: " 1360 if (InsertionPt != BB->
end())
1361 Builder.insertDbgValueIntrinsic(APN, DIVar, DIExpr, DII->
getDebugLoc(),
1378 if (
auto DDI = dyn_cast<DbgDeclareInst>(&BI))
1384 for (
auto &
I : Dbgs) {
1398 if (
LoadInst *LI = dyn_cast<LoadInst>(U))
1399 return LI->isVolatile();
1401 return SI->isVolatile();
1406 for (
auto &AIUse : AI->
uses()) {
1407 User *U = AIUse.getUser();
1409 if (AIUse.getOperandNo() == 1)
1411 }
else if (
LoadInst *LI = dyn_cast<LoadInst>(U)) {
1413 }
else if (
CallInst *CI = dyn_cast<CallInst>(U)) {
1419 DIB.insertDbgValueIntrinsic(AI, DDI->
getVariable(), DerefExpr,
1431 assert(BB &&
"No BasicBlock to clone dbg.value(s) from.");
1432 if (InsertedPHIs.
size() == 0)
1437 for (
auto &
I : *BB) {
1438 if (
auto DbgII = dyn_cast<DbgVariableIntrinsic>(&
I)) {
1439 if (
auto *Loc = dyn_cast_or_null<PHINode>(DbgII->getVariableLocation()))
1440 DbgValueMap.
insert({Loc, DbgII});
1443 if (DbgValueMap.
size() == 0)
1450 for (
auto PHI : InsertedPHIs) {
1456 for (
auto VI : PHI->operand_values()) {
1457 auto V = DbgValueMap.
find(
VI);
1458 if (V != DbgValueMap.
end()) {
1459 auto *DbgII = cast<DbgVariableIntrinsic>(V->second);
1463 assert(InsertionPt != Parent->
end() &&
"Ill-formed basic block");
1464 NewDbgII->insertBefore(&*InsertionPt);
1487 if (
auto *DII = dyn_cast<DbgVariableIntrinsic>(U))
1488 if (DII->isAddressOfVariable())
1522 bool DerefBefore,
int Offset,
bool DerefAfter) {
1526 auto *DIVar = DII->getVariable();
1527 auto *DIExpr = DII->getExpression();
1528 assert(DIVar &&
"Missing variable");
1532 Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, InsertBefore);
1533 if (DII == InsertBefore)
1537 return !DbgAddrs.empty();
1542 int Offset,
bool DerefAfter) {
1544 DerefBefore,
Offset, DerefAfter);
1552 assert(DIVar &&
"Missing variable");
1557 if (!DIExpr || DIExpr->getNumElements() < 1 ||
1558 DIExpr->getElement(0) != dwarf::DW_OP_deref)
1567 Ops.
append(DIExpr->elements_begin() + 1, DIExpr->elements_end());
1571 Builder.insertDbgValueIntrinsic(NewAddress, DIVar, DIExpr, Loc, DVI);
1579 for (
auto UI = MDV->use_begin(), UE = MDV->use_end(); UI != UE;) {
1581 if (
auto *DVI = dyn_cast<DbgValueInst>(U.
getUser()))
1594 if (DbgUsers.
empty())
1598 auto &DL = M.getDataLayout();
1608 bool WithStackValue = isa<DbgValueInst>(DII);
1619 doSalvage(DII, Ops);
1623 std::initializer_list<uint64_t> Opcodes) {
1625 doSalvage(DII, Ops);
1628 if (
auto *CI = dyn_cast<CastInst>(&I)) {
1629 if (!CI->isNoopCast(DL))
1634 for (
auto *DII : DbgUsers) {
1639 }
else if (
auto *
GEP = dyn_cast<GetElementPtrInst>(&I)) {
1641 M.getDataLayout().getIndexSizeInBits(
GEP->getPointerAddressSpace());
1646 if (
GEP->accumulateConstantOffset(M.getDataLayout(),
Offset))
1647 for (
auto *DII : DbgUsers)
1650 }
else if (
auto *BI = dyn_cast<BinaryOperator>(&I)) {
1653 if (!ConstInt || ConstInt->getBitWidth() > 64)
1657 for (
auto *DII : DbgUsers) {
1658 switch (BI->getOpcode()) {
1660 applyOffset(DII, Val);
1662 case Instruction::Sub:
1663 applyOffset(DII, -int64_t(Val));
1665 case Instruction::Mul:
1666 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_mul});
1668 case Instruction::SDiv:
1669 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_div});
1671 case Instruction::SRem:
1672 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_mod});
1674 case Instruction::Or:
1675 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_or});
1677 case Instruction::And:
1678 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_and});
1680 case Instruction::Xor:
1681 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_xor});
1683 case Instruction::Shl:
1684 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_shl});
1686 case Instruction::LShr:
1687 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_shr});
1689 case Instruction::AShr:
1690 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_shra});
1698 }
else if (isa<LoadInst>(&I)) {
1700 for (
auto *DII : DbgUsers) {
1729 bool Changed =
false;
1731 if (isa<Instruction>(&To)) {
1734 for (
auto *DII : Users) {
1744 }
else if (!DT.
dominates(&DomPoint, DII)) {
1745 DeleteOrSalvage.
insert(DII);
1751 for (
auto *DII : Users) {
1752 if (DeleteOrSalvage.
count(DII))
1766 if (!DeleteOrSalvage.
empty()) {
1771 for (
auto *DII : DeleteOrSalvage) {
1801 return SameSize && LosslessConversion;
1814 assert(&From != &To &&
"Can't replace something with itself");
1820 return DII.getExpression();
1834 assert(FromBits != ToBits &&
"Unexpected no-op conversion");
1838 if (FromBits < ToBits)
1856 return Identity(DII);
1862 (ToBits - 1), dwarf::DW_OP_shr,
1863 dwarf::DW_OP_lit0, dwarf::DW_OP_not,
1864 dwarf::DW_OP_mul, dwarf::DW_OP_or});
1876 unsigned NumDeadInst = 0;
1880 while (EndInst != &BB->
front()) {
1889 if (!isa<DbgInfoIntrinsic>(Inst))
1899 std::vector <DominatorTree::UpdateType> Updates;
1906 Successor->removePredecessor(BB, PreserveLCSSA);
1922 unsigned NumInstrsRemoved = 0;
1924 while (BBI != BBE) {
1925 if (!BBI->use_empty())
1932 return NumInstrsRemoved;
1959 DTU->deleteEdgeRelaxed(BB, UnwindDestBB);
1985 InvokeArgs, OpBundles, CI->
getName(), BB);
2006 bool Changed =
false;
2014 if (
auto *CI = dyn_cast<CallInst>(&
I)) {
2017 if (
Function *F = dyn_cast<Function>(Callee)) {
2041 if (!isa<UnreachableInst>(CI->getNextNode())) {
2048 }
else if ((isa<ConstantPointerNull>(Callee) &&
2050 isa<UndefValue>(Callee)) {
2055 if (CI->doesNotReturn()) {
2059 if (!isa<UnreachableInst>(CI->getNextNode())) {
2066 }
else if (
auto *
SI = dyn_cast<StoreInst>(&
I)) {
2072 if (
SI->isVolatile())
continue;
2074 Value *Ptr =
SI->getOperand(1);
2076 if (isa<UndefValue>(Ptr) ||
2077 (isa<ConstantPointerNull>(Ptr) &&
2079 SI->getPointerAddressSpace()))) {
2088 if (
auto *II = dyn_cast<InvokeInst>(Terminator)) {
2091 if ((isa<ConstantPointerNull>(Callee) &&
2093 isa<UndefValue>(Callee)) {
2097 if (II->use_empty() && II->onlyReadsMemory()) {
2099 BasicBlock *NormalDestBB = II->getNormalDest();
2100 BasicBlock *UnwindDestBB = II->getUnwindDest();
2103 II->eraseFromParent();
2105 DTU->deleteEdgeRelaxed(BB, UnwindDestBB);
2110 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) {
2112 struct CatchPadDenseMapInfo {
2127 if (LHS == getEmptyKey() || LHS == getTombstoneKey() ||
2128 RHS == getEmptyKey() || RHS == getTombstoneKey())
2138 detail::DenseSetEmpty Empty;
2140 E = CatchSwitch->handler_end();
2143 auto *CatchPad = cast<CatchPadInst>(HandlerBB->
getFirstNonPHI());
2144 if (!HandlerSet.insert({CatchPad, Empty}).second) {
2145 CatchSwitch->removeHandler(
I);
2157 }
while (!Worklist.
empty());
2164 if (
auto *II = dyn_cast<InvokeInst>(TI)) {
2172 if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
2174 UnwindDest = CRI->getUnwindDest();
2175 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(TI)) {
2177 CatchSwitch->getParentPad(),
nullptr, CatchSwitch->getNumHandlers(),
2178 CatchSwitch->getName(), CatchSwitch);
2179 for (
BasicBlock *PadBB : CatchSwitch->handlers())
2182 NewTI = NewCatchSwitch;
2183 UnwindDest = CatchSwitch->getUnwindDest();
2212 NumRemoved += F.
size()-Reachable.
size();
2217 if (Reachable.
count(BB))
2227 std::vector<DominatorTree::UpdateType> Updates;
2228 for (
auto *BB : DeadBlockSet) {
2237 BB->dropAllReferences();
2241 if (Reachable.
count(BB)) {
2247 if (BB->getTerminator())
2248 BB->getInstList().pop_back();
2251 "applying corresponding DTU updates.");
2261 for (
auto *BB : DeadBlockSet) {
2279 for (
const auto &MD : Metadata) {
2280 unsigned Kind = MD.first;
2348 if (isa<LoadInst>(K) || isa<StoreInst>(K))
2354 unsigned KnownIDs[] = {
2376 if (!isa<LoadInst>(I))
2388 static const unsigned KnownIDs[] = {
2397 template <
typename RootType,
typename DominatesFn>
2399 const RootType &Root,
2400 const DominatesFn &Dominates) {
2407 if (!Dominates(Root, U))
2411 <<
"' as " << *To <<
" in " << *U <<
"\n");
2425 auto *
I = cast<Instruction>(U.
getUser());
2426 if (
I->getParent() == BB)
2446 auto ProperlyDominates = [&DT](
const BasicBlock *BB,
const Use &U) {
2447 auto *
I = cast<Instruction>(U.getUser())->
getParent();
2459 if (
F->hasFnAttribute(
"gc-leaf-function"))
2462 if (
auto IID =
F->getIntrinsicID())
2481 auto *NewTy = NewLI.
getType();
2484 if (NewTy->isPointerTy()) {
2491 if (!NewTy->isIntegerTy())
2496 auto *ITy = cast<IntegerType>(NewTy);
2501 MDB.createRange(NonNullInt, NullInt));
2506 auto *NewTy = NewLI.
getType();
2512 if (!NewTy->isPointerTy())
2525 for (
auto *DII : DbgUsers)
2526 DII->eraseFromParent();
2557 if (isa<DbgVariableIntrinsic>(I)) {
2575 BitPart(
Value *
P,
unsigned BW) : Provider(P) {
2576 Provenance.resize(BW);
2586 enum { Unset = -1 };
2617 auto I = BPS.find(V);
2621 auto &Result = BPS[V] =
None;
2626 if (
I->getOpcode() == Instruction::Or) {
2628 MatchBitReversals, BPS);
2630 MatchBitReversals, BPS);
2635 if (!A->Provider || A->Provider != B->Provider)
2638 Result = BitPart(A->Provider, BitWidth);
2639 for (
unsigned i = 0; i < A->Provenance.size(); ++i) {
2640 if (A->Provenance[i] != BitPart::Unset &&
2641 B->Provenance[i] != BitPart::Unset &&
2642 A->Provenance[i] != B->Provenance[i])
2643 return Result =
None;
2645 if (A->Provenance[i] == BitPart::Unset)
2646 Result->Provenance[i] = B->Provenance[i];
2648 Result->Provenance[i] = A->Provenance[i];
2655 if (
I->isLogicalShift() && isa<ConstantInt>(
I->getOperand(1))) {
2657 cast<ConstantInt>(
I->getOperand(1))->getLimitedValue(~0U);
2659 if (BitShift > BitWidth)
2663 MatchBitReversals, BPS);
2669 auto &
P = Result->Provenance;
2670 if (
I->getOpcode() == Instruction::Shl) {
2671 P.erase(std::prev(
P.end(), BitShift),
P.end());
2672 P.insert(
P.begin(), BitShift, BitPart::Unset);
2674 P.erase(
P.begin(), std::next(
P.begin(), BitShift));
2675 P.insert(
P.end(), BitShift, BitPart::Unset);
2683 if (
I->getOpcode() == Instruction::And &&
2684 isa<ConstantInt>(
I->getOperand(1))) {
2685 APInt Bit(
I->getType()->getPrimitiveSizeInBits(), 1);
2686 const APInt &AndMask = cast<ConstantInt>(
I->getOperand(1))->getValue();
2690 unsigned NumMaskedBits = AndMask.countPopulation();
2691 if (!MatchBitReversals && NumMaskedBits % 8 != 0)
2695 MatchBitReversals, BPS);
2700 for (
unsigned i = 0; i < BitWidth; ++i,
Bit <<= 1)
2702 if ((AndMask & Bit) == 0)
2703 Result->Provenance[i] = BitPart::Unset;
2708 if (
I->getOpcode() == Instruction::ZExt) {
2710 MatchBitReversals, BPS);
2714 Result = BitPart(Res->Provider, BitWidth);
2715 auto NarrowBitWidth =
2716 cast<IntegerType>(cast<ZExtInst>(
I)->getSrcTy())->
getBitWidth();
2717 for (
unsigned i = 0; i < NarrowBitWidth; ++i)
2718 Result->Provenance[i] = Res->Provenance[i];
2719 for (
unsigned i = NarrowBitWidth; i < BitWidth; ++i)
2720 Result->Provenance[i] = BitPart::Unset;
2727 Result = BitPart(V, BitWidth);
2728 for (
unsigned i = 0; i < BitWidth; ++i)
2729 Result->Provenance[i] = i;
2734 unsigned BitWidth) {
2735 if (From % 8 != To % 8)
2741 return From == BitWidth - To - 1;
2745 unsigned BitWidth) {
2746 return From == BitWidth - To - 1;
2750 Instruction *
I,
bool MatchBSwaps,
bool MatchBitReversals,
2754 if (!MatchBSwaps && !MatchBitReversals)
2761 unsigned DemandedBW = BW;
2765 DemandedTy = cast<IntegerType>(Trunc->getType());
2771 std::map<Value *, Optional<BitPart>> BPS;
2775 auto &BitProvenance = Res->Provenance;
2779 bool OKForBSwap = DemandedBW % 16 == 0, OKForBitReverse =
true;
2780 for (
unsigned i = 0; i < DemandedBW; ++i) {
2788 if (OKForBSwap && MatchBSwaps)
2790 else if (OKForBitReverse && MatchBitReversals)
2795 if (ITy != DemandedTy) {
2797 Value *Provider = Res->Provider;
2798 IntegerType *ProviderTy = cast<IntegerType>(Provider->getType());
2800 if (DemandedTy != ProviderTy) {
2846 case Instruction::Invoke:
2853 if (isa<IntrinsicInst>(I))
2861 case Instruction::ShuffleVector:
2864 case Instruction::Switch:
2865 case Instruction::ExtractValue:
2868 case Instruction::InsertValue:
2871 case Instruction::Alloca:
2875 return !cast<AllocaInst>(
I)->isStaticAlloca();
2876 case Instruction::GetElementPtr:
2880 for (
auto E = std::next(It, OpIdx); It !=
E; ++It)
static unsigned getBitWidth(Type *Ty, const DataLayout &DL)
Returns the bitwidth of the given scalar or pointer type.
static void appendOffset(SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
Append Ops with operations to apply the Offset.
void getAllMetadataOtherThanDebugLoc(SmallVectorImpl< std::pair< unsigned, MDNode *>> &MDs) const
This does the same thing as getAllMetadata, except that it filters out the debug location.
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...
Value * getValueOperand()
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred, DomTreeUpdater *DTU=nullptr)
Like BasicBlock::removePredecessor, this method is called when we're about to delete Pred as a predec...
class_match< UndefValue > m_Undef()
Match an arbitrary undef constant.
iterator_range< use_iterator > uses()
void removePredecessor(BasicBlock *Pred, bool DontDeleteUselessPHIs=false)
Notify the BasicBlock that the predecessor Pred is no longer able to reach it.
bool hasLocalLinkage() const
static unsigned enforceKnownAlignment(Value *V, unsigned Align, unsigned PrefAlign, const DataLayout &DL)
enforceKnownAlignment - If the specified pointer points to an object that we control, modify the object's alignment to PrefAlign.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
uint64_t getZExtValue() const
Get zero extended value.
unsigned getOrEnforceKnownAlignment(Value *V, unsigned 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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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...
bool replaceDbgDeclareForAlloca(AllocaInst *AI, Value *NewAllocaAddress, DIBuilder &Builder, bool DerefBefore, int Offset, bool DerefAfter)
Replaces llvm.dbg.declare instruction when the alloca it describes is replaced with a new value...
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
This represents the llvm.dbg.label instruction.
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
bool isMetadataTy() const
Return true if this is 'metadata'.
iterator erase(iterator where)
This class represents lattice values for constants.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
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...
A Module instance is used to store all the information related to an LLVM module. ...
void dropUnknownNonDebugMetadata(ArrayRef< unsigned > KnownIDs)
Drop all unknown metadata except for debug locations.
bool isBundleOperand(Value::const_user_iterator UI) const
Determine whether the passed iterator points to a bundle operand.
static bool CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ)
CanPropagatePredecessorsForPHIs - Return true if we can fold BB, an almost-empty BB ending in an unco...
bool exceedsNaturalStackAlignment(unsigned Align) const
Returns true if the given alignment exceeds the natural stack alignment.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static MetadataAsValue * wrapValueInMetadata(LLVMContext &C, Value *V)
Wrap V in a ValueAsMetadata instance.
Implements a dense probed hash-table based set.
void push_back(const T &Elt)
value_op_iterator value_op_begin()
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Remove all blocks that can not be reached from the function's entry.
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
void removeBlocks(const SmallPtrSetImpl< BasicBlock *> &DeadBlocks)
Remove all MemoryAcceses in a set of BasicBlocks about to be deleted.
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
This class represents a function call, abstracting a target machine's calling convention.
An efficient, type-erasing, non-owning reference to a callable.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
A cache of @llvm.assume calls within a function.
bool salvageDebugInfo(Instruction &I)
Assuming the instruction I is going to be deleted, attempt to salvage debug users of I by writing the...
LLVMContext & getContext() const
All values hold a context through their type.
bool isTerminator() const
bool replaceDbgUsesWithUndef(Instruction *I)
Replace all the uses of an SSA value in .dbg intrinsics with undef.
value_op_iterator value_op_end()
bool properlyDominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
properlyDominates - Returns true iff A dominates B and A != B.
STATISTIC(NumFunctions, "Total number of functions")
static void replaceUndefValuesInPhi(PHINode *PN, const IncomingValueMap &IncomingValues)
Replace the incoming undef values to a phi with the values from a block-to-value map.
bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
Optional< DIBasicType::Signedness > getSignedness() const
Return the signedness of this variable's type, or None if this type is neither signed nor unsigned...
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
const MDOperand & getOperand(unsigned I) const
Optional< DIExpression * > DbgValReplacement
A replacement for a dbg.value expression.
An instruction for reading from memory.
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...
iv Induction Variable Users
static Value * selectIncomingValueForBlock(Value *OldVal, BasicBlock *BB, IncomingValueMap &IncomingValues)
Determines the value to use as the phi node input for a block.
This defines the Use class.
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
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.
LLVMContext & getContext() const
Get the context in which this basic block lives.
Optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
static DIExpression * prepend(const DIExpression *Expr, bool DerefBefore, int64_t Offset=0, bool DerefAfter=false, bool StackValue=false)
Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value...
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
block_iterator block_end()
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
bool isIdenticalTo(const Instruction *I) const
Return true if the specified instruction is exactly identical to the current one. ...
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
The address of a basic block.
bool match(Val *V, const Pattern &P)
static DIExpression * prependOpcodes(const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false)
Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
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...
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
void patchReplacementInstruction(Instruction *I, Value *Repl)
Patch the replacement so that it is not more restrictive than the value being replaced.
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!)...
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
static constexpr UpdateKind Delete
PointerType * getType() const
Overload to return most specific pointer type.
A Use represents the edge between a Value definition and its users.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
static const Optional< BitPart > & collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals, std::map< Value *, Optional< BitPart >> &BPS)
Analyze the specified subexpression and see if it is capable of providing pieces of a bswap or bitrev...
bool isIntegerTy() const
True if this is an instance of IntegerType.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
This file contains the simple types necessary to represent the attributes associated with functions a...
bool canSimplifyInvokeNoUnwind(const Function *F)
static const unsigned MaximumAlignment
block_iterator block_begin()
bool contains(const APInt &Val) const
Return true if the specified value is in the set.
This file implements a class to represent arbitrary precision integral constant values and operations...
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...
static void replaceOneDbgValueForAlloca(DbgValueInst *DVI, Value *NewAddress, DIBuilder &Builder, int Offset)
void insertDebugValuesForPHIs(BasicBlock *BB, SmallVectorImpl< PHINode *> &InsertedPHIs)
Propagate dbg.value intrinsics through the newly inserted PHIs.
void addHandler(BasicBlock *Dest)
Add an entry to the switch instruction...
Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following: ...
void removeMemoryAccess(MemoryAccess *)
Remove a MemoryAccess from MemorySSA, including updating all definitions and uses.
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
void findDbgValues(SmallVectorImpl< DbgValueInst *> &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
int64_t getSExtValue() const
Get sign extended value.
Type * getType() const
All values are typed, get the type of this value.
Value handle that is nullable, but tries to track the Value.
bool insert(const value_type &X)
Insert a new element into the SetVector.
void copyNonnullMetadata(const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a nonnull metadata node to a new load instruction.
static bool isEqual(const Function &Caller, const Function &Callee)
match_combine_or< LTy, RTy > m_CombineOr(const LTy &L, const RTy &R)
Combine two pattern matchers matching L || R.
static DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes...
This is the common base class for debug info intrinsics for variables.
void andIRFlags(const Value *V)
Logical 'and' of any supported wrapping, exact, and fast-math flags of V and this instruction...
bool has(LibFunc F) const
Tests whether a library function is available.
iterator find(const KeyT &Val)
bool isMathLibCallNoop(CallSite CS, const TargetLibraryInfo *TLI)
Check whether the given call has no side-effects.
bool isIntOrPtrTy() const
Return true if this is an integer type or a pointer type.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
static bool areAllUsesEqual(Instruction *I)
areAllUsesEqual - Check whether the uses of a value are all the same.
const APInt & getValue() const
Return the constant as an APInt value reference.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
static MDNode * intersect(MDNode *A, MDNode *B)
void dropDebugUsers(Instruction &I)
Remove the debug intrinsic instructions for the given instruction.
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool replaceAllDbgUsesWith(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT)
Point debug users of From to To or salvage them.
bool EliminateDuplicatePHINodes(BasicBlock *BB)
Check for and eliminate duplicate PHI nodes in this block.
static void gatherIncomingValuesToPhi(PHINode *PN, IncomingValueMap &IncomingValues)
Create a map from block to value for the operands of a given phi.
static bool markAliveBlocks(Function &F, SmallPtrSetImpl< BasicBlock *> &Reachable, DomTreeUpdater *DTU=nullptr)
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
void takeName(Value *V)
Transfer the name from V to this value.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
amdgpu Simplify well known AMD library false Value * Callee
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
This class represents a truncation of integer types.
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
Value * getOperand(unsigned i) const
MDNode * intersectAccessGroups(const Instruction *Inst1, const Instruction *Inst2)
Compute the access-group list of access groups that Inst1 and Inst2 are both in.
Interval::succ_iterator succ_end(Interval *I)
use_iterator_impl< Use > use_iterator
iterator find(const_arg_type_t< KeyT > Val)
bool doesNotAccessMemory() const
Determine if the function does not access memory.
const BasicBlock & getEntryBlock() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
static bool valueCoversEntireFragment(Type *ValTy, DbgVariableIntrinsic *DII)
Check if the alloc size of ValTy is large enough to cover the variable (or fragment of the variable) ...
static MDNode * getMostGenericRange(MDNode *A, MDNode *B)
static bool isBitCastSemanticsPreserving(const DataLayout &DL, Type *FromTy, Type *ToTy)
Check if a bitcast between a value of type FromTy to type ToTy would losslessly preserve the bits and...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
const BasicBlock * getSinglePredecessor() const
Return the predecessor of this block if it has a single predecessor block.
static constexpr UpdateKind Insert
ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)
Parse out a conservative ConstantRange from !range metadata.
Value * getCalledValue() const
LLVM Basic Block Representation.
void push_back(EltTy NewVal)
The instances of the Type class are immutable: once they are created, they are never changed...
static bool LdStHasDebugValue(DILocalVariable *DIVar, DIExpression *DIExpr, Instruction *I)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
void deleteBB(BasicBlock *DelBB)
Delete DelBB.
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
static MDNode * getMostGenericAlignmentOrDereferenceable(MDNode *A, MDNode *B)
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
Value * getAddress() const
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
LLVM_NODISCARD bool empty() const
bool canReplaceOperandWithVariable(const Instruction *I, unsigned OpIdx)
Given an instruction, is it legal to set operand OpIdx to a non-constant value?
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if this function has the given attribute.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
const Instruction & front() const
std::pair< iterator, bool > insert(const ValueT &V)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool mayHaveSideEffects() const
Return true if the instruction may have side effects.
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...
DIExpression * getExpression() const
static bool CanMergeValues(Value *First, Value *Second)
CanMergeValues - Return true if we can choose one of these values to use in place of the other...
const Instruction * getNextNonDebugInstruction() const
Return a pointer to the next non-debug instruction in the same basic block as 'this', or nullptr if no such instruction exists.
void splice(iterator where, iplist_impl &L2)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
const Instruction & back() const
static DIExpression * appendToStack(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Convert DIExpr into a stack value if it isn't one already by appending DW_OP_deref if needed...
void setCallingConv(CallingConv::ID CC)
void copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a range metadata node to a new load instruction.
static void changeToCall(InvokeInst *II, DomTreeUpdater *DTU=nullptr)
changeToCall - Convert the specified invoke into a normal call.
Interval::pred_iterator pred_end(Interval *I)
Value * getPointerOperand()
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
bool callsGCLeafFunction(ImmutableCallSite CS, const TargetLibraryInfo &TLI)
Return true if the CallSite CS calls a gc leaf function.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
self_iterator getIterator()
Class to represent integer types.
static bool rewriteDebugUsers(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT, function_ref< DbgValReplacement(DbgVariableIntrinsic &DII)> RewriteExpr)
Point debug users of From to To using exprs given by RewriteExpr, possibly moving/deleting users to p...
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
bool succ_empty(const Instruction *I)
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr)
If the specified value is a trivially dead instruction, delete it.
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
static bool bitTransformIsCorrectForBitReverse(unsigned From, unsigned To, unsigned BitWidth)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
auto find(R &&Range, const T &Val) -> decltype(adl_begin(Range))
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly...
bool LowerDbgDeclare(Function &F)
Lowers llvm.dbg.declare intrinsics into appropriate set of llvm.dbg.value intrinsics.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
static void redirectValuesFromPredecessorsToPhi(BasicBlock *BB, const PredBlockVector &BBPreds, PHINode *PN)
Replace a value flowing from a block to a phi with potentially multiple instances of that value flowi...
bool recursivelySimplifyInstruction(Instruction *I, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr)
Recursively attempt to simplify an instruction.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
BasicBlock * getNormalDest() const
const InstListType & getInstList() const
Return the underlying instruction list container.
A SetVector that performs no allocations if smaller than a certain size.
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
base_list_type::iterator iterator
void moveAfter(BasicBlock *MovePos)
Unlink this basic block from its current function and insert it right after MovePos in the function M...
This is the shared class of boolean and integer constants.
TinyPtrVector< DbgVariableIntrinsic * > FindDbgAddrUses(Value *V)
Finds all intrinsics declaring local variables as living in the memory that 'V' points to...
BlockVerifier::State From
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
static unsigned replaceDominatedUsesWith(Value *From, Value *To, const RootType &Root, const DominatesFn &Dominates)
static bool bitTransformIsCorrectForBSwap(unsigned From, unsigned To, unsigned BitWidth)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
Module.h This file contains the declarations for the Module class.
Instruction * user_back()
Specialize the methods defined in Value, as we know that an instruction can only be used by other ins...
Provides information about what library functions are available for the current target.
bool RecursivelyDeleteDeadPHINode(PHINode *PN, const TargetLibraryInfo *TLI=nullptr)
If the specified value is an effectively dead PHI node, due to being a def-use chain of single-use no...
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates, bool ForceRemoveDuplicates=false)
Apply updates on all available trees.
LLVM_NODISCARD T pop_back_val()
DIExpression * createExpression(ArrayRef< uint64_t > Addr=None)
Create a new descriptor for the specified variable which has a complex address expression for its add...
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
bool hasOptimizedCodeGen(LibFunc F) const
Tests if the function is both available and a candidate for optimized code generation.
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 BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
unsigned removeAllNonTerminatorAndEHPadInstructions(BasicBlock *BB)
Remove all instructions from a basic block other than it's terminator and any present EH pad instruct...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
AttributeList getAttributes() const
Return the parameter attributes for this call.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
Value handle that asserts if the Value is deleted.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
void setOperand(unsigned i, Value *Val)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This file contains constants used for implementing Dwarf debug support.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
Class for arbitrary precision integers.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
void removeUnwindEdge(BasicBlock *BB, DomTreeUpdater *DTU=nullptr)
Replace 'BB's terminator with one that does not have an unwind successor block.
iterator_range< user_iterator > users()
InstListType::iterator iterator
Instruction iterators...
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
bool replaceDbgDeclare(Value *Address, Value *NewAddress, Instruction *InsertBefore, DIBuilder &Builder, bool DerefBefore, int Offset, bool DerefAfter)
Replaces llvm.dbg.declare instruction when the address it describes is replaced with a new value...
void deleteEdgeRelaxed(BasicBlock *From, BasicBlock *To)
Notify all available trees on an edge deletion.
bool isNonIntegralPointerType(PointerType *PT) const
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
Value * getVariableLocation(bool AllowNullOp=true) const
Get the location corresponding to the variable referenced by the debug info intrinsic.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
void recalculate(Function &F)
Recalculate all available trees and flush all BasicBlocks awaiting deletion immediately.
static bool simplifyAndDCEInstruction(Instruction *I, SmallSetVector< Instruction *, 16 > &WorkList, const DataLayout &DL, const TargetLibraryInfo *TLI)
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
static IntegerType * getInt32Ty(LLVMContext &C)
LLVM_NODISCARD bool empty() const
This represents the llvm.dbg.value instruction.
static InvokeInst * Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
bool isAddressOfVariable() const
Does this describe the address of a local variable.
bool isTokenTy() const
Return true if this is 'token'.
CallingConv::ID getCallingConv() const
StringRef getName() const
Return a constant reference to the value's name.
Establish a view to a call site for examination.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
const Function * getParent() const
Return the enclosing method, or null if none.
void insertAfter(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately after the specified instruction...
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
user_iterator_impl< User > user_iterator
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc...
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
void destroyConstant()
Called if some element of this constant is no longer valid.
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...
bool isBBPendingDeletion(BasicBlock *DelBB) const
Returns true if DelBB is awaiting deletion.
DILocalVariable * getVariable() const
static bool PhiHasDebugValue(DILocalVariable *DIVar, DIExpression *DIExpr, PHINode *APN)
See if there is a dbg.value intrinsic for DIVar for the PHI node.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
This pass computes, caches, and vends lazy value constraint information.
static bool isArray(AllocaInst *AI)
Determine whether this alloca is either a VLA or an array.
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void moveAfter(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
user_iterator user_begin()
const BasicBlock & front() const
BasicBlock * getUnwindDest() const
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Module * getParent()
Get the module that this global value is contained inside of...
bool isInstructionTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction is not used, and the instruction has no side ef...
LLVM Value Representation.
succ_range successors(Instruction *I)
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
void copyMetadata(const Instruction &SrcInst, ArrayRef< unsigned > WL=ArrayRef< unsigned >())
Copy metadata from SrcInst to this instruction.
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
static const Function * getParent(const Value *V)
void ConvertDebugDeclareToDebugValue(DbgVariableIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
bool wouldInstructionBeTriviallyDead(Instruction *I, const TargetLibraryInfo *TLI=nullptr)
Return true if the result produced by the instruction would have no side effects if it was not used...
void combineMetadataForCSE(Instruction *K, const Instruction *J, bool DoesKMove)
Combine the metadata of two instructions so that K can replace J.
uint64_t getTypeAllocSizeInBits(Type *Ty) const
Returns the offset in bits between successive objects of the specified type, including alignment padd...
bool isEHPad() const
Return true if the instruction is a variety of EH-block.
bool hasOneUse() const
Return true if there is exactly one user of this value.
bool hasDomTree() const
Returns true if it holds a DominatorTree.
bool recognizeBSwapOrBitReverseIdiom(Instruction *I, bool MatchBSwaps, bool MatchBitReversals, SmallVectorImpl< Instruction *> &InsertedInsts)
Try to match a bswap or bitreverse idiom.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
void setIncomingValue(unsigned i, Value *V)
static void Split(std::vector< std::string > &V, StringRef S)
Splits a string of comma separated items in to a vector of strings.
unsigned getNumOperands() const
Return number of MDNode operands.
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
static MDNode * getMostGenericFPMath(MDNode *A, MDNode *B)
This represents the llvm.dbg.declare instruction.
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
std::vector< uint32_t > Metadata
PAL metadata represented as a vector.
bool isArrayTy() const
True if this is an instance of ArrayType.
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
gep_type_iterator gep_type_begin(const User *GEP)