40 #define DEBUG_TYPE "inline-cost"
42 STATISTIC(NumCallsAnalyzed,
"Number of call sites analyzed");
46 cl::desc(
"Control the amount of inlining to perform (default = 225)"));
50 cl::desc(
"Threshold for inlining functions with inline hint"));
55 cl::desc(
"Threshold for inlining cold callsites"));
62 cl::desc(
"Threshold for inlining functions with cold attribute"));
67 cl::desc(
"Threshold for hot callsites "));
71 cl::desc(
"Maxmimum block frequency, expressed as a percentage of caller's "
72 "entry frequency, for a callsite to be cold in the absence of "
73 "profile information."));
77 class CallAnalyzer :
public InstVisitor<CallAnalyzer, bool> {
85 std::function<AssumptionCache &(Function &)> &GetAssumptionCache;
110 bool IsCallerRecursive;
111 bool IsRecursiveCall;
112 bool ExposesReturnsTwice;
113 bool HasDynamicAlloca;
114 bool ContainsNoDuplicateCall;
120 uint64_t AllocatedSize;
121 unsigned NumInstructions, NumVectorInstructions;
122 int FiftyPercentVectorBonus, TenPercentVectorBonus;
147 bool isAllocaDerivedArg(
Value *V);
148 bool lookupSROAArgAndCost(
Value *V,
Value *&Arg,
151 void disableSROA(
Value *V);
153 int InstructionCost);
157 template <
typename Callable>
158 bool simplifyInstruction(
Instruction &
I, Callable Evaluate);
170 bool isKnownNonNullInCallee(
Value *V);
231 : TTI(TTI), GetAssumptionCache(GetAssumptionCache), GetBFI(GetBFI),
233 CandidateCS(CSArg), Params(Params),
Threshold(Params.DefaultThreshold),
234 Cost(0), IsCallerRecursive(
false), IsRecursiveCall(
false),
235 ExposesReturnsTwice(
false), HasDynamicAlloca(
false),
236 ContainsNoDuplicateCall(
false), HasReturn(
false), HasIndirectBr(
false),
237 HasFrameEscape(
false), AllocatedSize(0), NumInstructions(0),
238 NumVectorInstructions(0), FiftyPercentVectorBonus(0),
239 TenPercentVectorBonus(0), VectorBonus(0), NumConstantArgs(0),
240 NumConstantOffsetPtrArgs(0), NumAllocaArgs(0), NumConstantPtrCmps(0),
241 NumConstantPtrDiffs(0), NumInstructionsSimplified(0),
242 SROACostSavings(0), SROACostSavingsLost(0) {}
247 int getCost() {
return Cost; }
251 unsigned NumConstantArgs;
252 unsigned NumConstantOffsetPtrArgs;
253 unsigned NumAllocaArgs;
254 unsigned NumConstantPtrCmps;
255 unsigned NumConstantPtrDiffs;
256 unsigned NumInstructionsSimplified;
257 unsigned SROACostSavings;
258 unsigned SROACostSavingsLost;
266 bool CallAnalyzer::isAllocaDerivedArg(
Value *V) {
267 return SROAArgValues.count(V);
272 bool CallAnalyzer::lookupSROAArgAndCost(
274 if (SROAArgValues.empty() || SROAArgCosts.empty())
278 if (ArgIt == SROAArgValues.
end())
282 CostIt = SROAArgCosts.
find(Arg);
283 return CostIt != SROAArgCosts.
end();
293 Cost += CostIt->second;
294 SROACostSavings -= CostIt->second;
295 SROACostSavingsLost += CostIt->second;
296 SROAArgCosts.
erase(CostIt);
300 void CallAnalyzer::disableSROA(
Value *V) {
303 if (lookupSROAArgAndCost(V, SROAArg, CostIt))
309 int InstructionCost) {
310 CostIt->second += InstructionCost;
311 SROACostSavings += InstructionCost;
326 if (
Constant *SimpleOp = SimplifiedValues.lookup(GTI.getOperand()))
334 if (
StructType *STy = GTI.getStructTypeOrNull()) {
353 if (
Constant *SimpleOp = SimplifiedValues.lookup(*
I))
367 if (
auto *AllocSize = dyn_cast_or_null<ConstantInt>(Size)) {
371 return Base::visitAlloca(I);
383 return Base::visitAlloca(I);
389 HasDynamicAlloca =
true;
393 bool CallAnalyzer::visitPHI(
PHINode &I) {
417 std::pair<Value *, APInt> BaseAndOffset = ConstantOffsetPtrs.lookup(Ptr);
418 if (BaseAndOffset.first) {
421 if (!accumulateGEPOffset(cast<GEPOperator>(I), BaseAndOffset.second)) {
429 ConstantOffsetPtrs[&
I] = BaseAndOffset;
434 SROAArgValues[&
I] = SROAArg;
443 if (!isa<Constant>(*I) && !SimplifiedValues.lookup(*I))
448 if (IsGEPOffsetConstant(I)) {
450 SROAArgValues[&
I] = SROAArg;
465 template <
typename Callable>
466 bool CallAnalyzer::simplifyInstruction(
Instruction &I, Callable Evaluate) {
471 COp = SimplifiedValues.lookup(
Op);
476 auto *
C = Evaluate(COps);
479 SimplifiedValues[&
I] =
C;
491 std::pair<Value *, APInt> BaseAndOffset =
494 if (BaseAndOffset.first)
495 ConstantOffsetPtrs[&
I] = BaseAndOffset;
500 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt))
501 SROAArgValues[&
I] = SROAArg;
518 std::pair<Value *, APInt> BaseAndOffset =
520 if (BaseAndOffset.first)
521 ConstantOffsetPtrs[&
I] = BaseAndOffset;
533 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt))
534 SROAArgValues[&
I] = SROAArg;
551 std::pair<Value *, APInt> BaseAndOffset = ConstantOffsetPtrs.lookup(Op);
552 if (BaseAndOffset.first)
553 ConstantOffsetPtrs[&
I] = BaseAndOffset;
559 if (lookupSROAArgAndCost(Op, SROAArg, CostIt))
560 SROAArgValues[&
I] = SROAArg;
565 bool CallAnalyzer::visitCastInst(
CastInst &I) {
586 disableSROA(Operand);
592 return CandidateCS.paramHasAttr(A->
getArgNo(), Attr);
595 bool CallAnalyzer::isKnownNonNullInCallee(
Value *V) {
601 if (
Argument *A = dyn_cast<Argument>(V))
602 if (paramHasAttr(A, Attribute::NonNull))
608 if (isAllocaDerivedArg(V))
617 bool CallAnalyzer::allowSizeGrowth(
CallSite CS) {
634 if (
InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
635 if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
646 if (PSI->hasProfileSummary())
647 return PSI->isColdCallSite(CS, CallerBFI);
657 auto CallSiteFreq = CallerBFI->
getBlockFreq(CallSiteBB);
658 auto CallerEntryFreq =
660 return CallSiteFreq < CallerEntryFreq * ColdProb;
665 if (!allowSizeGrowth(CS)) {
704 if (CallerBFI || PSI->hasSampleProfile()) {
705 if (PSI->isHotCallSite(CS, CallerBFI)) {
707 Threshold = Params.HotCallSiteThreshold.getValue();
708 }
else if (isColdCallSite(CS, CallerBFI)) {
713 if (PSI->isFunctionEntryHot(&Callee)) {
719 }
else if (PSI->isFunctionEntryCold(&Callee)) {
729 Threshold *= TTI.getInliningThresholdMultiplier();
732 bool CallAnalyzer::visitCmpInst(
CmpInst &I) {
745 Value *LHSBase, *RHSBase;
746 APInt LHSOffset, RHSOffset;
747 std::tie(LHSBase, LHSOffset) = ConstantOffsetPtrs.lookup(LHS);
749 std::tie(RHSBase, RHSOffset) = ConstantOffsetPtrs.lookup(RHS);
750 if (RHSBase && LHSBase == RHSBase) {
756 SimplifiedValues[&
I] =
C;
757 ++NumConstantPtrCmps;
775 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt)) {
776 if (isa<ConstantPointerNull>(I.
getOperand(1))) {
791 Value *LHSBase, *RHSBase;
792 APInt LHSOffset, RHSOffset;
793 std::tie(LHSBase, LHSOffset) = ConstantOffsetPtrs.lookup(LHS);
795 std::tie(RHSBase, RHSOffset) = ConstantOffsetPtrs.lookup(RHS);
796 if (RHSBase && LHSBase == RHSBase) {
802 SimplifiedValues[&
I] =
C;
803 ++NumConstantPtrDiffs;
811 return Base::visitSub(I);
817 Value *SimpleV =
nullptr;
818 if (
auto FI = dyn_cast<FPMathOperator>(&I))
820 FI->getFastMathFlags(),
DL);
823 return dyn_cast_or_null<Constant>(SimpleV);
826 if (simplifyInstruction(I, Evaluate))
836 bool CallAnalyzer::visitLoad(
LoadInst &I) {
851 bool CallAnalyzer::visitStore(
StoreInst &I) {
911 C = dyn_cast_or_null<Constant>(SimplifiedValues.lookup(*I));
925 bool CallAnalyzer::visitCallSite(
CallSite CS) {
926 if (CS.
hasFnAttr(Attribute::ReturnsTwice) &&
929 ExposesReturnsTwice =
true;
933 ContainsNoDuplicateCall =
true;
937 if (simplifyCallSite(F, CS))
943 switch (II->getIntrinsicID()) {
945 return Base::visitCallSite(CS);
947 case Intrinsic::load_relative:
952 case Intrinsic::memset:
953 case Intrinsic::memcpy:
954 case Intrinsic::memmove:
957 case Intrinsic::localescape:
958 HasFrameEscape =
true;
966 IsRecursiveCall =
true;
970 if (TTI.isLoweredToCall(F)) {
981 return Base::visitCallSite(CS);
994 Function *F = dyn_cast_or_null<Function>(SimplifiedValues.lookup(Callee));
996 return Base::visitCallSite(CS);
1003 auto IndirectCallParams = Params;
1005 CallAnalyzer CA(TTI, GetAssumptionCache, GetBFI, PSI, *F, CS,
1006 IndirectCallParams);
1007 if (CA.analyzeCall(CS)) {
1010 Cost -=
std::max(0, CA.getThreshold() - CA.getCost());
1013 return Base::visitCallSite(CS);
1016 bool CallAnalyzer::visitReturnInst(
ReturnInst &RI) {
1018 bool Free = !HasReturn;
1023 bool CallAnalyzer::visitBranchInst(
BranchInst &BI) {
1029 dyn_cast_or_null<ConstantInt>(
1039 if (isa<ConstantInt>(V))
1061 int64_t CostLowerBound =
1063 (int64_t)SI.
getNumCases() * InlineConstants::InstrCost + Cost);
1066 Cost = CostLowerBound;
1070 unsigned JumpTableSize = 0;
1071 unsigned NumCaseCluster =
1072 TTI.getEstimatedNumberOfCaseClusters(SI, JumpTableSize);
1076 if (JumpTableSize) {
1077 int64_t JTCost = (int64_t)JumpTableSize * InlineConstants::InstrCost +
1078 4 * InlineConstants::InstrCost;
1080 Cost =
std::min((int64_t)CostUpperBound, JTCost + Cost);
1099 if (NumCaseCluster <= 3) {
1105 int64_t ExpectedNumberOfCompare = 3 * (int64_t)NumCaseCluster / 2 - 1;
1106 int64_t SwitchCost =
1109 Cost =
std::min((int64_t)CostUpperBound, SwitchCost + Cost);
1122 HasIndirectBr =
true;
1126 bool CallAnalyzer::visitResumeInst(
ResumeInst &RI) {
1151 bool CallAnalyzer::visitInstruction(
Instruction &I) {
1154 if (TargetTransformInfo::TCC_Free == TTI.getUserCost(&I))
1172 bool CallAnalyzer::analyzeBlock(
BasicBlock *BB,
1182 if (isa<DbgInfoIntrinsic>(I))
1186 if (EphValues.
count(&*I))
1191 ++NumVectorInstructions;
1209 if (Base::visit(&*I))
1210 ++NumInstructionsSimplified;
1215 if (IsRecursiveCall || ExposesReturnsTwice || HasDynamicAlloca ||
1216 HasIndirectBr || HasFrameEscape)
1222 if (IsCallerRecursive &&
1241 ConstantInt *CallAnalyzer::stripAndComputeInBoundsConstantOffsets(
Value *&V) {
1253 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
1254 if (!GEP->
isInBounds() || !accumulateGEPOffset(*GEP, Offset))
1258 V = cast<Operator>(V)->getOperand(0);
1259 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1260 if (GA->isInterposable())
1262 V = GA->getAliasee();
1267 }
while (Visited.
insert(V).second);
1280 bool CallAnalyzer::analyzeCall(
CallSite CS) {
1293 assert(NumInstructions == 0);
1294 assert(NumVectorInstructions == 0);
1297 updateThreshold(CS, F);
1299 FiftyPercentVectorBonus = 3 *
Threshold / 2;
1300 TenPercentVectorBonus = 3 *
Threshold / 4;
1305 bool SingleBB =
true;
1311 Threshold += (SingleBBBonus + FiftyPercentVectorBonus);
1319 bool OnlyOneCallAndLocalLinkage =
1321 if (OnlyOneCallAndLocalLinkage)
1344 IsCallerRecursive =
true;
1353 FAI != FAE; ++FAI, ++CAI) {
1355 if (
Constant *C = dyn_cast<Constant>(CAI))
1356 SimplifiedValues[&*FAI] = C;
1358 Value *PtrArg = *CAI;
1359 if (
ConstantInt *C = stripAndComputeInBoundsConstantOffsets(PtrArg)) {
1360 ConstantOffsetPtrs[&*FAI] = std::make_pair(PtrArg, C->getValue());
1363 if (isa<AllocaInst>(PtrArg)) {
1364 SROAArgValues[&*FAI] = PtrArg;
1365 SROAArgCosts[PtrArg] = 0;
1369 NumConstantArgs = SimplifiedValues.size();
1370 NumConstantOffsetPtrArgs = ConstantOffsetPtrs.size();
1371 NumAllocaArgs = SROAArgValues.size();
1389 BBSetVector BBWorklist;
1392 for (
unsigned Idx = 0; Idx != BBWorklist.size(); ++Idx) {
1413 if (!analyzeBlock(BB, EphValues))
1420 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
1424 dyn_cast_or_null<ConstantInt>(SimplifiedValues.lookup(Cond))) {
1425 BBWorklist.insert(BI->
getSuccessor(SimpleCond->isZero() ? 1 : 0));
1429 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
1432 dyn_cast_or_null<ConstantInt>(SimplifiedValues.lookup(Cond))) {
1433 BBWorklist.insert(SI->
findCaseValue(SimpleCond)->getCaseSuccessor());
1458 if (!OnlyOneCallAndLocalLinkage && ContainsNoDuplicateCall)
1464 if (NumVectorInstructions <= NumInstructions / 10)
1466 else if (NumVectorInstructions <= NumInstructions / 2)
1467 Threshold -= (FiftyPercentVectorBonus - TenPercentVectorBonus);
1472 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1475 #define DEBUG_PRINT_STAT(x) dbgs() << " " #x ": " << x << "\n"
1488 #undef DEBUG_PRINT_STAT
1503 for (
unsigned I = 0,
E = CS.
arg_size(); I !=
E; ++
I) {
1511 unsigned NumStores = (TypeSize + PointerSize - 1) / PointerSize;
1519 NumStores =
std::min(NumStores, 8U);
1539 GetAssumptionCache, GetBFI, PSI);
1555 if (CS.
hasFnAttr(Attribute::AlwaysInline)) {
1581 CallAnalyzer CA(CalleeTTI, GetAssumptionCache, GetBFI, PSI, *Callee, CS,
1583 bool ShouldInline = CA.analyzeCall(CS);
1588 if (!ShouldInline && CA.getCost() < CA.getThreshold())
1590 if (ShouldInline && CA.getCost() >= CA.getThreshold())
1601 if (isa<IndirectBrInst>(BI->getTerminator()) || BI->hasAddressTaken())
1604 for (
auto &II : *BI) {
1615 if (!ReturnsTwice && CS.
isCall() &&
1623 llvm::Intrinsic::localescape)
1683 unsigned SizeOptLevel) {
1686 if (SizeOptLevel == 1)
1688 if (SizeOptLevel == 2)
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. ...
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()
Instruction::CastOps getOpcode() const
Return the opcode of this CastInst.
Thresholds to tune inline cost analysis.
This class is the base class for the comparison instructions.
FunTy * getCaller() const
Return the caller function for this call site.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
Base class for instruction visitors.
Type * getSourceElementType() const
STATISTIC(NumFunctions,"Total number of functions")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
ArrayRef< unsigned > getIndices() const
Optional< int > OptSizeThreshold
Threshold to use when the caller is optimized for size.
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
A Module instance is used to store all the information related to an LLVM module. ...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static int computeThresholdFromOptLevels(unsigned OptLevel, unsigned SizeOptLevel)
Analysis providing profile information.
const int OptMinSizeThreshold
Use when minsize (-Oz) is specified.
gep_type_iterator gep_type_end(const User *GEP)
An efficient, type-erasing, non-owning reference to a callable.
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
A cache of .assume calls within a function.
static void dump(StringRef Title, SpillInfo const &Spills)
const Function * getParent() const
Return the enclosing method, or null if none.
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
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.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
Type * getElementType() const
void reserve(size_type N)
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...
bool optForSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
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 isEquality() const
This is just a convenience that dispatches to the subclasses.
bool optForMinSize() const
Optimize this function for minimum size (-Oz).
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
unsigned arg_size() const
bool areInlineCompatible(const Function &Caller, const Function &Callee)
StringRef getName() const
Return a constant reference to the value's name.
iterator begin()
Instruction iterator methods.
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.
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1...
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
bool isUnconditional() const
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
This is the base class for all instructions that perform data casts.
const APInt & getValue() const
Return the constant as an APInt value reference.
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.
ValTy * getCalledValue() const
Return the pointer to function that is being called.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
bool isCall() const
Return true if a CallInst is enclosed.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
#define DEBUG_PRINT_STAT(x)
This class represents a cast from a pointer to an integer.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static cl::opt< int > ColdThreshold("inlinecold-threshold", cl::Hidden, cl::init(45), cl::desc("Threshold for inlining functions with cold attribute"))
BasicBlock * getSuccessor(unsigned i) const
This class represents a no-op cast from one type to another.
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
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 "))
bool isInBounds() const
Determine whether the GEP has the inbounds flag.
Class to represent pointers.
iterator find(const_arg_type_t< KeyT > Val)
uint64_t getElementOffset(unsigned Idx) const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
Function Alias Analysis false
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)
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."))
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.
bool isVectorTy() const
True if this is an instance of VectorType.
This function has undefined behavior.
This is an important base class in LLVM.
Resume the propagation of an exception.
bool isNoInline() const
Return true if the call should not be inlined.
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 isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static InlineCost getNever()
Value * getOperand(unsigned i) const
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if this function has the given attribute.
Value * getPointerOperand()
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...
Predicate getPredicate() const
Return the predicate for this instruction.
This class represents a cast from an integer to a pointer.
bool isPointerTy() const
True if this is an instance of PointerType.
LLVMContext & getContext() const
All values hold a context through their type.
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...
bool isConditional() const
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 cl::opt< int > ColdCallSiteThreshold("inline-cold-callsite-threshold", cl::Hidden, cl::init(45), cl::desc("Threshold for inlining cold callsites"))
BinaryOps getOpcode() const
InlineCost getInlineCost(CallSite CS, const InlineParams &Params, TargetTransformInfo &CalleeTTI, std::function< AssumptionCache &(Function &)> &GetAssumptionCache, Optional< function_ref< BlockFrequencyInfo &(Function &)>> GetBFI, ProfileSummaryInfo *PSI)
Get an InlineCost object representing the cost of inlining this callsite.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
InstrTy * getInstruction() const
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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...
ValTy * getArgument(unsigned ArgNo) const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isStaticAlloca() const
Return true if this alloca is in the entry block of the function and is a constant size...
Type * getType() const
All values are typed, get the type of this value.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
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 isZero() const
This is just a convenience method to make client code smaller for a common code.
const BasicBlock & getEntryBlock() const
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"))
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...
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
iterator_range< user_iterator > users()
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
Value * getCondition() const
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
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)"))
Value * getCondition() const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
int getCallsiteCost(CallSite CS, const DataLayout &DL)
Return the cost associated with a callsite, including parameter passing and the call/return instructi...
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool hasOneUse() const
Return true if there is exactly one user of this value.
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time...
unsigned getNumCases() const
Return the number of 'cases' in this switch instruction, excluding the default case.
bool hasLocalLinkage() const
OtherOps getOpcode() const
Get the opcode casted to the right type.
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
StringRef getValueAsString() const
Return the attribute's value as a string.
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...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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...
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
LLVM Value Representation.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
A vector that has set insertion semantics.
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...
const Value * getArraySize() const
Get the number of elements allocated.
static const Function * getParent(const Value *V)
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
print Print MemDeps of function
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
const int OptSizeThreshold
Use when optsize (-Os) is specified.
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...
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)...
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
static InlineCost getAlways()
Value * getPointerOperand()
const BasicBlock * getParent() 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.
an instruction to allocate memory on the stack
This instruction inserts a struct field of array element value into an aggregate value.
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
gep_type_iterator gep_type_begin(const User *GEP)