|
LLVM
7.0.0
|
#include "llvm/Transforms/Scalar/TailRecursionElimination.h"#include "llvm/ADT/STLExtras.h"#include "llvm/ADT/SmallPtrSet.h"#include "llvm/ADT/Statistic.h"#include "llvm/Analysis/CFG.h"#include "llvm/Analysis/CaptureTracking.h"#include "llvm/Analysis/GlobalsModRef.h"#include "llvm/Analysis/InlineCost.h"#include "llvm/Analysis/InstructionSimplify.h"#include "llvm/Analysis/Loads.h"#include "llvm/Analysis/OptimizationRemarkEmitter.h"#include "llvm/Analysis/TargetTransformInfo.h"#include "llvm/IR/CFG.h"#include "llvm/IR/CallSite.h"#include "llvm/IR/Constants.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/DerivedTypes.h"#include "llvm/IR/DiagnosticInfo.h"#include "llvm/IR/Function.h"#include "llvm/IR/InstIterator.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/Module.h"#include "llvm/IR/ValueHandle.h"#include "llvm/Pass.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"#include "llvm/Transforms/Scalar.h"#include "llvm/Transforms/Utils/BasicBlockUtils.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "tailcallelim" |
Functions | |
| STATISTIC (NumEliminated, "Number of tail calls removed") | |
| STATISTIC (NumRetDuped, "Number of return duplicated") | |
| STATISTIC (NumAccumAdded, "Number of accumulators introduced") | |
| static bool | canTRE (Function &F) |
| Scan the specified function for alloca instructions. More... | |
| static bool | markTails (Function &F, bool &AllCallsAreTailCalls, OptimizationRemarkEmitter *ORE) |
| 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, assuming that all instructions between the call and this instruction are movable. More... | |
| static bool | isDynamicConstant (Value *V, CallInst *CI, ReturnInst *RI) |
| Return true if the specified value is the same when the return would exit as it was when the initial iteration of the recursive function was executed. More... | |
| static Value * | getCommonReturnValue (ReturnInst *IgnoreRI, CallInst *CI) |
| Check to see if the function containing the specified tail call consistently returns the same runtime-constant value at all exit points except for IgnoreRI. More... | |
| static Value * | canTransformAccumulatorRecursion (Instruction *I, CallInst *CI) |
| If the specified instruction can be transformed using accumulator recursion elimination, return the constant which is the start of the accumulator value. More... | |
| static Instruction * | firstNonDbg (BasicBlock::iterator I) |
| static CallInst * | findTRECandidate (Instruction *TI, bool CannotTailCallElimCallsMarkedTail, const TargetTransformInfo *TTI) |
| static bool | eliminateRecursiveTailCall (CallInst *CI, ReturnInst *Ret, BasicBlock *&OldEntry, bool &TailCallsAreMarkedTail, SmallVectorImpl< PHINode *> &ArgumentPHIs, AliasAnalysis *AA, OptimizationRemarkEmitter *ORE) |
| static bool | foldReturnAndProcessPred (BasicBlock *BB, ReturnInst *Ret, BasicBlock *&OldEntry, bool &TailCallsAreMarkedTail, SmallVectorImpl< PHINode *> &ArgumentPHIs, bool CannotTailCallElimCallsMarkedTail, const TargetTransformInfo *TTI, AliasAnalysis *AA, OptimizationRemarkEmitter *ORE) |
| static bool | processReturningBlock (ReturnInst *Ret, BasicBlock *&OldEntry, bool &TailCallsAreMarkedTail, SmallVectorImpl< PHINode *> &ArgumentPHIs, bool CannotTailCallElimCallsMarkedTail, const TargetTransformInfo *TTI, AliasAnalysis *AA, OptimizationRemarkEmitter *ORE) |
| static bool | eliminateTailRecursion (Function &F, const TargetTransformInfo *TTI, AliasAnalysis *AA, OptimizationRemarkEmitter *ORE) |
| INITIALIZE_PASS_BEGIN (TailCallElim, "tailcallelim", "Tail Call Elimination", false, false) INITIALIZE_PASS_END(TailCallElim | |
Variables | |
| tailcallelim | |
| Tail Call | Elimination |
| Tail Call | false |
| #define DEBUG_TYPE "tailcallelim" |
Definition at line 84 of file TailRecursionElimination.cpp.
Referenced by eliminateRecursiveTailCall(), and markTails().
|
static |
Return true if it is safe to move the specified instruction from after the call to before the call, assuming that all instructions between the call and this instruction are movable.
Definition at line 320 of file TailRecursionElimination.cpp.
References llvm::MemoryLocation::get(), llvm::AAResults::getModRefInfo(), llvm::is_contained(), llvm::isModSet(), llvm::isSafeToLoadUnconditionally(), llvm::Instruction::mayHaveSideEffects(), and llvm::User::operands().
Referenced by eliminateRecursiveTailCall().
|
static |
If the specified instruction can be transformed using accumulator recursion elimination, return the constant which is the start of the accumulator value.
Otherwise return null.
Definition at line 414 of file TailRecursionElimination.cpp.
References assert(), getCommonReturnValue(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Value::hasOneUse(), llvm::Instruction::isAssociative(), llvm::Instruction::isCommutative(), and llvm::Instruction::user_back().
Referenced by eliminateRecursiveTailCall().
Scan the specified function for alloca instructions.
If it contains any dynamic allocas, returns false.
Definition at line 92 of file TailRecursionElimination.cpp.
References llvm::all_of(), llvm::MCID::Call, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::doesNotCapture(), llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getDataOperandNo(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::Instruction::getOpcode(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::instructions(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::isDataOperand(), llvm::AllocaInst::isStaticAlloca(), llvm::SPII::Load, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::onlyReadsMemory(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::MCID::Select, and llvm::SPII::Store.
Referenced by eliminateTailRecursion().
|
static |
Definition at line 491 of file TailRecursionElimination.cpp.
References llvm::PHINode::addIncoming(), llvm::Function::arg_begin(), llvm::Function::arg_end(), llvm::BasicBlock::begin(), canMoveAboveCall(), canTransformAccumulatorRecursion(), llvm::BasicBlock::Create(), llvm::PHINode::Create(), llvm::BranchInst::Create(), DEBUG_TYPE, E, llvm::OptimizationRemarkEmitter::emit(), llvm::BasicBlock::end(), llvm::iplist_impl< IntrusiveListT, TraitsT >::erase(), F(), llvm::BasicBlock::front(), llvm::CallBase< InstTy >::getArgOperand(), getCommonReturnValue(), llvm::Function::getContext(), llvm::Instruction::getDebugLoc(), llvm::Function::getEntryBlock(), llvm::BasicBlock::getInstList(), llvm::CallBase< InstTy >::getNumArgOperands(), llvm::User::getNumOperands(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::ReturnInst::getReturnValue(), llvm::Value::getType(), I, isDynamicConstant(), llvm::CallInst::isTailCall(), P, llvm::pred_begin(), llvm::pred_end(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::MipsISD::Ret, llvm::Instruction::setDebugLoc(), llvm::Value::setName(), llvm::User::setOperand(), and llvm::Value::takeName().
Referenced by foldReturnAndProcessPred(), and processReturningBlock().
|
static |
Definition at line 738 of file TailRecursionElimination.cpp.
References llvm::AnalysisUsage::addPreserved(), llvm::AnalysisUsage::addRequired(), llvm::Function::begin(), canTRE(), E, llvm::Function::end(), F(), foldReturnAndProcessPred(), llvm::Module::getDataLayout(), llvm::BasicBlock::getFirstNonPHIOrDbg(), llvm::Function::getFnAttribute(), llvm::Function::getFunctionType(), llvm::GlobalValue::getParent(), llvm::PassRegistry::getPassRegistry(), llvm::BasicBlock::getTerminator(), llvm::Attribute::getValueAsString(), INITIALIZE_PASS_BEGIN(), INITIALIZE_PASS_DEPENDENCY, llvm::initializeTailCallElimPass(), llvm::FunctionType::isVarArg(), markTails(), processReturningBlock(), llvm::MipsISD::Ret, runOnFunction(), and llvm::SimplifyInstruction().
Referenced by llvm::TailCallElimPass::run().
|
static |
Definition at line 440 of file TailRecursionElimination.cpp.
References llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_begin(), llvm::Function::arg_begin(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_end(), llvm::Function::arg_end(), llvm::BasicBlock::begin(), llvm::dyn_cast(), E, F(), firstNonDbg(), llvm::BasicBlock::front(), llvm::CallBase< InstTy >::getCalledFunction(), llvm::Function::getEntryBlock(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), I, llvm::TargetTransformInfo::isLoweredToCall(), and llvm::CallInst::isTailCall().
Referenced by foldReturnAndProcessPred(), and processReturningBlock().
|
static |
Definition at line 434 of file TailRecursionElimination.cpp.
References I.
Referenced by findTRECandidate().
|
static |
Definition at line 674 of file TailRecursionElimination.cpp.
References assert(), llvm::dbgs(), E, eliminateRecursiveTailCall(), llvm::BasicBlock::eraseFromParent(), findTRECandidate(), llvm::FoldReturnIntoUncondBranch(), llvm::BasicBlock::getFirstNonPHIOrDbg(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::BasicBlock::hasAddressTaken(), LLVM_DEBUG, llvm::pred_begin(), and llvm::pred_end().
Referenced by eliminateTailRecursion().
|
static |
Check to see if the function containing the specified tail call consistently returns the same runtime-constant value at all exit points except for IgnoreRI.
If so, return the returned value.
Definition at line 388 of file TailRecursionElimination.cpp.
References llvm::dyn_cast(), F(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), and isDynamicConstant().
Referenced by canTransformAccumulatorRecursion(), and eliminateRecursiveTailCall().
| INITIALIZE_PASS_BEGIN | ( | TailCallElim | , |
| "tailcallelim" | , | ||
| "Tail Call Elimination" | , | ||
| false | , | ||
| false | |||
| ) |
Referenced by eliminateTailRecursion().
|
static |
Return true if the specified value is the same when the return would exit as it was when the initial iteration of the recursive function was executed.
We currently handle static constants and arguments that are not modified as part of the recursion.
Definition at line 354 of file TailRecursionElimination.cpp.
References Arg, llvm::Function::arg_begin(), F(), llvm::CallBase< InstTy >::getArgOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getUniquePredecessor(), and SI.
Referenced by eliminateRecursiveTailCall(), and getCommonReturnValue().
|
static |
Definition at line 180 of file TailRecursionElimination.cpp.
References Arg, llvm::CallBase< InstTy >::arg_operands(), llvm::Function::args(), llvm::Function::callsFunctionThatReturnsTwice(), llvm::dbgs(), DEBUG_TYPE, llvm::CallBase< InstTy >::doesNotAccessMemory(), llvm::dyn_cast(), llvm::OptimizationRemarkEmitter::emit(), llvm::SmallVectorBase::empty(), llvm::OperandBundleUser< InstrTy, OpIteratorTy >::hasOperandBundles(), I, llvm::CallInst::isNoTailCall(), llvm::CallInst::isTailCall(), LLVM_DEBUG, llvm::make_range(), Modified, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::CallInst::setTailCall(), llvm::succ_begin(), and llvm::succ_end().
Referenced by eliminateTailRecursion().
|
static |
Definition at line 723 of file TailRecursionElimination.cpp.
References eliminateRecursiveTailCall(), and findTRECandidate().
Referenced by eliminateTailRecursion().
| STATISTIC | ( | NumEliminated | , |
| "Number of tail calls removed" | |||
| ) |
| STATISTIC | ( | NumRetDuped | , |
| "Number of return duplicated" | |||
| ) |
| STATISTIC | ( | NumAccumAdded | , |
| "Number of accumulators introduced" | |||
| ) |
| Tail Call Elimination |
Definition at line 831 of file TailRecursionElimination.cpp.
| Tail Call false |
Definition at line 831 of file TailRecursionElimination.cpp.
| tailcallelim |
Definition at line 831 of file TailRecursionElimination.cpp.
1.8.13