LLVM  4.0.0
Macros | Typedefs | Functions | Variables
ArgumentPromotion.cpp File Reference
#include "llvm/Transforms/IPO.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <set>
Include dependency graph for ArgumentPromotion.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "argpromotion"
 

Typedefs

typedef std::vector< uint64_t > IndicesVector
 A vector used to hold the indices of a single GEP instruction. More...
 

Functions

 STATISTIC (NumArgumentsPromoted,"Number of pointer arguments promoted")
 
 STATISTIC (NumAggregatesPromoted,"Number of aggregate arguments promoted")
 
 STATISTIC (NumByValArgsPromoted,"Number of byval arguments promoted")
 
 STATISTIC (NumArgumentsDead,"Number of dead pointer args eliminated")
 
static CallGraphNodePromoteArguments (CallGraphNode *CGN, CallGraph &CG, function_ref< AAResults &(Function &F)> AARGetter, unsigned MaxElements)
 PromoteArguments - This method checks the specified function to see if there are any promotable arguments and if it is safe to promote the function (for example, all callers are direct). More...
 
static bool isDenselyPacked (Type *type, const DataLayout &DL)
 Checks if a type could have padding bytes. More...
 
static bool canPaddingBeAccessed (Argument *arg)
 Checks if the padding bytes of an argument could be accessed. More...
 
static bool isSafeToPromoteArgument (Argument *Arg, bool isByValOrInAlloca, AAResults &AAR, unsigned MaxElements)
 isSafeToPromoteArgument - As you might guess from the name of this method, it checks to see if it is both safe and useful to promote the argument. More...
 
