30 #include "llvm/Config/llvm-config.h" 45 #define DEBUG_TYPE "inline-cost" 47 STATISTIC(NumCallsAnalyzed,
"Number of call sites analyzed");
51 cl::desc(
"Control the amount of inlining to perform (default = 225)"));
55 cl::desc(
"Threshold for inlining functions with inline hint"));
60 cl::desc(
"Threshold for inlining cold callsites"));
67 cl::desc(
"Threshold for inlining functions with cold attribute"));
72 cl::desc(
"Threshold for hot callsites "));
76 cl::desc(
"Threshold for locally hot callsites "));
80 cl::desc(
"Maxmimum block frequency, expressed as a percentage of caller's " 81 "entry frequency, for a callsite to be cold in the absence of " 82 "profile information."));
86 cl::desc(
"Minimum block frequency, expressed as a multiple of caller's " 87 "entry frequency, for a callsite to be hot in the absence of " 88 "profile information."));
92 cl::desc(
"Compute the full inline cost of a call site even when the cost " 93 "exceeds the threshold."));
97 class CallAnalyzer :
public InstVisitor<CallAnalyzer, bool> {
105 std::function<AssumptionCache &(Function &)> &GetAssumptionCache;
132 bool ComputeFullInlineCost;
134 bool IsCallerRecursive;
135 bool IsRecursiveCall;
136 bool ExposesReturnsTwice;
137 bool HasDynamicAlloca;
138 bool ContainsNoDuplicateCall;
141 bool HasUninlineableIntrinsic;
145 uint64_t AllocatedSize;
146 unsigned NumInstructions, NumVectorInstructions;
147 int VectorBonus, TenPercentVectorBonus;
182 bool EnableLoadElimination;
184 int LoadEliminationCost;
187 bool isAllocaDerivedArg(
Value *V);
191 void disableSROA(
Value *V);
194 int InstructionCost);
195 void disableLoadElimination();
200 template <
typename Callable>
201 bool simplifyInstruction(
Instruction &
I, Callable Evaluate);
213 bool isKnownNonNullInCallee(
Value *V);
280 : TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),
281 PSI(PSI), F(Callee), DL(F.
getParent()->getDataLayout()), ORE(ORE),
282 CandidateCS(CSArg), Params(Params), Threshold(Params.DefaultThreshold),
284 Params.ComputeFullInlineCost || ORE),
285 IsCallerRecursive(
false), IsRecursiveCall(
false),
286 ExposesReturnsTwice(
false), HasDynamicAlloca(
false),
287 ContainsNoDuplicateCall(
false), HasReturn(
false), HasIndirectBr(
false),
288 HasUninlineableIntrinsic(
false), InitsVargArgs(
false), AllocatedSize(0),
289 NumInstructions(0), NumVectorInstructions(0), VectorBonus(0),
290 SingleBBBonus(0), EnableLoadElimination(
true), LoadEliminationCost(0),
291 NumConstantArgs(0), NumConstantOffsetPtrArgs(0), NumAllocaArgs(0),
292 NumConstantPtrCmps(0), NumConstantPtrDiffs(0),
293 NumInstructionsSimplified(0), SROACostSavings(0),
294 SROACostSavingsLost(0) {}
299 int getCost() {
return Cost; }
303 unsigned NumConstantArgs;
304 unsigned NumConstantOffsetPtrArgs;
305 unsigned NumAllocaArgs;
306 unsigned NumConstantPtrCmps;
307 unsigned NumConstantPtrDiffs;
308 unsigned NumInstructionsSimplified;
309 unsigned SROACostSavings;
310 unsigned SROACostSavingsLost;
318 bool CallAnalyzer::isAllocaDerivedArg(
Value *V) {
319 return SROAArgValues.
count(V);
324 bool CallAnalyzer::lookupSROAArgAndCost(
326 if (SROAArgValues.
empty() || SROAArgCosts.
empty())
330 if (ArgIt == SROAArgValues.
end())
334 CostIt = SROAArgCosts.
find(Arg);
335 return CostIt != SROAArgCosts.
end();
345 Cost += CostIt->second;
346 SROACostSavings -= CostIt->second;
347 SROACostSavingsLost += CostIt->second;
348 SROAArgCosts.
erase(CostIt);
349 disableLoadElimination();
353 void CallAnalyzer::disableSROA(
Value *V) {
356 if (lookupSROAArgAndCost(V, SROAArg, CostIt))
362 int InstructionCost) {
363 CostIt->second += InstructionCost;
364 SROACostSavings += InstructionCost;
367 void CallAnalyzer::disableLoadElimination() {
368 if (EnableLoadElimination) {
369 Cost += LoadEliminationCost;
370 LoadEliminationCost = 0;
371 EnableLoadElimination =
false;
387 if (
Constant *SimpleOp = SimplifiedValues.
lookup(GTI.getOperand()))
395 if (
StructType *STy = GTI.getStructTypeOrNull()) {
427 if (
auto *AllocSize = dyn_cast_or_null<ConstantInt>(Size)) {
431 return Base::visitAlloca(I);
443 return Base::visitAlloca(I);
449 HasDynamicAlloca =
true;
453 bool CallAnalyzer::visitPHI(
PHINode &I) {
469 std::pair<Value *, APInt> FirstBaseAndOffset = {
nullptr, ZeroOffset};
470 Value *FirstV =
nullptr;
475 if (DeadBlocks.
count(Pred))
479 BasicBlock *KnownSuccessor = KnownSuccessors[Pred];
480 if (KnownSuccessor && KnownSuccessor != I.
getParent())
490 C = SimplifiedValues.
lookup(V);
492 std::pair<Value *, APInt> BaseAndOffset = {
nullptr, ZeroOffset};
494 BaseAndOffset = ConstantOffsetPtrs.
lookup(V);
496 if (!C && !BaseAndOffset.first)
513 if (FirstBaseAndOffset == BaseAndOffset)
527 FirstBaseAndOffset = BaseAndOffset;
532 SimplifiedValues[&
I] = FirstC;
537 if (FirstBaseAndOffset.first) {
538 ConstantOffsetPtrs[&
I] = FirstBaseAndOffset;
542 if (lookupSROAArgAndCost(FirstV, SROAArg, CostIt))
543 SROAArgValues[&
I] = SROAArg;
555 std::pair<Value *, APInt> BaseAndOffset =
557 if (!BaseAndOffset.first)
562 if (!accumulateGEPOffset(cast<GEPOperator>(I), BaseAndOffset.second))
566 ConstantOffsetPtrs[&
I] = BaseAndOffset;
580 if (!isa<Constant>(*I) && !SimplifiedValues.
lookup(*I))
585 if ((I.
isInBounds() && canFoldInboundsGEP(I)) || IsGEPOffsetConstant(I)) {
587 SROAArgValues[&
I] = SROAArg;
602 template <
typename Callable>
603 bool CallAnalyzer::simplifyInstruction(
Instruction &I, Callable Evaluate) {
613 auto *C = Evaluate(COps);
616 SimplifiedValues[&
I] =
C;
628 std::pair<Value *, APInt> BaseAndOffset =
631 if (BaseAndOffset.first)
632 ConstantOffsetPtrs[&
I] = BaseAndOffset;
637 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt))
638 SROAArgValues[&
I] = SROAArg;
656 std::pair<Value *, APInt> BaseAndOffset =
658 if (BaseAndOffset.first)
659 ConstantOffsetPtrs[&
I] = BaseAndOffset;
671 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt))
672 SROAArgValues[&
I] = SROAArg;
689 std::pair<Value *, APInt> BaseAndOffset = ConstantOffsetPtrs.
lookup(Op);
690 if (BaseAndOffset.first)
691 ConstantOffsetPtrs[&
I] = BaseAndOffset;
697 if (lookupSROAArgAndCost(Op, SROAArg, CostIt))
698 SROAArgValues[&
I] = SROAArg;
703 bool CallAnalyzer::visitCastInst(
CastInst &I) {
717 case Instruction::FPTrunc:
718 case Instruction::FPExt:
719 case Instruction::UIToFP:
720 case Instruction::SIToFP:
721 case Instruction::FPToUI:
722 case Instruction::FPToSI:
741 disableSROA(Operand);
750 bool CallAnalyzer::isKnownNonNullInCallee(
Value *V) {
756 if (
Argument *A = dyn_cast<Argument>(V))
763 if (isAllocaDerivedArg(V))
772 bool CallAnalyzer::allowSizeGrowth(
CallSite CS) {
789 if (
InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
790 if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
814 auto CallSiteFreq = CallerBFI->
getBlockFreq(CallSiteBB);
815 auto CallerEntryFreq =
817 return CallSiteFreq < CallerEntryFreq * ColdProb;
821 CallAnalyzer::getHotCallSiteThreshold(
CallSite CS,
850 if (!allowSizeGrowth(CS)) {
859 return B ? std::min(A,
B.getValue()) : A;
888 int SingleBBBonusPercent = 50;
889 int VectorBonusPercent = 150;
893 auto DisallowAllBonuses = [&]() {
894 SingleBBBonusPercent = 0;
895 VectorBonusPercent = 0;
896 LastCallToStaticBonus = 0;
907 SingleBBBonusPercent = 0;
908 VectorBonusPercent = 0;
933 Threshold = HotCallSiteThreshold.getValue();
940 DisallowAllBonuses();
957 DisallowAllBonuses();
965 Threshold *= TTI.getInliningThresholdMultiplier();
967 SingleBBBonus = Threshold * SingleBBBonusPercent / 100;
968 VectorBonus = Threshold * VectorBonusPercent / 100;
970 bool OnlyOneCallAndLocalLinkage =
975 if (OnlyOneCallAndLocalLinkage)
979 bool CallAnalyzer::visitCmpInst(
CmpInst &I) {
992 Value *LHSBase, *RHSBase;
993 APInt LHSOffset, RHSOffset;
994 std::tie(LHSBase, LHSOffset) = ConstantOffsetPtrs.
lookup(LHS);
996 std::tie(RHSBase, RHSOffset) = ConstantOffsetPtrs.
lookup(RHS);
997 if (RHSBase && LHSBase == RHSBase) {
1003 SimplifiedValues[&
I] =
C;
1004 ++NumConstantPtrCmps;
1022 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt)) {
1023 if (isa<ConstantPointerNull>(I.
getOperand(1))) {
1028 disableSROA(CostIt);
1038 Value *LHSBase, *RHSBase;
1039 APInt LHSOffset, RHSOffset;
1040 std::tie(LHSBase, LHSOffset) = ConstantOffsetPtrs.
lookup(LHS);
1042 std::tie(RHSBase, RHSOffset) = ConstantOffsetPtrs.
lookup(RHS);
1043 if (RHSBase && LHSBase == RHSBase) {
1049 SimplifiedValues[&
I] =
C;
1050 ++NumConstantPtrDiffs;
1058 return Base::visitSub(I);
1065 CLHS = SimplifiedValues.
lookup(LHS);
1068 CRHS = SimplifiedValues.
lookup(RHS);
1070 Value *SimpleV =
nullptr;
1071 if (
auto FI = dyn_cast<FPMathOperator>(&I))
1073 CRHS ? CRHS : RHS, FI->getFastMathFlags(), DL);
1078 if (
Constant *C = dyn_cast_or_null<Constant>(SimpleV))
1079 SimplifiedValues[&I] = C;
1098 bool CallAnalyzer::visitLoad(
LoadInst &I) {
1107 disableSROA(CostIt);
1113 if (EnableLoadElimination &&
1122 bool CallAnalyzer::visitStore(
StoreInst &I) {
1131 disableSROA(CostIt);
1142 disableLoadElimination();
1191 C = dyn_cast_or_null<Constant>(SimplifiedValues.
lookup(*I));
1205 bool CallAnalyzer::visitCallSite(
CallSite CS) {
1209 ExposesReturnsTwice =
true;
1213 ContainsNoDuplicateCall =
true;
1217 if (simplifyCallSite(F, CS))
1223 switch (II->getIntrinsicID()) {
1226 disableLoadElimination();
1227 return Base::visitCallSite(CS);
1237 disableLoadElimination();
1242 HasUninlineableIntrinsic =
true;
1245 InitsVargArgs =
true;
1253 IsRecursiveCall =
true;
1257 if (TTI.isLoweredToCall(F)) {
1269 disableLoadElimination();
1270 return Base::visitCallSite(CS);
1283 Function *F = dyn_cast_or_null<Function>(SimplifiedValues.
lookup(Callee));
1286 disableLoadElimination();
1287 return Base::visitCallSite(CS);
1295 auto IndirectCallParams = Params;
1297 CallAnalyzer CA(TTI, GetAssumptionCache, GetBFI, PSI, ORE, *F, CS,
1298 IndirectCallParams);
1299 if (CA.analyzeCall(CS)) {
1302 Cost -=
std::max(0, CA.getThreshold() - CA.getCost());
1306 disableLoadElimination();
1307 return Base::visitCallSite(CS);
1310 bool CallAnalyzer::visitReturnInst(
ReturnInst &RI) {
1312 bool Free = !HasReturn;
1317 bool CallAnalyzer::visitBranchInst(
BranchInst &BI) {
1323 dyn_cast_or_null<ConstantInt>(
1334 TrueC = SimplifiedValues.
lookup(TrueVal);
1337 FalseC = SimplifiedValues.
lookup(FalseVal);
1343 if (TrueC == FalseC && TrueC) {
1344 SimplifiedValues[&
SI] = TrueC;
1349 return Base::visitSelectInst(SI);
1351 std::pair<Value *, APInt> TrueBaseAndOffset =
1352 ConstantOffsetPtrs.
lookup(TrueVal);
1353 std::pair<Value *, APInt> FalseBaseAndOffset =
1354 ConstantOffsetPtrs.
lookup(FalseVal);
1355 if (TrueBaseAndOffset == FalseBaseAndOffset && TrueBaseAndOffset.first) {
1356 ConstantOffsetPtrs[&
SI] = TrueBaseAndOffset;
1360 if (lookupSROAArgAndCost(TrueVal, SROAArg, CostIt))
1361 SROAArgValues[&
SI] = SROAArg;
1365 return Base::visitSelectInst(SI);
1376 if (TrueC && FalseC) {
1378 SimplifiedValues[&
SI] =
C;
1382 return Base::visitSelectInst(SI);
1386 if (
Constant *SelectedC = dyn_cast<Constant>(SelectedV)) {
1387 SimplifiedValues[&
SI] = SelectedC;
1394 std::pair<Value *, APInt> BaseAndOffset =
1395 ConstantOffsetPtrs.
lookup(SelectedV);
1396 if (BaseAndOffset.first) {
1397 ConstantOffsetPtrs[&
SI] = BaseAndOffset;
1401 if (lookupSROAArgAndCost(SelectedV, SROAArg, CostIt))
1402 SROAArgValues[&
SI] = SROAArg;
1408 bool CallAnalyzer::visitSwitchInst(
SwitchInst &SI) {
1414 if (isa<ConstantInt>(V))
1436 int64_t CostLowerBound =
1437 std::min((int64_t)CostUpperBound,
1438 (int64_t)SI.
getNumCases() * InlineConstants::InstrCost + Cost);
1440 if (CostLowerBound > Threshold && !ComputeFullInlineCost) {
1441 Cost = CostLowerBound;
1445 unsigned JumpTableSize = 0;
1446 unsigned NumCaseCluster =
1447 TTI.getEstimatedNumberOfCaseClusters(SI, JumpTableSize);
1451 if (JumpTableSize) {
1452 int64_t JTCost = (int64_t)JumpTableSize * InlineConstants::InstrCost +
1453 4 * InlineConstants::InstrCost;
1455 Cost = std::min((int64_t)CostUpperBound, JTCost + Cost);
1474 if (NumCaseCluster <= 3) {
1480 int64_t ExpectedNumberOfCompare = 3 * (int64_t)NumCaseCluster / 2 - 1;
1481 int64_t SwitchCost =
1484 Cost = std::min((int64_t)CostUpperBound, SwitchCost + Cost);
1497 HasIndirectBr =
true;
1501 bool CallAnalyzer::visitResumeInst(
ResumeInst &RI) {
1526 bool CallAnalyzer::visitInstruction(
Instruction &I) {
1558 if (isa<DbgInfoIntrinsic>(I))
1562 if (EphValues.
count(&*I))
1567 ++NumVectorInstructions;
1574 if (Base::visit(&*I))
1575 ++NumInstructionsSimplified;
1579 using namespace ore;
1582 if (IsRecursiveCall)
1584 else if (ExposesReturnsTwice)
1585 IR =
"exposes returns twice";
1586 else if (HasDynamicAlloca)
1587 IR =
"dynamic alloca";
1588 else if (HasIndirectBr)
1589 IR =
"indirect branch";
1590 else if (HasUninlineableIntrinsic)
1591 IR =
"uninlinable intrinsic";
1592 else if (InitsVargArgs)
1599 <<
NV(
"Callee", &F) <<
" has uninlinable pattern (" 1601 <<
") and cost is not fully computed";
1609 if (IsCallerRecursive &&
1611 InlineResult IR =
"recursive and allocates too much stack space";
1616 <<
NV(
"Callee", &F) <<
" is " <<
NV(
"InlineResult", IR.
message)
1617 <<
". Cost is not fully computed";
1624 if (Cost >= Threshold && !ComputeFullInlineCost)
1637 ConstantInt *CallAnalyzer::stripAndComputeInBoundsConstantOffsets(
Value *&V) {
1650 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
1651 if (!GEP->
isInBounds() || !accumulateGEPOffset(*GEP, Offset))
1655 V = cast<Operator>(V)->getOperand(0);
1656 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1657 if (GA->isInterposable())
1659 V = GA->getAliasee();
1664 }
while (Visited.
insert(V).second);
1681 return (DeadBlocks.
count(Pred) ||
1682 (KnownSuccessors[Pred] && KnownSuccessors[Pred] != Succ));
1687 return (!DeadBlocks.
count(BB) &&
1689 [&](
BasicBlock *
P) {
return IsEdgeDead(P, BB); }));
1693 if (Succ == NextBB || !IsNewlyDead(Succ))
1697 while (!NewDead.
empty()) {
1699 if (DeadBlocks.
insert(Dead))
1728 assert(NumInstructions == 0);
1729 assert(NumVectorInstructions == 0);
1732 updateThreshold(CS, F);
1738 assert(SingleBBBonus >= 0);
1739 assert(VectorBonus >= 0);
1744 Threshold += (SingleBBBonus + VectorBonus);
1756 if (Cost >= Threshold && !ComputeFullInlineCost)
1770 IsCallerRecursive =
true;
1779 FAI != FAE; ++FAI, ++CAI) {
1781 if (
Constant *C = dyn_cast<Constant>(CAI))
1782 SimplifiedValues[&*FAI] = C;
1784 Value *PtrArg = *CAI;
1785 if (
ConstantInt *C = stripAndComputeInBoundsConstantOffsets(PtrArg)) {
1786 ConstantOffsetPtrs[&*FAI] = std::make_pair(PtrArg, C->getValue());
1789 if (isa<AllocaInst>(PtrArg)) {
1790 SROAArgValues[&*FAI] = PtrArg;
1791 SROAArgCosts[PtrArg] = 0;
1795 NumConstantArgs = SimplifiedValues.
size();
1796 NumConstantOffsetPtrArgs = ConstantOffsetPtrs.
size();
1797 NumAllocaArgs = SROAArgValues.
size();
1815 BBSetVector BBWorklist;
1817 bool SingleBB =
true;
1819 for (
unsigned Idx = 0; Idx != BBWorklist.size(); ++Idx) {
1822 if (Cost >= Threshold && !ComputeFullInlineCost)
1836 return "blockaddress";
1848 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
1852 dyn_cast_or_null<ConstantInt>(SimplifiedValues.
lookup(Cond))) {
1854 BBWorklist.insert(NextBB);
1855 KnownSuccessors[BB] = NextBB;
1856 findDeadBlocks(BB, NextBB);
1860 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
1863 dyn_cast_or_null<ConstantInt>(SimplifiedValues.
lookup(Cond))) {
1865 BBWorklist.insert(NextBB);
1866 KnownSuccessors[BB] = NextBB;
1867 findDeadBlocks(BB, NextBB);
1884 Threshold -= SingleBBBonus;
1889 bool OnlyOneCallAndLocalLinkage =
1894 if (!OnlyOneCallAndLocalLinkage && ContainsNoDuplicateCall)
1895 return "noduplicate";
1906 for (
Loop *L : LI) {
1908 if (DeadBlocks.
count(L->getHeader()))
1918 if (NumVectorInstructions <= NumInstructions / 10)
1919 Threshold -= VectorBonus;
1920 else if (NumVectorInstructions <= NumInstructions / 2)
1921 Threshold -= VectorBonus/2;
1923 return Cost <
std::max(1, Threshold);
1926 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 1929 #define DEBUG_PRINT_STAT(x) dbgs() << " " #x ": " << x << "\n" 1943 #undef DEBUG_PRINT_STAT 1958 for (
unsigned I = 0,
E = CS.
arg_size(); I !=
E; ++
I) {
1967 unsigned NumStores = (TypeSize + PointerSize - 1) / PointerSize;
1975 NumStores = std::min(NumStores, 8U);
1995 GetAssumptionCache, GetBFI, PSI, ORE);
2015 for (
unsigned I = 0,
E = CS.
arg_size(); I !=
E; ++
I)
2059 <<
"... (caller:" << Caller->
getName() <<
")\n");
2061 CallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE, *Callee, CS,
2068 if (!ShouldInline && CA.getCost() < CA.getThreshold())
2070 if (ShouldInline && CA.getCost() >= CA.getThreshold())
2081 if (isa<IndirectBrInst>(BI->getTerminator()) || BI->hasAddressTaken())
2084 for (
auto &II : *BI) {
2095 if (!ReturnsTwice && CS.
isCall() &&
2181 unsigned SizeOptLevel) {
2184 if (SizeOptLevel == 1)
2186 if (SizeOptLevel == 2)
static void collectEphemeralValues(const Loop *L, AssumptionCache *AC, SmallPtrSetImpl< const Value *> &EphValues)
Collect a loop's ephemeral values (those used only by an assume or similar intrinsics in the loop)...
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
Return a value (possibly void), from a function.
User::op_iterator arg_iterator
The type of iterator to use when looping over actual arguments at this call site. ...
unsigned getNumCases() const
Return the number of 'cases' in this switch instruction, excluding the default case.
A parsed version of the target data layout string in and methods for querying it. ...
static ConstantInt * getFalse(LLVMContext &Context)
Value * getPointerOperand()
Thresholds to tune inline cost analysis.
This class is the base class for the comparison instructions.
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
bool hasLocalLinkage() const
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
Base class for instruction visitors.
DiagnosticInfoOptimizationBase::Argument NV
unsigned arg_size() const
This class represents lattice values for constants.
BinaryOps getOpcode() const
Optional< int > OptSizeThreshold
Threshold to use when the caller is optimized for size.
A Module instance is used to store all the information related to an LLVM module. ...
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
static int computeThresholdFromOptLevels(unsigned OptLevel, unsigned SizeOptLevel)
static cl::opt< int > LocallyHotCallSiteThreshold("locally-hot-callsite-threshold", cl::Hidden, cl::init(525), cl::ZeroOrMore, cl::desc("Threshold for locally hot callsites "))
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
void push_back(const T &Elt)
Analysis providing profile information.
const int OptMinSizeThreshold
Use when minsize (-Oz) is specified.
Value * getCondition() const
gep_type_iterator gep_type_end(const User *GEP)
const Value * getTrueValue() const
An efficient, type-erasing, non-owning reference to a callable.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
A cache of @llvm.assume calls within a function.
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
LLVMContext & getContext() const
All values hold a context through their type.
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time...
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
static void dump(StringRef Title, SpillInfo const &Spills)
BasicBlock * getSuccessor(unsigned i) const
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
STATISTIC(NumFunctions, "Total number of functions")
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
block Block Frequency true
An instruction for reading from memory.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
Value * getCondition() const
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
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...
bool isVectorTy() const
True if this is an instance of VectorType.
void reserve(size_type N)
std::enable_if< std::is_unsigned< T >::value, T >::type SaturatingAdd(T X, T Y, bool *ResultOverflowed=nullptr)
Add two unsigned integers, X and Y, of type T.
Represents the cost of inlining a function.
bool isFunctionEntryCold(const Function *F)
Returns true if F has cold function entry.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool isNoInline() const
Return true if the call should not be inlined.
bool areInlineCompatible(const Function &Caller, const Function &Callee)
iterator begin()
Instruction iterator methods.
bool isHotCallSite(const CallSite &CS, BlockFrequencyInfo *BFI)
Returns true if CallSite CS is considered hot.
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
Value * SimplifyFPBinOp(unsigned Opcode, Value *LHS, Value *RHS, FastMathFlags FMF, const SimplifyQuery &Q)
Given operands for an FP BinaryOperator, fold the result or return null.
unsigned getAllocaAddrSpace() const
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
static bool isColdCallSite(CallSite CS, BlockFrequencyInfo &CallerBFI)
Return true if the block containing the call site has a BlockFrequency of less than ColdCCRelFreq% of...
This class represents the LLVM 'select' instruction.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
This is the base class for all instructions that perform data casts.
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
Optional< int > HintThreshold
Threshold to use for callees with inline hint.
Class to represent struct types.
A Use represents the edge between a Value definition and its users.
bool isInlineViable(Function &Callee)
Minimal filter to detect invalid constructs for inlining.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
InstrTy * getInstruction() const
#define DEBUG_PRINT_STAT(x)
This class represents a cast from a pointer to an integer.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
OtherOps getOpcode() const
Get the opcode casted to the right type.
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static cl::opt< int > ColdThreshold("inlinecold-threshold", cl::Hidden, cl::init(45), cl::desc("Threshold for inlining functions with cold attribute"))
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Type * getType() const
All values are typed, get the type of this value.
bool insert(const value_type &X)
Insert a new element into the SetVector.
bool isInBounds() const
Determine whether the GEP has the inbounds flag.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
This class represents a no-op cast from one type to another.
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
const APInt & getValue() const
Return the constant as an APInt value reference.
const int LastCallToStaticBonus
An instruction for storing to memory.
static cl::opt< int > HotCallSiteThreshold("hot-callsite-threshold", cl::Hidden, cl::init(3000), cl::ZeroOrMore, cl::desc("Threshold for hot callsites "))
static InlineCost getAlways(const char *Reason)
InlineResult is basically true or false.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
amdgpu Simplify well known AMD library false Value * Callee
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
Value * getOperand(unsigned i) const
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
Class to represent pointers.
bool isCall() const
Return true if a CallInst is enclosed.
iterator find(const_arg_type_t< KeyT > Val)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool hasProfileSummary()
Returns true if profile summary is available.
const BasicBlock & getEntryBlock() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
IntegerType * getIntPtrType(LLVMContext &C, unsigned AddressSpace=0) const
Returns an integer type with size at least as big as that of a pointer in the given address space...
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
initializer< Ty > init(const Ty &Val)
bool erase(const KeyT &Val)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
const int IndirectCallThreshold
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
Conditional or Unconditional Branch instruction.
This function has undefined behavior.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
Resume the propagation of an exception.
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if this function has the given attribute.
bool isPointerTy() const
True if this is an instance of PointerType.
Indirect Branch Instruction.
const int OptAggressiveThreshold
Use when -O3 is specified.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Optional< int > OptMinSizeThreshold
Threshold to use when the caller is optimized for minsize.
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
Value * getPointerOperand()
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
const Function * getFunction() const
Return the function this instruction belongs to.
This class represents a cast from an integer to a pointer.
const Value * getCondition() const
bool isAssumeLikeIntrinsic(const Instruction *I)
Return true if it is an intrinsic that cannot be speculated but also cannot trap. ...
Optional< int > LocallyHotCallSiteThreshold
Threshold to use when the callsite is considered hot relative to function entry.
const Value * getArraySize() const
Get the number of elements allocated.
static cl::opt< int > ColdCallSiteRelFreq("cold-callsite-rel-freq", cl::Hidden, cl::init(2), cl::ZeroOrMore, cl::desc("Maxmimum block frequency, expressed as a percentage of caller's " "entry frequency, for a callsite to be cold in the absence of " "profile information."))
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
InlineCost getInlineCost(CallSite CS, const InlineParams &Params, TargetTransformInfo &CalleeTTI, std::function< AssumptionCache &(Function &)> &GetAssumptionCache, Optional< function_ref< BlockFrequencyInfo &(Function &)>> GetBFI, ProfileSummaryInfo *PSI, OptimizationRemarkEmitter *ORE=nullptr)
Get an InlineCost object representing the cost of inlining this callsite.
std::enable_if< std::is_unsigned< T >::value, T >::type SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, and add the unsigned integer, A to the product.
static bool functionsHaveCompatibleAttributes(Function *Caller, Function *Callee, TargetTransformInfo &TTI)
Test that there are no attribute conflicts between Caller and Callee that prevent inlining...
uint64_t getEntryFreq() const
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
static cl::opt< int > ColdCallSiteThreshold("inline-cold-callsite-threshold", cl::Hidden, cl::init(45), cl::desc("Threshold for inlining cold callsites"))
Iterator for intrusive lists based on ilist_node.
This is the shared class of boolean and integer constants.
ValTy * getArgument(unsigned ArgNo) const
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options...
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static cl::opt< int > HotCallSiteRelFreq("hot-callsite-rel-freq", cl::Hidden, cl::init(60), cl::ZeroOrMore, cl::desc("Minimum block frequency, expressed as a multiple of caller's " "entry frequency, for a callsite to be hot in the absence of " "profile information."))
static cl::opt< bool > OptComputeFullInlineCost("inline-cost-full", cl::Hidden, cl::init(false), cl::desc("Compute the full inline cost of a call site even when the cost " "exceeds the threshold."))
LLVM_NODISCARD T pop_back_val()
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.
bool isConditional() const
pred_range predecessors(BasicBlock *BB)
Optional< int > ColdThreshold
Threshold to use for cold callees.
static cl::opt< int > HintThreshold("inlinehint-threshold", cl::Hidden, cl::init(325), cl::desc("Threshold for inlining functions with inline hint"))
unsigned getNumIncomingValues() const
Return the number of incoming edges.
CaseIt findCaseValue(const ConstantInt *C)
Search all of the case values for the specified constant.
static ConstantInt * getTrue(LLVMContext &Context)
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
iterator_range< user_iterator > users()
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
const Value * getFalseValue() const
amdgpu Simplify well known AMD library false Value Value * Arg
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
static cl::opt< int > InlineThreshold("inline-threshold", cl::Hidden, cl::init(225), cl::ZeroOrMore, cl::desc("Control the amount of inlining to perform (default = 225)"))
Predicate getPredicate() const
Return the predicate for this instruction.
FunTy * getCaller() const
Return the caller function for this call site.
static InlineCost getNever(const char *Reason)
bool isFunctionEntryHot(const Function *F)
Returns true if F has hot function entry.
uint64_t getElementOffset(unsigned Idx) const
LLVM_NODISCARD bool empty() const
Represents a single loop in the control flow graph.
int getCallsiteCost(CallSite CS, const DataLayout &DL)
Return the cost associated with a callsite, including parameter passing and the call/return instructi...
StringRef getName() const
Return a constant reference to the value's name.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Constant * ConstantFoldInstOperands(Instruction *I, ArrayRef< Constant *> Ops, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldInstOperands - Attempt to constant fold an instruction with the specified operands...
bool isUnconditional() const
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
LLVM_NODISCARD bool empty() 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...
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
bool isColdCallSite(const CallSite &CS, BlockFrequencyInfo *BFI)
Returns true if Callsite CS is considered cold.
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
const unsigned TotalAllocaSizeRecursiveCaller
Do not inline functions which allocate this many bytes on the stack when the caller is recursive...
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef< unsigned > getIndices() const
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool isEquality() const
This is just a convenience that dispatches to the subclasses.
A vector that has set insertion semantics.
succ_range successors(Instruction *I)
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Optional< int > ColdCallSiteThreshold
Threshold to use when the callsite is considered cold.
bool canConstantFoldCallTo(ImmutableCallSite CS, const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function...
static const Function * getParent(const Value *V)
print Print MemDeps of function
bool hasOneUse() const
Return true if there is exactly one user of this value.
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
const int OptSizeThreshold
Use when optsize (-Os) is specified.
bool nullPointerIsDefined() const
Check if null pointer dereferencing is considered undefined behavior for the function.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
Constant * ConstantFoldCall(ImmutableCallSite CS, Function *F, ArrayRef< Constant *> Operands, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
Value * getPointerOperand()
Statically lint checks LLVM IR
Type * getElementType() const
Optional< int > HotCallSiteThreshold
Threshold to use when the callsite is considered hot.
int DefaultThreshold
The default threshold to start with for a callee.
static InlineCost get(int Cost, int Threshold)
A wrapper class for inspecting calls to intrinsic functions.
const BasicBlock * getParent() const
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
gep_type_iterator gep_type_begin(const User *GEP)