LLVM 20.0.0git
|
#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 Value * | createByteGEP (IRBuilderBase &IRB, const DataLayout &DL, Value *Ptr, Type *ResElemTy, int64_t Offset) |
static Function * | doPromotion (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 Function * | promoteArguments (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). | |
#define DEBUG_TYPE "argpromotion" |
Definition at line 81 of file ArgumentPromotion.cpp.
|
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().
|
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().
|
static |
Definition at line 100 of file ArgumentPromotion.cpp.
References llvm::IRBuilderBase::CreatePtrAdd(), DL, llvm::IRBuilderBase::getInt(), llvm::Offset, and Ptr.
Referenced by doPromotion().
|
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().
|
static |
Determine that this argument is safe to promote, and find the argument parts it can be promoted into.
Definition at line 475 of file ArgumentPromotion.cpp.
References allCallersPassValidPointerForArgument(), llvm::append_range(), llvm::AAResults::canBasicBlockModify(), llvm::AAResults::canInstructionRangeModRef(), llvm::dbgs(), DL, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::SmallVectorBase< Size_T >::empty(), llvm::BasicBlock::front(), GEP, llvm::MemoryLocation::get(), llvm::Argument::getArgNo(), llvm::Function::getEntryBlock(), llvm::Argument::getParamAlign(), llvm::Argument::getParamByValType(), llvm::Argument::getParent(), llvm::StoreInst::getPointerOperandIndex(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::inverse_depth_first(), llvm::isAligned(), llvm::isGuaranteedToTransferExecutionToSuccessor(), LLVM_DEBUG, llvm::Offset, P, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::predecessors(), Ptr, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::size(), Size, llvm::sort(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace(), and llvm::Value::use_empty().
Referenced by promoteArguments().
|
static |
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).
If safe to promote some arguments, it calls the DoPromotion method.
Definition at line 752 of file ArgumentPromotion.cpp.
References llvm::CallBase::addParamAttr(), areTypesABICompatible(), DL, doPromotion(), llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::empty(), llvm::SmallVectorBase< Size_T >::empty(), F, FAM, findArgParts(), llvm::Instruction::getFunction(), llvm::CallBase::getFunctionType(), llvm::TargetTransformInfo::getMaxNumArgs(), llvm::AnalysisManager< IRUnitT, ExtraArgTs >::getResult(), I, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::CallBase::isCallee(), llvm::CallBase::isMustTailCall(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::CallBase::removeParamAttr().
Referenced by llvm::ArgumentPromotionPass::run().
STATISTIC | ( | NumArgumentsDead | , |
"Number of dead pointer args eliminated" | |||
) |
STATISTIC | ( | NumArgumentsPromoted | , |
"Number of pointer arguments promoted" | |||
) |