88 #define DEBUG_TYPE "local" 90 STATISTIC(NumRemoved,
"Number of unreachable basic blocks removed");
110 if (
auto *BI = dyn_cast<BranchInst>(T)) {
111 if (BI->isUnconditional())
return false;
115 if (
auto *Cond = dyn_cast<ConstantInt>(BI->getCondition())) {
118 BasicBlock *Destination = Cond->getZExtValue() ? Dest1 : Dest2;
119 BasicBlock *OldDest = Cond->getZExtValue() ? Dest2 : Dest1;
133 if (Dest2 == Dest1) {
139 assert(BI->getParent() &&
"Terminator not inserted in block!");
144 Value *Cond = BI->getCondition();
145 BI->eraseFromParent();
146 if (DeleteDeadConditions)
153 if (
auto *
SI = dyn_cast<SwitchInst>(T)) {
161 if (isa<UnreachableInst>(DefaultDest->getFirstNonPHIOrDbg()) &&
162 SI->getNumCases() > 0) {
163 TheOnlyDest =
SI->case_begin()->getCaseSuccessor();
167 for (
auto i =
SI->case_begin(), e =
SI->case_end(); i != e;) {
169 if (i->getCaseValue() == CI) {
170 TheOnlyDest = i->getCaseSuccessor();
176 if (i->getCaseSuccessor() == DefaultDest) {
178 unsigned NCases =
SI->getNumCases();
186 auto *CI = mdconst::extract<ConstantInt>(MD->
getOperand(MD_i));
187 Weights.
push_back(CI->getValue().getZExtValue());
190 unsigned idx = i->getCaseIndex();
191 Weights[0] += Weights[idx+1];
197 createBranchWeights(Weights));
201 DefaultDest->removePredecessor(ParentBB);
202 i =
SI->removeCase(i);
212 if (i->getCaseSuccessor() != TheOnlyDest)
213 TheOnlyDest =
nullptr;
219 if (CI && !TheOnlyDest) {
222 TheOnlyDest =
SI->getDefaultDest();
231 std::vector <DominatorTree::UpdateType> Updates;
233 Updates.reserve(
SI->getNumSuccessors() - 1);
238 if (Succ == TheOnlyDest) {
239 TheOnlyDest =
nullptr;
248 Value *Cond =
SI->getCondition();
249 SI->eraseFromParent();
250 if (DeleteDeadConditions)
257 if (
SI->getNumCases() == 1) {
260 auto FirstCase = *
SI->case_begin();
262 FirstCase.getCaseValue(),
"cond");
266 FirstCase.getCaseSuccessor(),
267 SI->getDefaultDest());
271 mdconst::dyn_extract<ConstantInt>(MD->
getOperand(2));
273 mdconst::dyn_extract<ConstantInt>(MD->
getOperand(1));
279 SIDef->getValue().getZExtValue()));
288 SI->eraseFromParent();
294 if (
auto *IBI = dyn_cast<IndirectBrInst>(T)) {
297 dyn_cast<BlockAddress>(IBI->getAddress()->stripPointerCasts())) {
298 BasicBlock *TheOnlyDest = BA->getBasicBlock();
299 std::vector <DominatorTree::UpdateType> Updates;
301 Updates.reserve(IBI->getNumDestinations() - 1);
306 for (
unsigned i = 0, e = IBI->getNumDestinations(); i != e; ++i) {
307 if (IBI->getDestination(i) == TheOnlyDest) {
308 TheOnlyDest =
nullptr;
318 IBI->eraseFromParent();
319 if (DeleteDeadConditions)
355 if (isa<TerminatorInst>(I))
366 if (DDI->getAddress())
388 if (II->getIntrinsicID() == Intrinsic::stacksave ||
389 II->getIntrinsicID() == Intrinsic::launder_invariant_group)
393 if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
394 II->getIntrinsicID() == Intrinsic::lifetime_end)
395 return isa<UndefValue>(II->getArgOperand(1));
401 if (II->getIntrinsicID() == Intrinsic::assume ||
402 II->getIntrinsicID() == Intrinsic::experimental_guard) {
403 if (
ConstantInt *Cond = dyn_cast<ConstantInt>(II->getArgOperand(0)))
404 return !Cond->isZero();
414 if (
Constant *
C = dyn_cast<Constant>(CI->getArgOperand(0)))
415 return C->isNullValue() || isa<UndefValue>(
C);
445 while (!DeadInsts.
empty()) {
449 "Live instruction found in dead worklist!");
457 Value *OpV = OpU.get();
486 for (++UI; UI != UE; ++UI) {
502 I = cast<Instruction>(*
I->user_begin())) {
508 if (!Visited.
insert(
I).second) {
553 WorkList.
insert(cast<Instruction>(U));
558 bool Changed =
false;
579 bool MadeChange =
false;
596 assert(!BI->isTerminator());
602 if (!WorkList.count(I))
606 while (!WorkList.empty()) {
631 if (!isa<PHINode>(BB->
begin()))
640 while (
PHINode *PN = dyn_cast<PHINode>(PhiIt)) {
642 Value *OldPhiIt = PhiIt;
650 if (PhiIt != OldPhiIt) PhiIt = &BB->
front();
662 assert(!(DT && DDT) &&
"Cannot call with both DT and DDT.");
665 while (
PHINode *PN = dyn_cast<PHINode>(DestBB->
begin())) {
666 Value *NewVal = PN->getIncomingValue(0);
670 PN->eraseFromParent();
674 assert(PredBB &&
"Block doesn't have a single predecessor!");
676 bool ReplaceEntryBB =
false;
678 ReplaceEntryBB =
true;
682 std::vector <DominatorTree::UpdateType> Updates;
683 if (DDT && !ReplaceEntryBB) {
684 Updates.reserve(1 + (2 *
pred_size(PredBB)));
721 BasicBlock *PredBBIDom = DTN->getIDom()->getBlock();
745 return First == Second || isa<UndefValue>(First) || isa<UndefValue>(Second);
773 if (BBPN && BBPN->getParent() == BB) {
776 if (BBPreds.
count(IBB) &&
780 <<
"Can't fold, phi node " << PN->
getName() <<
" in " 781 << Succ->
getName() <<
" is conflicting with " 782 << BBPN->getName() <<
" with regard to common predecessor " 794 if (BBPreds.
count(IBB) &&
798 <<
" is conflicting with regard to common " 799 <<
"predecessor " << IBB->
getName() <<
"\n");
826 if (!isa<UndefValue>(OldVal)) {
828 IncomingValues.
find(BB)->second == OldVal) &&
829 "Expected OldVal to match incoming value from BB!");
831 IncomingValues.
insert(std::make_pair(BB, OldVal));
836 if (It != IncomingValues.
end())
return It->second;
855 if (!isa<UndefValue>(V))
856 IncomingValues.
insert(std::make_pair(BB, V));
870 if (!isa<UndefValue>(V))
continue;
874 if (It == IncomingValues.
end())
continue;
891 assert(OldVal &&
"No entry in PHI for Pred BB!");
908 if (isa<PHINode>(OldVal) && cast<PHINode>(OldVal)->
getParent() == BB) {
909 PHINode *OldValPN = cast<PHINode>(OldVal);
926 for (
unsigned i = 0, e = BBPreds.
size(); i != e; ++i) {
950 "TryToSimplifyUncondBranchFromEmptyBlock called on entry block!");
954 if (BB == Succ)
return false;
972 if (!Succ->getSinglePredecessor()) {
974 while (isa<PHINode>(*BBI)) {
975 for (
Use &U : BBI->uses()) {
976 if (
PHINode* PN = dyn_cast<PHINode>(U.getUser())) {
977 if (PN->getIncomingBlock(U) != BB)
989 std::vector<DominatorTree::UpdateType> Updates;
991 Updates.reserve(1 + (2 *
pred_size(BB)));
1002 if (isa<PHINode>(Succ->begin())) {
1016 if (Succ->getSinglePredecessor()) {
1022 Succ->getInstList().
splice(Succ->getFirstNonPHI()->getIterator(),
1025 while (
PHINode *PN = dyn_cast<PHINode>(&BB->
front())) {
1027 assert(PN->use_empty() &&
"There shouldn't be any uses here!");
1028 PN->eraseFromParent();
1045 if (!Succ->hasName()) Succ->takeName(BB);
1065 struct PHIDenseMapInfo {
1066 static PHINode *getEmptyKey() {
1070 static PHINode *getTombstoneKey() {
1074 static unsigned getHashValue(
PHINode *PN) {
1084 if (LHS == getEmptyKey() || LHS == getTombstoneKey() ||
1085 RHS == getEmptyKey() || RHS == getTombstoneKey())
1095 bool Changed =
false;
1097 auto Inserted = PHISet.
insert(PN);
1098 if (!Inserted.second) {
1122 assert(PrefAlign > Align);
1126 if (
AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
1134 if (PrefAlign <= Align)
1141 AI->setAlignment(PrefAlign);
1145 if (
auto *GO = dyn_cast<GlobalObject>(V)) {
1148 if (PrefAlign <= Align)
1155 if (!GO->canIncreaseAlignment())
1158 GO->setAlignment(PrefAlign);
1171 "getOrEnforceKnownAlignment expects a pointer!");
1174 unsigned TrailZ = Known.countMinTrailingZeros();
1178 TrailZ = std::min(TrailZ,
unsigned(
sizeof(
unsigned) * CHAR_BIT - 1));
1180 unsigned Align = 1u << std::min(Known.getBitWidth() - 1, TrailZ);
1185 if (PrefAlign > Align)
1207 DVI->getVariable() == DIVar &&
1208 DVI->getExpression() == DIExpr)
1223 for (
auto *DVI : DbgValues) {
1224 assert(DVI->getValue() == APN);
1225 if ((DVI->getVariable() == DIVar) && (DVI->getExpression() == DIExpr))
1244 return ValueSize >= *FragmentSize;
1250 if (
auto FragmentSize = AI->getAllocationSizeInBits(DL))
1251 return ValueSize >= *FragmentSize;
1262 assert(DIVar &&
"Missing variable");
1269 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: " 1276 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, DII->
getDebugLoc(),
1296 if (
auto Fragment = DIExpr->getFragmentInfo()) {
1297 unsigned FragmentOffset = Fragment->OffsetInBits;
1299 DIExpr->elements_end() - 3);
1301 Ops.push_back(FragmentOffset);
1309 Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, DII->
getDebugLoc(),
1319 assert(DIVar &&
"Missing variable");
1328 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: " 1337 Instruction *DbgValue = Builder.insertDbgValueIntrinsic(
1348 assert(DIVar &&
"Missing variable");
1357 LLVM_DEBUG(
dbgs() <<
"Failed to convert dbg.declare to dbg.value: " 1368 if (InsertionPt != BB->
end())
1369 Builder.insertDbgValueIntrinsic(APN, DIVar, DIExpr, DII->
getDebugLoc(),
1386 if (
auto DDI = dyn_cast<DbgDeclareInst>(&BI))
1392 for (
auto &
I : Dbgs) {
1406 if (
LoadInst *LI = dyn_cast<LoadInst>(U))
1407 return LI->isVolatile();
1409 return SI->isVolatile();
1414 for (
auto &AIUse : AI->
uses()) {
1415 User *U = AIUse.getUser();
1417 if (AIUse.getOperandNo() == 1)
1419 }
else if (
LoadInst *LI = dyn_cast<LoadInst>(U)) {
1421 }
else if (
CallInst *CI = dyn_cast<CallInst>(U)) {
1427 DIB.insertDbgValueIntrinsic(AI, DDI->
getVariable(), DerefExpr,
1439 assert(BB &&
"No BasicBlock to clone dbg.value(s) from.");
1440 if (InsertedPHIs.
size() == 0)
1445 for (
auto &
I : *BB) {
1446 if (
auto DbgII = dyn_cast<DbgInfoIntrinsic>(&
I)) {
1447 if (
auto *Loc = dyn_cast_or_null<PHINode>(DbgII->getVariableLocation()))
1448 DbgValueMap.
insert({Loc, DbgII});
1451 if (DbgValueMap.
size() == 0)
1458 for (
auto PHI : InsertedPHIs) {
1464 for (
auto VI : PHI->operand_values()) {
1465 auto V = DbgValueMap.
find(
VI);
1466 if (V != DbgValueMap.
end()) {
1467 auto *DbgII = cast<DbgInfoIntrinsic>(V->second);
1471 assert(InsertionPt != Parent->
end() &&
"Ill-formed basic block");
1472 NewDbgII->insertBefore(&*InsertionPt);
1495 if (
auto *DII = dyn_cast<DbgInfoIntrinsic>(U))
1496 if (DII->isAddressOfVariable())
1530 bool DerefBefore,
int Offset,
bool DerefAfter) {
1534 auto *DIVar = DII->getVariable();
1535 auto *DIExpr = DII->getExpression();
1536 assert(DIVar &&
"Missing variable");
1540 Builder.insertDeclare(NewAddress, DIVar, DIExpr, Loc, InsertBefore);
1541 if (DII == InsertBefore)
1545 return !DbgAddrs.empty();
1550 int Offset,
bool DerefAfter) {
1552 DerefBefore,
Offset, DerefAfter);
1560 assert(DIVar &&
"Missing variable");
1565 if (!DIExpr || DIExpr->getNumElements() < 1 ||
1566 DIExpr->getElement(0) != dwarf::DW_OP_deref)
1575 Ops.
append(DIExpr->elements_begin() + 1, DIExpr->elements_end());
1579 Builder.insertDbgValueIntrinsic(NewAddress, DIVar, DIExpr, Loc, DVI);
1587 for (
auto UI = MDV->use_begin(), UE = MDV->use_end(); UI != UE;) {
1589 if (
auto *DVI = dyn_cast<DbgValueInst>(U.
getUser()))
1602 if (DbgUsers.
empty())
1606 auto &DL = M.getDataLayout();
1616 bool WithStackValue = isa<DbgValueInst>(DII);
1627 doSalvage(DII, Ops);
1631 std::initializer_list<uint64_t> Opcodes) {
1633 doSalvage(DII, Ops);
1636 if (
auto *CI = dyn_cast<CastInst>(&I)) {
1637 if (!CI->isNoopCast(DL))
1642 for (
auto *DII : DbgUsers) {
1647 }
else if (
auto *
GEP = dyn_cast<GetElementPtrInst>(&I)) {
1649 M.getDataLayout().getIndexSizeInBits(
GEP->getPointerAddressSpace());
1654 if (
GEP->accumulateConstantOffset(M.getDataLayout(),
Offset))
1655 for (
auto *DII : DbgUsers)
1658 }
else if (
auto *BI = dyn_cast<BinaryOperator>(&I)) {
1661 if (!ConstInt || ConstInt->getBitWidth() > 64)
1665 for (
auto *DII : DbgUsers) {
1666 switch (BI->getOpcode()) {
1668 applyOffset(DII, Val);
1670 case Instruction::Sub:
1671 applyOffset(DII, -int64_t(Val));
1673 case Instruction::Mul:
1674 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_mul});
1676 case Instruction::SDiv:
1677 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_div});
1679 case Instruction::SRem:
1680 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_mod});
1682 case Instruction::Or:
1683 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_or});
1685 case Instruction::And:
1686 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_and});
1688 case Instruction::Xor:
1689 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_xor});
1691 case Instruction::Shl:
1692 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_shl});
1694 case Instruction::LShr:
1695 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_shr});
1697 case Instruction::AShr:
1698 applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_shra});
1706 }
else if (isa<LoadInst>(&I)) {
1708 for (
auto *DII : DbgUsers) {
1737 bool Changed =
false;
1739 if (isa<Instruction>(&To)) {
1742 for (
auto *DII : Users) {
1752 }
else if (!DT.
dominates(&DomPoint, DII)) {
1753 DeleteOrSalvage.
insert(DII);
1759 for (
auto *DII : Users) {
1760 if (DeleteOrSalvage.
count(DII))
1774 if (!DeleteOrSalvage.
empty()) {
1779 for (
auto *DII : DeleteOrSalvage) {
1809 return SameSize && LosslessConversion;
1822 assert(&From != &To &&
"Can't replace something with itself");
1828 return DII.getExpression();
1842 assert(FromBits != ToBits &&
"Unexpected no-op conversion");
1846 if (FromBits < ToBits)
1864 return Identity(DII);
1870 (ToBits - 1), dwarf::DW_OP_shr,
1871 dwarf::DW_OP_lit0, dwarf::DW_OP_not,
1872 dwarf::DW_OP_mul, dwarf::DW_OP_or});
1884 unsigned NumDeadInst = 0;
1888 while (EndInst != &BB->
front()) {
1897 if (!isa<DbgInfoIntrinsic>(Inst))
1907 std::vector <DominatorTree::UpdateType> Updates;
1914 Successor->removePredecessor(BB, PreserveLCSSA);
1929 unsigned NumInstrsRemoved = 0;
1931 while (BBI != BBE) {
1932 if (!BBI->use_empty())
1939 return NumInstrsRemoved;
1965 DDT->deleteEdge(BB, UnwindDestBB);
1991 InvokeArgs, OpBundles, CI->
getName(), BB);
2012 bool Changed =
false;
2020 if (
auto *CI = dyn_cast<CallInst>(&
I)) {
2023 if (
Function *F = dyn_cast<Function>(Callee)) {
2029 if (IntrinsicID == Intrinsic::assume) {
2036 }
else if (IntrinsicID == Intrinsic::experimental_guard) {
2047 if (!isa<UnreachableInst>(CI->getNextNode())) {
2054 }
else if ((isa<ConstantPointerNull>(Callee) &&
2056 isa<UndefValue>(
Callee)) {
2061 if (CI->doesNotReturn()) {
2065 if (!isa<UnreachableInst>(CI->getNextNode())) {
2072 }
else if (
auto *
SI = dyn_cast<StoreInst>(&
I)) {
2078 if (
SI->isVolatile())
continue;
2082 if (isa<UndefValue>(Ptr) ||
2083 (isa<ConstantPointerNull>(Ptr) &&
2085 SI->getPointerAddressSpace()))) {
2094 if (
auto *II = dyn_cast<InvokeInst>(Terminator)) {
2097 if ((isa<ConstantPointerNull>(Callee) &&
2099 isa<UndefValue>(
Callee)) {
2103 if (II->use_empty() && II->onlyReadsMemory()) {
2105 BasicBlock *NormalDestBB = II->getNormalDest();
2106 BasicBlock *UnwindDestBB = II->getUnwindDest();
2109 II->eraseFromParent();
2111 DDT->deleteEdge(BB, UnwindDestBB);
2116 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(Terminator)) {
2118 struct CatchPadDenseMapInfo {
2133 if (LHS == getEmptyKey() || LHS == getTombstoneKey() ||
2134 RHS == getEmptyKey() || RHS == getTombstoneKey())
2144 detail::DenseSetEmpty Empty;
2146 E = CatchSwitch->handler_end();
2149 auto *CatchPad = cast<CatchPadInst>(HandlerBB->
getFirstNonPHI());
2150 if (!HandlerSet.insert({CatchPad, Empty}).second) {
2151 CatchSwitch->removeHandler(
I);
2163 }
while (!Worklist.
empty());
2170 if (
auto *II = dyn_cast<InvokeInst>(TI)) {
2178 if (
auto *CRI = dyn_cast<CleanupReturnInst>(TI)) {
2180 UnwindDest = CRI->getUnwindDest();
2181 }
else if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(TI)) {
2183 CatchSwitch->getParentPad(),
nullptr, CatchSwitch->getNumHandlers(),
2184 CatchSwitch->getName(), CatchSwitch);
2185 for (
BasicBlock *PadBB : CatchSwitch->handlers())
2188 NewTI = NewCatchSwitch;
2189 UnwindDest = CatchSwitch->getUnwindDest();
2217 NumRemoved += F.
size()-Reachable.
size();
2221 std::vector <DominatorTree::UpdateType> Updates;
2224 if (Reachable.
count(BB))
2234 BB->dropAllReferences();
2239 if (Reachable.
count(BB)) {
2261 for (
const auto &MD : Metadata) {
2262 unsigned Kind = MD.first;
2317 if (isa<LoadInst>(K) || isa<StoreInst>(K))
2322 unsigned KnownIDs[] = {
2332 template <
typename RootType,
typename DominatesFn>
2334 const RootType &Root,
2335 const DominatesFn &Dominates) {
2342 if (!Dominates(Root, U))
2346 <<
"' as " << *To <<
" in " << *U <<
"\n");
2360 auto *
I = cast<Instruction>(U.
getUser());
2361 if (
I->getParent() == BB)
2381 auto ProperlyDominates = [&DT](
const BasicBlock *BB,
const Use &U) {
2382 auto *
I = cast<Instruction>(U.getUser())->
getParent();
2394 if (
F->hasFnAttribute(
"gc-leaf-function"))
2397 if (
auto IID =
F->getIntrinsicID())
2399 return IID != Intrinsic::experimental_gc_statepoint &&
2400 IID != Intrinsic::experimental_deoptimize;
2416 auto *NewTy = NewLI.
getType();
2419 if (NewTy->isPointerTy()) {
2426 if (!NewTy->isIntegerTy())
2431 auto *ITy = cast<IntegerType>(NewTy);
2436 MDB.createRange(NonNullInt, NullInt));
2441 auto *NewTy = NewLI.
getType();
2447 if (!NewTy->isPointerTy())
2462 BitPart(
Value *
P,
unsigned BW) : Provider(P) {
2463 Provenance.resize(BW);
2473 enum { Unset = -1 };
2504 auto I = BPS.find(V);
2513 if (
I->getOpcode() == Instruction::Or) {
2515 MatchBitReversals, BPS);
2517 MatchBitReversals, BPS);
2522 if (!A->Provider || A->Provider != B->Provider)
2525 Result = BitPart(A->Provider, BitWidth);
2526 for (
unsigned i = 0; i < A->Provenance.size(); ++i) {
2527 if (A->Provenance[i] != BitPart::Unset &&
2528 B->Provenance[i] != BitPart::Unset &&
2529 A->Provenance[i] != B->Provenance[i])
2532 if (A->Provenance[i] == BitPart::Unset)
2533 Result->Provenance[i] = B->Provenance[i];
2535 Result->Provenance[i] = A->Provenance[i];
2542 if (
I->isLogicalShift() && isa<ConstantInt>(
I->getOperand(1))) {
2544 cast<ConstantInt>(
I->getOperand(1))->getLimitedValue(~0U);
2546 if (BitShift > BitWidth)
2550 MatchBitReversals, BPS);
2557 if (
I->getOpcode() == Instruction::Shl) {
2558 P.erase(std::prev(
P.end(), BitShift),
P.end());
2559 P.insert(
P.begin(), BitShift, BitPart::Unset);
2561 P.erase(
P.begin(), std::next(
P.begin(), BitShift));
2562 P.insert(
P.end(), BitShift, BitPart::Unset);
2570 if (
I->getOpcode() == Instruction::And &&
2571 isa<ConstantInt>(
I->getOperand(1))) {
2572 APInt Bit(
I->getType()->getPrimitiveSizeInBits(), 1);
2573 const APInt &AndMask = cast<ConstantInt>(
I->getOperand(1))->getValue();
2577 unsigned NumMaskedBits = AndMask.countPopulation();
2578 if (!MatchBitReversals && NumMaskedBits % 8 != 0)
2582 MatchBitReversals, BPS);
2587 for (
unsigned i = 0; i < BitWidth; ++i,
Bit <<= 1)
2589 if ((AndMask & Bit) == 0)
2590 Result->Provenance[i] = BitPart::Unset;
2595 if (
I->getOpcode() == Instruction::ZExt) {
2597 MatchBitReversals, BPS);
2601 Result = BitPart(Res->Provider, BitWidth);
2602 auto NarrowBitWidth =
2603 cast<IntegerType>(cast<ZExtInst>(
I)->getSrcTy())->
getBitWidth();
2604 for (
unsigned i = 0; i < NarrowBitWidth; ++i)
2605 Result->Provenance[i] = Res->Provenance[i];
2606 for (
unsigned i = NarrowBitWidth; i < BitWidth; ++i)
2607 Result->Provenance[i] = BitPart::Unset;
2614 Result = BitPart(V, BitWidth);
2615 for (
unsigned i = 0; i < BitWidth; ++i)
2616 Result->Provenance[i] = i;
2621 unsigned BitWidth) {
2622 if (From % 8 != To % 8)
2628 return From == BitWidth - To - 1;
2632 unsigned BitWidth) {
2633 return From == BitWidth - To - 1;
2637 Instruction *
I,
bool MatchBSwaps,
bool MatchBitReversals,
2641 if (!MatchBSwaps && !MatchBitReversals)
2648 unsigned DemandedBW = BW;
2652 DemandedTy = cast<IntegerType>(Trunc->getType());
2658 std::map<Value *, Optional<BitPart>> BPS;
2662 auto &BitProvenance = Res->Provenance;
2666 bool OKForBSwap = DemandedBW % 16 == 0, OKForBitReverse =
true;
2667 for (
unsigned i = 0; i < DemandedBW; ++i) {
2675 if (OKForBSwap && MatchBSwaps)
2676 Intrin = Intrinsic::bswap;
2677 else if (OKForBitReverse && MatchBitReversals)
2678 Intrin = Intrinsic::bitreverse;
2682 if (ITy != DemandedTy) {
2684 Value *Provider = Res->Provider;
2685 IntegerType *ProviderTy = cast<IntegerType>(Provider->getType());
2687 if (DemandedTy != ProviderTy) {
2733 case Instruction::Invoke:
2740 if (isa<IntrinsicInst>(I))
2748 case Instruction::ShuffleVector:
2751 case Instruction::Switch:
2752 case Instruction::ExtractValue:
2755 case Instruction::InsertValue:
2758 case Instruction::Alloca:
2762 return !cast<AllocaInst>(
I)->isStaticAlloca();
2763 case Instruction::GetElementPtr:
2767 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.
Value * getValueOperand()
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
Function * getCalledFunction() const
Return the function called, or null if this is an indirect function invocation.
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
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)
This class represents an incoming formal argument to a Function.
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.
void addAttribute(unsigned i, Attribute::AttrKind Kind)
adds the attribute to the list of attributes.
bool isMetadataTy() const
Return true if this is 'metadata'.
iterator erase(iterator where)
Compute iterated dominance frontiers using a linear time algorithm.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
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 MetadataAsValue * wrapValueInMetadata(LLVMContext &C, Value *V)
Wrap V in a ValueAsMetadata instance.
Implements a dense probed hash-table based set.
This class represents zero extension of integer types.
value_op_iterator value_op_begin()
static MDNode * getMostGenericAliasScope(MDNode *A, MDNode *B)
This class represents a function call, abstracting a target machine's calling convention.
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
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.
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...
static CallInst * Create(Value *Func, ArrayRef< Value *> Args, ArrayRef< OperandBundleDef > Bundles=None, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
const MDOperand & getOperand(unsigned I) const
This class represents a sign extension of integer types.
Optional< DIExpression * > DbgValReplacement
A replacement for a dbg.value expression.
An instruction for reading from memory.
CallingConv::ID getCallingConv() const
getCallingConv/setCallingConv - Get or set the calling convention of this function call...
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.
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.
void eraseNode(NodeT *BB)
eraseNode - Removes a node from the dominator tree.
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...
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
void MergeBasicBlockIntoOnlyPred(BasicBlock *BB, DominatorTree *DT=nullptr, DeferredDominance *DDT=nullptr)
BB is a block with one predecessor and its predecessor is known to have one successor (BB!)...
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 bool rewriteDebugUsers(Instruction &From, Value &To, Instruction &DomPoint, DominatorTree &DT, function_ref< DbgValReplacement(DbgInfoIntrinsic &DII)> RewriteExpr)
Point debug users of From to To using exprs given by RewriteExpr, possibly moving/deleting users to p...
Only used in LLVM metadata.
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: ...
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.
void deleteBB(BasicBlock *DelBB)
Delays the deletion of a basic block until a flush() event.
static DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
void setAttributes(AttributeList A)
Set the parameter attributes for this call.
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.
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)
An instruction for storing to memory.
bool removeUnreachableBlocks(Function &F, LazyValueInfo *LVI=nullptr, DeferredDominance *DDT=nullptr)
Remove all blocks that can not be reached from the function's entry.
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.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
void takeName(Value *V)
Transfer the name from V to this value.
AttributeList getAttributes() const
Return the parameter attributes for this call.
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.
Value * getOperand(unsigned i) const
void applyUpdates(ArrayRef< DominatorTree::UpdateType > Updates)
Queues multiple updates and discards duplicates.
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)
void deleteEdge(BasicBlock *From, BasicBlock *To)
Helper method for a single edge deletion.
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")
Subclasses of this class are all able to terminate a basic block.
Value * getVariableLocation(bool AllowNullOp=true) const
Get the location corresponding to the variable referenced by the debug info intrinsic.
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.
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 ...
This is an important class for using LLVM in a threaded context.
Conditional or Unconditional Branch instruction.
bool isAddressOfVariable() const
Does this describe the address of a local variable.
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
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
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?
void ConvertDebugDeclareToDebugValue(DbgInfoIntrinsic *DII, StoreInst *SI, DIBuilder &Builder)
===---------------------------------------------------------------——===// Dbg Intrinsic utilities ...
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...
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.
DILocalVariable * getVariable() const
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 copyRangeMetadata(const DataLayout &DL, const LoadInst &OldLI, MDNode *N, LoadInst &NewLI)
Copy a range metadata node to a new load instruction.
DIExpression * getExpression() const
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.
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
bool ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions=false, const TargetLibraryInfo *TLI=nullptr, DeferredDominance *DDT=nullptr)
If a terminator instruction is predicated on a constant value, convert it into an unconditional branc...
static MDNode * getMostGenericTBAA(MDNode *A, MDNode *B)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
If the specified value is a trivially dead instruction, delete it.
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.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
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 InvokeInst * Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException, ArrayRef< Value *> Args, const Twine &NameStr, Instruction *InsertBefore=nullptr)
Optional< uint64_t > getFragmentSizeInBits() const
Get the size (in bits) of the variable, or fragment of the variable that is described.
bool TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB, DeferredDominance *DDT=nullptr)
BB is known to contain an unconditional branch, and contains no instructions other than PHI nodes...
void setCallingConv(CallingConv::ID CC)
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.
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.
This is the common base class for debug info intrinsics.
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...
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...
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.
void removeUnwindEdge(BasicBlock *BB, DeferredDominance *DDT=nullptr)
Replace 'BB's terminator with one that does not have an unwind successor block.
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.
void setOperand(unsigned i_nocapture, Value *Val_nocapture)
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.
Class to defer updates to a DominatorTree.
iterator_range< user_iterator > users()
InstListType::iterator iterator
Instruction iterators...
TinyPtrVector< DbgInfoIntrinsic * > FindDbgAddrUses(Value *V)
Finds all intrinsics declaring local variables as living in the memory that 'V' points to...
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...
bool isNonIntegralPointerType(PointerType *PT) const
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
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 ...
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.
bool isTokenTy() const
Return true if this is 'token'.
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.
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)
unsigned pred_size(const BasicBlock *BB)
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...
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...
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.
void combineMetadataForCSE(Instruction *K, const Instruction *J)
Combine the metadata of two instructions so that K can replace J.
void RemovePredecessorAndSimplify(BasicBlock *BB, BasicBlock *Pred, DeferredDominance *DDT=nullptr)
Like BasicBlock::removePredecessor, this method is called when we're about to delete Pred as a predec...
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
void findDbgUsers(SmallVectorImpl< DbgInfoIntrinsic *> &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
unsigned changeToUnreachable(Instruction *I, bool UseLLVMTrap, bool PreserveLCSSA=false, DeferredDominance *DDT=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
void eraseBlock(BasicBlock *BB)
Inform the analysis cache that we have erased a block.
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
void recalculate(Function &F)
Drops all internal state and forces a (slow) recalculation of the DominatorTree based on the current ...
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.
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
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
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
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(BasicBlock *BB)
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, Instruction *InsertBefore=nullptr)
static const Function * getParent(const Value *V)
const Value * getCalledValue() const
Get a pointer to the function that is invoked by this instruction.
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...
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 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 ...
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
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.
static void changeToCall(InvokeInst *II, DeferredDominance *DDT=nullptr)
changeToCall - Convert the specified invoke into a normal call.
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.
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)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
void combineMetadata(Instruction *K, const Instruction *J, ArrayRef< unsigned > KnownIDs)
Combine the metadata of two instructions so that K can replace J.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static bool valueCoversEntireFragment(Type *ValTy, DbgInfoIntrinsic *DII)
Check if the alloc size of ValTy is large enough to cover the variable (or fragment of the variable) ...
Type * getElementType() const
unsigned replaceNonLocalUsesWith(Instruction *From, Value *To)
static bool markAliveBlocks(Function &F, SmallPtrSetImpl< BasicBlock *> &Reachable, DeferredDominance *DDT=nullptr)
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)