|
LLVM
5.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/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"#include "llvm/Transforms/Utils/Local.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) |
| 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) |
| static bool | foldReturnAndProcessPred (BasicBlock *BB, ReturnInst *Ret, BasicBlock *&OldEntry, bool &TailCallsAreMarkedTail, SmallVectorImpl< PHINode * > &ArgumentPHIs, bool CannotTailCallElimCallsMarkedTail, const TargetTransformInfo *TTI, AliasAnalysis *AA) |
| static bool | processReturningBlock (ReturnInst *Ret, BasicBlock *&OldEntry, bool &TailCallsAreMarkedTail, SmallVectorImpl< PHINode * > &ArgumentPHIs, bool CannotTailCallElimCallsMarkedTail, const TargetTransformInfo *TTI, AliasAnalysis *AA) |
| static bool | eliminateTailRecursion (Function &F, const TargetTransformInfo *TTI, AliasAnalysis *AA) |
| 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.
|
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 319 of file TailRecursionElimination.cpp.
References llvm::DL, llvm::MemoryLocation::get(), llvm::AAResults::getModRefInfo(), llvm::is_contained(), llvm::isSafeToLoadUnconditionally(), L, llvm::Instruction::mayHaveSideEffects(), llvm::MRI_Mod, 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 413 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::dyn_cast(), I, llvm::instructions(), and llvm::AllocaInst::isStaticAlloca().
Referenced by eliminateTailRecursion().
|
static |
Definition at line 490 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(), E, llvm::emitOptimizationRemark(), llvm::BasicBlock::end(), llvm::iplist_impl< IntrusiveListT, TraitsT >::erase(), F, llvm::BasicBlock::front(), llvm::CallInst::getArgOperand(), getCommonReturnValue(), llvm::Function::getContext(), llvm::Instruction::getDebugLoc(), llvm::Function::getEntryBlock(), llvm::BasicBlock::getInstList(), llvm::Value::getName(), llvm::CallInst::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::Value::replaceAllUsesWith(), 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 734 of file TailRecursionElimination.cpp.
References llvm::Function::begin(), canTRE(), E, llvm::Function::end(), foldReturnAndProcessPred(), llvm::Module::getDataLayout(), llvm::BasicBlock::getFirstNonPHIOrDbg(), llvm::Function::getFnAttribute(), llvm::Function::getFunctionType(), llvm::GlobalValue::getParent(), llvm::BasicBlock::getTerminator(), llvm::Attribute::getValueAsString(), llvm::FunctionType::isVarArg(), markTails(), processReturningBlock(), llvm::MipsISD::Ret, and llvm::SimplifyInstruction().
Referenced by llvm::TailCallElimPass::run().
|
static |
Definition at line 439 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::CallInst::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 433 of file TailRecursionElimination.cpp.
References I.
Referenced by findTRECandidate().
|
static |
Definition at line 669 of file TailRecursionElimination.cpp.
References assert(), llvm::dbgs(), DEBUG, E, eliminateRecursiveTailCall(), llvm::BasicBlock::eraseFromParent(), findTRECandidate(), llvm::FoldReturnIntoUncondBranch(), llvm::BasicBlock::getFirstNonPHIOrDbg(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::BasicBlock::hasAddressTaken(), 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 387 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 | |||
| ) |
|
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 353 of file TailRecursionElimination.cpp.
References llvm::Function::arg_begin(), F, llvm::CallInst::getArgOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getUniquePredecessor(), and SI.
Referenced by eliminateRecursiveTailCall(), and getCommonReturnValue().
Definition at line 180 of file TailRecursionElimination.cpp.
References A, llvm::CallInst::arg_operands(), llvm::Function::args(), llvm::Function::callsFunctionThatReturnsTwice(), llvm::CallInst::doesNotAccessMemory(), llvm::dyn_cast(), llvm::emitOptimizationRemark(), llvm::SmallVectorBase::empty(), F, llvm::Instruction::getDebugLoc(), llvm::OperandBundleUser< InstrTy, OpIteratorTy >::hasOperandBundles(), I, llvm::CallInst::isNoTailCall(), llvm::CallInst::isTailCall(), llvm::make_range(), 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 720 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 823 of file TailRecursionElimination.cpp.
| Tail Call false |
Definition at line 823 of file TailRecursionElimination.cpp.
| tailcallelim |
Definition at line 823 of file TailRecursionElimination.cpp.
1.8.6