28#define DEBUG_TYPE "function-specialization"
30STATISTIC(NumSpecsCreated,
"Number of specializations created");
34 "Force function specialization for every call site with a constant "
39 "The maximum number of clones allowed for a single function "
44 "The maximum number of incoming values a PHI node can have to be "
45 "considered during the specialization bonus estimation"));
49 "The maximum number of predecessors a basic block can have to be "
50 "considered during the estimation of dead code"));
54 "Don't specialize functions that have less than this number of "
59 "Maximum codesize growth allowed per function"));
63 "Reject specializations whose codesize savings are less than this"
64 "much percent of the original function size"));
68 "Reject specializations whose latency savings are less than this"
69 "much percent of the original function size"));
73 "Reject specializations whose inlining bonus is less than this"
74 "much percent of the original function size"));
78 "Enable function specialization on the address of global values"));
86 "Enable specialization of functions that take a literal constant as an "
95 (Pred == BB || Pred == Succ || DeadBlocks.
contains(Pred));
105Cost InstCostVisitor::estimateBasicBlocks(
109 while (!WorkList.
empty()) {
115 if (!DeadBlocks.
insert(BB).second)
120 if (
auto *II = dyn_cast<IntrinsicInst>(&
I))
121 if (II->getIntrinsicID() == Intrinsic::ssa_copy)
130 <<
" for user " <<
I <<
"\n");
138 canEliminateSuccessor(BB, SuccBB, DeadBlocks))
145 if (
auto *
C = dyn_cast<Constant>(V))
147 return KnownConstants.
lookup(V);
152 while (!PendingPHIs.empty()) {
156 B += getUserBonus(Phi);
163 LLVM_DEBUG(
dbgs() <<
"FnSpecialization: Analysing bonus for constant: "
164 <<
C->getNameOrAsOperand() <<
"\n");
166 for (
auto *U :
A->users())
167 if (
auto *UI = dyn_cast<Instruction>(U))
169 B += getUserBonus(UI,
A,
C);
171 LLVM_DEBUG(
dbgs() <<
"FnSpecialization: Accumulated bonus {CodeSize = "
172 <<
B.CodeSize <<
", Latency = " <<
B.Latency
173 <<
"} for argument " << *
A <<
"\n");
184 : KnownConstants.
end();
187 if (
auto *
I = dyn_cast<SwitchInst>(
User)) {
188 CodeSize = estimateSwitchInst(*
I);
189 }
else if (
auto *
I = dyn_cast<BranchInst>(
User)) {
190 CodeSize = estimateBranchInst(*
I);
211 <<
", Latency = " <<
Latency <<
"} for user "
216 if (
auto *UI = dyn_cast<Instruction>(U))
218 B += getUserBonus(UI,
User,
C);
224 assert(LastVisited != KnownConstants.
end() &&
"Invalid iterator!");
226 if (
I.getCondition() != LastVisited->first)
229 auto *
C = dyn_cast<ConstantInt>(LastVisited->second);
233 BasicBlock *Succ =
I.findCaseValue(
C)->getCaseSuccessor();
238 for (
const auto &Case :
I.cases()) {
241 canEliminateSuccessor(
I.getParent(), BB, DeadBlocks))
245 return estimateBasicBlocks(WorkList);
249 assert(LastVisited != KnownConstants.
end() &&
"Invalid iterator!");
251 if (
I.getCondition() != LastVisited->first)
254 BasicBlock *Succ =
I.getSuccessor(LastVisited->second->isOneValue());
259 canEliminateSuccessor(
I.getParent(), Succ, DeadBlocks))
262 return estimateBasicBlocks(WorkList);
269 bool Inserted = VisitedPHIs.insert(&
I).second;
272 for (
unsigned Idx = 0,
E =
I.getNumIncomingValues();
Idx !=
E; ++
Idx) {
274 if (
auto *Inst = dyn_cast<Instruction>(V))
275 if (Inst == &
I || DeadBlocks.
contains(
I.getIncomingBlock(
Idx)))
280 PendingPHIs.push_back(&
I);
292 assert(LastVisited != KnownConstants.
end() &&
"Invalid iterator!");
295 return LastVisited->second;
307 for (
unsigned Idx = 0,
E =
I.getNumOperands() - 1;
Idx !=
E; ++
Idx) {
320 assert(LastVisited != KnownConstants.
end() &&
"Invalid iterator!");
322 if (isa<ConstantPointerNull>(LastVisited->second))
331 for (
unsigned Idx = 0,
E =
I.getNumOperands();
Idx !=
E; ++
Idx) {
344 assert(LastVisited != KnownConstants.
end() &&
"Invalid iterator!");
346 if (
I.getCondition() != LastVisited->first)
349 Value *
V = LastVisited->second->isZeroValue() ?
I.getFalseValue()
361 assert(LastVisited != KnownConstants.
end() &&
"Invalid iterator!");
363 bool Swap =
I.getOperand(1) == LastVisited->first;
364 Value *
V = Swap ?
I.getOperand(0) :
I.getOperand(1);
376 assert(LastVisited != KnownConstants.
end() &&
"Invalid iterator!");
382 assert(LastVisited != KnownConstants.
end() &&
"Invalid iterator!");
384 bool Swap =
I.getOperand(1) == LastVisited->first;
385 Value *
V = Swap ?
I.getOperand(0) :
I.getOperand(1);
391 return dyn_cast_or_null<Constant>(Swap ?
398 Value *StoreValue =
nullptr;
404 if (
auto *Bitcast = dyn_cast<BitCastInst>(
User)) {
410 if (
auto *Store = dyn_cast<StoreInst>(
User)) {
412 if (StoreValue ||
Store->isVolatile())
414 StoreValue =
Store->getValueOperand();
424 return getCandidateConstant(StoreValue);
435 if (
auto *ConstVal = dyn_cast<ConstantInt>(Val))
437 auto *Alloca = dyn_cast<AllocaInst>(Val);
440 return getPromotableAlloca(Alloca, Call);
466void FunctionSpecializer::promoteConstantStackValues(
Function *
F) {
467 for (
User *U :
F->users()) {
469 auto *
Call = dyn_cast<CallInst>(U);
476 for (
const Use &U :
Call->args()) {
477 unsigned Idx =
Call->getArgOperandNo(&U);
484 auto *ConstVal = getConstantStackValue(Call, ArgOp);
490 "specialized.arg." +
Twine(++NGlobals));
491 if (ArgOpType != ConstVal->getType())
504 auto *II = dyn_cast<IntrinsicInst>(&Inst);
507 if (II->getIntrinsicID() != Intrinsic::ssa_copy)
509 Inst.replaceAllUsesWith(II->getOperand(0));
510 Inst.eraseFromParent();
516void FunctionSpecializer::cleanUpSSA() {
538 if (NumSpecsCreated > 0)
539 dbgs() <<
"FnSpecialization: Created " << NumSpecsCreated
540 <<
" specializations in module " << M.
getName() <<
"\n");
542 removeDeadFunctions();
554 unsigned NumCandidates = 0;
556 if (!isCandidateFunction(&
F))
559 auto [It, Inserted] = FunctionMetrics.try_emplace(&
F);
566 Metrics.analyzeBasicBlock(&BB, GetTTI(
F), EphValues);
583 int64_t Sz = *
Metrics.NumInsts.getValue();
584 assert(Sz > 0 &&
"CodeSize should be positive");
586 unsigned FuncSize =
static_cast<unsigned>(Sz);
589 <<
F.getName() <<
" is " << FuncSize <<
"\n");
591 if (Inserted &&
Metrics.isRecursive)
592 promoteConstantStackValues(&
F);
594 if (!findSpecializations(&
F, FuncSize, AllSpecs, SM)) {
596 dbgs() <<
"FnSpecialization: No possible specializations found for "
597 <<
F.getName() <<
"\n");
604 if (!NumCandidates) {
607 <<
"FnSpecialization: No possible specializations found in module\n");
614 auto CompareScore = [&AllSpecs](
unsigned I,
unsigned J) {
615 return AllSpecs[
I].Score > AllSpecs[J].Score;
617 const unsigned NSpecs =
618 std::min(NumCandidates *
MaxClones,
unsigned(AllSpecs.
size()));
620 std::iota(BestSpecs.
begin(), BestSpecs.
begin() + NSpecs, 0);
621 if (AllSpecs.
size() > NSpecs) {
622 LLVM_DEBUG(
dbgs() <<
"FnSpecialization: Number of candidates exceed "
623 <<
"the maximum number of clones threshold.\n"
624 <<
"FnSpecialization: Specializing the "
626 <<
" most profitable candidates.\n");
627 std::make_heap(BestSpecs.
begin(), BestSpecs.
begin() + NSpecs, CompareScore);
628 for (
unsigned I = NSpecs,
N = AllSpecs.
size();
I <
N; ++
I) {
629 BestSpecs[NSpecs] =
I;
630 std::push_heap(BestSpecs.
begin(), BestSpecs.
end(), CompareScore);
631 std::pop_heap(BestSpecs.
begin(), BestSpecs.
end(), CompareScore);
635 LLVM_DEBUG(
dbgs() <<
"FnSpecialization: List of specializations \n";
636 for (
unsigned I = 0;
I < NSpecs; ++
I) {
637 const Spec &S = AllSpecs[BestSpecs[
I]];
638 dbgs() <<
"FnSpecialization: Function " << S.
F->
getName()
639 <<
" , score " << S.
Score <<
"\n";
641 dbgs() <<
"FnSpecialization: FormalArg = "
650 for (
unsigned I = 0;
I < NSpecs; ++
I) {
651 Spec &S = AllSpecs[BestSpecs[
I]];
652 S.
Clone = createSpecialization(S.
F, S.
Sig);
658 Call->setCalledFunction(S.
Clone);
662 OriginalFuncs.insert(S.
F);
671 auto [Begin,
End] = SM[
F];
672 updateCallSites(
F, AllSpecs.
begin() + Begin, AllSpecs.
begin() +
End);
676 if (
F->getReturnType()->isVoidTy())
678 if (
F->getReturnType()->isStructTy()) {
679 auto *STy = cast<StructType>(
F->getReturnType());
685 "Return value ought to be tracked");
689 for (
User *U :
F->users()) {
690 if (
auto *CS = dyn_cast<CallBase>(U)) {
692 if (CS->getCalledFunction() !=
F)
703 if (FunctionMetrics[
F].isRecursive)
704 promoteConstantStackValues(
F);
709void FunctionSpecializer::removeDeadFunctions() {
712 <<
F->getName() <<
"\n");
715 F->eraseFromParent();
717 FullySpecialized.clear();
725 Clone->
setName(
F->getName() +
".specialized." +
Twine(NSpecs));
730bool FunctionSpecializer::findSpecializations(
Function *
F,
unsigned FuncSize,
741 if (isArgumentInteresting(&Arg))
742 Args.push_back(&Arg);
747 for (
User *U :
F->users()) {
748 if (!isa<CallInst>(U) && !isa<InvokeInst>(U))
750 auto &CS = *cast<CallBase>(U);
753 if (CS.getCalledFunction() !=
F)
758 if (CS.hasFnAttr(Attribute::MinSize))
770 Constant *
C = getCandidateConstant(CS.getArgOperand(
A->getArgNo()));
773 LLVM_DEBUG(
dbgs() <<
"FnSpecialization: Found interesting argument "
774 <<
A->getName() <<
" : " <<
C->getNameOrAsOperand()
783 if (
auto It = UniqueSpecs.
find(S); It != UniqueSpecs.
end()) {
790 if (CS.getFunction() ==
F)
792 const unsigned Index = It->second;
801 Score += getInliningBonus(
A.Formal,
A.Actual);
806 LLVM_DEBUG(
dbgs() <<
"FnSpecialization: Specialization bonus {CodeSize = "
807 <<
B.CodeSize <<
", Latency = " <<
B.Latency
808 <<
", Inlining = " << Score <<
"}\n");
810 FunctionGrowth[
F] += FuncSize -
B.CodeSize;
812 auto IsProfitable = [](
Bonus &
B,
unsigned Score,
unsigned FuncSize,
813 unsigned FuncGrowth) ->
bool {
833 if (!IsProfitable(
B, Score, FuncSize, FunctionGrowth[
F]))
837 Score += std::max(
B.CodeSize,
B.Latency);
839 if (CS.getFunction() !=
F)
841 const unsigned Index = AllSpecs.
size() - 1;
842 UniqueSpecs[S] =
Index;
844 It->second.second =
Index + 1;
848 return !UniqueSpecs.
empty();
851bool FunctionSpecializer::isCandidateFunction(
Function *
F) {
852 if (
F->isDeclaration() ||
F->arg_empty())
855 if (
F->hasFnAttribute(Attribute::NoDuplicate))
859 if (Specializations.contains(
F))
863 if (
F->hasOptSize() ||
873 if (
F->hasFnAttribute(Attribute::AlwaysInline))
876 LLVM_DEBUG(
dbgs() <<
"FnSpecialization: Try function: " <<
F->getName()
898 Specializations.insert(Clone);
909 Function *CalledFunction = dyn_cast<Function>(
C->stripPointerCasts());
914 auto &CalleeTTI = (GetTTI)(*CalledFunction);
921 int InliningBonus = 0;
922 for (
User *U :
A->users()) {
923 if (!isa<CallInst>(U) && !isa<InvokeInst>(U))
925 auto *CS = cast<CallBase>(U);
926 if (CS->getCalledOperand() !=
A)
943 getInlineCost(*CS, CalledFunction, Params, CalleeTTI, GetAC, GetTLI);
948 InliningBonus += Params.DefaultThreshold;
952 LLVM_DEBUG(
dbgs() <<
"FnSpecialization: Inlining bonus " << InliningBonus
953 <<
" for user " << *U <<
"\n");
956 return InliningBonus > 0 ?
static_cast<unsigned>(InliningBonus) : 0;
961bool FunctionSpecializer::isArgumentInteresting(
Argument *
A) {
966 Type *Ty =
A->getType();
973 if (
A->hasByValAttr() && !
A->getParent()->onlyReadsMemory())
985 :
SCCPSolver::isOverdefined(Solver.getLatticeValueFor(
A));
989 dbgs() <<
"FnSpecialization: Found interesting parameter "
990 <<
A->getNameOrAsOperand() <<
"\n";
992 dbgs() <<
"FnSpecialization: Nothing to do, parameter "
993 <<
A->getNameOrAsOperand() <<
" is already constant\n";
995 return IsOverdefined;
1000Constant *FunctionSpecializer::getCandidateConstant(
Value *V) {
1001 if (isa<PoisonValue>(V))
1012 if (
C &&
C->getType()->isPointerTy() && !
C->isNullValue())
1020void FunctionSpecializer::updateCallSites(
Function *
F,
const Spec *Begin,
1024 for (
User *U :
F->users())
1025 if (
auto *CS = dyn_cast<CallBase>(U);
1026 CS && CS->getCalledFunction() ==
F &&
1030 unsigned NCallsLeft = ToUpdate.
size();
1032 bool ShouldDecrementCount = CS->getFunction() ==
F;
1035 const Spec *BestSpec =
nullptr;
1037 if (!S.Clone || (BestSpec && S.Score <= BestSpec->
Score))
1041 unsigned ArgNo = Arg.Formal->getArgNo();
1042 return getCandidateConstant(CS->getArgOperand(ArgNo)) != Arg.Actual;
1052 CS->setCalledFunction(BestSpec->
Clone);
1053 ShouldDecrementCount =
true;
1056 if (ShouldDecrementCount)
1064 FullySpecialized.insert(
F);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
static cl::opt< bool > ForceSpecialization("force-specialization", cl::init(false), cl::Hidden, cl::desc("Force function specialization for every call site with a constant " "argument"))
static cl::opt< unsigned > MinLatencySavings("funcspec-min-latency-savings", cl::init(70), cl::Hidden, cl::desc("Reject specializations whose latency savings are less than this" "much percent of the original function size"))
static Constant * findConstantFor(Value *V, ConstMap &KnownConstants)
static cl::opt< unsigned > MinCodeSizeSavings("funcspec-min-codesize-savings", cl::init(20), cl::Hidden, cl::desc("Reject specializations whose codesize savings are less than this" "much percent of the original function size"))
static Function * cloneCandidateFunction(Function *F, unsigned NSpecs)
Clone the function F and remove the ssa_copy intrinsics added by the SCCPSolver in the cloned version...
static void removeSSACopy(Function &F)
static cl::opt< unsigned > MaxCodeSizeGrowth("funcspec-max-codesize-growth", cl::init(3), cl::Hidden, cl::desc("Maximum codesize growth allowed per function"))
static cl::opt< unsigned > MaxClones("funcspec-max-clones", cl::init(3), cl::Hidden, cl::desc("The maximum number of clones allowed for a single function " "specialization"))
static cl::opt< unsigned > MinInliningBonus("funcspec-min-inlining-bonus", cl::init(300), cl::Hidden, cl::desc("Reject specializations whose inlining bonus is less than this" "much percent of the original function size"))
static cl::opt< unsigned > MaxIncomingPhiValues("funcspec-max-incoming-phi-values", cl::init(4), cl::Hidden, cl::desc("The maximum number of incoming values a PHI node can have to be " "considered during the specialization bonus estimation"))
static cl::opt< unsigned > MaxBlockPredecessors("funcspec-max-block-predecessors", cl::init(2), cl::Hidden, cl::desc("The maximum number of predecessors a basic block can have to be " "considered during the estimation of dead code"))
static cl::opt< unsigned > MinFunctionSize("funcspec-min-function-size", cl::init(300), cl::Hidden, cl::desc("Don't specialize functions that have less than this number of " "instructions"))
static cl::opt< bool > SpecializeOnAddress("funcspec-on-address", cl::init(false), cl::Hidden, cl::desc("Enable function specialization on the address of global values"))
static cl::opt< bool > SpecializeLiteralConstant("funcspec-for-literal-constant", cl::init(false), cl::Hidden, cl::desc("Enable specialization of functions that take a literal constant as an " "argument"))
mir Rename Register Operands
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
an instruction to allocate memory on the stack
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
void clear(IRUnitT &IR, llvm::StringRef Name)
Clear any cached analysis results for a single unit of IR.
This class represents an incoming formal argument to a Function.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
LLVM Basic Block Representation.
uint64_t getEntryFreq() const
BlockFrequency getBlockFreq(const BasicBlock *BB) const
getblockFreq - Return block frequency.
uint64_t getFrequency() const
Returns the frequency as a fixpoint number scaled by the entry frequency.
Conditional or Unconditional Branch instruction.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This class represents a function call, abstracting a target machine's calling convention.
This is the base class for all instructions that perform data casts.
This class is the base class for the comparison instructions.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is an important base class in LLVM.
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...
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
bool contains(const_arg_type_t< KeyT > Val) const
Return true if the specified key is in the map, false otherwise.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
This class represents a freeze function that returns random concrete value if an operand is either a ...
bool run()
Attempt to specialize functions in the module to enable constant propagation across function boundari...
InstCostVisitor getInstCostVisitorFor(Function *F)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
const BasicBlock & front() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
void setLinkage(LinkageTypes LT)
@ InternalLinkage
Rename collisions when linking (static functions).
Represents the cost of inlining a function.
int getCostDelta() const
Get the cost delta from the threshold for inlining.
bool isBlockExecutable(BasicBlock *BB)
Bonus getSpecializationBonus(Argument *A, Constant *C)
Compute a bonus for replacing argument A with constant C.
Bonus getBonusFromPendingPHIs()
void visit(Iterator Start, Iterator End)
An instruction for reading from memory.
StringRef getName() const
Get a short "name" for the module.
SCCPSolver - This interface class is a general purpose solver for Sparse Conditional Constant Propaga...
void resetLatticeValueFor(CallBase *Call)
Invalidate the Lattice Value of Call and its users after specializing the call.
bool isStructLatticeConstant(Function *F, StructType *STy)
void addTrackedFunction(Function *F)
addTrackedFunction - If the SCCP solver is supposed to track calls into and out of the specified func...
const MapVector< Function *, ValueLatticeElement > & getTrackedRetVals()
getTrackedRetVals - Get the inferred return value map.
void solveWhileResolvedUndefsIn(Module &M)
void addArgumentTrackedFunction(Function *F)
void solveWhileResolvedUndefs()
std::vector< ValueLatticeElement > getStructLatticeValueFor(Value *V) const
Constant * getConstantOrNull(Value *V) const
Return either a Constant or nullptr for a given Value.
bool isBlockExecutable(BasicBlock *BB) const
bool markBlockExecutable(BasicBlock *BB)
markBlockExecutable - This method can be used by clients to mark all of the blocks that are known to ...
void setLatticeValueForSpecializationArguments(Function *F, const SmallVectorImpl< ArgInfo > &Args)
Set the Lattice Value for the arguments of a specialization F.
static bool isOverdefined(const ValueLatticeElement &LV)
void markFunctionUnreachable(Function *F)
Mark all of the blocks in function F non-executable.
bool isArgumentTrackedFunction(Function *F)
Returns true if the given function is in the solver's set of argument-tracked functions.
This class represents the LLVM 'select' instruction.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
bool isPointerTy() const
True if this is an instance of PointerType.
bool isStructTy() const
True if this is an instance of StructType.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isIntegerTy() const
True if this is an instance of IntegerType.
A Use represents the edge between a Value definition and its users.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void setName(const Twine &Name)
Change the name of the value.
std::string getNameOrAsOperand() const
iterator_range< user_iterator > users()
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
StringRef getName() const
Return a constant reference to the value's name.
std::pair< iterator, bool > insert(const ValueT &V)
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
@ C
The default llvm calling convention, compatible with C.
const int IndirectCallThreshold
@ Bitcast
Perform the operation on a different, but equivalently sized type.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
hash_code hash_value(const FixedPointSemantics &Val)
bool canConstantFoldCallTo(const CallBase *Call, const Function *F)
canConstantFoldCallTo - Return true if its even possible to fold a call to the specified function.
auto successors(const MachineBasicBlock *BB)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value,...
Constant * ConstantFoldCompareInstOperands(unsigned Predicate, Constant *LHS, Constant *RHS, const DataLayout &DL, const TargetLibraryInfo *TLI=nullptr, const Instruction *I=nullptr)
Attempt to constant fold a compare instruction (icmp/fcmp) with the specified operands.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
Constant * ConstantFoldCall(const CallBase *Call, Function *F, ArrayRef< Constant * > Operands, const TargetLibraryInfo *TLI=nullptr)
ConstantFoldCall - Attempt to constant fold a call to the specified function with the specified argum...
InlineCost getInlineCost(CallBase &Call, const InlineParams &Params, TargetTransformInfo &CalleeTTI, function_ref< AssumptionCache &(Function &)> GetAssumptionCache, function_ref< const TargetLibraryInfo &(Function &)> GetTLI, function_ref< BlockFrequencyInfo &(Function &)> GetBFI=nullptr, ProfileSummaryInfo *PSI=nullptr, OptimizationRemarkEmitter *ORE=nullptr)
Get an InlineCost object representing the cost of inlining this callsite.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Constant * ConstantFoldUnaryOpOperand(unsigned Opcode, Constant *Op, const DataLayout &DL)
Attempt to constant fold a unary operation with the specified operand.
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.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Constant * ConstantFoldCastOperand(unsigned Opcode, Constant *C, Type *DestTy, const DataLayout &DL)
Attempt to constant fold a cast with the specified operand.
Value * simplifyBinOp(unsigned Opcode, Value *LHS, Value *RHS, const SimplifyQuery &Q)
Given operands for a BinaryOperator, fold the result or return null.
bool isGuaranteedNotToBeUndefOrPoison(const Value *V, AssumptionCache *AC=nullptr, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr, unsigned Depth=0)
Return true if this function can prove that V does not have undef bits and is never poison.
InlineParams getInlineParams()
Generate the parameters to tune the inline cost analysis based only on the commandline options.
auto predecessors(const MachineBasicBlock *BB)
Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt Offset, const DataLayout &DL)
Return the value that a load from C with offset Offset would produce if it is constant and determinab...
Function * CloneFunction(Function *F, ValueToValueMapTy &VMap, ClonedCodeInfo *CodeInfo=nullptr)
Return a copy of the specified function and add it to that function's module.
Helper struct shared between Function Specialization and SCCP Solver.
Utility to calculate the size and a few similar metrics for a set of basic blocks.
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).
static unsigned getHashValue(const SpecSig &S)
static bool isEqual(const SpecSig &LHS, const SpecSig &RHS)
static SpecSig getEmptyKey()
static SpecSig getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
SmallVector< ArgInfo, 4 > Args
SmallVector< CallBase * > CallSites