LLVM  11.0.0git
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/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/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.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/NoFolder.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/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormatVariadic.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(CallBase &OldCS, CallBase &NewCS)>> ReplaceCallSite)
 DoPromotion - This method actually performs the promotion of the specified arguments, and returns the new function. More...
 
static bool allCallersPassValidPointerForArgument (Argument *Arg, Type *Ty)
 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, Type *ByValTy, 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 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(CallBase &OldCS, CallBase &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 91 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 99 of file ArgumentPromotion.cpp.

Function Documentation

◆ allCallersPassValidPointerForArgument()

static bool allCallersPassValidPointerForArgument ( Argument Arg,
Type Ty 
)
static

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

Definition at line 478 of file ArgumentPromotion.cpp.

References Callee, DL, llvm::Argument::getArgNo(), llvm::CallBase::getArgOperand(), 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(CallBase &OldCS, CallBase &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 105 of file ArgumentPromotion.cpp.

References llvm::Function::arg_begin(), llvm::CallBase::arg_begin(), llvm::Function::arg_end(), llvm::CallBase::arg_end(), llvm::AMDGPU::HSAMD::Kernel::Key::Args, assert(), llvm::SmallVectorImpl< T >::clear(), llvm::Function::copyAttributesFrom(), llvm::Instruction::copyMetadata(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::Function::Create(), llvm::GetElementPtrInst::Create(), llvm::CallInst::Create(), llvm::InvokeInst::Create(), llvm::IRBuilderBase::CreateGEP(), llvm::IRBuilderBase::CreateLoad(), llvm::dbgs(), DL, llvm::dyn_cast(), llvm::numbers::e, E, llvm::StructType::element_begin(), llvm::StructType::element_end(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::Instruction::eraseFromParent(), F(), llvm::formatv(), GEP, llvm::ConstantInt::get(), llvm::FunctionType::get(), llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::Instruction::getAAMetadata(), llvm::GlobalValue::getAddressSpace(), llvm::LoadInst::getAlign(), llvm::DataLayout::getAllocaAddrSpace(), llvm::Function::getAttributes(), llvm::CallBase::getAttributes(), llvm::Function::getBasicBlockList(), llvm::CallBase::getCalledFunction(), llvm::CallBase::getCallingConv(), llvm::Function::getContext(), llvm::Module::getDataLayout(), llvm::StructType::getElementType(), llvm::AttributeList::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::CallBase::getOperandBundlesAsDefs(), llvm::AttributeList::getParamAttributes(), llvm::GlobalValue::getParent(), llvm::DataLayout::getPrefTypeAlign(), llvm::AttributeList::getRetAttributes(), llvm::FunctionType::getReturnType(), llvm::Function::getSubprogram(), llvm::Value::getType(), llvm::GetElementPtrInst::getTypeAtIndex(), 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::make_range(), llvm::User::op_begin(), llvm::User::op_end(), Operands, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setAAMetadata(), llvm::LoadInst::setAlignment(), llvm::CallBase::setAttributes(), llvm::CallBase::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(), and llvm::Value::users().

Referenced by promoteArguments().

◆ INITIALIZE_PASS_BEGIN()

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

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

References llvm::lltok::equal.

Referenced by markIndicesSafe(), and prefixIn().

◆ isSafeToPromoteArgument()

static bool isSafeToPromoteArgument ( Argument Arg,
Type ByValTy,
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 562 of file ArgumentPromotion.cpp.

References allCallersPassValidPointerForArgument(), assert(), C, llvm::AAResults::canBasicBlockModify(), llvm::AAResults::canInstructionRangeModRef(), llvm::dbgs(), llvm::numbers::e, llvm::SmallVectorBase< SmallVectorSizeType< T > >::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, Operands, 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 526 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 507 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(CallBase &OldCS, CallBase &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 1107 of file ArgumentPromotion.cpp.

◆ false

Promote by reference arguments to false

Definition at line 1107 of file ArgumentPromotion.cpp.

◆ scalars

Promote by reference arguments to scalars

Definition at line 1107 of file ArgumentPromotion.cpp.