LLVM  16.0.0git
Macros | Functions
ArgumentPromotion.cpp File Reference
#include "llvm/Transforms/IPO/ArgumentPromotion.h"
#include "llvm/ADT/DepthFirstIterator.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/CallGraph.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/MemoryLocation.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/Dominators.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/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/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <utility>
#include <vector>
Include dependency graph for ArgumentPromotion.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "argpromotion"
 

Functions

 STATISTIC (NumArgumentsPromoted, "Number of pointer 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, FunctionAnalysisManager &FAM, const DenseMap< Argument *, SmallVector< OffsetAndArgPart, 4 >> &ArgsToPromote)
 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 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, FunctionAnalysisManager &FAM, unsigned MaxElements, 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...
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "argpromotion"

Definition at line 79 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 426 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 688 of file ArgumentPromotion.cpp.

References llvm::all_of(), and F.

Referenced by promoteArguments().

◆ createByteGEP()

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

◆ doPromotion()

static Function* doPromotion ( Function F,
FunctionAnalysisManager FAM,
const DenseMap< Argument *, SmallVector< OffsetAndArgPart, 4 >> &  ArgsToPromote 
)
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 149 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::Function::copyAttributesFrom(), llvm::GlobalObject::copyMetadata(), llvm::Instruction::copyMetadata(), llvm::Function::Create(), llvm::CallInst::Create(), llvm::InvokeInst::Create(), llvm::IRBuilderBase::CreateAlignedLoad(), llvm::IRBuilderBase::CreateAlignedStore(), llvm::IRBuilderBase::CreateAlloca(), createByteGEP(), llvm::dbgs(), DL, E, llvm::Instruction::eraseFromParent(), F, FAM, llvm::FunctionType::get(), llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::CallBase::getAttributes(), llvm::Function::getBasicBlockList(), llvm::CallBase::getCalledFunction(), llvm::CallBase::getCaller(), llvm::CallBase::getCallingConv(), llvm::AttributeList::getFnAttrs(), llvm::Value::getName(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::AttributeList::getParamAttrs(), llvm::LoadInst::getPointerOperandIndex(), llvm::StoreInst::getPointerOperandIndex(), llvm::AnalysisManager< IRUnitT, ExtraArgTs >::getResult(), llvm::AttributeList::getRetAttrs(), llvm::FunctionType::getReturnType(), 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::isAllocaPromotable(), llvm::FunctionType::isVarArg(), LLVM_DEBUG, llvm_unreachable, llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::lookup(), llvm::make_scope_exit(), llvm::max(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::PromoteMemToReg(), Ptr, llvm::Value::replaceAllUsesWith(), llvm::Instruction::setAAMetadata(), llvm::AllocaInst::setAlignment(), llvm::Function::setAttributes(), llvm::CallBase::setAttributes(), llvm::CallBase::setCallingConv(), llvm::Value::setName(), SI, llvm::Value::takeName(), llvm::AttributeFuncs::updateMinLegalVectorWidthAttr(), llvm::Value::use_empty(), 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

◆ promoteArguments()

static Function* promoteArguments ( Function F,
FunctionAnalysisManager FAM,
unsigned  MaxElements,
bool  IsRecursive 
)
static

◆ STATISTIC() [1/2]

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

◆ STATISTIC() [2/2]

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