static CallGraphNodeDoPromotion (Function *F, SmallPtrSetImpl< Argument * > &ArgsToPromote, SmallPtrSetImpl< Argument * > &ByValArgsToTransform, CallGraph &CG)
 DoPromotion - This method actually performs the promotion of the specified arguments, and returns the new function. More...
 
 INITIALIZE_PASS_BEGIN (ArgPromotion,"argpromotion","Promote 'by reference' arguments to scalars", false, false) INITIALIZE_PASS_END(ArgPromotion
 
static bool runImpl (CallGraphSCC &SCC, CallGraph &CG, function_ref< AAResults &(Function &F)> AARGetter, unsigned MaxElements)
 
static bool AllCallersPassInValidPointerForArgument (Argument *Arg)
 AllCallersPassInValidPointerForArgument - Return true if we can prove that all callees pass in a valid pointer for the specified function argument. More...
 
static bool IsPrefix (const IndicesVector &Prefix, const IndicesVector &Longer)
 Returns true if Prefix is a prefix of longer. More...
 
static bool PrefixIn (const IndicesVector &Indices, std::set< IndicesVector > &Set)
 Checks if Indices, or a prefix of Indices, is in Set. More...
 
static void MarkIndicesSafe (const IndicesVector &ToMark, std::set< IndicesVector > &Safe)
 Mark the given indices (ToMark) as safe in the given set of indices (Safe). More...
 

Variables

 argpromotion
 
Promote by reference arguments to scalars
 
Promote by reference arguments to false
 

Macro Definition Documentation

#define DEBUG_TYPE   "argpromotion"

Definition at line 57 of file ArgumentPromotion.cpp.

Typedef Documentation

typedef std::vector<uint64_t> IndicesVector

A vector used to hold the indices of a single GEP instruction.

Definition at line 92 of file ArgumentPromotion.cpp.

Function Documentation

static bool AllCallersPassInValidPointerForArgument ( Argument Arg)
static

AllCallersPassInValidPointerForArgument - Return true if we can prove that all callees pass in a valid pointer for the specified function argument.

Definition at line 370 of file ArgumentPromotion.cpp.

References assert(), llvm::Argument::getArgNo(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getArgument(), llvm::Module::getDataLayout(), llvm::Argument::getParent(), llvm::GlobalValue::getParent(), llvm::isDereferenceablePointer(), and llvm::Value::users().

Referenced by isSafeToPromoteArgument().

static bool canPaddingBeAccessed ( Argument Arg)
static
static CallGraphNode * DoPromotion ( Function F,
SmallPtrSetImpl< Argument * > &  ArgsToPromote,
SmallPtrSetImpl< Argument * > &  ByValArgsToTransform,
CallGraph CG 
)
static

DoPromotion - This method actually performs the promotion of the specified arguments, and returns the new function.

At this point, we know that it's safe to do so.

Definition at line 632 of file ArgumentPromotion.cpp.

References advance(), llvm::Function::arg_begin(), llvm::Function::arg_end(), AMDGPU::RuntimeMD::KeyName::Args, assert(), B, llvm::Call, llvm::SmallVectorImpl< T >::clear(), llvm::Function::copyAttributesFrom(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::Function::Create(), llvm::GetElementPtrInst::Create(), llvm::CallInst::Create(), llvm::InvokeInst::Create(), llvm::dbgs(), DEBUG, llvm::dyn_cast(), E, llvm::StructType::element_begin(), llvm::StructType::element_end(), llvm::Instruction::eraseFromParent(), llvm::GlobalValue::ExternalLinkage, F, llvm::AttributeSet::FunctionIndex, GEP, llvm::ConstantInt::get(), llvm::FunctionType::get(), llvm::Instruction::getAAMetadata(), llvm::LoadInst::getAlignment(), llvm::Function::getAttributes(), llvm::Function::getBasicBlockList(), llvm::Type::getContext(), llvm::Function::getContext(), llvm::Value::getContext(), llvm::AttributeSet::getFnAttributes(), llvm::Module::getFunctionList(), llvm::Function::getFunctionType(), llvm::GetElementPtrInst::getIndexedType(), llvm::Type::getInt32Ty(), llvm::Type::getInt64Ty(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::GlobalValue::getLinkage(), llvm::Value::getName(), llvm::StructType::getName(), llvm::StructType::getNumElements(), llvm::GetElementPtrInst::getNumIndices(), llvm::User::getNumOperands(), llvm::CallGraphNode::getNumReferences(), llvm::CallGraph::getOrInsertFunction(), llvm::AttributeSet::getParamAttributes(), llvm::GlobalValue::getParent(), llvm::AttributeSet::getRetAttributes(), llvm::FunctionType::getReturnType(), llvm::Function::getSubprogram(), llvm::Value::getType(), llvm::AttributeSet::hasAttributes(), I, i, llvm::GetElementPtrInst::idx_begin(), llvm::GetElementPtrInst::idx_end(), llvm::ARM_PROC::IE, llvm::iplist_impl< IntrusiveListT, TraitsT >::insert(), llvm::Type::isStructTy(), llvm::FunctionType::isVarArg(), L, llvm::User::op_begin(), llvm::User::op_end(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::CallGraph::removeFunctionFromModule(), llvm::Value::replaceAllUsesWith(), llvm::CallGraphNode::replaceCallEdge(), llvm::AttributeSet::ReturnIndex, llvm::Instruction::setAAMetadata(), llvm::LoadInst::setAlignment(), llvm::Instruction::setDebugLoc(), llvm::GlobalValue::setLinkage(), llvm::Value::setName(), llvm::Function::setSubprogram(), llvm::CallInst::setTailCall(), llvm::SmallVectorTemplateCommon< T >::size(), llvm::CallGraphNode::stealCalledFunctionsFrom(), llvm::Value::takeName(), llvm::Value::use_empty(), llvm::Instruction::user_back(), llvm::Value::user_back(), llvm::Value::users(), and llvm::utostr().

Referenced by PromoteArguments().

INITIALIZE_PASS_BEGIN ( ArgPromotion  ,
"argpromotion"  ,
"Promote 'by reference' arguments to scalars ,
false  ,
false   
)
static bool isDenselyPacked ( Type type,
const DataLayout DL 
)
static
static bool IsPrefix ( const IndicesVector Prefix,
const IndicesVector Longer 
)
static

Returns true if Prefix is a prefix of longer.

That means, Longer has a size that is greater than or equal to the size of prefix, and each of the elements in Prefix is the same as the corresponding elements in Longer.

This means it also returns true when Prefix and Longer are equal!

Definition at line 393 of file ArgumentPromotion.cpp.

References llvm::lltok::equal.

Referenced by MarkIndicesSafe(), and PrefixIn().

static bool isSafeToPromoteArgument ( Argument Arg,
bool  isByValOrInAlloca,
AAResults AAR,
unsigned  MaxElements 
)
static

isSafeToPromoteArgument - As you might guess from the name of this method, it checks to see if it is both safe and useful to promote the argument.

This method limits promotion of aggregates to only promote up to three elements of the aggregate in order to avoid exploding the number of arguments passed in.

Definition at line 456 of file ArgumentPromotion.cpp.

References AllCallersPassInValidPointerForArgument(), C, llvm::AAResults::canBasicBlockModify(), llvm::AAResults::canInstructionRangeModRef(), llvm::dbgs(), DEBUG, llvm::SmallVectorBase::empty(), llvm::BasicBlock::front(), llvm::Function::front(), GEP, llvm::MemoryLocation::get(), llvm::Value::getName(), llvm::Argument::getParent(), I, i, llvm::ARM_PROC::IE, llvm::inverse_depth_first_ext(), llvm::SPII::Load, MarkIndicesSafe(), llvm::MRI_Mod, P, llvm::predecessors(), PrefixIn(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::Value::use_empty(), and llvm::Value::uses().

Referenced by PromoteArguments().

static void MarkIndicesSafe ( const IndicesVector ToMark,
std::set< IndicesVector > &  Safe 
)
static

Mark the given indices (ToMark) as safe in the given set of indices (Safe).

Marking safe usually means adding ToMark to Safe. However, if there is already a prefix of Indices in Safe, Indices are implicitely marked safe already. Furthermore, any indices that Indices is itself a prefix of, are removed from Safe (since they are implicitely safe because of Indices now).

Definition at line 420 of file ArgumentPromotion.cpp.

References llvm::WebAssembly::End, and IsPrefix().

Referenced by isSafeToPromoteArgument().

static bool PrefixIn ( const IndicesVector Indices,
std::set< IndicesVector > &  Set 
)
static

Checks if Indices, or a prefix of Indices, is in Set.

Definition at line 401 of file ArgumentPromotion.cpp.

References IsPrefix().

Referenced by isSafeToPromoteArgument().

static CallGraphNode * PromoteArguments ( CallGraphNode CGN,
CallGraph CG,
function_ref< AAResults &(Function &F)>  AARGetter,
unsigned  MaxElements 
)
static
static bool runImpl ( CallGraphSCC SCC,
CallGraph CG,
function_ref< AAResults &(Function &F)>  AARGetter,
unsigned  MaxElements 
)
static
STATISTIC ( NumArgumentsPromoted  ,
"Number of pointer arguments promoted"   
)
STATISTIC ( NumAggregatesPromoted  ,
"Number of aggregate arguments promoted"   
)
STATISTIC ( NumByValArgsPromoted  ,
"Number of byval arguments promoted"   
)
STATISTIC ( NumArgumentsDead  ,
"Number of dead pointer args eliminated"   
)

Variable Documentation

argpromotion

Definition at line 112 of file ArgumentPromotion.cpp.

Promote by reference arguments to false

Definition at line 112 of file ArgumentPromotion.cpp.

Promote by reference arguments to scalars

Definition at line 112 of file ArgumentPromotion.cpp.