92#define DEBUG_TYPE "tailcallelim"
94STATISTIC(NumEliminated,
"Number of tail calls removed");
95STATISTIC(NumRetDuped,
"Number of return duplicated");
96STATISTIC(NumAccumAdded,
"Number of accumulators introduced");
98 "Number of tail calls/recursion eliminations prevented due to cold "
99 "calling convention or attribute");
106 if (!Opts.disable_tail_call_elim_for_cold_calls)
112 if (Caller && (Caller->hasFnAttribute(Attribute::Cold) ||
148 return !AI || AI->isStaticAlloca();
153struct LocalStackValueTracker {
157 void walk(
Value *Root) {
159 SmallPtrSet<Use *, 32> Visited;
161 auto AddUsesToWorklist = [&](
Value *
V) {
162 for (
auto &U :
V->uses()) {
163 if (!Visited.
insert(&U).second)
169 AddUsesToWorklist(Root);
171 while (!Worklist.
empty()) {
175 switch (
I->getOpcode()) {
176 case Instruction::Call:
177 case Instruction::Invoke: {
183 II &&
II->getIntrinsicID() == Intrinsic::stackrestore)
189 if (CB.isArgOperand(U) && CB.isByValArgument(CB.getArgOperandNo(U)))
192 CB.isDataOperand(U) && CB.doesNotCapture(CB.getDataOperandNo(U));
193 callUsesLocalStack(CB, IsNocapture);
201 case Instruction::Load: {
206 case Instruction::Store: {
207 if (
U->getOperandNo() == 0)
208 EscapePoints.insert(
I);
211 case Instruction::BitCast:
212 case Instruction::GetElementPtr:
213 case Instruction::PHI:
214 case Instruction::Select:
215 case Instruction::AddrSpaceCast:
218 EscapePoints.insert(
I);
222 AddUsesToWorklist(
I);
226 void callUsesLocalStack(CallBase &CB,
bool IsNocapture) {
228 LocalStackUsers.insert(&CB);
236 EscapePoints.insert(&CB);
239 SmallPtrSet<Instruction *, 32> LocalStackUsers;
240 SmallPtrSet<Instruction *, 32> EscapePoints;
248 switch (
II->getIntrinsicID()) {
249 case Intrinsic::frameaddress:
252 case Intrinsic::addressofreturnaddress:
253 case Intrinsic::eh_dwarf_cfa:
254 case Intrinsic::localaddress:
255 case Intrinsic::sponentry:
256 case Intrinsic::stackaddress:
257 case Intrinsic::stacksave:
258 case Intrinsic::swift_async_context_addr:
268 if (
F.callsFunctionThatReturnsTwice())
273 LocalStackValueTracker Tracker;
275 if (Arg.hasByValAttr())
311 VisitType Escaped = UNESCAPED;
313 for (
auto &
I : *BB) {
314 if (Tracker.EscapePoints.count(&
I))
327 if (
II->getIntrinsicID() == Intrinsic::stackrestore)
332 bool DisableForCold =
339 ++NumTREPreventedCold;
349 bool SafeToTail =
true;
350 for (
auto &Arg : CI->
args()) {
354 if (!
A->hasByValAttr())
363 <<
"marked as tail call candidate (readnone)";
371 if (!IsNoTail && Escaped == UNESCAPED &&
372 !Tracker.LocalStackUsers.count(CI))
377 auto &State = Visited[SuccBB];
378 if (State < Escaped) {
380 if (State == ESCAPED)
387 if (!WorklistEscaped.
empty()) {
392 while (!WorklistUnescaped.
empty()) {
394 if (Visited[NextBB] == UNESCAPED) {
403 for (
CallInst *CI : DeferredTails) {
404 if (Visited[CI->getParent()] != ESCAPED) {
407 LLVM_DEBUG(
dbgs() <<
"Marked as tail call candidate: " << *CI <<
"\n");
422 if (
II->getIntrinsicID() == Intrinsic::lifetime_end)
427 if (
I->mayHaveSideEffects())
476class TailRecursionEliminator {
477 const ScalarOptions &Opts;
479 const TargetTransformInfo *TTI;
481 OptimizationRemarkEmitter *ORE;
483 BlockFrequencyInfo *
const BFI;
484 ProfileSummaryInfo *
const PSI;
485 const bool UpdateFunctionEntryCount;
496 PHINode *RetPN =
nullptr;
499 PHINode *RetKnownPN =
nullptr;
508 uint64_t EliminateBlocksFrequencySum = 0;
515 PHINode *AccPN =
nullptr;
520 Constant *AccumulatorInitialValue =
nullptr;
522 TailRecursionEliminator(
const ScalarOptions &Opts,
Function &F,
524 OptimizationRemarkEmitter *ORE, DomTreeUpdater &DTU,
525 BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
526 bool UpdateFunctionEntryCount)
527 : Opts(Opts), F(F), TTI(TTI), AA(AA), ORE(ORE), DTU(DTU), BFI(BFI),
528 PSI(PSI), UpdateFunctionEntryCount(UpdateFunctionEntryCount),
530 BFI ? BFI->getBlockFreq(&F.getEntryBlock()).getFrequency() : 0
U),
531 OrigEntryCount(F.getEntryCount() ? *F.getEntryCount() : 0) {
534 assert(OrigEntryBBFreq != 0 &&
535 "If a BFI was provided, the function should have an entry "
536 "basic block with a non-zero frequency.");
540 Constant *findBaseCaseRetConstant(Instruction *AccRecInstr);
542 Constant *canTransformAccumulatorRecursion(Instruction *
I, CallInst *CI);
544 CallInst *findTRECandidate(BasicBlock *BB);
546 void createTailRecurseLoopHeader(CallInst *CI);
548 void insertAccumulator(Instruction *AccRecInstr);
550 bool eliminateCall(CallInst *CI);
552 void cleanupAndFinalize();
554 bool processBlock(BasicBlock &BB);
556 void copyByValueOperandIntoLocalTemp(CallInst *CI,
int OpndIdx);
558 void copyLocalTempOfByValueOperandIntoArguments(CallInst *CI,
int OpndIdx,
559 Instruction *InsertPt);
562 static bool eliminate(
Function &F,
const TargetTransformInfo *TTI,
564 DomTreeUpdater &DTU, BlockFrequencyInfo *BFI,
565 ProfileSummaryInfo *PSI,
bool UpdateFunctionEntryCount);
591TailRecursionEliminator::findBaseCaseRetConstant(
Instruction *AccRecInstr) {
596 auto SetOrMatchBaseCase = [&](
Constant *
C) {
599 return BaseCaseVal ==
C;
602 for (BasicBlock &BB :
F) {
604 if (!RI || !RI->getReturnValue())
607 Value *RV = RI->getReturnValue();
611 if (RV == AccRecInstr)
619 if (!
C || !SetOrMatchBaseCase(
C))
623 for (SelectInst *SI : RetSelects) {
625 if (!
C || !SetOrMatchBaseCase(
C))
636TailRecursionEliminator::canTransformAccumulatorRecursion(Instruction *
I,
639 if ((!
I->isAssociative() || !
I->isCommutative()) &&
640 !IsUnaryAccumulatorRecurrence)
643 assert(
I->getNumOperands() >= 2 &&
644 "Associative/commutative operations should have at least 2 args!");
647 if (IsUnaryAccumulatorRecurrence) {
650 if (
I->getOperand(0) != CI)
655 AccInitVal = findBaseCaseRetConstant(
I);
664 if ((
I->getOperand(0) == CI &&
I->getOperand(1) == CI) ||
665 (
I->getOperand(0) != CI &&
I->getOperand(1) != CI))
676CallInst *TailRecursionEliminator::findTRECandidate(BasicBlock *BB) {
679 if (&BB->
front() == TI)
684 CallInst *CI =
nullptr;
691 if (BBI == BB->
begin())
697 "Incompatible call site attributes(Tail,NoTail)");
706 if (BB == &
F.getEntryBlock() && &BB->
front() == CI &&
713 for (;
I !=
E && FI != FE; ++
I, ++FI)
714 if (*
I != &*FI)
break;
715 if (
I ==
E && FI == FE)
722void TailRecursionEliminator::createTailRecurseLoopHeader(CallInst *CI) {
723 HeaderBB = &
F.getEntryBlock();
726 HeaderBB->
setName(
"tailrecurse");
735 NEBI = NewEntry->
begin();
739 AI->moveBefore(NEBI);
749 I->replaceAllUsesWith(PN);
751 ArgumentPHIs.push_back(PN);
758 Type *RetType =
F.getReturnType();
760 Type *BoolType = Type::getInt1Ty(
F.getContext());
776void TailRecursionEliminator::insertAccumulator(Instruction *AccRecInstr) {
777 assert(!AccPN &&
"Trying to insert multiple accumulators");
779 AccumulatorRecursionInstr = AccRecInstr;
795 if (
P == &
F.getEntryBlock()) {
807void TailRecursionEliminator::copyByValueOperandIntoLocalTemp(CallInst *CI,
811 const DataLayout &
DL =
F.getDataLayout();
818 Value *NewAlloca =
new AllocaInst(
819 AggTy,
DL.getAllocaAddrSpace(),
nullptr, Alignment,
823 Value *
Size = Builder.getInt64(
DL.getTypeAllocSize(AggTy));
826 Builder.CreateMemCpy(NewAlloca, Alignment,
836void TailRecursionEliminator::copyLocalTempOfByValueOperandIntoArguments(
837 CallInst *CI,
int OpndIdx, Instruction *InsertPt) {
840 const DataLayout &
DL =
F.getDataLayout();
846 Value *
Size = Builder.getInt64(
DL.getTypeAllocSize(AggTy));
850 Builder.CreateMemCpy(
F.getArg(OpndIdx), Alignment,
855bool TailRecursionEliminator::eliminateCall(CallInst *CI) {
864 for (++BBI; &*BBI != Ret; ++BBI) {
873 Constant *AccInitVal = canTransformAccumulatorRecursion(&*BBI, CI);
875 if (AccPN || !AccInitVal)
884 AccumulatorInitialValue = AccInitVal;
894 return OptimizationRemark(
DEBUG_TYPE,
"tailcall-recursion", CI)
895 <<
"transforming tail recursion into loop";
901 createTailRecurseLoopHeader(CI);
906 copyByValueOperandIntoLocalTemp(CI,
I);
914 copyLocalTempOfByValueOperandIntoArguments(CI,
I, Ret);
920 F.removeParamAttr(
I, Attribute::ReadOnly);
921 ArgumentPHIs[
I]->addIncoming(
F.getArg(
I), BB);
927 insertAccumulator(AccRecInstr);
954 RetSelects.push_back(SI);
961 AccPN->
addIncoming(AccRecInstr ? AccRecInstr : AccPN, BB);
971 DTU.
applyUpdates({{DominatorTree::Insert, BB, HeaderBB}});
973 if (!Opts.tre_disable_entrycount_recompute && UpdateFunctionEntryCount &&
975 assert(
F.getEntryCount().has_value());
979 assert(&
F.getEntryBlock() != BB);
980 auto RelativeBBFreq =
981 static_cast<double>(BFI->
getBlockFreq(BB).getFrequency()) /
982 static_cast<double>(OrigEntryBBFreq);
984 static_cast<uint64_t>(std::round(RelativeBBFreq * OrigEntryCount));
985 auto OldEntryCount = *
F.getEntryCount();
986 if (OldEntryCount <= ToSubtract) {
988 errs() <<
"[TRE] The entrycount attributable to the recursive call, "
990 <<
", should be strictly lower than the function entry count, "
991 << OldEntryCount <<
"\n");
993 F.setEntryCount(OldEntryCount - ToSubtract);
999void TailRecursionEliminator::cleanupAndFinalize() {
1005 for (PHINode *PN : ArgumentPHIs) {
1014 Instruction *AccRecInstr = AccumulatorRecursionInstr;
1015 auto MaterializeAccumulator = [&](
Value *OtherVal,
1018 New->setName(
"accumulator.ret.tr");
1019 New->setOperand(AccRecInstr->
getOperand(0) == AccPN, OtherVal);
1020 New->insertBefore(InsertPt);
1021 New->dropLocation();
1025 if (RetSelects.empty()) {
1037 for (BasicBlock &BB :
F) {
1059 for (BasicBlock &BB :
F) {
1068 RetSelects.push_back(SI);
1075 for (SelectInst *SI : RetSelects) {
1077 SI->setFalseValue(AccPN);
1080 MaterializeAccumulator(
SI->getFalseValue(),
SI->getIterator()));
1087 uint64_t BaseCaseBlocksFrequencySum = 0;
1088 for (BasicBlock &BB :
F)
1092 if (EliminateBlocksFrequencySum + BaseCaseBlocksFrequencySum == 0)
1094 SmallVector<uint32_t> Testing =
fitWeights({EliminateBlocksFrequencySum, BaseCaseBlocksFrequencySum});
1095 MDBuilder MDB(
F.getContext());
1096 MDNode *BranchWeights = MDB.createBranchWeights(
1097 {Testing[0], Testing[1]},
1099 for (SelectInst *SI : RetSelects)
1100 SI->setMetadata(LLVMContext::MD_prof, BranchWeights);
1105bool TailRecursionEliminator::processBlock(BasicBlock &BB) {
1115 CallInst *CI = findTRECandidate(&BB);
1121 <<
"INTO UNCOND BRANCH PRED: " << BB);
1138 CallInst *CI = findTRECandidate(&BB);
1141 return eliminateCall(CI);
1147bool TailRecursionEliminator::eliminate(
1149 OptimizationRemarkEmitter *ORE, DomTreeUpdater &DTU,
1150 BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
1151 bool UpdateFunctionEntryCount) {
1152 if (
F.getFnAttribute(
"disable-tail-calls").getValueAsBool())
1156 bool MadeChange =
false;
1157 MadeChange |=
markTails(Opts,
F, ORE, PSI, BFI);
1161 if (
F.getFunctionType()->isVarArg())
1168 TailRecursionEliminator TRE(Opts,
F,
TTI, AA, ORE, DTU, BFI, PSI,
1169 UpdateFunctionEntryCount);
1171 for (BasicBlock &BB :
F)
1172 MadeChange |= TRE.processBlock(BB);
1174 TRE.cleanupAndFinalize();
1180struct TailCallElim :
public FunctionPass {
1182 TailCallElim() : FunctionPass(
ID) {
1186 void getAnalysisUsage(AnalysisUsage &AU)
const override {
1189 AU.
addRequired<OptimizationRemarkEmitterWrapperPass>();
1196 if (skipFunction(
F))
1199 auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>();
1200 auto *DT = DTWP ? &DTWP->getDomTree() :
nullptr;
1201 auto *PDTWP = getAnalysisIfAvailable<PostDominatorTreeWrapperPass>();
1202 auto *PDT = PDTWP ? &PDTWP->getPostDomTree() :
nullptr;
1206 DomTreeUpdater DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Eager);
1208 return TailRecursionEliminator::eliminate(
1209 F, &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
F),
1210 &getAnalysis<AAResultsWrapperPass>().getAAResults(),
1211 &getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE(), DTU,
1212 nullptr,
nullptr,
false);
1217char TailCallElim::ID = 0;
1227 return new TailCallElim();
1238 auto *BFI =
F.getEntryCount().has_value()
1249 DomTreeUpdater DTU(DT, PDT, DomTreeUpdater::UpdateStrategy::Eager);
1250 bool Changed = TailRecursionEliminator::eliminate(
1251 F, &
TTI, &
AA, &ORE, DTU, BFI, PSI, UpdateFunctionEntryCount);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool runOnFunction(Function &F, bool PostInlining)
This is the interface for a simple mod/ref and alias analysis over globals.
This file provides various utilities for inspecting and working with the control flow graph in LLVM I...
Module.h This file contains the declarations for the Module class.
uint64_t IntrinsicInst * II
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file contains the declarations for profiling metadata utility functions.
This file defines the SmallPtrSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool canTRE(Function &F)
Scan the specified function for alloca instructions.
static bool returnsCurrentFrameAddress(const IntrinsicInst *II)
Returns true if II returns an address in the current function's frame.
static bool isUnaryAccumulatorRecurrence(Instruction *I)
static bool canMoveAboveCall(Instruction *I, CallInst *CI, AliasAnalysis *AA)
Return true if it is safe to move the specified instruction from after the call to before the call,...
static bool markTails(const ScalarOptions &Opts, Function &F, OptimizationRemarkEmitter *ORE, ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI)
static bool shouldDisableTailCallsForCold(const ScalarOptions &Opts, const CallBase *CB, const Function *Caller, const ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI)
A manager for alias analyses.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
This class represents an incoming formal argument to a Function.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
const Function * getParent() const
Return the enclosing method, or null if none.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const Instruction & front() const
LLVM_ABI InstListType::const_iterator getFirstNonPHIOrPseudoProbe() const
Returns an iterator to the first instruction in this block that is not a PHINode or a pseudo operatio...
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
LLVM_ABI 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.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
bool doesNotAccessMemory(unsigned OpNo) const
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
CallingConv::ID getCallingConv() const
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
LLVM_ABI bool isMustTailCall() const
Tests if this call site must be tail call optimized.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
bool onlyReadsMemory(unsigned OpNo) const
Type * getParamByValType(unsigned ArgNo) const
Extract the byval type for a call or parameter.
bool hasOperandBundlesOtherThan(ArrayRef< uint32_t > IDs) const
Return true if this operand bundle user contains operand bundles with tags other than those specified...
Value * getArgOperand(unsigned i) const
void setArgOperand(unsigned i, Value *v)
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
unsigned arg_size() const
This class represents a function call, abstracting a target machine's calling convention.
bool isNoTailCall() const
void setTailCall(bool IsTc=true)
static LLVM_ABI Constant * getIdentity(Instruction *I, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary or intrinsic Instruction.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
static DebugLoc getCompilerGenerated()
LLVM_ABI void deleteBB(BasicBlock *DelBB)
Delete DelBB.
Analysis pass which computes a DominatorTree.
FunctionPass class - This class is used to implement most global optimizations.
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
void recalculate(FuncT &F)
Notify DTU that the entry block was replaced.
LLVM_ABI Instruction * clone() const
Create a copy of 'this' instruction that is identical in all ways except the following:
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI void insertBefore(InstListType::iterator InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified position.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI bool mayHaveSideEffects() const LLVM_READONLY
Return true if the instruction may have side effects.
void dropPoisonGeneratingAnnotations()
Drops flags, attributes and metadata that may generate poison.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
A wrapper class for inspecting calls to intrinsic functions.
@ OB_clang_arc_attachedcall
An instruction for reading from memory.
static LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
Analysis pass which computes a PostDominatorTree.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
An analysis pass based on the new PM to deliver ProfileSummaryInfo.
Analysis providing profile information.
bool hasProfileSummary() const
Returns true if profile summary is available.
bool isColdBlock(const BBType *BB, BFIT *BFI) const
Returns true if BasicBlock BB is considered cold.
LLVM_ABI bool isColdCallSite(const CallBase &CB, BlockFrequencyInfo *BFI) const
Returns true if call site CB is considered cold.
LLVM_ABI bool isFunctionEntryCold(const Function *F) const
Returns true if F has cold function entry.
Value * getReturnValue() const
Convenience accessor. Returns null if there is no return value.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", InsertPosition InsertBefore=nullptr, const Instruction *MDFrom=nullptr)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Analysis pass providing the TargetTransformInfo.
bool isVoidTy() const
Return true if this is 'void'.
static UncondBrInst * Create(BasicBlock *Target, InsertPosition InsertBefore=nullptr)
void dropAllReferences()
Drop all references to operands.
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
const ParentTy * getParent() const
self_iterator getIterator()
Abstract Attribute helper functions.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
@ BasicBlock
Various leaf nodes.
Add a small namespace to avoid name clashes with the classes used in the streaming interface.
NodeAddr< UseNode * > Use
friend class Instruction
Iterator for Instructions in a `BasicBlock.
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.
LLVM_ABI FunctionPass * createTailCallEliminationPass()
auto pred_end(const MachineBasicBlock *BB)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto successors(const MachineBasicBlock *BB)
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
LLVM_ABI ReturnInst * FoldReturnIntoUncondBranch(ReturnInst *RI, BasicBlock *BB, BasicBlock *Pred, DomTreeUpdater *DTU=nullptr)
This method duplicates the specified return instruction into a predecessor which ends in an unconditi...
const ScalarOptions & getScalarOptions(const LLVMContext &C)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI Value * simplifyInstruction(Instruction *I, const SimplifyQuery &Q)
See if we can compute a simplified version of this instruction.
LLVM_ABI SmallVector< uint32_t > fitWeights(ArrayRef< uint64_t > Weights)
Push the weights right to fit in uint32_t.
bool isModSet(const ModRefInfo MRI)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI bool isSafeToLoadUnconditionally(Value *V, Align Alignment, const APInt &Size, const SimplifyQuery &SQ, bool IgnoreFree=false)
Return true if we know that executing a load from this value cannot trap.
PredIterator< BasicBlock, Value::user_iterator > pred_iterator
auto pred_begin(const MachineBasicBlock *BB)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
bool pred_empty(const BasicBlock *BB)
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI void initializeTailCallElimPass(PassRegistry &)
AAResults AliasAnalysis
Temporary typedef for legacy code that uses a generic AliasAnalysis pointer or reference.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.