LLVM  15.0.0git
Macros | 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/ScopeExit.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Twine.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/Analysis/ValueTracking.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/raw_ostream.h"
#include "llvm/Transforms/IPO.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <utility>
#include <vector>

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "argpromotion"
 

Functions

 STATISTIC (NumArgumentsPromoted, "Number of pointer arguments promoted")
 
 STATISTIC (NumByValArgsPromoted, "Number of byval arguments promoted")
 
 STATISTIC (NumArgumentsDead, "Number of dead pointer args eliminated")
 
static ValuecreateByteGEP (IRBuilderBase &IRB, const DataLayout &DL, Value *Ptr, Type *ResElemTy, int64_t Offset)
 
static FunctiondoPromotion (Function *F, const DenseMap< Argument *, SmallVector< OffsetAndArgPart, 4 >> &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, Align NeededAlign, uint64_t NeededDerefBytes)
 Return true if we can prove that all callees pass in a valid pointer for the specified function argument. More...
 
static bool findArgParts (Argument *Arg, const DataLayout &DL, AAResults &AAR, unsigned MaxElements, bool IsRecursive, SmallVectorImpl< OffsetAndArgPart > &ArgPartsVec)
 Determine that this argument is safe to promote, and find the argument parts it can be promoted into. More...
 
static bool canPaddingBeAccessed (Argument *Arg)
 Checks if the padding bytes of an argument could be accessed. More...
 
static bool areTypesABICompatible (ArrayRef< Type * > Types, const Function &F, const TargetTransformInfo &TTI)
 Check if callers and callee agree on how promoted arguments would be passed. 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, bool IsRecursive)
 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 86 of file ArgumentPromotion.cpp.

Function Documentation

◆ allCallersPassValidPointerForArgument()

static bool allCallersPassValidPointerForArgument ( Argument Arg,
Align  NeededAlign,
uint64_t  NeededDerefBytes 
)
static

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

Definition at line 444 of file ArgumentPromotion.cpp.

References llvm::all_of(), Arg, Callee, DL, and llvm::isDereferenceableAndAlignedPointer().

Referenced by findArgParts().

◆ areTypesABICompatible()

static bool areTypesABICompatible ( ArrayRef< Type * >  Types,
const Function F,
const TargetTransformInfo TTI 
)
static

Check if callers and callee agree on how promoted arguments would be passed.

Definition at line 751 of file ArgumentPromotion.cpp.

References llvm::all_of(), and F.

Referenced by promoteArguments().

◆ canPaddingBeAccessed()

static bool canPaddingBeAccessed ( Argument Arg)
static

◆ createByteGEP()

static Value* createByteGEP ( IRBuilderBase IRB,
const DataLayout DL,
Value Ptr,
Type ResElemTy,
int64_t  Offset 
)
static

◆ doPromotion()

static Function* doPromotion ( Function F,
const DenseMap< Argument *, SmallVector< OffsetAndArgPart, 4 >> &  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 156 of file ArgumentPromotion.cpp.

References llvm::append_range(), Arg, llvm::Function::arg_begin(), llvm::CallBase::arg_begin(), llvm::CallBase::arg_end(), llvm::AMDGPU::HSAMD::Kernel::Key::Args, assert(), llvm::Function::begin(), llvm::SmallVectorImpl< T >::clear(), llvm::commonAlignment(), llvm::Function::copyAttributesFrom(), llvm::GlobalObject::copyMetadata(), llvm::Instruction::copyMetadata(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::Function::Create(), llvm::GetElementPtrInst::Create(), llvm::CallInst::Create(), llvm::InvokeInst::Create(), llvm::IRBuilderBase::CreateAlignedLoad(), createByteGEP(), llvm::IRBuilderBase::CreateGEP(), llvm::dbgs(), DL, E, llvm::StructType::elements(), F, llvm::ConstantInt::get(), llvm::FunctionType::get(), llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::CallBase::getAttributes(), llvm::Function::getBasicBlockList(), llvm::CallBase::getCalledFunction(), llvm::CallBase::getCaller(), llvm::CallBase::getCallingConv(), llvm::StructLayout::getElementOffset(), llvm::StructType::getElementType(), llvm::AttributeList::getFnAttrs(), llvm::Type::getInt32Ty(), llvm::Value::getName(), llvm::StructType::getNumElements(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::AttributeList::getParamAttrs(), llvm::AttributeList::getRetAttrs(), llvm::FunctionType::getReturnType(), llvm::Value::getType(), I, llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::insert(), llvm::SmallVectorImpl< T >::insert(), llvm::FunctionType::isVarArg(), LLVM_DEBUG, llvm_unreachable, llvm::make_scope_exit(), llvm::max(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::Instruction::setAAMetadata(), llvm::Function::setAttributes(), llvm::CallBase::setAttributes(), llvm::CallBase::setCallingConv(), llvm::Value::setName(), llvm::Value::stripAndAccumulateConstantOffsets(), llvm::Value::takeName(), llvm::AttributeFuncs::updateMinLegalVectorWidthAttr(), and llvm::Value::users().

Referenced by promoteArguments().

◆ findArgParts()

static bool findArgParts ( Argument Arg,
const DataLayout DL,
AAResults AAR,
unsigned  MaxElements,
bool  IsRecursive,
SmallVectorImpl< OffsetAndArgPart > &  ArgPartsVec 
)
static

Determine that this argument is safe to promote, and find the argument parts it can be promoted into.

Definition at line 466 of file ArgumentPromotion.cpp.

References allCallersPassValidPointerForArgument(), llvm::append_range(), Arg, B, BB, llvm::AAResults::canBasicBlockModify(), llvm::AAResults::canInstructionRangeModRef(), llvm::dbgs(), DL, llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::empty(), GEP, llvm::MemoryLocation::get(), llvm::LoadInst::getAlign(), llvm::LoadInst::getPointerOperand(), llvm::Value::getType(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::inverse_depth_first_ext(), llvm::isAligned(), llvm::isGuaranteedToTransferExecutionToSuccessor(), llvm::Type::isPointerTy(), llvm::LoadInst::isSimple(), LLVM_DEBUG, llvm::SPII::Load, llvm::max(), llvm::Mod, llvm::None, P, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::predecessors(), llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::size(), llvm::sort(), llvm::Value::stripAndAccumulateConstantOffsets(), llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::try_emplace(), and llvm::Value::users().

Referenced by promoteArguments().

◆ INITIALIZE_PASS_BEGIN()

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

◆ 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,
bool  IsRecursive 
)
static

◆ STATISTIC() [1/3]

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

◆ STATISTIC() [2/3]

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

◆ STATISTIC() [3/3]

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

Variable Documentation

◆ argpromotion

argpromotion

Definition at line 1016 of file ArgumentPromotion.cpp.

◆ false

Promote by reference arguments to false

Definition at line 1017 of file ArgumentPromotion.cpp.

◆ scalars

Promote by reference arguments to scalars

Definition at line 1017 of file ArgumentPromotion.cpp.