29 #include "llvm/Config/llvm-config.h" 43 #define DEBUG_TYPE "inline-cost" 45 STATISTIC(NumCallsAnalyzed,
"Number of call sites analyzed");
49 cl::desc(
"Control the amount of inlining to perform (default = 225)"));
53 cl::desc(
"Threshold for inlining functions with inline hint"));
58 cl::desc(
"Threshold for inlining cold callsites"));
65 cl::desc(
"Threshold for inlining functions with cold attribute"));
70 cl::desc(
"Threshold for hot callsites "));
74 cl::desc(
"Threshold for locally hot callsites "));
78 cl::desc(
"Maxmimum block frequency, expressed as a percentage of caller's " 79 "entry frequency, for a callsite to be cold in the absence of " 80 "profile information."));
84 cl::desc(
"Minimum block frequency, expressed as a multiple of caller's " 85 "entry frequency, for a callsite to be hot in the absence of " 86 "profile information."));
90 cl::desc(
"Compute the full inline cost of a call site even when the cost " 91 "exceeds the threshold."));
95 class CallAnalyzer :
public InstVisitor<CallAnalyzer, bool> {
103 std::function<AssumptionCache &(Function &)> &GetAssumptionCache;
130 bool ComputeFullInlineCost;
132 bool IsCallerRecursive;
133 bool IsRecursiveCall;
134 bool ExposesReturnsTwice;
135 bool HasDynamicAlloca;
136 bool ContainsNoDuplicateCall;
139 bool HasUninlineableIntrinsic;
143 uint64_t AllocatedSize;
144 unsigned NumInstructions, NumVectorInstructions;
145 int VectorBonus, TenPercentVectorBonus;
180 bool EnableLoadElimination;
182 int LoadEliminationCost;
185 bool isAllocaDerivedArg(
Value *V);
189 void disableSROA(
Value *V);
192 int InstructionCost);
193 void disableLoadElimination();
198 template <
typename Callable>
199 bool simplifyInstruction(
Instruction &
I, Callable Evaluate);
211 bool isKnownNonNullInCallee(
Value *V);
277 : TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),
278 PSI(PSI), F(Callee), DL(F.
getParent()->getDataLayout()), ORE(ORE),
279 CandidateCS(CSArg), Params(Params), Threshold(Params.DefaultThreshold),
281 Params.ComputeFullInlineCost || ORE),
282 IsCallerRecursive(
false), IsRecursiveCall(
false),
283 ExposesReturnsTwice(
false), HasDynamicAlloca(
false),
284 ContainsNoDuplicateCall(
false), HasReturn(
false), HasIndirectBr(
false),
285 HasUninlineableIntrinsic(
false), UsesVarArgs(
false), AllocatedSize(0),
286 NumInstructions(0), NumVectorInstructions(0), VectorBonus(0),
287 SingleBBBonus(0), EnableLoadElimination(
true), LoadEliminationCost(0),
288 NumConstantArgs(0), NumConstantOffsetPtrArgs(0), NumAllocaArgs(0),
289 NumConstantPtrCmps(0), NumConstantPtrDiffs(0),
290 NumInstructionsSimplified(0), SROACostSavings(0),
291 SROACostSavingsLost(0) {}
296 int getCost() {
return Cost; }
300 unsigned NumConstantArgs;
301 unsigned NumConstantOffsetPtrArgs;
302 unsigned NumAllocaArgs;
303 unsigned NumConstantPtrCmps;
304 unsigned NumConstantPtrDiffs;
305 unsigned NumInstructionsSimplified;
306 unsigned SROACostSavings;
307 unsigned SROACostSavingsLost;
315 bool CallAnalyzer::isAllocaDerivedArg(
Value *V) {
316 return SROAArgValues.
count(V);
321 bool CallAnalyzer::lookupSROAArgAndCost(
323 if (SROAArgValues.
empty() || SROAArgCosts.
empty())
327 if (ArgIt == SROAArgValues.
end())
331 CostIt = SROAArgCosts.
find(Arg);
332 return CostIt != SROAArgCosts.
end();
342 Cost += CostIt->second;
343 SROACostSavings -= CostIt->second;
344 SROACostSavingsLost += CostIt->second;
345 SROAArgCosts.
erase(CostIt);
346 disableLoadElimination();
350 void CallAnalyzer::disableSROA(
Value *V) {
353 if (lookupSROAArgAndCost(V, SROAArg, CostIt))
359 int InstructionCost) {
360 CostIt->second += InstructionCost;
361 SROACostSavings += InstructionCost;
364 void CallAnalyzer::disableLoadElimination() {
365 if (EnableLoadElimination) {
366 Cost += LoadEliminationCost;
367 LoadEliminationCost = 0;
368 EnableLoadElimination =
false;
384 if (
Constant *SimpleOp = SimplifiedValues.
lookup(GTI.getOperand()))
392 if (
StructType *STy = GTI.getStructTypeOrNull()) {
424 if (
auto *AllocSize = dyn_cast_or_null<ConstantInt>(Size)) {
428 return Base::visitAlloca(I);
440 return Base::visitAlloca(I);
446 HasDynamicAlloca =
true;
450 bool CallAnalyzer::visitPHI(
PHINode &I) {
466 std::pair<Value *, APInt> FirstBaseAndOffset = {
nullptr, ZeroOffset};
467 Value *FirstV =
nullptr;
472 if (DeadBlocks.
count(Pred))
476 BasicBlock *KnownSuccessor = KnownSuccessors[Pred];
477 if (KnownSuccessor && KnownSuccessor != I.
getParent())
487 C = SimplifiedValues.
lookup(V);
489 std::pair<Value *, APInt> BaseAndOffset = {
nullptr, ZeroOffset};
491 BaseAndOffset = ConstantOffsetPtrs.
lookup(V);
493 if (!C && !BaseAndOffset.first)
510 if (FirstBaseAndOffset == BaseAndOffset)
524 FirstBaseAndOffset = BaseAndOffset;
529 SimplifiedValues[&
I] = FirstC;
534 if (FirstBaseAndOffset.first) {
535 ConstantOffsetPtrs[&
I] = FirstBaseAndOffset;
539 if (lookupSROAArgAndCost(FirstV, SROAArg, CostIt))
540 SROAArgValues[&
I] = SROAArg;
552 std::pair<Value *, APInt> BaseAndOffset =
554 if (!BaseAndOffset.first)
559 if (!accumulateGEPOffset(cast<GEPOperator>(I), BaseAndOffset.second))
563 ConstantOffsetPtrs[&
I] = BaseAndOffset;
577 if (!isa<Constant>(*I) && !SimplifiedValues.
lookup(*I))
582 if ((I.
isInBounds() && canFoldInboundsGEP(I)) || IsGEPOffsetConstant(I)) {
584 SROAArgValues[&
I] = SROAArg;
599 template <
typename Callable>
600 bool CallAnalyzer::simplifyInstruction(
Instruction &I, Callable Evaluate) {
610 auto *C = Evaluate(COps);
613 SimplifiedValues[&
I] =
C;
625 std::pair<Value *, APInt> BaseAndOffset =
628 if (BaseAndOffset.first)
629 ConstantOffsetPtrs[&
I] = BaseAndOffset;
634 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt))
635 SROAArgValues[&
I] = SROAArg;
653 std::pair<Value *, APInt> BaseAndOffset =
655 if (BaseAndOffset.first)
656 ConstantOffsetPtrs[&
I] = BaseAndOffset;
668 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt))
669 SROAArgValues[&
I] = SROAArg;
686 std::pair<Value *, APInt> BaseAndOffset = ConstantOffsetPtrs.
lookup(Op);
687 if (BaseAndOffset.first)
688 ConstantOffsetPtrs[&
I] = BaseAndOffset;
694 if (lookupSROAArgAndCost(Op, SROAArg, CostIt))
695 SROAArgValues[&
I] = SROAArg;
700 bool CallAnalyzer::visitCastInst(
CastInst &I) {
714 case Instruction::FPTrunc:
715 case Instruction::FPExt:
716 case Instruction::UIToFP:
717 case Instruction::SIToFP:
718 case Instruction::FPToUI:
719 case Instruction::FPToSI:
737 disableSROA(Operand);
746 bool CallAnalyzer::isKnownNonNullInCallee(
Value *V) {
752 if (
Argument *A = dyn_cast<Argument>(V))
753 if (paramHasAttr(A, Attribute::NonNull))
759 if (isAllocaDerivedArg(V))
768 bool CallAnalyzer::allowSizeGrowth(
CallSite CS) {
785 if (
InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
786 if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
810 auto CallSiteFreq = CallerBFI->
getBlockFreq(CallSiteBB);
811 auto CallerEntryFreq =
813 return CallSiteFreq < CallerEntryFreq * ColdProb;
817 CallAnalyzer::getHotCallSiteThreshold(
CallSite CS,
846 if (!allowSizeGrowth(CS)) {
855 return B ? std::min(A,
B.getValue()) : A;
884 int SingleBBBonusPercent = 50;
885 int VectorBonusPercent = 150;
889 auto DisallowAllBonuses = [&]() {
890 SingleBBBonusPercent = 0;
891 VectorBonusPercent = 0;
892 LastCallToStaticBonus = 0;
903 SingleBBBonusPercent = 0;
904 VectorBonusPercent = 0;
929 Threshold = HotCallSiteThreshold.getValue();
936 DisallowAllBonuses();
953 DisallowAllBonuses();
961 Threshold *= TTI.getInliningThresholdMultiplier();
963 SingleBBBonus = Threshold * SingleBBBonusPercent / 100;
964 VectorBonus = Threshold * VectorBonusPercent / 100;
966 bool OnlyOneCallAndLocalLinkage =
971 if (OnlyOneCallAndLocalLinkage)
975 bool CallAnalyzer::visitCmpInst(
CmpInst &I) {
988 Value *LHSBase, *RHSBase;
989 APInt LHSOffset, RHSOffset;
990 std::tie(LHSBase, LHSOffset) = ConstantOffsetPtrs.
lookup(LHS);
992 std::tie(RHSBase, RHSOffset) = ConstantOffsetPtrs.
lookup(RHS);
993 if (RHSBase && LHSBase == RHSBase) {
999 SimplifiedValues[&
I] =
C;
1000 ++NumConstantPtrCmps;
1018 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt)) {
1019 if (isa<ConstantPointerNull>(I.
getOperand(1))) {
1024 disableSROA(CostIt);
1034 Value *LHSBase, *RHSBase;
1035 APInt LHSOffset, RHSOffset;
1036 std::tie(LHSBase, LHSOffset) = ConstantOffsetPtrs.
lookup(LHS);
1038 std::tie(RHSBase, RHSOffset) = ConstantOffsetPtrs.
lookup(RHS);
1039 if (RHSBase && LHSBase == RHSBase) {
1045 SimplifiedValues[&
I] =
C;
1046 ++NumConstantPtrDiffs;
1054 return Base::visitSub(I);
1061 CLHS = SimplifiedValues.
lookup(LHS);
1064 CRHS = SimplifiedValues.
lookup(RHS);
1066 Value *SimpleV =
nullptr;
1067 if (
auto FI = dyn_cast<FPMathOperator>(&I))
1069 CRHS ? CRHS : RHS, FI->getFastMathFlags(), DL);
1074 if (
Constant *C = dyn_cast_or_null<Constant>(SimpleV))
1075 SimplifiedValues[&I] = C;
1094 bool CallAnalyzer::visitLoad(
LoadInst &I) {
1103 disableSROA(CostIt);
1109 if (EnableLoadElimination &&
1118 bool CallAnalyzer::visitStore(
StoreInst &I) {
1127 disableSROA(CostIt);
1138 disableLoadElimination();
1187 C = dyn_cast_or_null<Constant>(SimplifiedValues.
lookup(*I));
1201 bool CallAnalyzer::visitCallSite(
CallSite CS) {
1202 if (CS.
hasFnAttr(Attribute::ReturnsTwice) &&
1205 ExposesReturnsTwice =
true;
1209 ContainsNoDuplicateCall =
true;
1213 if (simplifyCallSite(F, CS))
1219 switch (II->getIntrinsicID()) {
1222 disableLoadElimination();
1223 return Base::visitCallSite(CS);
1225 case Intrinsic::load_relative:
1230 case Intrinsic::memset:
1231 case Intrinsic::memcpy:
1232 case Intrinsic::memmove:
1233 disableLoadElimination();
1236 case Intrinsic::icall_branch_funnel:
1237 case Intrinsic::localescape:
1238 HasUninlineableIntrinsic =
true;
1240 case Intrinsic::vastart:
1241 case Intrinsic::vaend:
1250 IsRecursiveCall =
true;
1254 if (TTI.isLoweredToCall(F)) {
1266 disableLoadElimination();
1267 return Base::visitCallSite(CS);
1280 Function *F = dyn_cast_or_null<Function>(SimplifiedValues.
lookup(Callee));
1283 disableLoadElimination();
1284 return Base::visitCallSite(CS);
1292 auto IndirectCallParams = Params;
1294 CallAnalyzer CA(TTI, GetAssumptionCache, GetBFI, PSI, ORE, *F, CS,
1295 IndirectCallParams);
1296 if (CA.analyzeCall(CS)) {
1299 Cost -=
std::max(0, CA.getThreshold() - CA.getCost());
1303 disableLoadElimination();
1304 return Base::visitCallSite(CS);
1307 bool CallAnalyzer::visitReturnInst(
ReturnInst &RI) {
1309 bool Free = !HasReturn;
1314 bool CallAnalyzer::visitBranchInst(
BranchInst &BI) {
1320 dyn_cast_or_null<ConstantInt>(
1331 TrueC = SimplifiedValues.
lookup(TrueVal);
1334 FalseC = SimplifiedValues.
lookup(FalseVal);
1340 if (TrueC == FalseC && TrueC) {
1341 SimplifiedValues[&
SI] = TrueC;
1346 return Base::visitSelectInst(SI);
1348 std::pair<Value *, APInt> TrueBaseAndOffset =
1349 ConstantOffsetPtrs.
lookup(TrueVal);
1350 std::pair<Value *, APInt> FalseBaseAndOffset =
1351 ConstantOffsetPtrs.
lookup(FalseVal);
1352 if (TrueBaseAndOffset == FalseBaseAndOffset && TrueBaseAndOffset.first) {
1353 ConstantOffsetPtrs[&
SI] = TrueBaseAndOffset;
1357 if (lookupSROAArgAndCost(TrueVal, SROAArg, CostIt))
1358 SROAArgValues[&
SI] = SROAArg;
1362 return Base::visitSelectInst(SI);
1373 if (TrueC && FalseC) {
1375 SimplifiedValues[&
SI] =
C;
1379 return Base::visitSelectInst(SI);
1383 if (
Constant *SelectedC = dyn_cast<Constant>(SelectedV)) {
1384 SimplifiedValues[&
SI] = SelectedC;
1391 std::pair<Value *, APInt> BaseAndOffset =
1392 ConstantOffsetPtrs.
lookup(SelectedV);
1393 if (BaseAndOffset.first) {
1394 ConstantOffsetPtrs[&
SI] = BaseAndOffset;
1398 if (lookupSROAArgAndCost(SelectedV, SROAArg, CostIt))
1399 SROAArgValues[&
SI] = SROAArg;
1405 bool CallAnalyzer::visitSwitchInst(
SwitchInst &SI) {
1411 if (isa<ConstantInt>(V))
1433 int64_t CostLowerBound =
1434 std::min((int64_t)CostUpperBound,
1435 (int64_t)SI.
getNumCases() * InlineConstants::InstrCost + Cost);
1437 if (CostLowerBound > Threshold && !ComputeFullInlineCost) {
1438 Cost = CostLowerBound;
1442 unsigned JumpTableSize = 0;
1443 unsigned NumCaseCluster =
1444 TTI.getEstimatedNumberOfCaseClusters(SI, JumpTableSize);
1448 if (JumpTableSize) {
1449 int64_t JTCost = (int64_t)JumpTableSize * InlineConstants::InstrCost +
1450 4 * InlineConstants::InstrCost;
1452 Cost = std::min((int64_t)CostUpperBound, JTCost + Cost);
1471 if (NumCaseCluster <= 3) {
1477 int64_t ExpectedNumberOfCompare = 3 * (int64_t)NumCaseCluster / 2 - 1;
1478 int64_t SwitchCost =
1481 Cost = std::min((int64_t)CostUpperBound, SwitchCost + Cost);
1494 HasIndirectBr =
true;
1498 bool CallAnalyzer::visitResumeInst(
ResumeInst &RI) {
1523 bool CallAnalyzer::visitInstruction(
Instruction &I) {
1544 bool CallAnalyzer::analyzeBlock(
BasicBlock *BB,
1554 if (isa<DbgInfoIntrinsic>(I))
1558 if (EphValues.
count(&*I))
1563 ++NumVectorInstructions;
1570 if (Base::visit(&*I))
1571 ++NumInstructionsSimplified;
1575 using namespace ore;
1577 if (IsRecursiveCall || ExposesReturnsTwice || HasDynamicAlloca ||
1578 HasIndirectBr || HasUninlineableIntrinsic || UsesVarArgs) {
1584 <<
" has uninlinable pattern and cost is not fully computed";
1592 if (IsCallerRecursive &&
1599 <<
" is recursive and allocates too much stack space. Cost is " 1600 "not fully computed";
1607 if (Cost >= Threshold && !ComputeFullInlineCost)
1620 ConstantInt *CallAnalyzer::stripAndComputeInBoundsConstantOffsets(
Value *&V) {
1633 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
1634 if (!GEP->
isInBounds() || !accumulateGEPOffset(*GEP, Offset))
1638 V = cast<Operator>(V)->getOperand(0);
1639 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1640 if (GA->isInterposable())
1642 V = GA->getAliasee();
1647 }
while (Visited.
insert(V).second);
1664 return (DeadBlocks.
count(Pred) ||
1665 (KnownSuccessors[Pred] && KnownSuccessors[Pred] != Succ));
1670 return (!DeadBlocks.
count(BB) &&
1672 [&](
BasicBlock *
P) {
return IsEdgeDead(P, BB); }));
1676 if (Succ == NextBB || !IsNewlyDead(Succ))
1680 while (!NewDead.
empty()) {
1682 if (DeadBlocks.
insert(Dead))
1698 bool CallAnalyzer::analyzeCall(
CallSite CS) {
1711 assert(NumInstructions == 0);
1712 assert(NumVectorInstructions == 0);
1715 updateThreshold(CS, F);
1720 Threshold += (SingleBBBonus + VectorBonus);
1732 if (Cost >= Threshold && !ComputeFullInlineCost)
1746 IsCallerRecursive =
true;
1755 FAI != FAE; ++FAI, ++CAI) {
1757 if (
Constant *C = dyn_cast<Constant>(CAI))
1758 SimplifiedValues[&*FAI] = C;
1760 Value *PtrArg = *CAI;
1761 if (
ConstantInt *C = stripAndComputeInBoundsConstantOffsets(PtrArg)) {
1762 ConstantOffsetPtrs[&*FAI] = std::make_pair(PtrArg, C->getValue());
1765 if (isa<AllocaInst>(PtrArg)) {
1766 SROAArgValues[&*FAI] = PtrArg;
1767 SROAArgCosts[PtrArg] = 0;
1771 NumConstantArgs = SimplifiedValues.
size();
1772 NumConstantOffsetPtrArgs = ConstantOffsetPtrs.
size();
1773 NumAllocaArgs = SROAArgValues.
size();
1791 BBSetVector BBWorklist;
1793 bool SingleBB =
true;
1795 for (
unsigned Idx = 0; Idx != BBWorklist.size(); ++Idx) {
1798 if (Cost >= Threshold && !ComputeFullInlineCost)
1816 if (!analyzeBlock(BB, EphValues))
1823 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
1827 dyn_cast_or_null<ConstantInt>(SimplifiedValues.
lookup(Cond))) {
1829 BBWorklist.insert(NextBB);
1830 KnownSuccessors[BB] = NextBB;
1831 findDeadBlocks(BB, NextBB);
1835 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
1838 dyn_cast_or_null<ConstantInt>(SimplifiedValues.
lookup(Cond))) {
1840 BBWorklist.insert(NextBB);
1841 KnownSuccessors[BB] = NextBB;
1842 findDeadBlocks(BB, NextBB);
1859 Threshold -= SingleBBBonus;
1864 bool OnlyOneCallAndLocalLinkage =
1869 if (!OnlyOneCallAndLocalLinkage && ContainsNoDuplicateCall)
1875 if (NumVectorInstructions <= NumInstructions / 10)
1876 Threshold -= VectorBonus;
1877 else if (NumVectorInstructions <= NumInstructions / 2)
1878 Threshold -= VectorBonus/2;
1880 return Cost <
std::max(1, Threshold);
1883 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 1886 #define DEBUG_PRINT_STAT(x) dbgs() << " " #x ": " << x << "\n" 1900 #undef DEBUG_PRINT_STAT 1915 for (
unsigned I = 0,
E = CS.
arg_size(); I !=
E; ++
I) {
1924 unsigned NumStores = (TypeSize + PointerSize - 1) / PointerSize;
1932 NumStores = std::min(NumStores, 8U);
1952 GetAssumptionCache, GetBFI, PSI, ORE);
1972 for (
unsigned I = 0,
E = CS.
arg_size(); I !=
E; ++
I)
1981 if (CS.
hasFnAttr(Attribute::AlwaysInline)) {
2011 <<
"... (caller:" << Caller->
getName() <<
")\n");
2013 CallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, ORE, *Callee, CS,
2015 bool ShouldInline = CA.analyzeCall(CS);
2020 if (!ShouldInline && CA.getCost() < CA.getThreshold())
2022 if (ShouldInline && CA.getCost() >= CA.getThreshold())
2033 if (isa<IndirectBrInst>(BI->getTerminator()) || BI->hasAddressTaken())
2036 for (
auto &II : *BI) {
2047 if (!ReturnsTwice && CS.
isCall() &&
2057 case llvm::Intrinsic::icall_branch_funnel:
2060 case llvm::Intrinsic::localescape:
2062 case llvm::Intrinsic::vastart:
2063 case llvm::Intrinsic::vaend:
2134 unsigned SizeOptLevel) {
2137 if (SizeOptLevel == 1)
2139 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.
void push_back(const T &Elt)
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
Compute iterated dominance frontiers using a linear time algorithm.
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.
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...
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.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
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)
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 "))
amdgpu Simplify well known AMD library false Value * Callee
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)
Subclasses of this class are all able to terminate a basic block.
* 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).
static InlineCost getNever()
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 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.
bool isFunctionEntryHot(const Function *F)
Returns true if F has hot function entry.
uint64_t getElementOffset(unsigned Idx) const
LLVM_NODISCARD bool empty() const
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.
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
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())
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
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.
succ_range successors(BasicBlock *BB)
A vector that has set insertion semantics.
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
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...
static InlineCost getAlways()
Value * getPointerOperand()
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)