LLVM  3.7.0
Macros | Functions | Variables
TailRecursionElimination.cpp File Reference
#include "llvm/Transforms/Scalar.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/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/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/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
Include dependency graph for TailRecursionElimination.cpp:

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")
 
 INITIALIZE_PASS_BEGIN (TailCallElim,"tailcallelim","Tail Call Elimination", false, false) INITIALIZE_PASS_END(TailCallElim
 
static bool CanTRE (Function &F)
 Scan the specified function for alloca instructions. 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 ValuegetCommonReturnValue (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 InstructionFirstNonDbg (BasicBlock::iterator I)
 

Variables

 tailcallelim
 
Tail Call Elimination
 
Tail Call false
 

Macro Definition Documentation

#define DEBUG_TYPE   "tailcallelim"

Definition at line 81 of file TailRecursionElimination.cpp.

Function Documentation

static bool CanTRE ( Function F)
static

Scan the specified function for alloca instructions.

If it contains any dynamic allocas, returns false.

Definition at line 143 of file TailRecursionElimination.cpp.

References I.

static Instruction* FirstNonDbg ( BasicBlock::iterator  I)
static

Definition at line 559 of file TailRecursionElimination.cpp.

References I.

static Value* getCommonReturnValue ( ReturnInst IgnoreRI,
CallInst CI 
)
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 512 of file TailRecursionElimination.cpp.

References llvm::Function::begin(), llvm::dyn_cast(), llvm::Function::end(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), and isDynamicConstant().

INITIALIZE_PASS_BEGIN ( TailCallElim  ,
"tailcallelim"  ,
"Tail Call Elimination ,
false  ,
false   
)
static bool isDynamicConstant ( Value V,
CallInst CI,
ReturnInst RI 
)
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 478 of file TailRecursionElimination.cpp.

References llvm::Function::arg_begin(), llvm::CallInst::getArgOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::BasicBlock::getUniquePredecessor(), and SI.

Referenced by getCommonReturnValue().

STATISTIC ( NumEliminated  ,
"Number of tail calls removed"   
)
STATISTIC ( NumRetDuped  ,
"Number of return duplicated"   
)
STATISTIC ( NumAccumAdded  ,
"Number of accumulators introduced"   
)

Variable Documentation

Tail Call Elimination

Definition at line 129 of file TailRecursionElimination.cpp.

Tail Call false

Definition at line 129 of file TailRecursionElimination.cpp.

tailcallelim

Definition at line 129 of file TailRecursionElimination.cpp.