86#define DEBUG_TYPE "inline-function"
95 cl::desc(
"Convert noalias attributes to metadata during inlining."));
100 cl::desc(
"Use the llvm.experimental.noalias.scope.decl "
101 "intrinsic during inlining."));
109 cl::desc(
"Convert align attributes to assumptions during inlining."));
112 "max-inst-checked-for-throw-during-inlining",
cl::Hidden,
113 cl::desc(
"the maximum number of instructions analyzed for may throw during "
114 "attribute inference in inlined body"),
120 class LandingPadInliningInfo {
131 PHINode *InnerEHValuesPHI =
nullptr;
137 : OuterResumeDest(
II->getUnwindDest()) {
143 for (; isa<PHINode>(
I); ++
I) {
146 UnwindDestPHIValues.
push_back(
PHI->getIncomingValueForBlock(InvokeBB));
149 CallerLPad = cast<LandingPadInst>(
I);
155 return OuterResumeDest;
172 void addIncomingPHIValuesFor(
BasicBlock *BB)
const {
173 addIncomingPHIValuesForInto(BB, OuterResumeDest);
178 for (
unsigned i = 0, e = UnwindDestPHIValues.
size(); i != e; ++i, ++
I) {
180 phi->addIncoming(UnwindDestPHIValues[i], src);
188 while (It != BB.
end()) {
189 if (
auto *IntrinsicCall = dyn_cast<ConvergenceControlInst>(It)) {
190 if (IntrinsicCall->isEntry()) {
191 return IntrinsicCall;
200BasicBlock *LandingPadInliningInfo::getInnerResumeDest() {
201 if (InnerResumeDest)
return InnerResumeDest;
207 OuterResumeDest->
getName() +
".body");
210 const unsigned PHICapacity = 2;
215 for (
unsigned i = 0, e = UnwindDestPHIValues.
size(); i != e; ++i, ++
I) {
216 PHINode *OuterPHI = cast<PHINode>(
I);
218 OuterPHI->
getName() +
".lpad-body");
229 InnerEHValuesPHI->
addIncoming(CallerLPad, OuterResumeDest);
232 return InnerResumeDest;
239void LandingPadInliningInfo::forwardResume(
248 addIncomingPHIValuesForInto(Src, Dest);
256 if (
auto *FPI = dyn_cast<FuncletPadInst>(EHPad))
257 return FPI->getParentPad();
258 return cast<CatchSwitchInst>(EHPad)->getParentPad();
269 while (!Worklist.
empty()) {
276 Value *UnwindDestToken =
nullptr;
277 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(CurrentPad)) {
278 if (CatchSwitch->hasUnwindDest()) {
279 UnwindDestToken = &*CatchSwitch->getUnwindDest()->getFirstNonPHIIt();
287 for (
auto HI = CatchSwitch->handler_begin(),
288 HE = CatchSwitch->handler_end();
289 HI != HE && !UnwindDestToken; ++HI) {
298 if (!isa<CleanupPadInst>(Child) && !isa<CatchSwitchInst>(Child))
302 auto Memo = MemoMap.
find(ChildPad);
303 if (Memo == MemoMap.
end()) {
310 Value *ChildUnwindDestToken = Memo->second;
311 if (!ChildUnwindDestToken)
317 if (isa<ConstantTokenNone>(ChildUnwindDestToken)) {
318 UnwindDestToken = ChildUnwindDestToken;
326 auto *CleanupPad = cast<CleanupPadInst>(CurrentPad);
327 for (
User *U : CleanupPad->users()) {
328 if (
auto *CleanupRet = dyn_cast<CleanupReturnInst>(U)) {
329 if (
BasicBlock *RetUnwindDest = CleanupRet->getUnwindDest())
330 UnwindDestToken = &*RetUnwindDest->getFirstNonPHIIt();
335 Value *ChildUnwindDestToken;
336 if (
auto *Invoke = dyn_cast<InvokeInst>(U)) {
337 ChildUnwindDestToken = &*Invoke->getUnwindDest()->getFirstNonPHIIt();
338 }
else if (isa<CleanupPadInst>(U) || isa<CatchSwitchInst>(U)) {
340 auto Memo = MemoMap.
find(ChildPad);
341 if (Memo == MemoMap.
end()) {
348 ChildUnwindDestToken = Memo->second;
349 if (!ChildUnwindDestToken)
358 if (isa<Instruction>(ChildUnwindDestToken) &&
361 UnwindDestToken = ChildUnwindDestToken;
367 if (!UnwindDestToken)
375 if (
auto *UnwindPad = dyn_cast<Instruction>(UnwindDestToken))
378 UnwindParent =
nullptr;
379 bool ExitedOriginalPad =
false;
381 ExitedPad && ExitedPad != UnwindParent;
382 ExitedPad = dyn_cast<Instruction>(
getParentPad(ExitedPad))) {
384 if (isa<CatchPadInst>(ExitedPad))
386 MemoMap[ExitedPad] = UnwindDestToken;
387 ExitedOriginalPad |= (ExitedPad == EHPad);
390 if (ExitedOriginalPad)
391 return UnwindDestToken;
422 if (
auto *CPI = dyn_cast<CatchPadInst>(EHPad))
423 EHPad = CPI->getCatchSwitch();
426 auto Memo = MemoMap.
find(EHPad);
427 if (Memo != MemoMap.
end())
432 assert((UnwindDestToken ==
nullptr) != (MemoMap.
count(EHPad) != 0));
434 return UnwindDestToken;
441 MemoMap[EHPad] =
nullptr;
447 Value *AncestorToken;
449 auto *AncestorPad = dyn_cast<Instruction>(AncestorToken);
452 if (isa<CatchPadInst>(AncestorPad))
461 assert(!MemoMap.
count(AncestorPad) || MemoMap[AncestorPad]);
462 auto AncestorMemo = MemoMap.
find(AncestorPad);
463 if (AncestorMemo == MemoMap.
end()) {
466 UnwindDestToken = AncestorMemo->second;
470 LastUselessPad = AncestorPad;
471 MemoMap[LastUselessPad] =
nullptr;
473 TempMemos.
insert(LastUselessPad);
491 while (!Worklist.
empty()) {
493 auto Memo = MemoMap.
find(UselessPad);
494 if (Memo != MemoMap.
end() && Memo->second) {
522 MemoMap[UselessPad] = UnwindDestToken;
523 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(UselessPad)) {
524 assert(CatchSwitch->getUnwindDest() ==
nullptr &&
"Expected useless pad");
525 for (
BasicBlock *HandlerBlock : CatchSwitch->handlers()) {
526 auto *CatchPad = &*HandlerBlock->getFirstNonPHIIt();
527 for (
User *U : CatchPad->users()) {
528 assert((!isa<InvokeInst>(U) ||
531 ->getFirstNonPHIIt()) == CatchPad)) &&
532 "Expected useless pad");
533 if (isa<CatchSwitchInst>(U) || isa<CleanupPadInst>(U))
534 Worklist.
push_back(cast<Instruction>(U));
538 assert(isa<CleanupPadInst>(UselessPad));
540 assert(!isa<CleanupReturnInst>(U) &&
"Expected useless pad");
542 (!isa<InvokeInst>(U) ||
544 &*cast<InvokeInst>(U)->getUnwindDest()->getFirstNonPHIIt()) ==
546 "Expected useless pad");
547 if (isa<CatchSwitchInst>(U) || isa<CleanupPadInst>(U))
548 Worklist.
push_back(cast<Instruction>(U));
553 return UnwindDestToken;
579 if (
F->getIntrinsicID() == Intrinsic::experimental_deoptimize ||
580 F->getIntrinsicID() == Intrinsic::experimental_guard)
591 auto *FuncletPad = cast<Instruction>(FuncletBundle->Inputs[0]);
592 Value *UnwindDestToken =
594 if (UnwindDestToken && !isa<ConstantTokenNone>(UnwindDestToken))
598 if (
auto *CatchPad = dyn_cast<CatchPadInst>(FuncletPad))
599 MemoKey = CatchPad->getCatchSwitch();
601 MemoKey = FuncletPad;
602 assert(FuncletUnwindMap->count(MemoKey) &&
603 (*FuncletUnwindMap)[MemoKey] == UnwindDestToken &&
604 "must get memoized to avoid confusing later searches");
629 LandingPadInliningInfo Invoke(
II);
635 if (
InvokeInst *
II = dyn_cast<InvokeInst>(
I->getTerminator()))
636 InlinedLPads.
insert(
II->getLandingPadInst());
643 InlinedLPad->reserveClauses(OuterNum);
644 for (
unsigned OuterIdx = 0; OuterIdx != OuterNum; ++OuterIdx)
645 InlinedLPad->addClause(OuterLPad->
getClause(OuterIdx));
647 InlinedLPad->setCleanup(
true);
654 &*BB, Invoke.getOuterResumeDest()))
657 Invoke.addIncomingPHIValuesFor(NewBB);
660 if (
ResumeInst *RI = dyn_cast<ResumeInst>(BB->getTerminator()))
661 Invoke.forwardResume(RI, InlinedLPads);
691 UnwindDestPHIValues.
push_back(
PHI.getIncomingValueForBlock(InvokeBB));
698 for (
Value *V : UnwindDestPHIValues) {
700 PHI->addIncoming(V, Src);
710 if (
auto *CRI = dyn_cast<CleanupReturnInst>(BB->getTerminator())) {
711 if (CRI->unwindsToCaller()) {
712 auto *CleanupPad = CRI->getCleanupPad();
714 CRI->eraseFromParent();
721 isa<ConstantTokenNone>(FuncletUnwindMap[CleanupPad]));
722 FuncletUnwindMap[CleanupPad] =
732 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(
I)) {
733 if (CatchSwitch->unwindsToCaller()) {
734 Value *UnwindDestToken;
735 if (
auto *ParentPad =
736 dyn_cast<Instruction>(CatchSwitch->getParentPad())) {
746 if (UnwindDestToken && !isa<ConstantTokenNone>(UnwindDestToken))
759 CatchSwitch->getParentPad(), UnwindDest,
760 CatchSwitch->getNumHandlers(), CatchSwitch->
getName(),
761 CatchSwitch->getIterator());
762 for (
BasicBlock *PadBB : CatchSwitch->handlers())
763 NewCatchSwitch->addHandler(PadBB);
768 FuncletUnwindMap[NewCatchSwitch] = UnwindDestToken;
769 Replacement = NewCatchSwitch;
771 }
else if (!isa<FuncletPadInst>(
I)) {
777 I->replaceAllUsesWith(Replacement);
778 I->eraseFromParent();
788 &*BB, UnwindDest, &FuncletUnwindMap))
801 MDNode *CallsiteStackContext) {
807 for (
auto MIBStackIter = MIBStackContext->
op_begin(),
808 CallsiteStackIter = CallsiteStackContext->
op_begin();
809 MIBStackIter != MIBStackContext->
op_end() &&
810 CallsiteStackIter != CallsiteStackContext->
op_end();
811 MIBStackIter++, CallsiteStackIter++) {
812 auto *Val1 = mdconst::dyn_extract<ConstantInt>(*MIBStackIter);
813 auto *Val2 = mdconst::dyn_extract<ConstantInt>(*CallsiteStackIter);
815 if (Val1->getZExtValue() != Val2->getZExtValue())
822 Call->setMetadata(LLVMContext::MD_memprof,
nullptr);
826 Call->setMetadata(LLVMContext::MD_callsite,
nullptr);
830 const std::vector<Metadata *> &MIBList) {
837 CallStack.addCallStack(cast<MDNode>(MIB));
838 bool MemprofMDAttached =
CallStack.buildAndAttachMIBMetadata(CI);
840 if (!MemprofMDAttached)
850 MDNode *InlinedCallsiteMD) {
852 MDNode *ClonedCallsiteMD =
nullptr;
855 if (OrigCallsiteMD) {
860 ClonedCall->
setMetadata(LLVMContext::MD_callsite, ClonedCallsiteMD);
872 std::vector<Metadata *> NewMIBList;
877 for (
auto &MIBOp : OrigMemProfMD->
operands()) {
878 MDNode *MIB = dyn_cast<MDNode>(MIBOp);
885 NewMIBList.push_back(MIB);
887 if (NewMIBList.empty()) {
903 bool ContainsMemProfMetadata,
908 if (!CallsiteMD && !ContainsMemProfMetadata)
912 for (
const auto &Entry : VMap) {
915 auto *OrigCall = dyn_cast_or_null<CallBase>(Entry.first);
916 auto *ClonedCall = dyn_cast_or_null<CallBase>(Entry.second);
917 if (!OrigCall || !ClonedCall)
936 MDNode *MemParallelLoopAccess =
937 CB.
getMetadata(LLVMContext::MD_mem_parallel_loop_access);
941 if (!MemParallelLoopAccess && !AccessGroup && !AliasScope && !NoAlias)
947 if (!
I.mayReadOrWriteMemory())
950 if (MemParallelLoopAccess) {
953 I.getMetadata(LLVMContext::MD_mem_parallel_loop_access),
954 MemParallelLoopAccess);
955 I.setMetadata(LLVMContext::MD_mem_parallel_loop_access,
956 MemParallelLoopAccess);
961 I.getMetadata(LLVMContext::MD_access_group), AccessGroup));
965 I.getMetadata(LLVMContext::MD_alias_scope), AliasScope));
969 I.getMetadata(LLVMContext::MD_noalias), NoAlias));
987 dyn_cast<Function>(
I->getCalledOperand()->stripPointerCasts());
988 if (CalledFn && CalledFn->isIntrinsic() &&
I->doesNotThrow() &&
993 I->getOperandBundlesAsDefs(OpBundles);
998 I->replaceAllUsesWith(NewInst);
999 I->eraseFromParent();
1008class ScopedAliasMetadataDeepCloner {
1012 void addRecursiveMetadataUses();
1015 ScopedAliasMetadataDeepCloner(
const Function *
F);
1027ScopedAliasMetadataDeepCloner::ScopedAliasMetadataDeepCloner(
1031 if (
const MDNode *M =
I.getMetadata(LLVMContext::MD_alias_scope))
1033 if (
const MDNode *M =
I.getMetadata(LLVMContext::MD_noalias))
1037 if (
const auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&
I))
1038 MD.insert(Decl->getScopeList());
1041 addRecursiveMetadataUses();
1044void ScopedAliasMetadataDeepCloner::addRecursiveMetadataUses() {
1046 while (!
Queue.empty()) {
1049 if (
const MDNode *OpMD = dyn_cast<MDNode>(
Op))
1050 if (MD.insert(OpMD))
1051 Queue.push_back(OpMD);
1055void ScopedAliasMetadataDeepCloner::clone() {
1056 assert(MDMap.empty() &&
"clone() already called ?");
1061 MDMap[
I].reset(DummyNodes.
back().get());
1070 if (
const MDNode *M = dyn_cast<MDNode>(
Op))
1077 MDTuple *TempM = cast<MDTuple>(MDMap[
I]);
1094 if (
MDNode *M =
I.getMetadata(LLVMContext::MD_alias_scope))
1095 if (
MDNode *MNew = MDMap.lookup(M))
1096 I.setMetadata(LLVMContext::MD_alias_scope, MNew);
1098 if (
MDNode *M =
I.getMetadata(LLVMContext::MD_noalias))
1099 if (
MDNode *MNew = MDMap.lookup(M))
1100 I.setMetadata(LLVMContext::MD_noalias, MNew);
1102 if (
auto *Decl = dyn_cast<NoAliasScopeDeclInst>(&
I))
1103 if (
MDNode *MNew = MDMap.lookup(Decl->getScopeList()))
1104 Decl->setScopeList(MNew);
1123 if (CB.
paramHasAttr(Arg.getArgNo(), Attribute::NoAlias) && !Arg.use_empty())
1126 if (NoAliasArgs.
empty())
1146 for (
unsigned i = 0, e = NoAliasArgs.
size(); i != e; ++i) {
1149 std::string
Name = std::string(CalledFunc->
getName());
1152 Name +=
A->getName();
1154 Name +=
": argument ";
1162 NewScopes.
insert(std::make_pair(
A, NewScope));
1179 VMI != VMIE; ++VMI) {
1180 if (
const Instruction *
I = dyn_cast<Instruction>(VMI->first)) {
1184 Instruction *NI = dyn_cast<Instruction>(VMI->second);
1188 bool IsArgMemOnlyCall =
false, IsFuncCall =
false;
1191 if (
const LoadInst *LI = dyn_cast<LoadInst>(
I))
1192 PtrArgs.
push_back(LI->getPointerOperand());
1193 else if (
const StoreInst *SI = dyn_cast<StoreInst>(
I))
1194 PtrArgs.
push_back(SI->getPointerOperand());
1195 else if (
const VAArgInst *VAAI = dyn_cast<VAArgInst>(
I))
1196 PtrArgs.
push_back(VAAI->getPointerOperand());
1198 PtrArgs.
push_back(CXI->getPointerOperand());
1200 PtrArgs.
push_back(RMWI->getPointerOperand());
1201 else if (
const auto *Call = dyn_cast<CallBase>(
I)) {
1205 if (Call->doesNotAccessMemory())
1217 IsArgMemOnlyCall =
true;
1220 for (
Value *Arg : Call->args()) {
1224 if (!Arg->getType()->isPointerTy())
1235 if (PtrArgs.
empty() && !IsFuncCall)
1244 for (
const Value *V : PtrArgs) {
1248 for (
const Value *O : Objects)
1254 bool RequiresNoCaptureBefore =
false, UsesAliasingPtr =
false,
1255 UsesUnknownObject =
false;
1256 for (
const Value *V : ObjSet) {
1260 bool IsNonPtrConst = isa<ConstantInt>(V) || isa<ConstantFP>(V) ||
1261 isa<ConstantPointerNull>(V) ||
1262 isa<ConstantDataVector>(V) || isa<UndefValue>(V);
1269 if (
const Argument *
A = dyn_cast<Argument>(V)) {
1271 UsesAliasingPtr =
true;
1273 UsesAliasingPtr =
true;
1279 RequiresNoCaptureBefore =
true;
1285 UsesUnknownObject =
true;
1291 if (UsesUnknownObject)
1296 if (IsFuncCall && !IsArgMemOnlyCall)
1297 RequiresNoCaptureBefore =
true;
1315 if (!RequiresNoCaptureBefore ||
1337 bool CanAddScopes = !UsesAliasingPtr;
1338 if (CanAddScopes && IsFuncCall)
1339 CanAddScopes = IsArgMemOnlyCall;
1344 Scopes.push_back(NewScopes[
A]);
1347 if (!Scopes.empty())
1349 LLVMContext::MD_alias_scope,
1360 "Expected to be in same basic block!");
1362 assert(BeginIt !=
End->getIterator() &&
"Non-empty BB has empty iterator");
1373 auto &Context = CalledFunction->
getContext();
1377 bool HasAttrToPropagate =
false;
1385 Attribute::Dereferenceable, Attribute::DereferenceableOrNull,
1386 Attribute::NonNull, Attribute::Alignment, Attribute::Range};
1388 for (
unsigned I = 0, E = CB.
arg_size();
I < E; ++
I) {
1394 ValidObjParamAttrs.
back().addAttribute(Attribute::ReadNone);
1396 ValidObjParamAttrs.
back().addAttribute(Attribute::ReadOnly);
1401 ValidExactParamAttrs.
back().addAttribute(Attr);
1404 HasAttrToPropagate |= ValidObjParamAttrs.
back().hasAttributes();
1405 HasAttrToPropagate |= ValidExactParamAttrs.
back().hasAttributes();
1409 if (!HasAttrToPropagate)
1414 const auto *InnerCB = dyn_cast<CallBase>(&Ins);
1417 auto *NewInnerCB = dyn_cast_or_null<CallBase>(VMap.
lookup(InnerCB));
1422 if (InlinedFunctionInfo.
isSimplified(InnerCB, NewInnerCB))
1426 for (
unsigned I = 0, E = InnerCB->arg_size();
I < E; ++
I) {
1431 if (NewInnerCB->paramHasAttr(
I, Attribute::ByVal))
1435 if (
match(NewInnerCB->getArgOperand(
I),
1440 const Argument *Arg = dyn_cast<Argument>(InnerCB->getArgOperand(
I));
1451 if (AL.getParamDereferenceableBytes(
I) >
1452 NewAB.getDereferenceableBytes())
1454 if (AL.getParamDereferenceableOrNullBytes(
I) >
1455 NewAB.getDereferenceableOrNullBytes())
1457 if (AL.getParamAlignment(
I).valueOrOne() >
1458 NewAB.getAlignment().valueOrOne())
1460 if (
auto ExistingRange = AL.getParamRange(
I)) {
1461 if (
auto NewRange = NewAB.getRange()) {
1464 NewAB.removeAttribute(Attribute::Range);
1465 NewAB.addRangeAttr(CombinedRange);
1468 AL = AL.addParamAttributes(Context,
I, NewAB);
1469 }
else if (NewInnerCB->getArgOperand(
I)->getType()->isPointerTy()) {
1471 const Value *UnderlyingV =
1473 Arg = dyn_cast<Argument>(UnderlyingV);
1482 AL = AL.addParamAttributes(Context,
I, ValidObjParamAttrs[ArgNo]);
1489 if (AL.hasParamAttr(
I, Attribute::ReadOnly) &&
1490 AL.hasParamAttr(
I, Attribute::WriteOnly))
1491 AL = AL.addParamAttribute(Context,
I, Attribute::ReadNone);
1494 if (AL.hasParamAttr(
I, Attribute::ReadNone)) {
1495 AL = AL.removeParamAttribute(Context,
I, Attribute::ReadOnly);
1496 AL = AL.removeParamAttribute(Context,
I, Attribute::WriteOnly);
1500 if (AL.hasParamAttr(
I, Attribute::ReadOnly) ||
1501 AL.hasParamAttr(
I, Attribute::ReadNone))
1502 AL = AL.removeParamAttribute(Context,
I, Attribute::Writable);
1504 NewInnerCB->setAttributes(AL);
1548 auto &Context = CalledFunction->
getContext();
1550 for (
auto &BB : *CalledFunction) {
1551 auto *RI = dyn_cast<ReturnInst>(BB.getTerminator());
1552 if (!RI || !isa<CallBase>(RI->
getOperand(0)))
1554 auto *RetVal = cast<CallBase>(RI->
getOperand(0));
1558 auto *NewRetVal = dyn_cast_or_null<CallBase>(VMap.
lookup(RetVal));
1564 if (InlinedFunctionInfo.
isSimplified(RetVal, NewRetVal))
1584 if (RI->
getParent() != RetVal->getParent() ||
1597 AL.getRetDereferenceableOrNullBytes())
1599 AttributeList NewAL = AL.addRetAttributes(Context, ValidUB);
1637 Attribute NewRange = AL.getRetAttr(Attribute::Range);
1655 (RetVal->hasOneUse() && !RetVal->hasRetAttr(Attribute::NoUndef)))
1658 NewRetVal->setAttributes(NewAL);
1674 bool DTCalculated =
false;
1678 if (!Arg.getType()->isPointerTy() || Arg.hasPassPointeeByValueCopyAttr() ||
1685 if (!DTCalculated) {
1687 DTCalculated =
true;
1696 DL, ArgVal, Alignment->value());
1708 Builder.
getInt64(M->getDataLayout().getTypeStoreSize(ByValType));
1721 CI->
setDebugLoc(DILocation::get(SP->getContext(), 0, 0, SP));
1758 Align Alignment =
DL.getPrefTypeAlign(ByValType);
1764 Alignment = std::max(Alignment, *ByValAlignment);
1768 nullptr, Alignment, Arg->
getName());
1779 for (
User *U : V->users())
1781 if (
II->isLifetimeStartOrEnd())
1792 if (Ty == Int8PtrTy)
1797 if (U->getType() != Int8PtrTy)
continue;
1798 if (U->stripPointerCasts() != AI)
continue;
1818 return DILocation::get(Ctx, OrigDL.
getLine(), OrigDL.
getCol(),
1835 InlinedAtNode = DILocation::getDistinct(
1836 Ctx, InlinedAtNode->getLine(), InlinedAtNode->getColumn(),
1837 InlinedAtNode->getScope(), InlinedAtNode->getInlinedAt());
1846 bool NoInlineLineTables = Fn->
hasFnAttribute(
"no-inline-line-tables");
1852 auto updateLoopInfoLoc = [&Ctx, &InlinedAtNode,
1854 if (
auto *Loc = dyn_cast_or_null<DILocation>(MD))
1860 if (!NoInlineLineTables)
1868 if (CalleeHasDebugInfo && !NoInlineLineTables)
1878 if (
auto *AI = dyn_cast<AllocaInst>(&
I))
1885 if (isa<PseudoProbeInst>(
I))
1888 I.setDebugLoc(TheCallDL);
1893 assert(DVR->getDebugLoc() &&
"Debug Value must have debug loc");
1894 if (NoInlineLineTables) {
1895 DVR->setDebugLoc(TheCallDL);
1901 DVR->getMarker()->getParent()->
getContext(), IANodes);
1902 DVR->setDebugLoc(IDL);
1906 for (; FI != Fn->
end(); ++FI) {
1909 for (
DbgRecord &DVR :
I.getDbgRecordRange()) {
1915 if (NoInlineLineTables) {
1917 while (BI != FI->end()) {
1918 if (isa<DbgInfoIntrinsic>(BI)) {
1919 BI = BI->eraseFromParent();
1922 BI->dropDbgRecords();
1931#define DEBUG_TYPE "assignment-tracking"
1939 errs() <<
"# Finding caller local variables escaped by callee\n");
1942 if (!Arg->getType()->isPointerTy()) {
1954 assert(Arg->getType()->isPtrOrPtrVectorTy());
1955 APInt TmpOffset(
DL.getIndexTypeSizeInBits(Arg->getType()), 0,
false);
1957 Arg->stripAndAccumulateConstantOffsets(
DL, TmpOffset,
true));
1959 LLVM_DEBUG(
errs() <<
" | SKIP: Couldn't walk back to base storage\n");
1970 auto CollectAssignsForStorage = [&](
auto *DbgAssign) {
1972 if (DbgAssign->getDebugLoc().getInlinedAt())
1980 return EscapedLocals;
1986 << Start->getParent()->getName() <<
" from "
1999 for (
auto BBI = Start; BBI !=
End; ++BBI) {
2005#define DEBUG_TYPE "inline-function"
2019 for (
auto Entry : VMap) {
2020 if (!isa<BasicBlock>(Entry.first) || !Entry.second)
2022 auto *OrigBB = cast<BasicBlock>(Entry.first);
2023 auto *ClonedBB = cast<BasicBlock>(Entry.second);
2025 if (!ClonedBBs.
insert(ClonedBB).second) {
2037 EntryClone, CallerBFI->
getBlockFreq(CallSiteBlock), ClonedBBs);
2047 auto CallSiteCount =
2050 std::min(CallSiteCount.value_or(0), CalleeEntryCount.
getCount());
2055 Function *Callee, int64_t EntryDelta,
2057 auto CalleeCount = Callee->getEntryCount();
2061 const uint64_t PriorEntryCount = CalleeCount->getCount();
2066 (EntryDelta < 0 && static_cast<uint64_t>(-EntryDelta) > PriorEntryCount)
2068 : PriorEntryCount + EntryDelta;
2070 auto updateVTableProfWeight = [](
CallBase *CB,
const uint64_t NewEntryCount,
2079 uint64_t CloneEntryCount = PriorEntryCount - NewEntryCount;
2080 for (
auto Entry : *VMap) {
2081 if (isa<CallInst>(Entry.first))
2082 if (
auto *CI = dyn_cast_or_null<CallInst>(Entry.second)) {
2083 CI->updateProfWeight(CloneEntryCount, PriorEntryCount);
2084 updateVTableProfWeight(CI, CloneEntryCount, PriorEntryCount);
2087 if (isa<InvokeInst>(Entry.first))
2088 if (
auto *
II = dyn_cast_or_null<InvokeInst>(Entry.second)) {
2089 II->updateProfWeight(CloneEntryCount, PriorEntryCount);
2090 updateVTableProfWeight(
II, CloneEntryCount, PriorEntryCount);
2096 Callee->setEntryCount(NewEntryCount);
2100 if (!VMap || VMap->
count(&BB))
2102 if (
CallInst *CI = dyn_cast<CallInst>(&
I)) {
2103 CI->updateProfWeight(NewEntryCount, PriorEntryCount);
2104 updateVTableProfWeight(CI, NewEntryCount, PriorEntryCount);
2107 II->updateProfWeight(NewEntryCount, PriorEntryCount);
2108 updateVTableProfWeight(
II, NewEntryCount, PriorEntryCount);
2135 bool IsRetainRV = RVCallKind == objcarc::ARCInstKind::RetainRV,
2136 IsUnsafeClaimRV = !IsRetainRV;
2138 for (
auto *RI : Returns) {
2140 bool InsertRetainCall = IsRetainRV;
2149 if (isa<CastInst>(
I))
2152 if (
auto *
II = dyn_cast<IntrinsicInst>(&
I)) {
2153 if (
II->getIntrinsicID() != Intrinsic::objc_autoreleaseReturnValue ||
2163 if (IsUnsafeClaimRV) {
2167 II->eraseFromParent();
2168 InsertRetainCall =
false;
2172 auto *CI = dyn_cast<CallInst>(&
I);
2187 NewCall->copyMetadata(*CI);
2188 CI->replaceAllUsesWith(NewCall);
2189 CI->eraseFromParent();
2190 InsertRetainCall =
false;
2194 if (InsertRetainCall) {
2225static const std::pair<std::vector<int64_t>, std::vector<int64_t>>
2233 std::vector<int64_t> CalleeCounterMap;
2234 std::vector<int64_t> CalleeCallsiteMap;
2235 CalleeCounterMap.resize(CalleeCounters, -1);
2236 CalleeCallsiteMap.resize(CalleeCallsites, -1);
2239 if (Ins.getNameValue() == &Caller)
2241 const auto OldID =
static_cast<uint32_t>(Ins.getIndex()->getZExtValue());
2242 if (CalleeCounterMap[OldID] == -1)
2244 const auto NewID =
static_cast<uint32_t>(CalleeCounterMap[OldID]);
2246 Ins.setNameValue(&Caller);
2247 Ins.setIndex(NewID);
2252 if (Ins.getNameValue() == &Caller)
2254 const auto OldID =
static_cast<uint32_t>(Ins.getIndex()->getZExtValue());
2255 if (CalleeCallsiteMap[OldID] == -1)
2257 const auto NewID =
static_cast<uint32_t>(CalleeCallsiteMap[OldID]);
2259 Ins.setNameValue(&Caller);
2260 Ins.setIndex(NewID);
2264 std::deque<BasicBlock *> Worklist;
2281 Worklist.push_back(StartBB);
2282 while (!Worklist.empty()) {
2283 auto *BB = Worklist.front();
2284 Worklist.pop_front();
2285 bool Changed =
false;
2288 Changed |= RewriteInstrIfNeeded(*BBID);
2292 BBID->moveBefore(BB->getFirstInsertionPt());
2295 if (
auto *Inc = dyn_cast<InstrProfIncrementInst>(&
I)) {
2296 if (isa<InstrProfIncrementInstStep>(Inc)) {
2303 if (isa<Constant>(Inc->getStep())) {
2304 assert(!Inc->getNextNode() || !isa<SelectInst>(Inc->getNextNode()));
2305 Inc->eraseFromParent();
2307 assert(isa_and_nonnull<SelectInst>(Inc->getNextNode()));
2308 RewriteInstrIfNeeded(*Inc);
2310 }
else if (Inc != BBID) {
2315 Inc->eraseFromParent();
2318 }
else if (
auto *CS = dyn_cast<InstrProfCallsite>(&
I)) {
2319 Changed |= RewriteCallsiteInsIfNeeded(*CS);
2322 if (!BBID || Changed)
2324 if (Seen.
insert(Succ).second)
2325 Worklist.push_back(Succ);
2329 llvm::all_of(CalleeCounterMap, [&](
const auto &V) {
return V != 0; }) &&
2330 "Counter index mapping should be either to -1 or to non-zero index, "
2332 "index corresponds to the entry BB of the caller");
2334 llvm::all_of(CalleeCallsiteMap, [&](
const auto &V) {
return V != 0; }) &&
2335 "Callsite index mapping should be either to -1 or to non-zero index, "
2336 "because there should have been at least a callsite - the inlined one "
2337 "- which would have had a 0 index.");
2339 return {std::move(CalleeCounterMap), std::move(CalleeCallsiteMap)};
2358 bool MergeAttributes,
2360 bool InsertLifetime,
2363 return InlineFunction(CB, IFI, MergeAttributes, CalleeAAR, InsertLifetime,
2375 const auto CallsiteID =
2376 static_cast<uint32_t>(CallsiteIDIns->getIndex()->getZExtValue());
2381 auto Ret =
InlineFunction(CB, IFI, MergeAttributes, CalleeAAR, InsertLifetime,
2383 if (!Ret.isSuccess())
2388 CallsiteIDIns->eraseFromParent();
2393 const auto IndicesMaps =
remapIndices(Caller, StartBB, CtxProf,
2394 NumCalleeCounters, NumCalleeCallsites);
2399 const auto &[CalleeCounterMap, CalleeCallsiteMap] = IndicesMaps;
2401 (Ctx.counters().size() +
2402 llvm::count_if(CalleeCounterMap, [](
auto V) { return V != -1; }) ==
2404 "The caller's counters size should have grown by the number of new "
2405 "distinct counters inherited from the inlined callee.");
2406 Ctx.resizeCounters(NewCountersSize);
2410 auto CSIt = Ctx.callsites().find(CallsiteID);
2411 if (CSIt == Ctx.callsites().end())
2413 auto CalleeCtxIt = CSIt->second.find(CalleeGUID);
2416 if (CalleeCtxIt == CSIt->second.end())
2421 auto &CalleeCtx = CalleeCtxIt->second;
2422 assert(CalleeCtx.guid() == CalleeGUID);
2424 for (
auto I = 0U;
I < CalleeCtx.counters().
size(); ++
I) {
2425 const int64_t NewIndex = CalleeCounterMap[
I];
2426 if (NewIndex >= 0) {
2427 assert(NewIndex != 0 &&
"counter index mapping shouldn't happen to a 0 "
2428 "index, that's the caller's entry BB");
2429 Ctx.counters()[NewIndex] = CalleeCtx.counters()[
I];
2432 for (
auto &[
I, OtherSet] : CalleeCtx.callsites()) {
2433 const int64_t NewCSIdx = CalleeCallsiteMap[
I];
2434 if (NewCSIdx >= 0) {
2436 "callsite index mapping shouldn't happen to a 0 index, the "
2437 "caller must've had at least one callsite (with such an index)");
2438 Ctx.ingestAllContexts(NewCSIdx, std::move(OtherSet));
2444 auto Deleted = Ctx.callsites().erase(CallsiteID);
2448 CtxProf.
update(Updater, Caller);
2461 bool MergeAttributes,
2463 bool InsertLifetime,
2468 if (isa<CallBrInst>(CB))
2481 Value *ConvergenceControlToken =
nullptr;
2497 ConvergenceControlToken = OBUse.Inputs[0].get();
2515 if (!ConvergenceControlToken &&
2518 "convergent call needs convergencectrl operand");
2533 if (CalledFunc->
hasGC()) {
2534 if (!Caller->hasGC())
2535 Caller->setGC(CalledFunc->
getGC());
2536 else if (CalledFunc->
getGC() != Caller->getGC())
2550 Caller->hasPersonalityFn()
2551 ? Caller->getPersonalityFn()->stripPointerCasts()
2553 if (CalledPersonality) {
2554 if (!CallerPersonality)
2555 Caller->setPersonalityFn(CalledPersonality);
2560 else if (CalledPersonality != CallerPersonality)
2567 if (CallerPersonality) {
2570 std::optional<OperandBundleUse> ParentFunclet =
2573 CallSiteEHPad = cast<FuncletPadInst>(ParentFunclet->Inputs.front());
2577 if (CallSiteEHPad) {
2578 if (Personality == EHPersonality::MSVC_CXX) {
2581 if (isa<CleanupPadInst>(CallSiteEHPad)) {
2584 for (
const BasicBlock &CalledBB : *CalledFunc) {
2585 if (isa<CatchSwitchInst>(CalledBB.getFirstNonPHIIt()))
2592 for (
const BasicBlock &CalledBB : *CalledFunc) {
2593 if (CalledBB.isEHPad())
2603 bool EHPadForCallUnwindsLocally =
false;
2604 if (CallSiteEHPad && isa<CallInst>(CB)) {
2606 Value *CallSiteUnwindDestToken =
2609 EHPadForCallUnwindsLocally =
2610 CallSiteUnwindDestToken &&
2611 !isa<ConstantTokenNone>(CallSiteUnwindDestToken);
2642 auto &
DL = Caller->getDataLayout();
2649 E = CalledFunc->
arg_end();
I != E; ++
I, ++AI, ++ArgNo) {
2650 Value *ActualArg = *AI;
2658 &CB, CalledFunc, IFI,
2660 if (ActualArg != *AI)
2665 VMap[&*
I] = ActualArg;
2685 false, Returns,
".i",
2686 &InlinedFunctionInfo);
2688 FirstNewBlock = LastBlock; ++FirstNewBlock;
2692 if (RVCallKind != objcarc::ARCInstKind::None)
2703 CalledFunc->
front());
2711 for (ByValInit &
Init : ByValInits)
2713 &*FirstNewBlock, IFI, CalledFunc);
2715 std::optional<OperandBundleUse> ParentDeopt =
2721 CallBase *ICS = dyn_cast_or_null<CallBase>(VH);
2742 std::vector<Value *> MergedDeoptArgs;
2743 MergedDeoptArgs.reserve(ParentDeopt->Inputs.size() +
2744 ChildOB.Inputs.size());
2749 OpDefs.
emplace_back(
"deopt", std::move(MergedDeoptArgs));
2779 SAMetadataCloner.clone();
2780 SAMetadataCloner.remap(FirstNewBlock, Caller->end());
2802 make_range(FirstNewBlock->getIterator(), Caller->end()))
2804 if (
auto *
II = dyn_cast<AssumeInst>(&
I))
2808 if (ConvergenceControlToken) {
2810 if (IntrinsicCall) {
2823 E = FirstNewBlock->end();
I != E; ) {
2842 while (isa<AllocaInst>(
I) &&
2843 !cast<AllocaInst>(
I)->use_empty() &&
2853 Caller->getEntryBlock().splice(InsertPoint, &*FirstNewBlock,
2866 bool InlinedMustTailCalls =
false, InlinedDeoptimizeCalls =
false;
2869 if (
CallInst *CI = dyn_cast<CallInst>(&CB))
2870 CallSiteTailKind = CI->getTailCallKind();
2885 if (!VarArgsToForward.
empty() &&
2886 ((ForwardVarArgsTo &&
2892 if (!Attrs.isEmpty() || !VarArgsAttrs.
empty()) {
2893 for (
unsigned ArgNo = 0;
2895 ArgAttrs.
push_back(Attrs.getParamAttrs(ArgNo));
2901 Attrs.getRetAttrs(), ArgAttrs);
2916 InlinedDeoptimizeCalls |=
2917 F->getIntrinsicID() == Intrinsic::experimental_deoptimize;
2936 ChildTCK = std::min(CallSiteTailKind, ChildTCK);
2955 if ((InsertLifetime || Caller->isPresplitCoroutine()) &&
2957 IRBuilder<> builder(&*FirstNewBlock, FirstNewBlock->begin());
2972 auto &
DL = Caller->getDataLayout();
2974 TypeSize AllocaTypeSize =
DL.getTypeAllocSize(AllocaType);
2975 uint64_t AllocaArraySize = AIArraySize->getLimitedValue();
2978 if (AllocaArraySize == 0)
2984 AllocaArraySize != std::numeric_limits<uint64_t>::max() &&
2985 std::numeric_limits<uint64_t>::max() / AllocaArraySize >=
2988 AllocaArraySize * AllocaTypeSize);
2996 if (InlinedMustTailCalls &&
2997 RI->
getParent()->getTerminatingMustTailCall())
2999 if (InlinedDeoptimizeCalls &&
3000 RI->
getParent()->getTerminatingDeoptimizeCall())
3019 if (InlinedMustTailCalls && RI->
getParent()->getTerminatingMustTailCall())
3021 if (InlinedDeoptimizeCalls && RI->
getParent()->getTerminatingDeoptimizeCall())
3031 if (
auto *
II = dyn_cast<InvokeInst>(&CB)) {
3034 if (isa<LandingPadInst>(FirstNonPHI)) {
3044 if (CallSiteEHPad) {
3055 if (
auto *CleanupRet = dyn_cast<CleanupReturnInst>(BB->getTerminator()))
3056 if (CleanupRet->unwindsToCaller() && EHPadForCallUnwindsLocally)
3063 if (
auto *CatchSwitch = dyn_cast<CatchSwitchInst>(
I)) {
3064 if (isa<ConstantTokenNone>(CatchSwitch->getParentPad()))
3065 CatchSwitch->setParentPad(CallSiteEHPad);
3067 auto *FPI = cast<FuncletPadInst>(
I);
3068 if (isa<ConstantTokenNone>(FPI->getParentPad()))
3069 FPI->setParentPad(CallSiteEHPad);
3074 if (InlinedDeoptimizeCalls) {
3080 if (Caller->getReturnType() == CB.
getType()) {
3082 return RI->
getParent()->getTerminatingDeoptimizeCall() !=
nullptr;
3087 Caller->getParent(), Intrinsic::experimental_deoptimize,
3088 {Caller->getReturnType()});
3114 "Expected at least the deopt operand bundle");
3118 Builder.
CreateCall(NewDeoptIntrinsic, CallArgs, OpBundles);
3139 if (InlinedMustTailCalls) {
3141 Type *NewRetTy = Caller->getReturnType();
3148 RI->
getParent()->getTerminatingMustTailCall();
3149 if (!ReturnedMustTail) {
3158 auto *OldCast = dyn_cast_or_null<BitCastInst>(RI->getReturnValue());
3161 OldCast->eraseFromParent();
3181 make_range(FirstNewBlock->getIterator(), Caller->end()))
3183 if (
auto *CB = dyn_cast<CallBase>(&
I))
3192 if (Returns.
size() == 1 && std::distance(FirstNewBlock, Caller->end()) == 1) {
3195 FirstNewBlock->end());
3197 Caller->back().eraseFromParent();
3210 if (&CB == R->getReturnValue())
3219 Returns[0]->eraseFromParent();
3221 if (MergeAttributes)
3235 BranchInst *CreatedBranchToNormalDest =
nullptr;
3246 CalledFunc->
getName() +
".exit");
3253 CalledFunc->
getName() +
".exit");
3267 "splitBasicBlock broken!");
3273 Caller->splice(AfterCallBB->
getIterator(), Caller, FirstNewBlock,
3281 if (Returns.
size() > 1) {
3286 PHI->insertBefore(AfterCallBB->
begin());
3297 "Ret value not consistent in function!");
3298 PHI->addIncoming(RI->getReturnValue(), RI->
getParent());
3314 if (CreatedBranchToNormalDest)
3316 }
else if (!Returns.
empty()) {
3320 if (&CB == Returns[0]->getReturnValue())
3327 BasicBlock *ReturnBB = Returns[0]->getParent();
3332 AfterCallBB->
splice(AfterCallBB->
begin(), ReturnBB);
3334 if (CreatedBranchToNormalDest)
3338 Returns[0]->eraseFromParent();
3351 if (InlinedMustTailCalls &&
pred_empty(AfterCallBB))
3356 assert(cast<BranchInst>(Br)->isUnconditional() &&
"splitBasicBlock broken!");
3357 BasicBlock *CalleeEntry = cast<BranchInst>(Br)->getSuccessor(0);
3376 auto &
DL = Caller->getDataLayout();
3378 PHI->replaceAllUsesWith(V);
3379 PHI->eraseFromParent();
3383 if (MergeAttributes)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB, ArrayRef< BasicBlock * > Preds, BranchInst *BI, bool HasLoopExit)
Update the PHI nodes in OrigBB to include the values coming from NewBB.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static cl::opt< bool > NoAliases("csky-no-aliases", cl::desc("Disable the emission of assembler pseudo instructions"), cl::init(false), cl::Hidden)
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Module.h This file contains the declarations for the Module class.
static AttrBuilder IdentifyValidUBGeneratingAttributes(CallBase &CB)
static at::StorageToVarsMap collectEscapedLocals(const DataLayout &DL, const CallBase &CB)
Find Alloca and linked DbgAssignIntrinsic for locals escaped by CB.
static void fixupLineNumbers(Function *Fn, Function::iterator FI, Instruction *TheCall, bool CalleeHasDebugInfo)
Update inlined instructions' line numbers to to encode location where these instructions are inlined.
static void removeCallsiteMetadata(CallBase *Call)
static void propagateMemProfHelper(const CallBase *OrigCall, CallBase *ClonedCall, MDNode *InlinedCallsiteMD)
static Value * getUnwindDestToken(Instruction *EHPad, UnwindDestMemoTy &MemoMap)
Given an EH pad, find where it unwinds.
static cl::opt< bool > PreserveAlignmentAssumptions("preserve-alignment-assumptions-during-inlining", cl::init(false), cl::Hidden, cl::desc("Convert align attributes to assumptions during inlining."))
static void HandleInlinedLandingPad(InvokeInst *II, BasicBlock *FirstNewBlock, ClonedCodeInfo &InlinedCodeInfo)
If we inlined an invoke site, we need to convert calls in the body of the inlined function into invok...
static Value * getUnwindDestTokenHelper(Instruction *EHPad, UnwindDestMemoTy &MemoMap)
Helper for getUnwindDestToken that does the descendant-ward part of the search.
static BasicBlock * HandleCallsInBlockInlinedThroughInvoke(BasicBlock *BB, BasicBlock *UnwindEdge, UnwindDestMemoTy *FuncletUnwindMap=nullptr)
When we inline a basic block into an invoke, we have to turn all of the calls that can throw into inv...
static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &IANodes)
Returns a DebugLoc for a new DILocation which is a clone of OrigDL inlined at InlinedAt.
static cl::opt< bool > UseNoAliasIntrinsic("use-noalias-intrinsic-during-inlining", cl::Hidden, cl::init(true), cl::desc("Use the llvm.experimental.noalias.scope.decl " "intrinsic during inlining."))
static void PropagateCallSiteMetadata(CallBase &CB, Function::iterator FStart, Function::iterator FEnd)
When inlining a call site that has !llvm.mem.parallel_loop_access, !llvm.access.group,...
static AttrBuilder IdentifyValidPoisonGeneratingAttributes(CallBase &CB)
static void propagateMemProfMetadata(Function *Callee, CallBase &CB, bool ContainsMemProfMetadata, const ValueMap< const Value *, WeakTrackingVH > &VMap)
static void updateCallProfile(Function *Callee, const ValueToValueMapTy &VMap, const ProfileCount &CalleeEntryCount, const CallBase &TheCall, ProfileSummaryInfo *PSI, BlockFrequencyInfo *CallerBFI)
Update the branch metadata for cloned call instructions.
static void updateCallerBFI(BasicBlock *CallSiteBlock, const ValueToValueMapTy &VMap, BlockFrequencyInfo *CallerBFI, BlockFrequencyInfo *CalleeBFI, const BasicBlock &CalleeEntryBlock)
Update the block frequencies of the caller after a callee has been inlined.
static void AddReturnAttributes(CallBase &CB, ValueToValueMapTy &VMap, ClonedCodeInfo &InlinedFunctionInfo)
static bool MayContainThrowingOrExitingCallAfterCB(CallBase *Begin, ReturnInst *End)
static void HandleByValArgumentInit(Type *ByValType, Value *Dst, Value *Src, Module *M, BasicBlock *InsertBlock, InlineFunctionInfo &IFI, Function *CalledFunc)
static cl::opt< bool > EnableNoAliasConversion("enable-noalias-to-md-conversion", cl::init(true), cl::Hidden, cl::desc("Convert noalias attributes to metadata during inlining."))
static void AddAliasScopeMetadata(CallBase &CB, ValueToValueMapTy &VMap, const DataLayout &DL, AAResults *CalleeAAR, ClonedCodeInfo &InlinedFunctionInfo)
If the inlined function has noalias arguments, then add new alias scopes for each noalias argument,...
static const std::pair< std::vector< int64_t >, std::vector< int64_t > > remapIndices(Function &Caller, BasicBlock *StartBB, PGOContextualProfile &CtxProf, uint32_t CalleeCounters, uint32_t CalleeCallsites)
static IntrinsicInst * getConvergenceEntry(BasicBlock &BB)
static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock, ClonedCodeInfo &InlinedCodeInfo)
If we inlined an invoke site, we need to convert calls in the body of the inlined function into invok...
static void inlineRetainOrClaimRVCalls(CallBase &CB, objcarc::ARCInstKind RVCallKind, const SmallVectorImpl< ReturnInst * > &Returns)
An operand bundle "clang.arc.attachedcall" on a call indicates the call result is implicitly consumed...
static Value * getParentPad(Value *EHPad)
Helper for getUnwindDestToken/getUnwindDestTokenHelper.
static void fixupAssignments(Function::iterator Start, Function::iterator End)
Update inlined instructions' DIAssignID metadata.
static bool allocaWouldBeStaticInEntry(const AllocaInst *AI)
Return the result of AI->isStaticAlloca() if AI were moved to the entry block.
static bool isUsedByLifetimeMarker(Value *V)
static void removeMemProfMetadata(CallBase *Call)
static Value * HandleByValArgument(Type *ByValType, Value *Arg, Instruction *TheCall, const Function *CalledFunc, InlineFunctionInfo &IFI, MaybeAlign ByValAlignment)
When inlining a call site that has a byval argument, we have to make the implicit memcpy explicit by ...
static void AddAlignmentAssumptions(CallBase &CB, InlineFunctionInfo &IFI)
If the inlined function has non-byval align arguments, then add @llvm.assume-based alignment assumpti...
static void trackInlinedStores(Function::iterator Start, Function::iterator End, const CallBase &CB)
static cl::opt< unsigned > InlinerAttributeWindow("max-inst-checked-for-throw-during-inlining", cl::Hidden, cl::desc("the maximum number of instructions analyzed for may throw during " "attribute inference in inlined body"), cl::init(4))
static void AddParamAndFnBasicAttributes(const CallBase &CB, ValueToValueMapTy &VMap, ClonedCodeInfo &InlinedFunctionInfo)
static bool haveCommonPrefix(MDNode *MIBStackContext, MDNode *CallsiteStackContext)
static void PropagateOperandBundles(Function::iterator InlinedBB, Instruction *CallSiteEHPad)
Bundle operands of the inlined function must be added to inlined call sites.
static bool hasLifetimeMarkers(AllocaInst *AI)
static void updateMemprofMetadata(CallBase *CI, const std::vector< Metadata * > &MIBList)
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
uint64_t IntrinsicInst * II
This file defines common analysis utilities used by the ObjC ARC Optimizer.
This file defines ARC utility functions which are used by various parts of the compiler.
This file contains the declarations for profiling metadata utility functions.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
MemoryEffects getMemoryEffects(const CallBase *Call)
Return the behavior of the given call site.
Class for arbitrary precision integers.
an instruction to allocate memory on the stack
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
PointerType * getType() const
Overload to return most specific pointer type.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
bool isUsedWithInAlloca() const
Return true if this alloca is used as an inalloca argument to a call.
const Value * getArraySize() const
Get the number of elements allocated.
This class represents an incoming formal argument to a Function.
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
static uint64_t getGUID(const Function &F)
A cache of @llvm.assume calls within a function.
void registerAssumption(AssumeInst *CI)
Add an @llvm.assume intrinsic to this function's cache.
An instruction that atomically checks whether a specified value is in a memory location,...
an instruction that atomically reads a memory location, combines it with another value,...
AttrBuilder & addAlignmentAttr(MaybeAlign Align)
This turns an alignment into the form used internally in Attribute.
Attribute getAttribute(Attribute::AttrKind Kind) const
Return Attribute with the given Kind.
uint64_t getDereferenceableBytes() const
Retrieve the number of dereferenceable bytes, if the dereferenceable attribute exists (zero is return...
bool hasAttributes() const
Return true if the builder has IR-level attributes.
AttrBuilder & addAttribute(Attribute::AttrKind Val)
Add an attribute to the builder.
MaybeAlign getAlignment() const
Retrieve the alignment attribute, if it exists.
AttrBuilder & addDereferenceableAttr(uint64_t Bytes)
This turns the number of dereferenceable bytes into the form used internally in Attribute.
uint64_t getDereferenceableOrNullBytes() const
Retrieve the number of dereferenceable_or_null bytes, if the dereferenceable_or_null attribute exists...
AttrBuilder & removeAttribute(Attribute::AttrKind Val)
Remove an attribute from the builder.
AttrBuilder & addDereferenceableOrNullAttr(uint64_t Bytes)
This turns the number of dereferenceable_or_null bytes into the form used internally in Attribute.
AttrBuilder & addRangeAttr(const ConstantRange &CR)
Add range attribute.
AttributeList addRetAttributes(LLVMContext &C, const AttrBuilder &B) const
Add a return value attribute to the list.
static AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
AttributeSet getParamAttrs(unsigned ArgNo) const
The attributes for the argument or parameter at the given index are returned.
AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const
Remove the specified attribute from this set.
static AttributeSet get(LLVMContext &C, const AttrBuilder &B)
const ConstantRange & getRange() const
Returns the value of the range attribute.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results,...
bool isValid() const
Return true if the attribute is any kind of attribute.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
InstListType::const_iterator getFirstNonPHIIt() const
Iterator returning form of getFirstNonPHI.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
const Function * getParent() const
Return the enclosing method, or null if none.
SymbolTableList< BasicBlock >::iterator eraseFromParent()
Unlink 'this' from the containing function and delete it.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
void splice(BasicBlock::iterator ToIt, BasicBlock *FromBB)
Transfer all instructions from FromBB to this basic block at ToIt.
void removePredecessor(BasicBlock *Pred, bool KeepOneInputPHIs=false)
Update PHI nodes in this BasicBlock before removal of predecessor Pred.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
void setBlockFreq(const BasicBlock *BB, BlockFrequency Freq)
void setBlockFreqAndScale(const BasicBlock *ReferenceBB, BlockFrequency Freq, SmallPtrSetImpl< BasicBlock * > &BlocksToScale)
Set the frequency of ReferenceBB to Freq and scale the frequencies of the blocks in BlocksToScale suc...
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
void setCallingConv(CallingConv::ID CC)
MaybeAlign getRetAlign() const
Extract the alignment of the return value.
void getOperandBundlesAsDefs(SmallVectorImpl< OperandBundleDef > &Defs) const
Return the list of operand bundles attached to this instruction as a vector of OperandBundleDefs.
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
std::optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
void removeRetAttrs(const AttributeMask &AttrsToRemove)
Removes the attributes from the return value.
bool hasRetAttr(Attribute::AttrKind Kind) const
Determine whether the return value has the given attribute.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
CallingConv::ID getCallingConv() const
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Get the attribute of a given kind from a given arg.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
static CallBase * addOperandBundle(CallBase *CB, uint32_t ID, OperandBundleDef OB, InsertPosition InsertPt=nullptr)
Create a clone of CB with operand bundle OB added.
AttributeSet getRetAttributes() const
Return the return attributes for this call.
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a call or parameter.
Value * getCalledOperand() const
void setAttributes(AttributeList A)
Set the attributes for this call.
std::optional< ConstantRange > getRange() const
If this return value has a range attribute, return the value range of the argument.
bool doesNotThrow() const
Determine if the call cannot unwind.
Value * getArgOperand(unsigned i) const
uint64_t getRetDereferenceableBytes() const
Extract the number of dereferenceable bytes for a call or parameter (0=unknown).
bool isConvergent() const
Determine if the invoke is convergent.
FunctionType * getFunctionType() const
static CallBase * Create(CallBase *CB, ArrayRef< OperandBundleDef > Bundles, InsertPosition InsertPt=nullptr)
Create a clone of CB with a different set of operand bundles and insert it before InsertPt.
uint64_t getRetDereferenceableOrNullBytes() const
Extract the number of dereferenceable_or_null bytes for a call (0=unknown).
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
bool hasOperandBundles() const
Return true if this User has any operand bundles.
Function * getCaller()
Helper to get the caller (the parent function).
This class represents a function call, abstracting a target machine's calling convention.
void setTailCallKind(TailCallKind TCK)
TailCallKind getTailCallKind() const
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
bool isMustTailCall() const
static CatchSwitchInst * Create(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumHandlers, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static CleanupReturnInst * Create(Value *CleanupPad, BasicBlock *UnwindBB=nullptr, InsertPosition InsertBefore=nullptr)
This is the shared class of boolean and integer constants.
This class represents a range of values.
ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
This is an important base class in LLVM.
const Constant * stripPointerCasts() const
static InstrProfIncrementInst * getBBInstrumentation(BasicBlock &BB)
Get the instruction instrumenting a BB, or nullptr if not present.
static InstrProfCallsite * getCallsiteInstrumentation(CallBase &CB)
Get the instruction instrumenting a callsite, or nullptr if that cannot be found.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
Base class for non-instruction debug metadata records that have positions within IR.
DILocation * get() const
Get the underlying DILocation.
MDNode * getScope() const
static DebugLoc appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Rebuild the entire inlined-at chain for this instruction so that the top of the chain now is inlined-...
iterator find(const_arg_type_t< KeyT > Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
void recalculate(ParentType &Func)
recalculate - compute a dominator tree for the given function
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Class to represent profile counts.
uint64_t getCount() const
const BasicBlock & getEntryBlock() const
BasicBlockListType::iterator iterator
FunctionType * getFunctionType() const
Returns the FunctionType for me.
const BasicBlock & front() const
iterator_range< arg_iterator > args()
DISubprogram * getSubprogram() const
Get the attached subprogram.
bool hasGC() const
hasGC/getGC/setGC/clearGC - The name of the garbage collection algorithm to use during code generatio...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
bool hasPersonalityFn() const
Check whether this function has a personality function.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
MaybeAlign getParamAlign(unsigned ArgNo) const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
const std::string & getGC() const
std::optional< ProfileCount > getEntryCount(bool AllowSynthetic=false) const
Get the entry count for this function.
Type * getReturnType() const
Returns the type of the ret val.
void setCallingConv(CallingConv::ID CC)
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
CallInst * CreateStackSave(const Twine &Name="")
Create a call to llvm.stacksave.
CallInst * CreateLifetimeStart(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.start intrinsic.
CallInst * CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue, unsigned Alignment, Value *OffsetValue=nullptr)
Create an assume intrinsic call that represents an alignment assumption on the provided pointer.
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
CallInst * CreateLifetimeEnd(Value *Ptr, ConstantInt *Size=nullptr)
Create a lifetime.end intrinsic.
CallInst * CreateStackRestore(Value *Ptr, const Twine &Name="")
Create a call to llvm.stackrestore.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
CallInst * CreateMemCpy(Value *Dst, MaybeAlign DstAlign, Value *Src, MaybeAlign SrcAlign, uint64_t Size, bool isVolatile=false, MDNode *TBAATag=nullptr, MDNode *TBAAStructTag=nullptr, MDNode *ScopeTag=nullptr, MDNode *NoAliasTag=nullptr)
Create and insert a memcpy between the specified pointers.
Instruction * CreateNoAliasScopeDeclaration(Value *Scope)
Create a llvm.experimental.noalias.scope.decl intrinsic call.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
This class captures the data input to the InlineFunction call, and records the auxiliary results prod...
bool UpdateProfile
Update profile for callee as well as cloned version.
function_ref< AssumptionCache &(Function &)> GetAssumptionCache
If non-null, InlineFunction will update the callgraph to reflect the changes it makes.
BlockFrequencyInfo * CalleeBFI
SmallVector< AllocaInst *, 4 > StaticAllocas
InlineFunction fills this in with all static allocas that get copied into the caller.
BlockFrequencyInfo * CallerBFI
SmallVector< CallBase *, 8 > InlinedCallSites
All of the new call sites inlined into the caller.
InlineResult is basically true or false.
static InlineResult success()
static InlineResult failure(const char *Reason)
This represents the llvm.instrprof.callsite intrinsic.
This represents the llvm.instrprof.increment intrinsic.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
bool hasMetadata() const
Return true if this instruction has any metadata attached to it.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
const Function * getFunction() const
Return the function this instruction belongs to.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
A wrapper class for inspecting calls to intrinsic functions.
static bool mayLowerToFunctionCall(Intrinsic::ID IID)
Check if the intrinsic might lower into a regular function call in the course of IR transformations.
This is an important class for using LLVM in a threaded context.
@ OB_clang_arc_attachedcall
The landingpad instruction holds all of the information necessary to generate correct exception handl...
bool isCleanup() const
Return 'true' if this landingpad instruction is a cleanup.
unsigned getNumClauses() const
Get the number of clauses for this landing pad.
Constant * getClause(unsigned Idx) const
Get the value of the clause at index Idx.
An instruction for reading from memory.
MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())
Return metadata appropriate for an alias scope root node.
MDNode * createAnonymousAliasScopeDomain(StringRef Name=StringRef())
Return metadata appropriate for an alias scope domain node.
void replaceAllUsesWith(Metadata *MD)
RAUW a temporary.
static MDNode * concatenate(MDNode *A, MDNode *B)
Methods for metadata merging.
ArrayRef< MDOperand > operands() const
op_iterator op_end() const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
op_iterator op_begin() const
LLVMContext & getContext() const
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
bool onlyAccessesInaccessibleMem() const
Whether this function only (at most) accesses inaccessible memory.
bool onlyAccessesArgPointees() const
Whether this function only (at most) accesses argument memory.
A Module instance is used to store all the information related to an LLVM module.
A container for an operand bundle being viewed as a set of values rather than a set of uses.
The instrumented contextual profile, produced by the CtxProfAnalysis.
void update(Visitor, const Function &F)
uint32_t getNumCounters(const Function &F) const
uint32_t allocateNextCounterIndex(const Function &F)
uint32_t getNumCallsites(const Function &F) const
uint32_t allocateNextCallsiteIndex(const Function &F)
A node (context) in the loaded contextual profile, suitable for mutation during IPO passes.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Analysis providing profile information.
std::optional< uint64_t > getProfileCount(const CallBase &CallInst, BlockFrequencyInfo *BFI, bool AllowSynthetic=false) const
Returns the profile count for CallInst.
Resume the propagation of an exception.
Return a value (possibly void), from a function.
A vector that has set insertion semantics.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt64Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
This class represents the va_arg llvm instruction, which returns an argument of the specified type gi...
ValueT lookup(const KeyT &Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
size_type count(const KeyT &Val) const
Return 1 if the specified key is in the map, 0 otherwise.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
LLVMContext & getContext() const
All values hold a context through their type.
StringRef getName() const
Return a constant reference to the value's name.
void takeName(Value *V)
Transfer the name from V to this value.
std::pair< iterator, bool > insert(const ValueT &V)
constexpr ScalarTy getFixedValue() const
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
const ParentTy * getParent() const
self_iterator getIterator()
Class to build a trie of call stack contexts for a particular profiled allocation call,...
Helper class to iterate through stack ids in both metadata (memprof MIB and callsite) and the corresp...
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
AttributeMask typeIncompatible(Type *Ty, AttributeSet AS, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
void mergeAttributesForInlining(Function &Caller, const Function &Callee)
Merge caller's and callee's attributes.
Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
bool match(Val *V, const Pattern &P)
match_combine_and< class_match< Constant >, match_unless< constantexpr_match > > m_ImmConstant()
Match an arbitrary immediate Constant and ignore it.
AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID)
Return a range of dbg.assign intrinsics which use \ID as an operand.
void trackAssignments(Function::iterator Start, Function::iterator End, const StorageToVarsMap &Vars, const DataLayout &DL, bool DebugPrints=false)
Track assignments to Vars between Start and End.
void remapAssignID(DenseMap< DIAssignID *, DIAssignID * > &Map, Instruction &I)
Replace DIAssignID uses and attachments with IDs from Map.
SmallVector< DbgVariableRecord * > getDVRAssignmentMarkers(const Instruction *Inst)
initializer< Ty > init(const Ty &Val)
MDNode * getMIBStackNode(const MDNode *MIB)
Returns the stack node from an MIB metadata node.
ARCInstKind getAttachedARCFunctionKind(const CallBase *CB)
This function returns the ARCInstKind of the function attached to operand bundle clang_arc_attachedca...
ARCInstKind
Equivalence classes of instructions in the ARC Model.
std::optional< Function * > getAttachedARCFunction(const CallBase *CB)
This function returns operand bundle clang_arc_attachedcall's argument, which is the address of the A...
bool isRetainOrClaimRV(ARCInstKind Kind)
Check whether the function is retainRV/unsafeClaimRV.
const Value * GetRCIdentityRoot(const Value *V)
The RCIdentity root of a value V is a dominating value U for which retaining or releasing U is equiva...
bool hasAttachedCallOpBundle(const CallBase *CB)
This is an optimization pass for GlobalISel generic memory operations.
UnaryFunction for_each(R &&Range, UnaryFunction F)
Provide wrappers to std::for_each which take ranges instead of having to pass begin/end explicitly.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
BasicBlock * changeToInvokeAndSplitBasicBlock(CallInst *CI, BasicBlock *UnwindEdge, DomTreeUpdater *DTU=nullptr)
Convert the CallInst to InvokeInst with the specified unwind edge basic block.
auto successors(const MachineBasicBlock *BB)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool PointerMayBeCapturedBefore(const Value *V, bool ReturnCaptures, bool StoreCaptures, const Instruction *I, const DominatorTree *DT, bool IncludeI=false, unsigned MaxUsesToExplore=0, const LoopInfo *LI=nullptr)
PointerMayBeCapturedBefore - Return true if this pointer value may be captured by the enclosing funct...
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool isScopedEHPersonality(EHPersonality Pers)
Returns true if this personality uses scope-style EH IR instructions: catchswitch,...
Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
Align getKnownAlignment(Value *V, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to infer an alignment for the specified pointer.
Align getOrEnforceKnownAlignment(Value *V, MaybeAlign PrefAlign, const DataLayout &DL, const Instruction *CxtI=nullptr, AssumptionCache *AC=nullptr, const DominatorTree *DT=nullptr)
Try to ensure that the alignment of V is at least PrefAlign bytes.
void CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, bool ModuleLevelChanges, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr)
This works exactly like CloneFunctionInto, except that it does some simple constant prop and DCE on t...
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
unsigned changeToUnreachable(Instruction *I, bool PreserveLCSSA=false, DomTreeUpdater *DTU=nullptr, MemorySSAUpdater *MSSAU=nullptr)
Insert an unreachable instruction before the specified instruction, making it and the rest of the cod...
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool salvageKnowledge(Instruction *I, AssumptionCache *AC=nullptr, DominatorTree *DT=nullptr)
Calls BuildAssumeFromInst and if the resulting llvm.assume is valid insert if before I.
void updateProfileCallee(Function *Callee, int64_t EntryDelta, const ValueMap< const Value *, WeakTrackingVH > *VMap=nullptr)
Updates profile information by adjusting the entry count by adding EntryDelta then scaling callsite i...
bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
MDNode * uniteAccessGroups(MDNode *AccGroups1, MDNode *AccGroups2)
Compute the union of two access-group lists.
InlineResult InlineFunction(CallBase &CB, InlineFunctionInfo &IFI, bool MergeAttributes=false, AAResults *CalleeAAR=nullptr, bool InsertLifetime=true, Function *ForwardVarArgsTo=nullptr)
This function inlines the called function into the basic block of the caller.
bool isAsynchronousEHPersonality(EHPersonality Pers)
Returns true if this personality function catches asynchronous exceptions.
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...
bool isEscapeSource(const Value *V)
Returns true if the pointer is one which would have been considered an escape by isNonEscapingLocalOb...
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
void getUnderlyingObjects(const Value *V, SmallVectorImpl< const Value * > &Objects, const LoopInfo *LI=nullptr, unsigned MaxLookup=6)
This method is similar to getUnderlyingObject except that it can look through phi and select instruct...
bool pred_empty(const BasicBlock *BB)
void updateLoopMetadataDebugLocations(Instruction &I, function_ref< Metadata *(Metadata *)> Updater)
Update the debug locations contained within the MD_loop metadata attached to the instruction I,...
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
void scaleProfData(Instruction &I, uint64_t S, uint64_t T)
Scaling the profile data attached to 'I' using the ratio of S/T.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
This struct can be used to capture information about code being cloned, while it is being cloned.
bool ContainsDynamicAllocas
This is set to true if the cloned code contains a 'dynamic' alloca.
bool isSimplified(const Value *From, const Value *To) const
bool ContainsCalls
This is set to true if the cloned code contains a normal call instruction.
bool ContainsMemProfMetadata
This is set to true if there is memprof related metadata (memprof or callsite metadata) in the cloned...
std::vector< WeakTrackingVH > OperandBundleCallSites
All cloned call sites that have operand bundles attached are appended to this vector.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.
static Instruction * tryGetVTableInstruction(CallBase *CB)
Helper struct for trackAssignments, below.