39 #define DEBUG_TYPE "inline-cost"
41 STATISTIC(NumCallsAnalyzed,
"Number of call sites analyzed");
45 cl::desc(
"Control the amount of inlining to perform (default = 225)"));
49 cl::desc(
"Threshold for inlining functions with inline hint"));
56 cl::desc(
"Threshold for inlining functions with cold attribute"));
61 cl::desc(
"Threshold for hot callsites "));
65 class CallAnalyzer :
public InstVisitor<CallAnalyzer, bool> {
73 std::function<AssumptionCache &(Function &)> &GetAssumptionCache;
92 bool IsCallerRecursive;
94 bool ExposesReturnsTwice;
95 bool HasDynamicAlloca;
96 bool ContainsNoDuplicateCall;
102 uint64_t AllocatedSize;
103 unsigned NumInstructions, NumVectorInstructions;
104 int FiftyPercentVectorBonus, TenPercentVectorBonus;
129 bool isAllocaDerivedArg(
Value *V);
130 bool lookupSROAArgAndCost(
Value *V,
Value *&Arg,
133 void disableSROA(
Value *V);
135 int InstructionCost);
150 bool isKnownNonNullInCallee(
Value *V);
207 : TTI(TTI), GetAssumptionCache(GetAssumptionCache), PSI(PSI),
F(Callee),
208 CandidateCS(CSArg), Params(Params),
Threshold(Params.DefaultThreshold),
209 Cost(0), IsCallerRecursive(
false), IsRecursiveCall(
false),
210 ExposesReturnsTwice(
false), HasDynamicAlloca(
false),
211 ContainsNoDuplicateCall(
false), HasReturn(
false), HasIndirectBr(
false),
212 HasFrameEscape(
false), AllocatedSize(0), NumInstructions(0),
213 NumVectorInstructions(0), FiftyPercentVectorBonus(0),
214 TenPercentVectorBonus(0), VectorBonus(0), NumConstantArgs(0),
215 NumConstantOffsetPtrArgs(0), NumAllocaArgs(0), NumConstantPtrCmps(0),
216 NumConstantPtrDiffs(0), NumInstructionsSimplified(0),
217 SROACostSavings(0), SROACostSavingsLost(0) {}
222 int getCost() {
return Cost; }
226 unsigned NumConstantArgs;
227 unsigned NumConstantOffsetPtrArgs;
228 unsigned NumAllocaArgs;
229 unsigned NumConstantPtrCmps;
230 unsigned NumConstantPtrDiffs;
231 unsigned NumInstructionsSimplified;
232 unsigned SROACostSavings;
233 unsigned SROACostSavingsLost;
241 bool CallAnalyzer::isAllocaDerivedArg(
Value *V) {
242 return SROAArgValues.count(V);
247 bool CallAnalyzer::lookupSROAArgAndCost(
249 if (SROAArgValues.empty() || SROAArgCosts.empty())
253 if (ArgIt == SROAArgValues.
end())
257 CostIt = SROAArgCosts.
find(Arg);
258 return CostIt != SROAArgCosts.
end();
268 Cost += CostIt->second;
269 SROACostSavings -= CostIt->second;
270 SROACostSavingsLost += CostIt->second;
271 SROAArgCosts.
erase(CostIt);
275 void CallAnalyzer::disableSROA(
Value *V) {
278 if (lookupSROAArgAndCost(V, SROAArg, CostIt))
284 int InstructionCost) {
285 CostIt->second += InstructionCost;
286 SROACostSavings += InstructionCost;
294 if (!isa<Constant>(*
I) && !SimplifiedValues.lookup(*
I))
313 if (
Constant *SimpleOp = SimplifiedValues.lookup(GTI.getOperand()))
321 if (
StructType *STy = GTI.getStructTypeOrNull()) {
339 if (
auto *AllocSize = dyn_cast_or_null<ConstantInt>(Size)) {
340 const DataLayout &DL =
F.getParent()->getDataLayout();
344 return Base::visitAlloca(I);
350 const DataLayout &DL =
F.getParent()->getDataLayout();
357 return Base::visitAlloca(I);
363 HasDynamicAlloca =
true;
367 bool CallAnalyzer::visitPHI(
PHINode &I) {
391 std::pair<Value *, APInt> BaseAndOffset = ConstantOffsetPtrs.lookup(Ptr);
392 if (BaseAndOffset.first) {
395 if (!accumulateGEPOffset(cast<GEPOperator>(I), BaseAndOffset.second)) {
403 ConstantOffsetPtrs[&
I] = BaseAndOffset;
408 SROAArgValues[&
I] = SROAArg;
414 if (isGEPOffsetConstant(I)) {
416 SROAArgValues[&
I] = SROAArg;
432 COp = SimplifiedValues.lookup(I.
getOperand(0));
435 SimplifiedValues[&
I] =
C;
440 std::pair<Value *, APInt> BaseAndOffset =
443 if (BaseAndOffset.first)
444 ConstantOffsetPtrs[&
I] = BaseAndOffset;
449 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt))
450 SROAArgValues[&
I] = SROAArg;
460 COp = SimplifiedValues.lookup(I.
getOperand(0));
463 SimplifiedValues[&
I] =
C;
470 const DataLayout &DL =
F.getParent()->getDataLayout();
472 std::pair<Value *, APInt> BaseAndOffset =
474 if (BaseAndOffset.first)
475 ConstantOffsetPtrs[&
I] = BaseAndOffset;
487 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt))
488 SROAArgValues[&
I] = SROAArg;
497 COp = SimplifiedValues.lookup(I.
getOperand(0));
500 SimplifiedValues[&
I] =
C;
508 const DataLayout &DL =
F.getParent()->getDataLayout();
510 std::pair<Value *, APInt> BaseAndOffset = ConstantOffsetPtrs.lookup(Op);
511 if (BaseAndOffset.first)
512 ConstantOffsetPtrs[&
I] = BaseAndOffset;
518 if (lookupSROAArgAndCost(Op, SROAArg, CostIt))
519 SROAArgValues[&
I] = SROAArg;
524 bool CallAnalyzer::visitCastInst(
CastInst &I) {
528 COp = SimplifiedValues.lookup(I.
getOperand(0));
531 SimplifiedValues[&
I] =
C;
545 COp = SimplifiedValues.lookup(Operand);
547 const DataLayout &DL =
F.getParent()->getDataLayout();
549 SimplifiedValues[&
I] =
C;
555 disableSROA(Operand);
562 return CandidateCS.paramHasAttr(ArgNo + 1, Attr);
565 bool CallAnalyzer::isKnownNonNullInCallee(
Value *V) {
571 if (
Argument *A = dyn_cast<Argument>(V))
572 if (paramHasAttr(A, Attribute::NonNull))
578 if (isAllocaDerivedArg(V))
587 bool CallAnalyzer::allowSizeGrowth(
CallSite CS) {
604 if (
InvokeInst *II = dyn_cast<InvokeInst>(Instr)) {
605 if (isa<UnreachableInst>(II->getNormalDest()->getTerminator()))
615 if (!allowSizeGrowth(CS)) {
629 return B ? std::max(A,
B.getValue()) : A;
645 uint64_t TotalWeight;
647 PSI->isHotCount(TotalWeight)) {
649 }
else if (PSI->isFunctionEntryHot(&Callee)) {
654 }
else if (PSI->isFunctionEntryCold(&Callee)) {
662 Threshold *= TTI.getInliningThresholdMultiplier();
665 bool CallAnalyzer::visitCmpInst(
CmpInst &I) {
668 if (!isa<Constant>(LHS))
669 if (
Constant *SimpleLHS = SimplifiedValues.lookup(LHS))
671 if (!isa<Constant>(RHS))
672 if (
Constant *SimpleRHS = SimplifiedValues.lookup(RHS))
674 if (
Constant *CLHS = dyn_cast<Constant>(LHS)) {
675 if (
Constant *CRHS = dyn_cast<Constant>(RHS))
678 SimplifiedValues[&
I] =
C;
688 Value *LHSBase, *RHSBase;
689 APInt LHSOffset, RHSOffset;
690 std::tie(LHSBase, LHSOffset) = ConstantOffsetPtrs.lookup(LHS);
692 std::tie(RHSBase, RHSOffset) = ConstantOffsetPtrs.lookup(RHS);
693 if (RHSBase && LHSBase == RHSBase) {
699 SimplifiedValues[&
I] =
C;
700 ++NumConstantPtrCmps;
718 if (lookupSROAArgAndCost(I.
getOperand(0), SROAArg, CostIt)) {
719 if (isa<ConstantPointerNull>(I.
getOperand(1))) {
734 Value *LHSBase, *RHSBase;
735 APInt LHSOffset, RHSOffset;
736 std::tie(LHSBase, LHSOffset) = ConstantOffsetPtrs.lookup(LHS);
738 std::tie(RHSBase, RHSOffset) = ConstantOffsetPtrs.lookup(RHS);
739 if (RHSBase && LHSBase == RHSBase) {
745 SimplifiedValues[&
I] =
C;
746 ++NumConstantPtrDiffs;
754 return Base::visitSub(I);
759 const DataLayout &DL =
F.getParent()->getDataLayout();
760 if (!isa<Constant>(LHS))
761 if (
Constant *SimpleLHS = SimplifiedValues.lookup(LHS))
763 if (!isa<Constant>(RHS))
764 if (
Constant *SimpleRHS = SimplifiedValues.lookup(RHS))
766 Value *SimpleV =
nullptr;
767 if (
auto FI = dyn_cast<FPMathOperator>(&I))
773 if (
Constant *
C = dyn_cast_or_null<Constant>(SimpleV)) {
774 SimplifiedValues[&
I] =
C;
785 bool CallAnalyzer::visitLoad(
LoadInst &I) {
800 bool CallAnalyzer::visitStore(
StoreInst &I) {
837 if (AggC && InsertedC) {
838 SimplifiedValues[&
I] =
868 C = dyn_cast_or_null<Constant>(SimplifiedValues.lookup(*I));
882 bool CallAnalyzer::visitCallSite(
CallSite CS) {
883 if (CS.
hasFnAttr(Attribute::ReturnsTwice) &&
886 ExposesReturnsTwice =
true;
890 ContainsNoDuplicateCall =
true;
894 if (simplifyCallSite(F, CS))
900 switch (II->getIntrinsicID()) {
902 return Base::visitCallSite(CS);
904 case Intrinsic::load_relative:
909 case Intrinsic::memset:
910 case Intrinsic::memcpy:
911 case Intrinsic::memmove:
914 case Intrinsic::localescape:
915 HasFrameEscape =
true;
923 IsRecursiveCall =
true;
927 if (TTI.isLoweredToCall(F)) {
938 return Base::visitCallSite(CS);
951 Function *F = dyn_cast_or_null<Function>(SimplifiedValues.lookup(Callee));
953 return Base::visitCallSite(CS);
960 auto IndirectCallParams = Params;
962 CallAnalyzer CA(TTI, GetAssumptionCache, PSI, *F, CS, IndirectCallParams);
963 if (CA.analyzeCall(CS)) {
966 Cost -= std::max(0, CA.getThreshold() - CA.getCost());
969 return Base::visitCallSite(CS);
972 bool CallAnalyzer::visitReturnInst(
ReturnInst &RI) {
974 bool Free = !HasReturn;
979 bool CallAnalyzer::visitBranchInst(
BranchInst &BI) {
985 dyn_cast_or_null<ConstantInt>(
995 if (isa<ConstantInt>(V))
1010 SuccessorBlocks.
insert(I.getCaseSuccessor());
1026 HasIndirectBr =
true;
1030 bool CallAnalyzer::visitResumeInst(
ResumeInst &RI) {
1055 bool CallAnalyzer::visitInstruction(
Instruction &I) {
1058 if (TargetTransformInfo::TCC_Free == TTI.getUserCost(&I))
1076 bool CallAnalyzer::analyzeBlock(
BasicBlock *BB,
1086 if (isa<DbgInfoIntrinsic>(I))
1090 if (EphValues.
count(&*I))
1095 ++NumVectorInstructions;
1101 bool hasSoftFloatAttr =
false;
1109 hasSoftFloatAttr =
true;
1122 if (Base::visit(&*I))
1123 ++NumInstructionsSimplified;
1128 if (IsRecursiveCall || ExposesReturnsTwice || HasDynamicAlloca ||
1129 HasIndirectBr || HasFrameEscape)
1135 if (IsCallerRecursive &&
1154 ConstantInt *CallAnalyzer::stripAndComputeInBoundsConstantOffsets(
Value *&V) {
1167 if (
GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
1168 if (!GEP->
isInBounds() || !accumulateGEPOffset(*GEP, Offset))
1172 V = cast<Operator>(V)->getOperand(0);
1173 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
1174 if (GA->isInterposable())
1176 V = GA->getAliasee();
1181 }
while (Visited.
insert(V).second);
1194 bool CallAnalyzer::analyzeCall(
CallSite CS) {
1207 assert(NumInstructions == 0);
1208 assert(NumVectorInstructions == 0);
1211 updateThreshold(CS, F);
1213 FiftyPercentVectorBonus = 3 *
Threshold / 2;
1214 TenPercentVectorBonus = 3 *
Threshold / 4;
1220 bool SingleBB =
true;
1226 Threshold += (SingleBBBonus + FiftyPercentVectorBonus);
1230 for (
unsigned I = 0,
E = CS.
arg_size(); I !=
E; ++
I) {
1238 unsigned NumStores = (TypeSize + PointerSize - 1) / PointerSize;
1246 NumStores =
std::min(NumStores, 8U);
1260 bool OnlyOneCallAndLocalLinkage =
1262 if (OnlyOneCallAndLocalLinkage)
1285 IsCallerRecursive =
true;
1294 FAI != FAE; ++FAI, ++CAI) {
1296 if (
Constant *C = dyn_cast<Constant>(CAI))
1297 SimplifiedValues[&*FAI] = C;
1299 Value *PtrArg = *CAI;
1300 if (
ConstantInt *C = stripAndComputeInBoundsConstantOffsets(PtrArg)) {
1301 ConstantOffsetPtrs[&*FAI] = std::make_pair(PtrArg, C->getValue());
1304 if (isa<AllocaInst>(PtrArg)) {
1305 SROAArgValues[&*FAI] = PtrArg;
1306 SROAArgCosts[PtrArg] = 0;
1310 NumConstantArgs = SimplifiedValues.size();
1311 NumConstantOffsetPtrArgs = ConstantOffsetPtrs.size();
1312 NumAllocaArgs = SROAArgValues.size();
1330 BBSetVector BBWorklist;
1333 for (
unsigned Idx = 0; Idx != BBWorklist.size(); ++Idx) {
1354 if (!analyzeBlock(BB, EphValues))
1361 if (
BranchInst *BI = dyn_cast<BranchInst>(TI)) {
1365 dyn_cast_or_null<ConstantInt>(SimplifiedValues.lookup(Cond))) {
1366 BBWorklist.insert(BI->
getSuccessor(SimpleCond->isZero() ? 1 : 0));
1370 }
else if (
SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
1373 dyn_cast_or_null<ConstantInt>(SimplifiedValues.lookup(Cond))) {
1399 if (!OnlyOneCallAndLocalLinkage && ContainsNoDuplicateCall)
1405 if (NumVectorInstructions <= NumInstructions / 10)
1407 else if (NumVectorInstructions <= NumInstructions / 2)
1408 Threshold -= (FiftyPercentVectorBonus - TenPercentVectorBonus);
1413 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1416 #define DEBUG_PRINT_STAT(x) dbgs() << " " #x ": " << x << "\n"
1429 #undef DEBUG_PRINT_STAT
1435 template <
typename AttrKind>
1454 GetAssumptionCache, PSI);
1469 if (CS.
hasFnAttr(Attribute::AlwaysInline)) {
1495 CallAnalyzer CA(CalleeTTI, GetAssumptionCache, PSI, *Callee, CS, Params);
1496 bool ShouldInline = CA.analyzeCall(CS);
1501 if (!ShouldInline && CA.getCost() < CA.getThreshold())
1503 if (ShouldInline && CA.getCost() >= CA.getThreshold())
1514 if (isa<IndirectBrInst>(BI->getTerminator()) || BI->hasAddressTaken())
1517 for (
auto &II : *BI) {
1528 if (!ReturnsTwice && CS.
isCall() &&
1536 llvm::Intrinsic::localescape)
1594 unsigned SizeOptLevel) {
1597 if (SizeOptLevel == 1)
1599 if (SizeOptLevel == 2)
Return a value (possibly void), from a function.
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.
CaseIt case_end()
Returns a read/write iterator that points one past the last in the SwitchInst.
This class is the base class for the comparison instructions.
FunTy * getCaller() const
getCaller - Return the caller function for this call site
LLVM Argument representation.
Base class for instruction visitors.
Value * getAggregateOperand()
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.
bool canConstantFoldCallTo(const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function...
A Module instance is used to store all the information related to an LLVM module. ...
static int computeThresholdFromOptLevels(unsigned OptLevel, unsigned SizeOptLevel)
Analysis providing profile information.
const int OptMinSizeThreshold
Use when minsize (-Oz) is specified.
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
gep_type_iterator gep_type_end(const User *GEP)
CaseIt case_begin()
Returns a read/write iterator that points to the first case in the SwitchInst.
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.
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)
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.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
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...
InlineCost getInlineCost(CallSite CS, const InlineParams &Params, TargetTransformInfo &CalleeTTI, std::function< AssumptionCache &(Function &)> &GetAssumptionCache, ProfileSummaryInfo *PSI)
Get an InlineCost object representing the cost of inlining this callsite.
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
getCalledValue - Return the pointer to function that is being called.
bool isCall() const
isCall - 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...
Function Alias Analysis false
BasicBlock * getSuccessor(unsigned i) const
This class represents a no-op cast from one type to another.
Value * getInsertedValueOperand()
bool isFloatingPointTy() const
Return true if this is one of the six floating-point types.
const int LastCallToStaticBonus
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
An instruction for storing to memory.
static cl::opt< int > ColdThreshold("inlinecold-threshold", cl::Hidden, cl::init(225), cl::desc("Threshold for inlining functions with cold attribute"))
static cl::opt< int > HotCallSiteThreshold("hot-callsite-threshold", cl::Hidden, cl::init(3000), cl::ZeroOrMore, cl::desc("Threshold for hot callsites "))
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 etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
bool isInBounds() const
Determine whether the GEP has the inbounds flag.
Class to represent pointers.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
uint64_t getElementOffset(unsigned Idx) const
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs ...
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
initializer< Ty > init(const Ty &Val)
bool erase(const KeyT &Val)
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...
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
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 * getPointerOperand()
Value * getOperand(unsigned i) const
bool hasFnAttr(Attribute::AttrKind Kind) const
Return true if this function has the given attribute.
Value * getPointerOperand()
Value * SimplifyFPBinOp(unsigned Opcode, Value *LHS, Value *RHS, const FastMathFlags &FMF, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for an FP BinaryOperator, fold the result or return null.
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.
User::op_iterator arg_iterator
arg_iterator - The type of iterator to use when looping over actual arguments at this call site...
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
bool extractProfTotalWeight(uint64_t &TotalVal) const
Retrieve total raw weight values of a branch.
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 bool attributeMatches(Function *F1, Function *F2, AttrKind Attr)
Test that two functions either have or have not the given attribute at the same time.
BinaryOps getOpcode() const
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.
BasicBlockTy * getCaseSuccessor()
Resolves successor for current case.
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...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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()
Value * SimplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const DominatorTree *DT=nullptr, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr)
Given operands for a BinaryOperator, fold the result or return null.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
Value * getCondition() const
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)"))
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Value * getCondition() const
BasicBlock * getDefaultDest() const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
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 ...
iterator find(const KeyT &Val)
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...
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.
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
getCalledFunction - Return the function being called if this is a direct call, otherwise return null ...
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
A vector that has set insertion semantics.
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
const Value * getArraySize() const
Get the number of elements allocated.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
print Print MemDeps of function
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
StringRef - Represent a constant reference to a string, i.e.
const int OptSizeThreshold
Use when optsize (-Os) is specified.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
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 GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
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.
Constant * ConstantFoldCall(Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
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)