LLVM 20.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/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/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/PromoteMemToReg.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 (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.
 
static bool allCallersPassValidPointerForArgument (Argument *Arg, SmallPtrSetImpl< CallBase * > &RecursiveCalls, Align NeededAlign, uint64_t NeededDerefBytes)
 Return true if we can prove that all callees pass in a valid pointer for the specified function argument.
 
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.
 
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.
 
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).
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "argpromotion"

Definition at line 81 of file ArgumentPromotion.cpp.

Function Documentation

◆ allCallersPassValidPointerForArgument()

static bool allCallersPassValidPointerForArgument ( Argument Arg,
SmallPtrSetImpl< CallBase * > &  RecursiveCalls,
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(), DL, llvm::Argument::getParent(), 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 735 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 113 of file ArgumentPromotion.cpp.

References llvm::Function::addFnAttr(), llvm::append_range(), llvm::Function::arg_begin(), llvm::CallBase::arg_begin(), llvm::CallBase::arg_end(), 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, llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorBase< Size_T >::empty(), llvm::Instruction::eraseFromParent(), F, FAM, llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::AttributeSet::getAllocSizeArgs(), llvm::Function::getAttributes(), llvm::CallBase::getAttributes(), llvm::CallBase::getCalledFunction(), llvm::CallBase::getCaller(), llvm::CallBase::getCallingConv(), llvm::AttributeList::getFnAttrs(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::AttributeList::getParamAttrs(), llvm::LoadInst::getPointerOperandIndex(), llvm::StoreInst::getPointerOperandIndex(), llvm::AnalysisManager< IRUnitT, ExtraArgTs >::getResult(), llvm::AttributeList::getRetAttrs(), llvm::Attribute::getWithAllocSizeArgs(), llvm::Instruction::hasMetadata(), I, II, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::isAllocaPromotable(), LLVM_DEBUG, llvm_unreachable, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), llvm::make_scope_exit(), llvm::Offset, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::PromoteMemToReg(), Ptr, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::RecursivelyDeleteTriviallyDeadInstructionsPermissive(), llvm::Value::replaceAllUsesWith(), RetTy, llvm::Instruction::setAAMetadata(), llvm::AllocaInst::setAlignment(), llvm::CallBase::setAttributes(), llvm::Function::setAttributes(), llvm::CallBase::setCallingConv(), llvm::Function::setIsNewDbgInfoFormat(), llvm::Value::setName(), llvm::SmallVectorBase< Size_T >::size(), llvm::Function::splice(), llvm::Value::takeName(), llvm::AttributeFuncs::updateMinLegalVectorWidthAttr(), and llvm::Value::use_empty().

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"   
)