LLVM
15.0.0git
|
#include "llvm/Transforms/IPO/ArgumentPromotion.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.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/CGSCCPassManager.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/CallGraphSCCPass.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/MemoryLocation.h"
#include "llvm/Analysis/TargetLibraryInfo.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/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/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO.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 (NumByValArgsPromoted, "Number of byval 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, const DenseMap< Argument *, SmallVector< OffsetAndArgPart, 4 >> &ArgsToPromote, SmallPtrSetImpl< Argument * > &ByValArgsToTransform, Optional< function_ref< void(CallBase &OldCS, CallBase &NewCS)>> ReplaceCallSite) |
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 | canPaddingBeAccessed (Argument *Arg) |
Checks if the padding bytes of an argument could be accessed. 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 Function * | promoteArguments (Function *F, function_ref< AAResults &(Function &F)> AARGetter, unsigned MaxElements, Optional< function_ref< void(CallBase &OldCS, CallBase &NewCS)>> ReplaceCallSite, const TargetTransformInfo &TTI, 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... | |
INITIALIZE_PASS_BEGIN (ArgPromotion, "argpromotion", "Promote 'by reference' arguments to scalars", false, false) INITIALIZE_PASS_END(ArgPromotion | |
Variables | |
argpromotion | |
Promote by reference arguments to | scalars |
Promote by reference arguments to | false |
#define DEBUG_TYPE "argpromotion" |
Definition at line 86 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 444 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 751 of file ArgumentPromotion.cpp.
References llvm::all_of(), and F.
Referenced by promoteArguments().
|
static |
Checks if the padding bytes of an argument could be accessed.
Definition at line 716 of file ArgumentPromotion.cpp.
References llvm::append_range(), Arg, assert(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SPII::Store, and llvm::Value::users().
Referenced by promoteArguments().
|
static |
Definition at line 106 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::getNonOpaquePointerElementType(), llvm::Type::getPointerAddressSpace(), llvm::Type::getPointerTo(), llvm::Value::getType(), llvm::GetElementPtrInst::getTypeAtIndex(), llvm::APInt::getZero(), llvm::Type::isOpaquePointerTy(), and llvm::Type::isSized().
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 156 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::commonAlignment(), llvm::Function::copyAttributesFrom(), llvm::GlobalObject::copyMetadata(), llvm::Instruction::copyMetadata(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::Function::Create(), llvm::GetElementPtrInst::Create(), llvm::CallInst::Create(), llvm::InvokeInst::Create(), llvm::IRBuilderBase::CreateAlignedLoad(), createByteGEP(), llvm::IRBuilderBase::CreateGEP(), llvm::dbgs(), DL, E, llvm::StructType::elements(), F, llvm::ConstantInt::get(), llvm::FunctionType::get(), llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::CallBase::getAttributes(), llvm::Function::getBasicBlockList(), llvm::CallBase::getCalledFunction(), llvm::CallBase::getCaller(), llvm::CallBase::getCallingConv(), llvm::StructLayout::getElementOffset(), llvm::StructType::getElementType(), llvm::AttributeList::getFnAttrs(), llvm::Type::getInt32Ty(), llvm::Value::getName(), llvm::StructType::getNumElements(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::AttributeList::getParamAttrs(), llvm::AttributeList::getRetAttrs(), llvm::FunctionType::getReturnType(), llvm::Value::getType(), 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::SmallVectorImpl< T >::insert(), llvm::FunctionType::isVarArg(), LLVM_DEBUG, llvm_unreachable, llvm::make_scope_exit(), llvm::max(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::Instruction::setAAMetadata(), llvm::Function::setAttributes(), llvm::CallBase::setAttributes(), llvm::CallBase::setCallingConv(), llvm::Value::setName(), llvm::Value::stripAndAccumulateConstantOffsets(), llvm::Value::takeName(), llvm::AttributeFuncs::updateMinLegalVectorWidthAttr(), and llvm::Value::users().
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 466 of file ArgumentPromotion.cpp.
References allCallersPassValidPointerForArgument(), llvm::append_range(), Arg, B, BB, llvm::AAResults::canBasicBlockModify(), llvm::AAResults::canInstructionRangeModRef(), llvm::dbgs(), DL, llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::empty(), GEP, llvm::MemoryLocation::get(), llvm::LoadInst::getAlign(), llvm::LoadInst::getPointerOperand(), llvm::Value::getType(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::inverse_depth_first_ext(), llvm::isAligned(), llvm::isGuaranteedToTransferExecutionToSuccessor(), llvm::Type::isPointerTy(), llvm::LoadInst::isSimple(), LLVM_DEBUG, llvm::SPII::Load, llvm::max(), llvm::Mod, llvm::None, P, llvm::SmallVectorImpl< T >::pop_back_val(), llvm::predecessors(), llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::size(), llvm::sort(), llvm::Value::stripAndAccumulateConstantOffsets(), llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::try_emplace(), and llvm::Value::users().
Referenced by promoteArguments().
INITIALIZE_PASS_BEGIN | ( | ArgPromotion | , |
"argpromotion" | , | ||
"Promote 'by reference' arguments to scalars" | , | ||
false | , | ||
false | |||
) |
|
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 769 of file ArgumentPromotion.cpp.
References llvm::CallBase::addParamAttr(), llvm::all_of(), llvm::append_range(), areTypesABICompatible(), BB, canPaddingBeAccessed(), llvm::dbgs(), DL, doPromotion(), llvm::SmallPtrSetImplBase::empty(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::empty(), F, findArgParts(), llvm::Instruction::getFunction(), llvm::CallBase::getFunctionType(), I, llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::CallBase::isCallee(), llvm::ArgumentPromotionPass::isDenselyPacked(), llvm::CallBase::isMustTailCall(), llvm::Type::isSingleValueType(), LLVM_DEBUG, move, and llvm::CallBase::removeParamAttr().
Referenced by llvm::ArgumentPromotionPass::run().
argpromotion |
Definition at line 1016 of file ArgumentPromotion.cpp.
Definition at line 1017 of file ArgumentPromotion.cpp.
Definition at line 1017 of file ArgumentPromotion.cpp.