LLVM 22.0.0git
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/OptimizationRemarkEmitter.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 isArgUnmodifiedByAllCalls (Argument *Arg, FunctionAnalysisManager &FAM)
static bool findArgParts (Argument *Arg, const DataLayout &DL, AAResults &AAR, unsigned MaxElements, bool IsRecursive, SmallVectorImpl< OffsetAndArgPart > &ArgPartsVec, FunctionAnalysisManager &FAM)
 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 82 of file ArgumentPromotion.cpp.

Function Documentation

◆ allCallersPassValidPointerForArgument()

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

References llvm::all_of(), DL, llvm::Argument::getParent(), and llvm::isDereferenceableAndAlignedPointer().

Referenced by findArgParts().

◆ areTypesABICompatible()

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

References llvm::all_of(), and F.

Referenced by promoteArguments().

◆ createByteGEP()

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

◆ doPromotion()

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

References llvm::Function::addFnAttr(), llvm::append_range(), llvm::CallBase::arg_begin(), llvm::Function::arg_begin(), llvm::CallBase::arg_end(), assert(), llvm::Function::begin(), llvm::cast(), llvm::SmallVectorImpl< T >::clear(), llvm::Function::copyAttributesFrom(), llvm::GlobalObject::copyMetadata(), llvm::Instruction::copyMetadata(), llvm::CallInst::Create(), llvm::Function::Create(), llvm::InvokeInst::Create(), llvm::IRBuilderBase::CreateAlignedLoad(), llvm::IRBuilderBase::CreateAlignedStore(), llvm::IRBuilderBase::CreateAlloca(), createByteGEP(), llvm::dbgs(), DEBUG_TYPE, DL, llvm::dyn_cast(), E(), llvm::OptimizationRemarkEmitter::emit(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::Instruction::eraseFromParent(), F, FAM, llvm::FunctionType::get(), llvm::PoisonValue::get(), llvm::CallBase::getAttributes(), llvm::Function::getAttributes(), llvm::CallBase::getCalledFunction(), llvm::CallBase::getCaller(), llvm::CallBase::getCallingConv(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::LoadInst::getPointerOperandIndex(), llvm::StoreInst::getPointerOperandIndex(), llvm::Attribute::getWithAllocSizeArgs(), llvm::Instruction::hasMetadata(), I, II, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::isa(), llvm::isAllocaPromotable(), LLVM_DEBUG, llvm_unreachable, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), llvm::make_scope_exit(), llvm::Offset, llvm::Metadata::PoisonGeneratingIDs, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::PromoteMemToReg(), Ptr, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::RecursivelyDeleteTriviallyDeadInstructionsPermissive(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setAAMetadata(), llvm::AllocaInst::setAlignment(), llvm::CallBase::setAttributes(), llvm::Function::setAttributes(), llvm::CallBase::setCallingConv(), llvm::Value::setName(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::Function::splice(), llvm::Value::takeName(), and llvm::Value::use_empty().

Referenced by promoteArguments().

◆ findArgParts()

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

◆ isArgUnmodifiedByAllCalls()

◆ promoteArguments()

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