Go to the documentation of this file.
77 #define DEBUG_TYPE "code-extractor"
85 cl::desc(
"Aggregate arguments to code-extracted functions"));
90 bool AllowVarArgs,
bool AllowAlloca) {
92 if (
BB.hasAddressTaken())
101 ToVisit.push_back(&Inst);
103 while (!ToVisit.empty()) {
105 if (!Visited.
insert(Curr).second)
107 if (isa<BlockAddress const>(Curr))
110 if (isa<Instruction>(Curr) && cast<Instruction>(Curr)->
getParent() != &
BB)
113 for (
auto const &U : Curr->
operands()) {
114 if (
auto *UU = dyn_cast<User>(U))
115 ToVisit.push_back(UU);
122 if (isa<AllocaInst>(
I)) {
128 if (
const auto *II = dyn_cast<InvokeInst>(
I)) {
131 if (
auto *UBB = II->getUnwindDest())
132 if (!Result.count(UBB))
139 if (
const auto *CSI = dyn_cast<CatchSwitchInst>(
I)) {
140 if (
auto *UBB = CSI->getUnwindDest())
141 if (!Result.count(UBB))
143 for (
auto *HBB : CSI->handlers())
144 if (!Result.count(
const_cast<BasicBlock*
>(HBB)))
151 if (
const auto *CPI = dyn_cast<CatchPadInst>(
I)) {
152 for (
const auto *U : CPI->users())
153 if (
const auto *CRI = dyn_cast<CatchReturnInst>(U))
154 if (!Result.count(
const_cast<BasicBlock*
>(CRI->getParent())))
162 if (
const auto *CPI = dyn_cast<CleanupPadInst>(
I)) {
163 for (
const auto *U : CPI->users())
164 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(U))
165 if (!Result.count(
const_cast<BasicBlock*
>(CRI->getParent())))
169 if (
const auto *CRI = dyn_cast<CleanupReturnInst>(
I)) {
170 if (
auto *UBB = CRI->getUnwindDest())
171 if (!Result.count(UBB))
176 if (
const CallInst *CI = dyn_cast<CallInst>(
I)) {
177 if (
const Function *
F = CI->getCalledFunction()) {
178 auto IID =
F->getIntrinsicID();
179 if (IID == Intrinsic::vastart) {
188 if (IID == Intrinsic::eh_typeid_for)
200 bool AllowVarArgs,
bool AllowAlloca) {
201 assert(!BBs.
empty() &&
"The set of blocks to extract must be non-empty");
211 if (!Result.insert(
BB))
215 LLVM_DEBUG(
dbgs() <<
"Region front block: " << Result.front()->getName()
218 for (
auto *
BB : Result) {
223 if (
BB == Result.front()) {
225 LLVM_DEBUG(
dbgs() <<
"The first block cannot be an unwind block\n");
234 if (!Result.count(PBB)) {
235 LLVM_DEBUG(
dbgs() <<
"No blocks in this region may have entries from "
236 "outside the region except for the first block!\n"
237 <<
"Problematic source BB: " <<
BB->getName() <<
"\n"
238 <<
"Problematic destination BB: " << PBB->getName()
250 bool AllowVarArgs,
bool AllowAlloca,
253 BPI(BPI), AC(AC), AllowVarArgs(AllowVarArgs),
262 BPI(BPI), AC(AC), AllowVarArgs(
false),
272 if (Blocks.
count(
I->getParent()))
281 if (isa<Argument>(V))
return true;
283 if (!Blocks.
count(
I->getParent()))
290 auto hasNonCommonExitSucc = [&](
BasicBlock *Block) {
293 if (Blocks.
count(Succ))
295 if (!CommonExitBlock) {
296 CommonExitBlock = Succ;
299 if (CommonExitBlock != Succ)
305 if (
any_of(Blocks, hasNonCommonExitSucc))
308 return CommonExitBlock;
314 if (
auto *AI = dyn_cast<AllocaInst>(&II))
315 Allocas.push_back(AI);
317 findSideEffectInfoForBlock(
BB);
321 void CodeExtractorAnalysisCache::findSideEffectInfoForBlock(
BasicBlock &
BB) {
323 unsigned Opcode = II.getOpcode();
324 Value *MemAddr =
nullptr;
330 MemAddr =
SI->getPointerOperand();
336 if (isa<Constant>(MemAddr))
339 if (!isa<AllocaInst>(Base)) {
340 SideEffectingBlocks.insert(&
BB);
343 BaseMemAddrs[&
BB].insert(Base);
351 SideEffectingBlocks.insert(&
BB);
355 if (II.mayHaveSideEffects()) {
356 SideEffectingBlocks.insert(&
BB);
366 if (SideEffectingBlocks.count(&
BB))
368 auto It = BaseMemAddrs.find(&
BB);
369 if (It != BaseMemAddrs.end())
370 return It->second.count(
Addr);
376 AllocaInst *AI = cast<AllocaInst>(
Addr->stripInBoundsConstantOffsets());
379 if (Blocks.count(&
BB))
389 BasicBlock *SinglePredFromOutlineRegion =
nullptr;
390 assert(!Blocks.count(CommonExitBlock) &&
391 "Expect a block outside the region!");
393 if (!Blocks.count(Pred))
395 if (!SinglePredFromOutlineRegion) {
396 SinglePredFromOutlineRegion = Pred;
397 }
else if (SinglePredFromOutlineRegion != Pred) {
398 SinglePredFromOutlineRegion =
nullptr;
403 if (SinglePredFromOutlineRegion)
404 return SinglePredFromOutlineRegion;
410 while (
I !=
BB->end()) {
411 PHINode *Phi = dyn_cast<PHINode>(
I);
423 assert(!getFirstPHI(CommonExitBlock) &&
"Phi not expected");
431 if (Blocks.count(Pred))
436 Blocks.insert(CommonExitBlock);
437 return CommonExitBlock;
444 CodeExtractor::LifetimeMarkerInfo
448 LifetimeMarkerInfo
Info;
458 Info.LifeStart = IntrInst;
464 Info.LifeEnd = IntrInst;
469 if (isa<DbgInfoIntrinsic>(IntrInst))
477 if (!
Info.LifeStart || !
Info.LifeEnd)
483 if ((
Info.SinkLifeStart ||
Info.HoistLifeEnd) &&
488 if (
Info.HoistLifeEnd && !ExitBlock)
500 auto moveOrIgnoreLifetimeMarkers =
501 [&](
const LifetimeMarkerInfo &LMI) ->
bool {
504 if (LMI.SinkLifeStart) {
507 SinkCands.
insert(LMI.LifeStart);
509 if (LMI.HoistLifeEnd) {
510 LLVM_DEBUG(
dbgs() <<
"Hoisting lifetime.end: " << *LMI.LifeEnd <<
"\n");
511 HoistCands.
insert(LMI.LifeEnd);
520 if (Blocks.count(
BB))
529 LifetimeMarkerInfo MarkerInfo = getLifetimeMarkers(CEAC, AI, ExitBlock);
530 bool Moved = moveOrIgnoreLifetimeMarkers(MarkerInfo);
546 if (U->stripInBoundsConstantOffsets() != AI)
562 << *
Bitcast <<
" in out-of-region lifetime marker "
563 << *IntrInst <<
"\n");
564 LifetimeBitcastUsers.push_back(IntrInst);
574 I->replaceUsesOfWith(
I->getOperand(1), CastI);
581 if (U->stripInBoundsConstantOffsets() == AI) {
583 LifetimeMarkerInfo LMI = getLifetimeMarkers(CEAC,
Bitcast, ExitBlock);
586 BitcastLifetimeInfo.push_back(LMI);
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))
631 return Callee->getIntrinsicID() == Intrinsic::vastart ||
632 Callee->getIntrinsicID() == Intrinsic::vaend;
636 for (
auto &
BB : *
F) {
637 if (Blocks.count(&
BB))
652 for (
auto &OI : II.operands()) {
670 void CodeExtractor::severSplitPHINodesOfEntry(
BasicBlock *&Header) {
671 unsigned NumPredsFromRegion = 0;
672 unsigned NumPredsOutsideRegion = 0;
683 ++NumPredsFromRegion;
685 ++NumPredsOutsideRegion;
689 if (NumPredsOutsideRegion <= 1)
return;
701 Blocks.remove(OldPred);
702 Blocks.insert(NewBB);
707 if (NumPredsFromRegion) {
720 for (AfterPHIs = OldPred->
begin(); isa<PHINode>(AfterPHIs); ++AfterPHIs) {
721 PHINode *PN = cast<PHINode>(AfterPHIs);
746 void CodeExtractor::severSplitPHINodesOfExits(
751 for (
PHINode &PN : ExitBB->phis()) {
756 IncomingVals.push_back(
i);
761 if (IncomingVals.size() <= 1)
768 ExitBB->getName() +
".split",
769 ExitBB->getParent(), ExitBB);
772 if (Blocks.count(PredBB))
773 PredBB->getTerminator()->replaceUsesOfWith(ExitBB, NewBB);
775 Blocks.insert(NewBB);
782 for (
unsigned i : IncomingVals)
784 for (
unsigned i :
reverse(IncomingVals))
791 void CodeExtractor::splitReturnBlocks() {
795 Block->splitBasicBlock(RI->getIterator(),
Block->getName() +
".ret");
813 Function *CodeExtractor::constructFunction(
const ValueSet &inputs,
814 const ValueSet &outputs,
824 switch (NumExitBlocks) {
831 std::vector<Type *> paramTy;
834 for (
Value *value : inputs) {
836 paramTy.push_back(value->getType());
843 paramTy.push_back(
output->getType());
849 dbgs() <<
"Function type: " << *RetTy <<
" f(";
850 for (
Type *
i : paramTy)
851 dbgs() << *
i <<
", ";
856 if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
863 AllowVarArgs && oldFunction->
isVarArg());
865 std::string SuffixToUse =
872 oldFunction->
getName() +
"." + SuffixToUse, M);
889 if (Attr.isStringAttribute()) {
890 if (Attr.getKindAsString() ==
"thunk")
893 switch (Attr.getKindAsEnum()) {
897 case Attribute::Alignment:
898 case Attribute::AllocSize:
899 case Attribute::ArgMemOnly:
900 case Attribute::Builtin:
901 case Attribute::ByVal:
903 case Attribute::Dereferenceable:
904 case Attribute::DereferenceableOrNull:
905 case Attribute::InAlloca:
906 case Attribute::InReg:
907 case Attribute::InaccessibleMemOnly:
908 case Attribute::InaccessibleMemOrArgMemOnly:
910 case Attribute::Naked:
911 case Attribute::Nest:
912 case Attribute::NoAlias:
913 case Attribute::NoBuiltin:
914 case Attribute::NoCapture:
915 case Attribute::NoMerge:
916 case Attribute::NoReturn:
917 case Attribute::NoSync:
918 case Attribute::NoUndef:
920 case Attribute::NonNull:
921 case Attribute::Preallocated:
922 case Attribute::ReadNone:
924 case Attribute::Returned:
925 case Attribute::ReturnsTwice:
926 case Attribute::SExt:
927 case Attribute::Speculatable:
928 case Attribute::StackAlignment:
929 case Attribute::StructRet:
930 case Attribute::SwiftError:
931 case Attribute::SwiftSelf:
932 case Attribute::WillReturn:
933 case Attribute::WriteOnly:
934 case Attribute::ZExt:
935 case Attribute::ImmArg:
936 case Attribute::ByRef:
942 case Attribute::AlwaysInline:
945 case Attribute::NoRecurse:
946 case Attribute::InlineHint:
947 case Attribute::MinSize:
948 case Attribute::NoCallback:
949 case Attribute::NoDuplicate:
950 case Attribute::NoFree:
951 case Attribute::NoImplicitFloat:
952 case Attribute::NoInline:
953 case Attribute::NonLazyBind:
954 case Attribute::NoRedZone:
955 case Attribute::NoUnwind:
956 case Attribute::NullPointerIsValid:
957 case Attribute::OptForFuzzing:
958 case Attribute::OptimizeNone:
959 case Attribute::OptimizeForSize:
960 case Attribute::SafeStack:
961 case Attribute::ShadowCallStack:
962 case Attribute::SanitizeAddress:
963 case Attribute::SanitizeMemory:
964 case Attribute::SanitizeThread:
965 case Attribute::SanitizeHWAddress:
966 case Attribute::SanitizeMemTag:
967 case Attribute::SpeculativeLoadHardening:
968 case Attribute::StackProtect:
969 case Attribute::StackProtectReq:
970 case Attribute::StackProtectStrong:
971 case Attribute::StrictFP:
972 case Attribute::UWTable:
973 case Attribute::VScaleRange:
974 case Attribute::NoCfCheck:
975 case Attribute::MustProgress:
976 case Attribute::NoProfile:
989 for (
unsigned i = 0,
e = inputs.size();
i !=
e; ++
i) {
997 StructTy, &*AI, Idx,
"gep_" + inputs[
i]->
getName(), TI);
998 RewriteVal =
new LoadInst(StructTy->getElementType(
i),
GEP,
999 "loadgep_" + inputs[
i]->getName(), TI);
1001 RewriteVal = &*AI++;
1003 std::vector<User *>
Users(inputs[
i]->user_begin(), inputs[
i]->user_end());
1006 if (Blocks.count(inst->getParent()))
1007 inst->replaceUsesOfWith(inputs[
i], RewriteVal);
1011 if (!AggregateArgs) {
1013 for (
unsigned i = 0,
e = inputs.size();
i !=
e; ++
i, ++AI)
1015 for (
unsigned i = 0,
e = outputs.size();
i !=
e; ++
i, ++AI)
1023 for (
auto &U :
Users)
1027 if (
I->isTerminator() &&
I->getFunction() == oldFunction &&
1028 !Blocks.count(
I->getParent()))
1029 I->replaceUsesOfWith(header, newHeader);
1044 for (
auto It =
BB->begin(), End =
BB->end(); It != End;) {
1045 auto *II = dyn_cast<IntrinsicInst>(&*It);
1047 if (!II || !II->isLifetimeStartOrEnd())
1057 if (II->getIntrinsicID() == Intrinsic::lifetime_start)
1058 LifetimesStart.
insert(Mem);
1059 II->eraseFromParent();
1081 bool InsertBefore) {
1082 for (
Value *Mem : Objects) {
1085 "Input memory not defined in original function");
1086 Value *&MemAsI8Ptr = Bitcasts[Mem];
1088 if (Mem->getType() == Int8PtrTy)
1099 Marker->insertBefore(
Term);
1103 if (!LifetimesStart.
empty()) {
1105 M, llvm::Intrinsic::lifetime_start, Int8PtrTy);
1106 insertMarkers(StartFn, LifetimesStart,
true);
1109 if (!LifetimesEnd.
empty()) {
1111 M, llvm::Intrinsic::lifetime_end, Int8PtrTy);
1112 insertMarkers(EndFn, LifetimesEnd,
false);
1122 ValueSet &outputs) {
1125 std::vector<Value *> params, StructValues, ReloadOutputs, Reloads;
1137 StructValues.push_back(
input);
1139 params.push_back(
input);
1140 if (
input->isSwiftError())
1141 SwiftErrorArgs.push_back(ArgNo);
1148 if (AggregateArgs) {
1149 StructValues.push_back(
output);
1153 nullptr,
output->getName() +
".loc",
1155 ReloadOutputs.push_back(alloca);
1156 params.push_back(alloca);
1162 if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
1163 std::vector<Type *> ArgTypes;
1164 for (
Value *V : StructValues)
1165 ArgTypes.push_back(V->getType());
1172 params.push_back(Struct);
1174 for (
unsigned i = 0,
e = inputs.size();
i !=
e; ++
i) {
1179 StructArgTy, Struct, Idx,
"gep_" + StructValues[
i]->
getName());
1187 NumExitBlocks > 1 ?
"targetBlock" :
"");
1199 for (
unsigned SwiftErrArgNo : SwiftErrorArgs) {
1200 call->addParamAttr(SwiftErrArgNo, Attribute::SwiftError);
1201 newFunction->
addParamAttr(SwiftErrArgNo, Attribute::SwiftError);
1205 unsigned FirstOut = inputs.size();
1207 std::advance(OutputArgBegin, inputs.size());
1210 for (
unsigned i = 0,
e = outputs.size();
i !=
e; ++
i) {
1211 Value *Output =
nullptr;
1212 if (AggregateArgs) {
1217 StructArgTy, Struct, Idx,
"gep_reload_" + outputs[
i]->
getName());
1221 Output = ReloadOutputs[
i];
1226 Reloads.push_back(
load);
1227 std::vector<User *>
Users(outputs[
i]->user_begin(), outputs[
i]->user_end());
1228 for (
unsigned u = 0,
e =
Users.size(); u !=
e; ++u) {
1238 codeReplacer, 0, codeReplacer);
1245 std::map<BasicBlock *, BasicBlock *> ExitBlockMap;
1247 unsigned switchVal = 0;
1254 BasicBlock *&NewTarget = ExitBlockMap[OldTarget];
1259 OldTarget->
getName() +
".exitStub",
1261 unsigned SuccNum = switchVal++;
1263 Value *brVal =
nullptr;
1264 switch (NumExitBlocks) {
1292 for (
unsigned i = 0,
e = outputs.size();
i !=
e; ++
i) {
1293 auto *OutI = dyn_cast<Instruction>(outputs[
i]);
1301 if (
auto *InvokeI = dyn_cast<InvokeInst>(OutI))
1302 InsertPt = InvokeI->getNormalDest()->getFirstInsertionPt();
1303 else if (
auto *Phi = dyn_cast<PHINode>(OutI))
1304 InsertPt = Phi->getParent()->getFirstInsertionPt();
1306 InsertPt = std::next(OutI->getIterator());
1310 Blocks.count(InsertBefore->
getParent())) &&
1311 "InsertPt should be in new function");
1313 "Number of output arguments should match "
1314 "the amount of defined values");
1315 if (AggregateArgs) {
1320 StructArgTy, &*OAI, Idx,
"gep_" + outputs[
i]->
getName(),
1327 new StoreInst(outputs[
i], &*OAI, InsertBefore);
1334 switch (NumExitBlocks) {
1383 void CodeExtractor::moveCodeToFunction(
Function *newFunction) {
1390 oldBlocks.remove(Block);
1393 newBlocks.push_back(Block);
1397 void CodeExtractor::calculateNewCallTerminatorWeights(
1409 Distribution BranchDist;
1416 BlockNode ExitNode(
i);
1417 uint64_t ExitFreq = ExitWeights[TI->
getSuccessor(
i)].getFrequency();
1419 BranchDist.addExit(ExitNode, ExitFreq);
1425 if (BranchDist.Total == 0) {
1431 BranchDist.normalize();
1434 for (
unsigned I = 0,
E = BranchDist.Weights.size();
I <
E; ++
I) {
1435 const auto &Weight = BranchDist.Weights[
I];
1438 BranchWeights[Weight.TargetNode.Index] = Weight.Amount;
1440 EdgeProbabilities[Weight.TargetNode.Index] = BP;
1444 LLVMContext::MD_prof,
1455 if (DVI->getFunction() != &
F)
1456 DVI->eraseFromParent();
1479 assert(OldSP->getUnit() &&
"Missing compile unit for subprogram");
1484 DISubprogram::SPFlagOptimized |
1485 DISubprogram::SPFlagLocalToUnit;
1488 0, SPType, 0, DINode::FlagZero, SPFlags);
1500 auto *DII = dyn_cast<DbgInfoIntrinsic>(&
I);
1505 if (
auto *DLI = dyn_cast<DbgLabelInst>(&
I)) {
1506 DILabel *OldLabel = DLI->getLabel();
1507 DINode *&NewLabel = RemappedMetadata[OldLabel];
1515 auto IsInvalidLocation = [&NewFunc](
Value *Location) {
1519 (!isa<Constant>(Location) && !isa<Instruction>(Location)))
1521 Instruction *LocationInst = dyn_cast<Instruction>(Location);
1522 return LocationInst && LocationInst->
getFunction() != &NewFunc;
1525 auto *DVI = cast<DbgVariableIntrinsic>(DII);
1527 if (
any_of(DVI->location_ops(), IsInvalidLocation)) {
1528 DebugIntrinsicsToDelete.push_back(DVI);
1534 DINode *&NewVar = RemappedMetadata[OldVar];
1538 OldVar->
getType(),
false, DINode::FlagZero,
1540 DVI->setVariable(cast<DILocalVariable>(NewVar));
1542 for (
auto *DII : DebugIntrinsicsToDelete)
1543 DII->eraseFromParent();
1553 auto updateLoopInfoLoc = [&Ctx,
1580 assert(BPI &&
"Both BPI and BFI are required to preserve profile info");
1582 if (Blocks.count(Pred))
1592 for (
auto It = Block->begin(), End = Block->end(); It != End;) {
1596 if (
auto *AI = dyn_cast<AssumeInst>(
I)) {
1599 AI->eraseFromParent();
1606 splitReturnBlocks();
1614 if (!Blocks.count(Succ)) {
1624 NumExitBlocks = ExitBlocks.
size();
1627 severSplitPHINodesOfEntry(header);
1628 severSplitPHINodesOfExits(ExitBlocks);
1632 "codeRepl", oldFunction,
1647 if (!
I.getDebugLoc())
1649 BranchI->setDebugLoc(
I.getDebugLoc());
1656 ValueSet inputs, outputs, SinkingCands, HoistingCands;
1658 findAllocas(CEAC, SinkingCands, HoistingCands, CommonExit);
1668 for (
auto *II : SinkingCands) {
1669 if (
auto *AI = dyn_cast<AllocaInst>(II)) {
1671 if (!FirstSunkAlloca)
1672 FirstSunkAlloca = AI;
1675 assert((SinkingCands.empty() || FirstSunkAlloca) &&
1676 "Did not expect a sink candidate without any allocas");
1677 for (
auto *II : SinkingCands) {
1678 if (!isa<AllocaInst>(II)) {
1679 cast<Instruction>(II)->moveAfter(FirstSunkAlloca);
1683 if (!HoistingCands.
empty()) {
1686 for (
auto *II : HoistingCands)
1699 constructFunction(inputs, outputs, header, newFuncRoot, codeReplacer,
1705 if (Count.hasValue())
1712 emitCallAndSwitchStatement(newFunction, codeReplacer, inputs, outputs);
1714 moveCodeToFunction(newFunction);
1726 if (BFI && NumExitBlocks > 1)
1727 calculateNewCallTerminatorWeights(codeReplacer, ExitWeights, BPI);
1739 for (
PHINode &PN : ExitBB->phis()) {
1740 Value *IncomingCodeReplacerVal =
nullptr;
1747 if (!IncomingCodeReplacerVal) {
1752 "PHI has two incompatbile incoming values from codeRepl");
1763 return isa<ReturnInst>(
Term) || isa<ResumeInst>(
Term);
1769 newFunction->
dump();
1783 auto *
I = dyn_cast_or_null<CallInst>(AssumeVH);
1788 if (
I->getFunction() != &OldFunc)
1795 auto *AffectedCI = dyn_cast_or_null<CallInst>(AffectedValVH);
1798 if (AffectedCI->getFunction() != &OldFunc)
1800 auto *AssumedInst = cast<Instruction>(AffectedCI->getOperand(0));
1801 if (AssumedInst->getFunction() != &OldFunc)
Move duplicate certain instructions close to their use
@ EndAttrKinds
Sentinal value useful for loops.
This class represents an incoming formal argument to a Function.
pred_range predecessors(BasicBlock *BB)
static StringRef getName(Value *V)
static IntegerType * getInt1Ty(LLVMContext &C)
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
DITypeRefArray getOrCreateTypeArray(ArrayRef< Metadata * > Elements)
Get a DITypeRefArray, create one if required.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Return a value (possibly void), from a function.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
A parsed version of the target data layout string in and methods for querying it.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
InstListType::iterator iterator
Instruction iterators...
const Function * getParent() const
Return the enclosing method, or null if none.
const BasicBlockListType & getBasicBlockList() const
Get the underlying elements of the Function...
void finalizeSubprogram(DISubprogram *SP)
Finalize a specific subprogram - no new variables may be added to this subprogram afterwards.
static Function * getFunction(Constant *C)
Represents a single loop in the control flow graph.
void dump() const
Support for debugging, callable in GDB: V->dump()
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
@ TombstoneKey
Use as Tombstone key for DenseMap of AttrKind.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static SwitchInst * Create(Value *Value, BasicBlock *Default, unsigned NumCases, Instruction *InsertBefore=nullptr)
DISubprogram * getSubprogram() const
Get the attached subprogram.
const BasicBlock & getEntryBlock() const
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
Value * removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty=true)
Remove an incoming value.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction.
@ EmptyKey
Use as Empty key for DenseMap of AttrKind.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
void updateLoopMetadataDebugLocations(Instruction &I, function_ref< DILocation *(const DILocation &)> Updater)
Update the debug locations contained within the MD_loop metadata attached to the instruction I,...
bool verifyFunction(const Function &F, raw_ostream *OS=nullptr)
Check a function for errors, useful for use when debugging a pass.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
ArrayRef< T > getArrayRef() const
StringRef getName() const
The instances of the Type class are immutable: once they are created, they are never changed.
static BranchProbability getZero()
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const
getNode - return the (Post)DominatorTree node for the specified basic block.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
user_iterator user_begin()
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DISubroutineType * createSubroutineType(DITypeRefArray ParameterTypes, DINode::DIFlags Flags=DINode::FlagZero, unsigned CC=0)
Create subroutine type.
LLVM_NODISCARD T pop_back_val()
Value * getPointerOperand()
succ_range successors(Instruction *I)
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
static IntegerType * getInt32Ty(LLVMContext &C)
bool empty() const
empty - Check if the array is empty.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM Basic Block Representation.
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.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
bool hasUWTable() const
True if the ABI mandates (or the user requested) that this function be in a unwind table.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
CaseIt removeCase(CaseIt I)
This method removes the specified case and its successor from the switch instruction.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
AttributeSet getFnAttributes() const
The function attributes are returned.
iterator begin()
Instruction iterator methods.
Optional< uint64_t > getProfileCountFromFreq(uint64_t Freq) const
Returns the estimated profile count of Freq.
Analysis providing branch probability information.
MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight)
Return metadata containing two branch weights.
static CallInst * Create(FunctionType *Ty, Value *F, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
DISPFlags
Debug info subprogram flags.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
void setBlockFreq(const BasicBlock *BB, uint64_t Freq)
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)
Create a new descriptor for the specified subprogram.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void setName(const Twine &Name)
Change the name of the value.
bool hasPersonalityFn() const
Check whether this function has a personality function.
bool stripDebugInfo(Function &F)
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
Analysis containing CSE Info
void changeImmediateDominator(DomTreeNodeBase< NodeT > *N, DomTreeNodeBase< NodeT > *NewIDom)
changeImmediateDominator - This method is used to update the dominator tree information when a node's...
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
The initial backend is deliberately restricted to z10 We should add support for later architectures at some point If an asm ties an i32 r result to an i64 input
@ InternalLinkage
Rename collisions when linking (static functions).
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
bool empty() const
Determine if the SetVector is empty or not.
bool isLifetimeStartOrEnd() const
Return true if the instruction is a llvm.lifetime.start or llvm.lifetime.end marker.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static BranchProbability getUnknown()
Distribution of unscaled probability weight.
AttributeList getAttributes() const
Return the attribute list for this Function.
void setSubprogram(DISubprogram *SP)
Set the attached subprogram.
This is the common base class for debug info intrinsics for variables.
Function::ProfileCount ProfileCount
inst_range instructions(Function *F)
An instruction for storing to memory.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Type * getReturnType() const
Returns the type of the ret val.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the generic address space (address sp...
BasicBlock * getSuccessor(unsigned idx) const
void setDefaultDest(BasicBlock *DefaultCase)
@ None
No attributes have been set.
Module * getParent()
Get the module that this global value is contained inside of...
void setIncomingBlock(unsigned i, BasicBlock *BB)
@ Bitcast
Perform the operation on a different, but equivalently sized type.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
This is an important class for using LLVM in a threaded context.
static BranchInst * Create(BasicBlock *IfTrue, Instruction *InsertBefore=nullptr)
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
S is passed via registers r2 But gcc stores them to the and then reload them to and r3 before issuing the call(r0 contains the address of the format string)
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...
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM currently emits rax rax movq rax rax ret It could narrow the loads and stores to emit rax rax movq rax rax ret The trouble is that there is a TokenFactor between the store and the load
void replaceUsesOfWith(Value *From, Value *To)
Replace uses of one Value with another.
bool isReachableFromEntry(const Use &U) const
Provide an overload for a Use.
bool isVoidTy() const
Return true if this is 'void'.
Value * getCondition() const
void setPersonalityFn(Constant *Fn)
A Module instance is used to store all the information related to an LLVM module.
StringRef getName() const
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
bool insert(const value_type &X)
Insert a new element into the SetVector.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void setEntryCount(ProfileCount Count, const DenseSet< GlobalValue::GUID > *Imports=nullptr)
Set the entry count for this function.
void setEdgeProbability(const BasicBlock *Src, const SmallVectorImpl< BranchProbability > &Probs)
Set the raw probabilities for all edges from the given block.
void setCondition(Value *V)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Class to represent struct types.
void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
A cache of @llvm.assume calls within a function.
Tagged DWARF-like metadata node.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Type * getType() const
All values are typed, get the type of this value.
const Function * getFunction() const
Return the function this instruction belongs to.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
static const Function * getParent(const Value *V)
LLVMContext & getContext() const
All values hold a context through their type.
self_iterator getIterator()
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This is the base class for all instructions that perform data casts.
StringRef getName() const
Return a constant reference to the value's name.
An instruction for reading from memory.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
DomTreeNodeBase< NodeT > * addNewBlock(NodeT *BB, NodeT *DomBB)
Add a new node to the dominator tree information.
const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
const Instruction & front() const
amdgpu Simplify well known AMD library false FunctionCallee Callee
LLVMContext & getContext() const
Get the context in which this basic block lives.
bool doesNotThrow() const
Determine if the function cannot unwind.
void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind)
adds the attribute to the list of attributes for the given arg.
static IntegerType * getInt64Ty(LLVMContext &C)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
MIPS Relocation Principles In there are several elements of the llvm::ISD::NodeType enum that deal with addresses and or relocations These are defined in include llvm Target TargetSelectionDAG td JumpTable
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
static ReturnInst * Create(LLVMContext &C, Value *retVal=nullptr, Instruction *InsertBefore=nullptr)
static constexpr sys::Memory::ProtectionFlags ReadOnly
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
Constant * getPersonalityFn() const
Get the personality function associated with this function.
A wrapper class for inspecting calls to intrinsic functions.
unsigned getAddressSpace() const
const BasicBlock & front() const
bool isVarArg() const
isVarArg - Return true if this function takes a variable number of arguments.
static Type * getVoidTy(LLVMContext &C)
const InstListType & getInstList() const
Return the underlying instruction list container.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
MutableArrayRef< ResultElem > assumptions()
Access the list of assumption handles currently tracked for this function.
const BasicBlock * getParent() const
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
iv Induction Variable Users
void unregisterAssumption(AssumeInst *CI)
Remove an @llvm.assume intrinsic from this function's cache if it has been added to the cache earlier...
uint32_t getAlignInBits() const
static IntegerType * getInt16Ty(LLVMContext &C)
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
This class represents a function call, abstracting a target machine's calling convention.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
static CastInst * CreatePointerCast(Value *S, Type *Ty, const Twine &Name, BasicBlock *InsertAtEnd)
Create a BitCast AddrSpaceCast, or a PtrToInt cast instruction.
an instruction to allocate memory on the stack
Class to represent profile counts.
void addCase(ConstantInt *OnVal, BasicBlock *Dest)
Add an entry to the switch instruction.
A vector that has set insertion semantics.
BasicBlock * SplitBlock(BasicBlock *Old, Instruction *SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="", bool Before=false)
Split the specified block at the specified instruction.
Representative of a block.
LLVM Value Representation.
iterator_range< user_iterator > users()
InstListType::const_iterator const_iterator
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
Class to represent function types.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
MutableArrayRef< ResultElem > assumptionsFor(const Value *V)
Access the list of assumptions which affect this value.