LLVM  8.0.1
Macros | Typedefs | Functions | Variables
ArgumentPromotion.cpp File Reference
#include "llvm/Transforms/IPO/ArgumentPromotion.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.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/Function.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Use.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "argpromotion"
 

Typedefs

using IndicesVector = std::vector< uint64_t >
 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 bool areFunctionArgsABICompatible (const Function &F, const TargetTransformInfo &TTI, SmallPtrSetImpl< Argument *> &ArgsToPromote, SmallPtrSetImpl< Argument *> &ByValArgsToTransform)
 
static FunctionpromoteArguments (Function *F, function_ref< AAResults &(Function &F)> AARGetter, unsigned MaxElements, Optional< function_ref< void(CallSite OldCS, CallSite NewCS)>> ReplaceCallSite, const TargetTransformInfo &TTI)
 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 90 of file ArgumentPromotion.cpp.

Typedef Documentation

◆ IndicesVector

using IndicesVector = std::vector<uint64_t>

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

Definition at line 98 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 481 of file ArgumentPromotion.cpp.

References assert(), Callee, 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().

◆ areFunctionArgsABICompatible()

static bool areFunctionArgsABICompatible ( const Function F,
const TargetTransformInfo TTI,
SmallPtrSetImpl< Argument *> &  ArgsToPromote,
SmallPtrSetImpl< Argument *> &  ByValArgsToTransform 
)
static

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

References llvm::Function::arg_begin(), llvm::Function::arg_end(), llvm::AMDGPU::HSAMD::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(), 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::GlobalValue::getAddressSpace(), llvm::LoadInst::getAlignment(), llvm::DataLayout::getAllocaAddrSpace(), llvm::Function::getAttributes(), llvm::AttributeList::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_DEBUG, llvm::User::op_begin(), llvm::User::op_end(), llvm::SmallVectorTemplateBase< T >::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(), llvm::utostr(), and llvm::RISCVFenceField::W.

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

References llvm::lltok::equal.

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

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

References allCallersPassInValidPointerForArgument(), C, llvm::AAResults::canBasicBlockModify(), llvm::AAResults::canInstructionRangeModRef(), llvm::dbgs(), 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_DEBUG, llvm::SPII::Load, markIndicesSafe(), llvm::Mod, P, llvm::predecessors(), prefixIn(), llvm::SmallVectorTemplateBase< T >::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 530 of file ArgumentPromotion.cpp.

References 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 511 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,
const TargetTransformInfo TTI 
)
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 1071 of file ArgumentPromotion.cpp.

◆ false

Promote by reference arguments to false

Definition at line 1071 of file ArgumentPromotion.cpp.

◆ scalars

Promote by reference arguments to scalars

Definition at line 1071 of file ArgumentPromotion.cpp.