LLVM  6.0.0svn
Macros | Typedefs | Functions | Variables
ArgumentPromotion.cpp File Reference
#include "llvm/Transforms/IPO/ArgumentPromotion.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/Optional.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/LazyCallGraph.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 "llvm/Transforms/IPO.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 FunctiondoPromotion (Function *F, SmallPtrSetImpl< Argument *> &ArgsToPromote, SmallPtrSetImpl< Argument *> &ByValArgsToTransform, Optional< function_ref< void(CallSite OldCS, CallSite NewCS)>> ReplaceCallSite)
 DoPromotion - This method actually performs the promotion of the specified arguments, and returns the new function. More...
 
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...
 
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 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 FunctionpromoteArguments (Function *F, function_ref< AAResults &(Function &F)> AARGetter, unsigned MaxElements, Optional< function_ref< void(CallSite OldCS, CallSite NewCS)>> ReplaceCallSite)
 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...
 
 INITIALIZE_PASS_BEGIN (ArgPromotion, "argpromotion", "Promote 'by reference' arguments to scalars", false, false) INITIALIZE_PASS_END(ArgPromotion
 

Variables

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

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "argpromotion"

Definition at line 60 of file ArgumentPromotion.cpp.

Typedef Documentation

◆ IndicesVector

typedef std::vector<uint64_t> IndicesVector

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

Definition at line 68 of file ArgumentPromotion.cpp.

Function Documentation

◆ allCallersPassInValidPointerForArgument()

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 453 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().

◆ canPaddingBeAccessed()

static bool canPaddingBeAccessed ( Argument arg)
static

◆ doPromotion()

static Function* doPromotion ( Function F,
SmallPtrSetImpl< Argument *> &  ArgsToPromote,
SmallPtrSetImpl< Argument *> &  ByValArgsToTransform,
Optional< function_ref< void(CallSite OldCS, CallSite NewCS)>>  ReplaceCallSite 
)
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 74 of file ArgumentPromotion.cpp.

References llvm::Function::arg_begin(), llvm::Function::arg_end(), llvm::AMDGPU::CodeObject::Kernel::Key::Args, assert(), 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::SmallVectorTemplateCommon< T >::end(), llvm::Instruction::eraseFromParent(), F, GEP, llvm::ConstantInt::get(), llvm::FunctionType::get(), llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::Instruction::getAAMetadata(), llvm::LoadInst::getAlignment(), llvm::DataLayout::getAllocaAddrSpace(), llvm::Function::getAttributes(), llvm::Function::getBasicBlockList(), llvm::Function::getContext(), llvm::Module::getDataLayout(), llvm::AttributeList::getFnAttributes(), llvm::Module::getFunctionList(), llvm::Function::getFunctionType(), llvm::GetElementPtrInst::getIndexedType(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), 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::AttributeList::getParamAttributes(), llvm::GlobalValue::getParent(), llvm::AttributeList::getRetAttributes(), llvm::FunctionType::getReturnType(), llvm::Function::getSubprogram(), llvm::Value::getType(), I, llvm::GetElementPtrInst::idx_begin(), llvm::GetElementPtrInst::idx_end(), llvm::ARM_PROC::IE, llvm::iplist_impl< IntrusiveListT, TraitsT >::insert(), llvm::SmallVectorImpl< T >::insert(), llvm::Type::isStructTy(), llvm::FunctionType::isVarArg(), llvm::User::op_begin(), llvm::User::op_end(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setAAMetadata(), llvm::LoadInst::setAlignment(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setCallingConv(), llvm::Value::setName(), llvm::Function::setSubprogram(), llvm::CallInst::setTailCall(), 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()

INITIALIZE_PASS_BEGIN ( ArgPromotion  ,
"argpromotion"  ,
"Promote 'by reference' arguments to scalars ,
false  ,
false   
)

◆ isDenselyPacked()

static bool isDenselyPacked ( Type type,
const DataLayout DL 
)
static

◆ isPrefix()

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 476 of file ArgumentPromotion.cpp.

References llvm::lltok::equal.

Referenced by llvm::HexagonMCInstrInfo::inRange(), markIndicesSafe(), prefixIn(), readPrefixes(), and RewriteIntelBracExpression().

◆ isSafeToPromoteArgument()

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 538 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, 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().

◆ markIndicesSafe()

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 502 of file ArgumentPromotion.cpp.

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

Referenced by isSafeToPromoteArgument().

◆ prefixIn()

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 483 of file ArgumentPromotion.cpp.

References isPrefix().

Referenced by isSafeToPromoteArgument().

◆ promoteArguments()

static Function* promoteArguments ( Function F,
function_ref< AAResults &(Function &F)>  AARGetter,
unsigned  MaxElements,
Optional< function_ref< void(CallSite OldCS, CallSite NewCS)>>  ReplaceCallSite 
)
static

◆ STATISTIC() [1/4]

STATISTIC ( NumArgumentsPromoted  ,
"Number of pointer arguments promoted"   
)

◆ STATISTIC() [2/4]

STATISTIC ( NumAggregatesPromoted  ,
"Number of aggregate arguments promoted"   
)

◆ STATISTIC() [3/4]

STATISTIC ( NumByValArgsPromoted  ,
"Number of byval arguments promoted"   
)

◆ STATISTIC() [4/4]

STATISTIC ( NumArgumentsDead  ,
"Number of dead pointer args eliminated"   
)

Variable Documentation

◆ argpromotion

argpromotion

Definition at line 999 of file ArgumentPromotion.cpp.

◆ false

Promote by reference arguments to false

Definition at line 999 of file ArgumentPromotion.cpp.

◆ scalars

Promote by reference arguments to scalars

Definition at line 999 of file ArgumentPromotion.cpp.