LLVM 17.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/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>
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, 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 79 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(), Arg, Callee, DL, and llvm::isDereferenceableAndAlignedPointer().
Referenced by findArgParts().
|
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().
|
static |
Definition at line 98 of file ArgumentPromotion.cpp.
References llvm::IRBuilderBase::CreateBitCast(), llvm::IRBuilderBase::CreateGEP(), DL, llvm::APInt::getBitWidth(), llvm::IRBuilderBase::getInt(), llvm::IRBuilderBase::getInt8PtrTy(), llvm::IRBuilderBase::getInt8Ty(), llvm::Type::getPointerTo(), llvm::GetElementPtrInst::getTypeAtIndex(), llvm::APInt::getZero(), llvm::Type::isSized(), llvm::Offset, Ptr, and llvm::SmallVectorTemplateBase< T, bool >::push_back().
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 149 of file ArgumentPromotion.cpp.
References llvm::append_range(), Arg, 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, E, llvm::SmallVectorBase< Size_T >::empty(), llvm::Instruction::eraseFromParent(), F, FAM, llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::PoisonValue::get(), llvm::CallBase::getAttributes(), llvm::CallBase::getCalledFunction(), llvm::CallBase::getCaller(), llvm::CallBase::getCallingConv(), llvm::AttributeList::getFnAttrs(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::AttributeList::getParamAttrs(), llvm::LoadInst::getPointerOperandIndex(), llvm::StoreInst::getPointerOperandIndex(), llvm::AnalysisManager< IRUnitT, ExtraArgTs >::getResult(), llvm::AttributeList::getRetAttrs(), I, 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::Value::replaceAllUsesWith(), RetTy, llvm::Instruction::setAAMetadata(), llvm::AllocaInst::setAlignment(), llvm::CallBase::setAttributes(), llvm::Function::setAttributes(), llvm::CallBase::setCallingConv(), llvm::Value::setName(), SI, 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 448 of file ArgumentPromotion.cpp.
References allCallersPassValidPointerForArgument(), llvm::append_range(), Arg, 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::StoreInst::getPointerOperandIndex(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::inverse_depth_first_ext(), llvm::isAligned(), llvm::isGuaranteedToTransferExecutionToSuccessor(), LLVM_DEBUG, llvm::Offset, P, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::predecessors(), Ptr, llvm::SmallVectorTemplateBase< T, bool >::push_back(), SI, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::size(), Size, llvm::sort(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::try_emplace().
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 705 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::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().