73#define DEBUG_TYPE "code-extractor"
81 cl::desc(
"Aggregate arguments to code-extracted functions"));
86 bool AllowVarArgs,
bool AllowAlloca) {
96 while (!ToVisit.
empty()) {
98 if (!Visited.
insert(Curr).second)
100 if (isa<BlockAddress const>(Curr))
103 if (isa<Instruction>(Curr) && cast<Instruction>(Curr)->
getParent() != &BB)
106 for (
auto const &U : Curr->
operands()) {
107 if (
auto *UU = dyn_cast<User>(U))
115 if (isa<AllocaInst>(
I)) {
121 if (
const auto *
II = dyn_cast<InvokeInst>(
I)) {
124 if (
auto *UBB =
II->getUnwindDest())
125 if (!Result.count(UBB))
132 if (
const auto *CSI = dyn_cast<CatchSwitchInst>(
I)) {
133 if (
auto *UBB = CSI->getUnwindDest())
134 if (!Result.count(UBB))
136 for (
const auto *HBB : CSI->handlers())
137 if (!Result.count(
const_cast<BasicBlock*
>(HBB)))
144 if (
const auto *CPI = dyn_cast<CatchPadInst>(
I)) {
145 for (
const auto *U : CPI->users())
146 if (
const auto *CRI = dyn_cast<CatchReturnInst>(U))
147 if (!Result.count(
const_cast<BasicBlock*
>(CRI->getParent())))
155 if (
const auto *CPI = dyn_cast<CleanupPadInst>(
I)) {
156 for (
const auto *U : CPI->users())
157 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(U))
158 if (!Result.count(
const_cast<BasicBlock*
>(CRI->getParent())))
162 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(
I)) {
163 if (
auto *UBB = CRI->getUnwindDest())
164 if (!Result.count(UBB))
169 if (
const CallInst *CI = dyn_cast<CallInst>(
I)) {
175 if (CI->isMustTailCall())
178 if (
const Function *
F = CI->getCalledFunction()) {
179 auto IID =
F->getIntrinsicID();
180 if (IID == Intrinsic::vastart) {
189 if (IID == Intrinsic::eh_typeid_for)
201 bool AllowVarArgs,
bool AllowAlloca) {
202 assert(!BBs.
empty() &&
"The set of blocks to extract must be non-empty");
212 if (!Result.insert(BB))
216 LLVM_DEBUG(
dbgs() <<
"Region front block: " << Result.front()->getName()
219 for (
auto *BB : Result) {
224 if (BB == Result.front()) {
226 LLVM_DEBUG(
dbgs() <<
"The first block cannot be an unwind block\n");
235 if (!Result.count(PBB)) {
236 LLVM_DEBUG(
dbgs() <<
"No blocks in this region may have entries from "
237 "outside the region except for the first block!\n"
238 <<
"Problematic source BB: " << BB->getName() <<
"\n"
239 <<
"Problematic destination BB: " << PBB->getName()
251 switch (TargetTriple.
getArch()) {
252 case Triple::ArchType::amdgcn:
253 case Triple::ArchType::r600:
266 bool AllowVarArgs,
bool AllowAlloca,
267 BasicBlock *AllocationBlock, std::string Suffix,
268 bool ArgsInZeroAddressSpace)
270 BPI(BPI), AC(AC), AllocationBlock(AllocationBlock),
271 AllowVarArgs(AllowVarArgs),
273 Suffix(Suffix), ArgsInZeroAddressSpace(ArgsInZeroAddressSpace) {}
279 if (
Blocks.count(
I->getParent()))
288 if (isa<Argument>(V))
return true;
290 if (!
Blocks.count(
I->getParent()))
302 if (!CommonExitBlock) {
303 CommonExitBlock = Succ;
306 if (CommonExitBlock != Succ)
315 return CommonExitBlock;
321 if (
auto *AI = dyn_cast<AllocaInst>(&
II))
322 Allocas.push_back(AI);
324 findSideEffectInfoForBlock(BB);
328void CodeExtractorAnalysisCache::findSideEffectInfoForBlock(
BasicBlock &BB) {
330 unsigned Opcode =
II.getOpcode();
331 Value *MemAddr =
nullptr;
333 case Instruction::Store:
334 case Instruction::Load: {
335 if (Opcode == Instruction::Store) {
337 MemAddr = SI->getPointerOperand();
343 if (isa<Constant>(MemAddr))
346 if (!isa<AllocaInst>(
Base)) {
347 SideEffectingBlocks.insert(&BB);
350 BaseMemAddrs[&BB].insert(
Base);
358 SideEffectingBlocks.insert(&BB);
362 if (
II.mayHaveSideEffects()) {
363 SideEffectingBlocks.insert(&BB);
373 if (SideEffectingBlocks.count(&BB))
375 auto It = BaseMemAddrs.find(&BB);
376 if (It != BaseMemAddrs.end())
377 return It->second.count(
Addr);
383 AllocaInst *AI = cast<AllocaInst>(
Addr->stripInBoundsConstantOffsets());
386 if (Blocks.count(&BB))
396 BasicBlock *SinglePredFromOutlineRegion =
nullptr;
397 assert(!Blocks.count(CommonExitBlock) &&
398 "Expect a block outside the region!");
400 if (!Blocks.count(Pred))
402 if (!SinglePredFromOutlineRegion) {
403 SinglePredFromOutlineRegion = Pred;
404 }
else if (SinglePredFromOutlineRegion != Pred) {
405 SinglePredFromOutlineRegion =
nullptr;
410 if (SinglePredFromOutlineRegion)
411 return SinglePredFromOutlineRegion;
417 while (
I != BB->
end()) {
418 PHINode *Phi = dyn_cast<PHINode>(
I);
430 assert(!getFirstPHI(CommonExitBlock) &&
"Phi not expected");
438 if (Blocks.count(Pred))
443 Blocks.insert(CommonExitBlock);
444 return CommonExitBlock;
451CodeExtractor::LifetimeMarkerInfo
455 LifetimeMarkerInfo
Info;
465 Info.LifeStart = IntrInst;
471 Info.LifeEnd = IntrInst;
480 if (!
Info.LifeStart || !
Info.LifeEnd)
486 if ((
Info.SinkLifeStart ||
Info.HoistLifeEnd) &&
491 if (
Info.HoistLifeEnd && !ExitBlock)
503 auto moveOrIgnoreLifetimeMarkers =
504 [&](
const LifetimeMarkerInfo &LMI) ->
bool {
507 if (LMI.SinkLifeStart) {
510 SinkCands.
insert(LMI.LifeStart);
512 if (LMI.HoistLifeEnd) {
513 LLVM_DEBUG(
dbgs() <<
"Hoisting lifetime.end: " << *LMI.LifeEnd <<
"\n");
514 HoistCands.
insert(LMI.LifeEnd);
523 if (Blocks.count(BB))
532 LifetimeMarkerInfo MarkerInfo = getLifetimeMarkers(CEAC, AI, ExitBlock);
533 bool Moved = moveOrIgnoreLifetimeMarkers(MarkerInfo);
545 for (
User *U : AI->users()) {
549 if (U->stripInBoundsConstantOffsets() != AI)
553 for (
User *BU : Bitcast->users()) {
554 auto *IntrInst = dyn_cast<LifetimeIntrinsic>(BU);
562 << *Bitcast <<
" in out-of-region lifetime marker "
563 << *IntrInst <<
"\n");
564 LifetimeBitcastUsers.
push_back(IntrInst);
574 I->replaceUsesOfWith(
I->getOperand(1), CastI);
580 for (
User *U : AI->users()) {
581 if (U->stripInBoundsConstantOffsets() == AI) {
583 LifetimeMarkerInfo LMI = getLifetimeMarkers(CEAC, Bitcast, ExitBlock);
599 if (Bitcasts.
empty())
602 LLVM_DEBUG(
dbgs() <<
"Sinking alloca (via bitcast): " << *AI <<
"\n");
604 for (
unsigned I = 0, E = Bitcasts.
size();
I != E; ++
I) {
606 const LifetimeMarkerInfo &LMI = BitcastLifetimeInfo[
I];
608 "Unsafe to sink bitcast without lifetime markers");
609 moveOrIgnoreLifetimeMarkers(LMI);
611 LLVM_DEBUG(
dbgs() <<
"Sinking bitcast-of-alloca: " << *BitcastAddr
613 SinkCands.
insert(BitcastAddr);
627 if (AllowVarArgs &&
F->getFunctionType()->isVarArg()) {
628 auto containsVarArgIntrinsic = [](
const Instruction &
I) {
629 if (
const CallInst *CI = dyn_cast<CallInst>(&
I))
630 if (
const Function *Callee = CI->getCalledFunction())
631 return Callee->getIntrinsicID() == Intrinsic::vastart ||
632 Callee->getIntrinsicID() == Intrinsic::vaend;
636 for (
auto &BB : *
F) {
637 if (Blocks.count(&BB))
651 bool IsSave =
II->getIntrinsicID() == Intrinsic::stacksave;
652 bool IsRestore =
II->getIntrinsicID() == Intrinsic::stackrestore;
653 if (IsSave &&
any_of(
II->users(), [&Blks = this->Blocks](
User *U) {
654 return !definedInRegion(Blks, U);
666 bool CollectGlobalInputs)
const {
671 for (
auto &OI :
II.operands()) {
673 if (!SinkCands.
count(V) &&
675 (CollectGlobalInputs && llvm::isa<llvm::GlobalVariable>(V))))
679 for (
User *U :
II.users())
691void CodeExtractor::severSplitPHINodesOfEntry(
BasicBlock *&Header) {
692 unsigned NumPredsFromRegion = 0;
693 unsigned NumPredsOutsideRegion = 0;
695 if (Header != &Header->getParent()->getEntryBlock()) {
696 PHINode *PN = dyn_cast<PHINode>(Header->begin());
704 ++NumPredsFromRegion;
706 ++NumPredsOutsideRegion;
710 if (NumPredsOutsideRegion <= 1)
return;
722 Blocks.remove(OldPred);
723 Blocks.insert(NewBB);
728 if (NumPredsFromRegion) {
741 for (AfterPHIs = OldPred->
begin(); isa<PHINode>(AfterPHIs); ++AfterPHIs) {
742 PHINode *PN = cast<PHINode>(AfterPHIs);
768void CodeExtractor::severSplitPHINodesOfExits() {
769 for (
BasicBlock *ExitBB : ExtractedFuncRetVals) {
772 for (
PHINode &PN : ExitBB->phis()) {
782 if (IncomingVals.
size() <= 1)
789 ExitBB->getName() +
".split",
790 ExitBB->getParent(), ExitBB);
793 if (Blocks.count(PredBB))
794 PredBB->getTerminator()->replaceUsesOfWith(ExitBB, NewBB);
796 Blocks.insert(NewBB);
803 for (
unsigned i : IncomingVals)
805 for (
unsigned i :
reverse(IncomingVals))
812void CodeExtractor::splitReturnBlocks() {
816 Block->splitBasicBlock(RI->getIterator(),
Block->getName() +
".ret");
832Function *CodeExtractor::constructFunctionDeclaration(
833 const ValueSet &inputs,
const ValueSet &outputs,
BlockFrequency EntryFreq,
842 std::vector<Type *> ParamTy;
843 std::vector<Type *> AggParamTy;
849 if (AggregateArgs && !ExcludeArgsFromAggregate.
contains(
value)) {
850 AggParamTy.push_back(
value->getType());
851 StructValues.insert(
value);
853 ParamTy.push_back(
value->getType());
857 for (
Value *output : outputs) {
859 if (AggregateArgs && !ExcludeArgsFromAggregate.
contains(output)) {
860 AggParamTy.push_back(output->getType());
861 StructValues.insert(output);
868 (ParamTy.size() + AggParamTy.size()) ==
869 (inputs.size() + outputs.size()) &&
870 "Number of scalar and aggregate params does not match inputs, outputs");
871 assert((StructValues.empty() || AggregateArgs) &&
872 "Expeced StructValues only with AggregateArgs set");
875 if (!AggParamTy.empty()) {
878 M->getContext(), ArgsInZeroAddressSpace ? 0 :
DL.getAllocaAddrSpace()));
883 dbgs() <<
"Function type: " << *
RetTy <<
" f(";
884 for (
Type *i : ParamTy)
885 dbgs() << *i <<
", ";
909 if (Attr.isStringAttribute()) {
910 if (Attr.getKindAsString() ==
"thunk")
913 switch (Attr.getKindAsEnum()) {
916 case Attribute::AllocSize:
917 case Attribute::Builtin:
918 case Attribute::Convergent:
919 case Attribute::JumpTable:
920 case Attribute::Naked:
921 case Attribute::NoBuiltin:
922 case Attribute::NoMerge:
923 case Attribute::NoReturn:
924 case Attribute::NoSync:
925 case Attribute::ReturnsTwice:
926 case Attribute::Speculatable:
927 case Attribute::StackAlignment:
928 case Attribute::WillReturn:
929 case Attribute::AllocKind:
930 case Attribute::PresplitCoroutine:
931 case Attribute::Memory:
932 case Attribute::NoFPClass:
933 case Attribute::CoroDestroyOnlyWhenComplete:
934 case Attribute::CoroElideSafe:
935 case Attribute::NoDivergenceSource:
938 case Attribute::AlwaysInline:
939 case Attribute::Cold:
940 case Attribute::DisableSanitizerInstrumentation:
941 case Attribute::FnRetThunkExtern:
943 case Attribute::HybridPatchable:
944 case Attribute::NoRecurse:
945 case Attribute::InlineHint:
946 case Attribute::MinSize:
947 case Attribute::NoCallback:
948 case Attribute::NoDuplicate:
949 case Attribute::NoFree:
950 case Attribute::NoImplicitFloat:
951 case Attribute::NoInline:
952 case Attribute::NonLazyBind:
953 case Attribute::NoRedZone:
954 case Attribute::NoUnwind:
955 case Attribute::NoSanitizeBounds:
956 case Attribute::NoSanitizeCoverage:
957 case Attribute::NullPointerIsValid:
958 case Attribute::OptimizeForDebugging:
959 case Attribute::OptForFuzzing:
960 case Attribute::OptimizeNone:
961 case Attribute::OptimizeForSize:
962 case Attribute::SafeStack:
963 case Attribute::ShadowCallStack:
964 case Attribute::SanitizeAddress:
965 case Attribute::SanitizeMemory:
966 case Attribute::SanitizeNumericalStability:
967 case Attribute::SanitizeThread:
968 case Attribute::SanitizeType:
969 case Attribute::SanitizeHWAddress:
970 case Attribute::SanitizeMemTag:
971 case Attribute::SanitizeRealtime:
972 case Attribute::SanitizeRealtimeBlocking:
973 case Attribute::SpeculativeLoadHardening:
974 case Attribute::StackProtect:
975 case Attribute::StackProtectReq:
976 case Attribute::StackProtectStrong:
977 case Attribute::StrictFP:
978 case Attribute::UWTable:
979 case Attribute::VScaleRange:
980 case Attribute::NoCfCheck:
981 case Attribute::MustProgress:
982 case Attribute::NoProfile:
983 case Attribute::SkipProfile:
986 case Attribute::Alignment:
987 case Attribute::AllocatedPointer:
988 case Attribute::AllocAlign:
989 case Attribute::ByVal:
990 case Attribute::Captures:
991 case Attribute::Dereferenceable:
992 case Attribute::DereferenceableOrNull:
993 case Attribute::ElementType:
994 case Attribute::InAlloca:
995 case Attribute::InReg:
996 case Attribute::Nest:
997 case Attribute::NoAlias:
998 case Attribute::NoUndef:
999 case Attribute::NonNull:
1000 case Attribute::Preallocated:
1001 case Attribute::ReadNone:
1002 case Attribute::ReadOnly:
1003 case Attribute::Returned:
1004 case Attribute::SExt:
1005 case Attribute::StructRet:
1006 case Attribute::SwiftError:
1007 case Attribute::SwiftSelf:
1008 case Attribute::SwiftAsync:
1009 case Attribute::ZExt:
1010 case Attribute::ImmArg:
1011 case Attribute::ByRef:
1012 case Attribute::WriteOnly:
1013 case Attribute::Writable:
1014 case Attribute::DeadOnUnwind:
1015 case Attribute::Range:
1016 case Attribute::Initializes:
1017 case Attribute::NoExt:
1023 case Attribute::DeadOnReturn:
1036 for (
Value *input : inputs) {
1037 if (StructValues.contains(input))
1040 ScalarAI->
setName(input->getName());
1041 if (input->isSwiftError())
1043 Attribute::SwiftError);
1046 for (
Value *output : outputs) {
1047 if (StructValues.contains(output))
1050 ScalarAI->
setName(output->getName() +
".out");
1057 if (Count.has_value())
1075 if (!
I.getDebugLoc())
1095 auto *
II = dyn_cast<LifetimeIntrinsic>(&
I);
1102 Value *Mem =
II->getOperand(0);
1106 if (
II->getIntrinsicID() == Intrinsic::lifetime_start)
1107 LifetimesStart.
insert(Mem);
1108 II->eraseFromParent();
1123 bool InsertBefore) {
1124 for (
Value *Mem : Objects) {
1127 "Input memory not defined in original function");
1135 Marker->insertBefore(Term->getIterator());
1139 if (!LifetimesStart.
empty()) {
1140 insertMarkers(Intrinsic::lifetime_start, LifetimesStart,
1144 if (!LifetimesEnd.
empty()) {
1145 insertMarkers(Intrinsic::lifetime_end, LifetimesEnd,
1150void CodeExtractor::moveCodeToFunction(
Function *newFunction) {
1151 auto newFuncIt = newFunction->
begin();
1154 Block->removeFromParent();
1161 newFuncIt = newFunction->
insert(std::next(newFuncIt),
Block);
1165void CodeExtractor::calculateNewCallTerminatorWeights(
1177 Distribution BranchDist;
1184 BlockNode ExitNode(i);
1187 BranchDist.addExit(ExitNode, ExitFreq);
1193 if (BranchDist.Total == 0) {
1199 BranchDist.normalize();
1202 for (
unsigned I = 0, E = BranchDist.Weights.size();
I < E; ++
I) {
1203 const auto &Weight = BranchDist.Weights[
I];
1206 BranchWeights[Weight.TargetNode.Index] = Weight.Amount;
1208 EdgeProbabilities[Weight.TargetNode.Index] = BP;
1212 LLVMContext::MD_prof,
1223 if (DVR->getFunction() != &
F)
1224 DVR->eraseFromParent();
1255 assert(OldSP->getUnit() &&
"Missing compile unit for subprogram");
1260 DISubprogram::SPFlagOptimized |
1261 DISubprogram::SPFlagLocalToUnit;
1264 0, SPType, 0, DINode::FlagZero, SPFlags);
1267 auto UpdateOrInsertDebugRecord = [&](
auto *DR,
Value *OldLoc,
Value *NewLoc,
1269 if (DR->getParent()->getParent() == &NewFunc) {
1270 DR->replaceVariableLocationOp(OldLoc, NewLoc);
1274 DIB.
insertDeclare(NewLoc, DR->getVariable(), Expr, DR->getDebugLoc(),
1279 NewLoc, DR->getVariable(), Expr, DR->getDebugLoc(),
1282 for (
auto [Input, NewVal] :
zip_equal(Inputs, NewValues)) {
1290 for (
auto *DVR : DPUsers)
1291 UpdateOrInsertDebugRecord(DVR, Input, NewVal, Expr, DVR->isDbgDeclare());
1294 auto IsInvalidLocation = [&NewFunc](
Value *Location) {
1297 if (!Location || (!isa<Constant>(Location) && !isa<Argument>(Location) &&
1298 !isa<Instruction>(Location)))
1301 if (
Argument *Arg = dyn_cast<Argument>(Location))
1302 return Arg->getParent() != &NewFunc;
1303 if (
Instruction *LocationInst = dyn_cast<Instruction>(Location))
1319 DINode *&NewVar = RemappedMetadata[OldVar];
1322 *OldVar->getScope(), *NewSP, Ctx, Cache);
1324 NewScope, OldVar->
getName(), OldVar->getFile(), OldVar->getLine(),
1325 OldVar->getType(),
false, DINode::FlagZero,
1326 OldVar->getAlignInBits());
1328 return cast<DILocalVariable>(NewVar);
1331 auto UpdateDbgLabel = [&](
auto *LabelRecord) {
1334 if (LabelRecord->getDebugLoc().getInlinedAt())
1336 DILabel *OldLabel = LabelRecord->getLabel();
1337 DINode *&NewLabel = RemappedMetadata[OldLabel];
1340 *OldLabel->
getScope(), *NewSP, Ctx, Cache);
1346 LabelRecord->setLabel(cast<DILabel>(NewLabel));
1349 auto UpdateDbgRecordsOnInst = [&](
Instruction &
I) ->
void {
1350 for (
DbgRecord &DR :
I.getDbgRecordRange()) {
1352 UpdateDbgLabel(DLR);
1378 UpdateDbgRecordsOnInst(
I);
1380 for (
auto *DVR : DVRsToDelete)
1381 DVR->getMarker()->MarkedInstr->dropOneDbgRecord(DVR);
1393 *NewSP, Ctx, Cache));
1396 auto updateLoopInfoLoc = [&Ctx, &Cache, NewSP](
Metadata *MD) ->
Metadata * {
1397 if (
auto *Loc = dyn_cast_or_null<DILocation>(MD))
1427 normalizeCFGForExtraction(header);
1433 if (
auto *AI = dyn_cast<AssumeInst>(&
I)) {
1436 AI->eraseFromParent();
1441 ValueSet SinkingCands, HoistingCands;
1443 findAllocas(CEAC, SinkingCands, HoistingCands, CommonExit);
1456 if (!HoistingCands.
empty()) {
1459 for (
auto *
II : HoistingCands)
1461 computeExtractedFuncRetVals();
1471 assert(BPI &&
"Both BPI and BFI are required to preserve profile info");
1479 for (
BasicBlock *Succ : ExtractedFuncRetVals) {
1494 while (ReplIP &&
Blocks.count(ReplIP))
1498 std::string SuffixToUse =
1505 Function *newFunction = constructFunctionDeclaration(
1506 inputs, outputs, EntryFreq, oldFunction->
getName() +
"." + SuffixToUse,
1507 StructValues, StructTy);
1510 emitFunctionBody(inputs, outputs, StructValues, newFunction, StructTy, header,
1511 SinkingCands, NewValues);
1513 std::vector<Value *> Reloads;
1514 CallInst *TheCall = emitReplacerCall(
1515 inputs, outputs, StructValues, newFunction, StructTy, oldFunction, ReplIP,
1516 EntryFreq, LifetimesStart.
getArrayRef(), Reloads);
1518 insertReplacerCall(oldFunction, header, TheCall->
getParent(), outputs,
1519 Reloads, ExitWeights);
1533void CodeExtractor::normalizeCFGForExtraction(
BasicBlock *&header) {
1536 splitReturnBlocks();
1539 severSplitPHINodesOfEntry(header);
1545 computeExtractedFuncRetVals();
1546 severSplitPHINodesOfExits();
1549void CodeExtractor::computeExtractedFuncRetVals() {
1550 ExtractedFuncRetVals.clear();
1558 bool IsNew = ExitBlocks.
insert(Succ).second;
1560 ExtractedFuncRetVals.push_back(Succ);
1565Type *CodeExtractor::getSwitchType() {
1568 assert(ExtractedFuncRetVals.size() < 0xffff &&
1569 "too many exit blocks for switch");
1570 switch (ExtractedFuncRetVals.size()) {
1582void CodeExtractor::emitFunctionBody(
1583 const ValueSet &inputs,
const ValueSet &outputs,
1584 const ValueSet &StructValues,
Function *newFunction,
1598 for (
auto *
II : SinkingCands) {
1599 if (!isa<AllocaInst>(
II)) {
1600 cast<Instruction>(
II)->moveBefore(*newFuncRoot,
1604 for (
auto *
II : SinkingCands) {
1605 if (
auto *AI = dyn_cast<AllocaInst>(
II)) {
1611 Argument *AggArg = StructValues.empty()
1617 for (
unsigned i = 0, e = inputs.size(), aggIdx = 0; i != e; ++i) {
1619 if (StructValues.contains(inputs[i])) {
1624 StructArgTy, AggArg,
Idx,
"gep_" + inputs[i]->
getName(), newFuncRoot);
1627 "loadgep_" + inputs[i]->getName(), newFuncRoot);
1640 unsigned AlignmentValue;
1641 const Triple &TargetTriple =
1649 inputs[i]->stripPointerCasts()->getPointerAlignment(
DL).value();
1651 AlignmentValue = inputs[i]->getPointerAlignment(
DL).value();
1654 LLVMContext::MD_align,
1657 MDB.createConstant(ConstantInt::get(
1660 RewriteVal = LoadGEP;
1663 RewriteVal = &*ScalarAI++;
1668 moveCodeToFunction(newFunction);
1670 for (
unsigned i = 0, e = inputs.size(); i != e; ++i) {
1671 Value *RewriteVal = NewValues[i];
1673 std::vector<User *>
Users(inputs[i]->user_begin(), inputs[i]->user_end());
1676 if (
Blocks.count(inst->getParent()))
1677 inst->replaceUsesOfWith(inputs[i], RewriteVal);
1685 std::map<BasicBlock *, BasicBlock *> ExitBlockMap;
1689 for (
auto P :
enumerate(ExtractedFuncRetVals)) {
1691 size_t SuccNum =
P.index();
1694 Context, OldTarget->
getName() +
".exitStub", newFunction);
1695 ExitBlockMap[OldTarget] = NewTarget;
1697 Value *brVal =
nullptr;
1699 assert(ExtractedFuncRetVals.size() < 0xffff &&
1700 "too many exit blocks for switch");
1701 switch (ExtractedFuncRetVals.size()) {
1707 brVal = ConstantInt::get(
RetTy, !SuccNum);
1710 brVal = ConstantInt::get(
RetTy, SuccNum);
1724 BasicBlock *NewTarget = ExitBlockMap[OldTarget];
1725 assert(NewTarget &&
"Unknown target block!");
1749 unsigned AggIdx = 0;
1751 for (
Value *Input : inputs) {
1752 if (StructValues.contains(Input))
1758 for (
Value *Output : outputs) {
1764 if (
auto *InvokeI = dyn_cast<InvokeInst>(Output))
1765 InsertPt = InvokeI->getNormalDest()->getFirstInsertionPt();
1766 else if (
auto *Phi = dyn_cast<PHINode>(Output))
1767 InsertPt =
Phi->getParent()->getFirstInsertionPt();
1768 else if (
auto *OutI = dyn_cast<Instruction>(Output))
1769 InsertPt = std::next(OutI->getIterator());
1772 if (StructValues.contains(Output))
1779 assert((InsertPt->getFunction() == newFunction ||
1780 Blocks.count(InsertPt->getParent())) &&
1781 "InsertPt should be in new function");
1783 if (StructValues.contains(Output)) {
1784 assert(AggArg &&
"Number of aggregate output arguments should match "
1785 "the number of defined values");
1790 StructArgTy, AggArg,
Idx,
"gep_" + Output->getName(), InsertPt);
1795 "Number of scalar output arguments should match "
1796 "the number of defined values");
1797 new StoreInst(Output, &*ScalarAI, InsertPt);
1802 if (ExtractedFuncRetVals.empty()) {
1808 return isa<ReturnInst>(Term) || isa<ResumeInst>(Term);
1814CallInst *CodeExtractor::emitReplacerCall(
1815 const ValueSet &inputs,
const ValueSet &outputs,
1816 const ValueSet &StructValues,
Function *newFunction,
1819 std::vector<Value *> &Reloads) {
1827 if (AllocationBlock)
1829 "AllocationBlock is not in the same function");
1831 AllocationBlock ? AllocationBlock : &oldFunction->
getEntryBlock();
1837 std::vector<Value *> params;
1840 for (
Value *input : inputs) {
1841 if (StructValues.contains(input))
1844 params.push_back(input);
1848 std::vector<Value *> ReloadOutputs;
1849 for (
Value *output : outputs) {
1850 if (StructValues.contains(output))
1854 output->getType(),
DL.getAllocaAddrSpace(),
nullptr,
1856 params.push_back(alloca);
1857 ReloadOutputs.push_back(alloca);
1861 if (!StructValues.empty()) {
1864 if (ArgsInZeroAddressSpace &&
DL.getAllocaAddrSpace() != 0) {
1866 Struct, PointerType ::get(Context, 0),
"structArg.ascast");
1867 StructSpaceCast->insertAfter(
Struct->getIterator());
1868 params.push_back(StructSpaceCast);
1870 params.push_back(
Struct);
1873 unsigned AggIdx = 0;
1874 for (
Value *input : inputs) {
1875 if (!StructValues.contains(input))
1882 StructArgTy,
Struct,
Idx,
"gep_" + input->getName());
1883 GEP->insertInto(codeReplacer, codeReplacer->
end());
1892 newFunction, params, ExtractedFuncRetVals.size() > 1 ?
"targetBlock" :
"",
1896 unsigned ParamIdx = 0;
1897 unsigned AggIdx = 0;
1898 for (
auto input : inputs) {
1899 if (StructValues.contains(input)) {
1902 if (input->isSwiftError())
1919 for (
unsigned i = 0, e = outputs.size(), scalarIdx = 0; i != e; ++i) {
1920 Value *Output =
nullptr;
1921 if (StructValues.contains(outputs[i])) {
1927 GEP->insertInto(codeReplacer, codeReplacer->
end());
1931 Output = ReloadOutputs[scalarIdx];
1936 outputs[i]->
getName() +
".reload", codeReplacer);
1937 Reloads.push_back(
load);
1943 codeReplacer, 0, codeReplacer);
1944 for (
auto P :
enumerate(ExtractedFuncRetVals)) {
1946 size_t SuccNum =
P.index();
1953 Type *OldFnRetTy = TheSwitch->
getParent()->getParent()->getReturnType();
1954 switch (ExtractedFuncRetVals.size()) {
1962 }
else if (OldFnRetTy->
isVoidTy()) {
2017void CodeExtractor::insertReplacerCall(
2026 for (
auto &U :
Users)
2030 if (
I->isTerminator() &&
I->getFunction() == oldFunction &&
2031 !
Blocks.count(
I->getParent()))
2032 I->replaceUsesOfWith(header, codeReplacer);
2038 for (
BasicBlock *ExitBB : ExtractedFuncRetVals)
2039 for (
PHINode &PN : ExitBB->phis()) {
2040 Value *IncomingCodeReplacerVal =
nullptr;
2047 if (!IncomingCodeReplacerVal) {
2052 "PHI has two incompatbile incoming values from codeRepl");
2056 for (
unsigned i = 0, e = outputs.size(); i != e; ++i) {
2058 std::vector<User *>
Users(outputs[i]->user_begin(), outputs[i]->user_end());
2061 if (inst->
getParent()->getParent() == oldFunction)
2067 if (BFI && ExtractedFuncRetVals.size() > 1)
2068 calculateNewCallTerminatorWeights(codeReplacer, ExitWeights, BPI);
2075 auto *
I = dyn_cast_or_null<CallInst>(AssumeVH);
2080 if (
I->getFunction() != &OldFunc)
2087 auto *AffectedCI = dyn_cast_or_null<CallInst>(AffectedValVH);
2090 if (AffectedCI->getFunction() != &OldFunc)
2092 auto *AssumedInst = cast<Instruction>(AffectedCI->getOperand(0));
2093 if (AssumedInst->getFunction() != &OldFunc)
2101 ExcludeArgsFromAggregate.
insert(Arg);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
This file contains the simple types necessary to represent the attributes associated with functions a...
static const Function * getParent(const Value *V)
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Given that RA is a live value
This file defines the DenseMap class.
DenseMap< Block *, BlockRelaxAux > Blocks
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.
iv Induction Variable Users
Move duplicate certain instructions close to their use
uint64_t IntrinsicInst * II
static StringRef getName(Value *V)
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
This class represents a conversion between pointers from one address space to another.
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
A cache of @llvm.assume calls within a function.
MutableArrayRef< ResultElem > assumptions()
Access the list of assumption handles currently tracked for this function.
LLVM_ABI void unregisterAssumption(AssumeInst *CI)
Remove an @llvm.assume intrinsic from this function's cache if it has been added to the cache earlier...
MutableArrayRef< ResultElem > assumptionsFor(const Value *V)
Access the list of assumptions which affect this value.
LLVM_ABI AttributeSet getFnAttrs() const
The function attributes are returned.
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
@ None
No attributes have been set.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
@ EndAttrKinds
Sentinel value useful for loops.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
LLVM_ABI iterator_range< filter_iterator< BasicBlock::const_iterator, std::function< bool(const Instruction &)> > > instructionsWithoutDebug(bool SkipPseudoOp=true) const
Return a const iterator range over the instructions in the block, skipping any debug instructions.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
InstListType::const_iterator const_iterator
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
LLVM_ABI 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.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this basic block belongs to.
InstListType::iterator iterator
Instruction iterators...
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
LLVM_ABI std::optional< uint64_t > getProfileCountFromFreq(BlockFrequency Freq) const
Returns the estimated profile count of Freq.
LLVM_ABI void setBlockFreq(const BasicBlock *BB, BlockFrequency Freq)
LLVM_ABI BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
Conditional or Unconditional Branch instruction.
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
Analysis providing branch probability information.
LLVM_ABI void setEdgeProbability(const BasicBlock *Src, const SmallVectorImpl< BranchProbability > &Probs)
Set the raw probabilities for all edges from the given block.
LLVM_ABI BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
static BranchProbability getUnknown()
static BranchProbability getZero()
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
Adds the attribute to the indicated argument.
This class represents a function call, abstracting a target machine's calling convention.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
This is the base class for all instructions that perform data casts.
static LLVM_ABI CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Create a BitCast, AddrSpaceCast or a PtrToInt cast instruction.
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI DISubroutineType * createSubroutineType(DITypeRefArray ParameterTypes, DINode::DIFlags Flags=DINode::FlagZero, unsigned CC=0)
Create subroutine type.
LLVM_ABI void finalizeSubprogram(DISubprogram *SP)
Finalize a specific subprogram - no new variables may be added to this subprogram afterwards.
LLVM_ABI DISubprogram * createFunction(DIScope *Scope, StringRef Name, StringRef LinkageName, DIFile *File, unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine, DINode::DIFlags Flags=DINode::FlagZero, DISubprogram::DISPFlags SPFlags=DISubprogram::SPFlagZero, DITemplateParameterArray TParams=nullptr, DISubprogram *Decl=nullptr, DITypeArray ThrownTypes=nullptr, DINodeArray Annotations=nullptr, StringRef TargetFuncName="", bool UseKeyInstructions=false)
Create a new descriptor for the specified subprogram.
LLVM_ABI DbgInstPtr insertDeclare(llvm::Value *Storage, DILocalVariable *VarInfo, DIExpression *Expr, const DILocation *DL, BasicBlock *InsertAtEnd)
Insert a new llvm.dbg.declare intrinsic call.
LLVM_ABI DbgInstPtr insertDbgValueIntrinsic(llvm::Value *Val, DILocalVariable *VarInfo, DIExpression *Expr, const DILocation *DL, InsertPosition InsertPt)
Insert a new llvm.dbg.value intrinsic call.
LLVM_ABI DITypeRefArray getOrCreateTypeArray(ArrayRef< Metadata * > Elements)
Get a DITypeRefArray, create one if required.
LLVM_ABI DIExpression * createExpression(ArrayRef< uint64_t > Addr={})
Create a new descriptor for the specified variable which has a complex address expression for its add...
LLVM_ABI DILocalVariable * createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, DIType *Ty, bool AlwaysPreserve=false, DINode::DIFlags Flags=DINode::FlagZero, uint32_t AlignInBits=0)
Create a new descriptor for an auto variable.
StringRef getName() const
bool isArtificial() const
unsigned getColumn() const
DILocalScope * getScope() const
Get the local scope for this label.
std::optional< unsigned > getCoroSuspendIdx() const
static LLVM_ABI DILocalScope * cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Traverses the scope chain rooted at RootScope until it hits a Subprogram, recreating the chain with "...
Tagged DWARF-like metadata node.
LLVM_ABI StringRef getName() const
Subprogram description. Uses SubclassData1.
DISPFlags
Debug info subprogram flags.
A parsed version of the target data layout string in and methods for querying it.
Records a position in IR for a source label (DILabel).
Base class for non-instruction debug metadata records that have positions within IR.
DebugLoc getDebugLoc() const
Record of a variable value-assignment, aka a non instruction representation of the dbg....
void setVariable(DILocalVariable *NewVar)
LLVM_ABI Value * getAddress() const
DILocalVariable * getVariable() const
LLVM_ABI iterator_range< location_op_iterator > location_ops() const
Get the locations corresponding to the variable referenced by the debug info intrinsic.
static LLVM_ABI DebugLoc replaceInlinedAtSubprogram(const DebugLoc &DL, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Rebuild the entire inline-at chain by replacing the subprogram at the end of the chain with NewSP.
LLVM_ABI DILocation * getInlinedAt() const
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
LLVM_ABI bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Class to represent profile counts.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
void setSubprogram(DISubprogram *SP)
Set the attached subprogram.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
const BasicBlock & getEntryBlock() const
DISubprogram * getSubprogram() const
Get the attached subprogram.
bool hasPersonalityFn() const
Check whether this function has a personality function.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
void setPersonalityFn(Constant *Fn)
AttributeList getAttributes() const
Return the attribute list for this Function.
const Function & getFunction() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
Function::iterator insert(Function::iterator Position, BasicBlock *BB)
Insert BB in the basic block list at Position.
bool doesNotReturn() const
Determine if the function cannot return.
Argument * getArg(unsigned i) const
void setEntryCount(ProfileCount Count, const DenseSet< GlobalValue::GUID > *Imports=nullptr)
Set the entry count for this function.
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
unsigned getAddressSpace() const
Module * getParent()
Get the module that this global value is contained inside of...
@ InternalLinkage
Rename collisions when linking (static functions).
LLVM_ABI bool isLifetimeStartOrEnd() const LLVM_READONLY
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI void moveBefore(InstListType::iterator InsertPos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
Value * getPointerOperand()
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
A Module instance is used to store all the information related to an LLVM module.
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
void setIncomingBlock(unsigned i, BasicBlock *BB)
LLVM_ABI Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static 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 PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
static LLVM_ABI PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Return a value (possibly void), from a function.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, InsertPosition InsertBefore=nullptr)
A vector that has set insertion semantics.
ArrayRef< value_type > getArrayRef() const
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
bool empty() const
Determine if the SetVector is empty or not.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool contains(const key_type &key) const
Check if the SetVector contains the given key.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
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...
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.
std::string str() const
str - Get the contents as an std::string.
constexpr bool empty() const
empty - Check if the string is empty.
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Type * getElementType(unsigned N) const
BasicBlock * getSuccessor(unsigned idx) const
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, InsertPosition InsertBefore=nullptr)
void setCondition(Value *V)
LLVM_ABI void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
void setDefaultDest(BasicBlock *DefaultCase)
Value * getCondition() const
LLVM_ABI CaseIt removeCase(CaseIt I)
This method removes the specified case and its successor from the switch instruction.
Triple - Helper class for working with autoconf configuration names.
ArchType getArch() const
Get the parsed architecture type of this triple.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
bool isVoidTy() const
Return true if this is 'void'.
This function has undefined behavior.
LLVM_ABI bool replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
user_iterator user_begin()
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void dump() const
Support for debugging, callable in GDB: V->dump()
const ParentTy * getParent() const
self_iterator getIterator()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI void remapAssignID(DenseMap< DIAssignID *, DIAssignID * > &Map, Instruction &I)
Replace DIAssignID uses and attachments with IDs from Map.
NodeAddr< PhiNode * > Phi
This is an optimization pass for GlobalISel generic memory operations.
detail::zippy< detail::zip_first, T, U, Args... > zip_equal(T &&t, U &&u, Args &&...args)
zip iterator that assumes that all iteratees have the same length.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
LLVM_ABI bool stripDebugInfo(Function &F)
Function::ProfileCount ProfileCount
auto successors(const MachineBasicBlock *BB)
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 any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
auto predecessors(const MachineBasicBlock *BB)
iterator_range< pointer_iterator< WrappedIteratorT > > make_pointer_range(RangeT &&Range)
LLVM_ABI void updateLoopMetadataDebugLocations(Instruction &I, function_ref< Metadata *(Metadata *)> Updater)
Update the debug locations contained within the MD_loop metadata attached to the instruction I,...
LLVM_ABI void findDbgUsers(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the debug info records describing a value.
Representative of a block.
Distribution of unscaled probability weight.