|
LLVM
5.0.0
|
#include "llvm/Transforms/IPO/ArgumentPromotion.h"#include "llvm/ADT/DepthFirstIterator.h"#include "llvm/ADT/Optional.h"#include "llvm/ADT/Statistic.h"#include "llvm/ADT/StringExtras.h"#include "llvm/Analysis/AliasAnalysis.h"#include "llvm/Analysis/AssumptionCache.h"#include "llvm/Analysis/BasicAliasAnalysis.h"#include "llvm/Analysis/CallGraph.h"#include "llvm/Analysis/CallGraphSCCPass.h"#include "llvm/Analysis/LazyCallGraph.h"#include "llvm/Analysis/Loads.h"#include "llvm/Analysis/TargetLibraryInfo.h"#include "llvm/IR/CFG.h"#include "llvm/IR/CallSite.h"#include "llvm/IR/Constants.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/DebugInfo.h"#include "llvm/IR/DerivedTypes.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/LLVMContext.h"#include "llvm/IR/Module.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"#include "llvm/Transforms/IPO.h"#include <set>Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "argpromotion" |
Typedefs | |
| typedef std::vector< uint64_t > | IndicesVector |
| A vector used to hold the indices of a single GEP instruction. More... | |
Functions | |
| STATISTIC (NumArgumentsPromoted,"Number of pointer arguments promoted") | |
| STATISTIC (NumAggregatesPromoted,"Number of aggregate arguments promoted") | |
| STATISTIC (NumByValArgsPromoted,"Number of byval arguments promoted") | |
| STATISTIC (NumArgumentsDead,"Number of dead pointer args eliminated") | |
| static Function * | doPromotion (Function *F, SmallPtrSetImpl< Argument * > &ArgsToPromote, SmallPtrSetImpl< Argument * > &ByValArgsToTransform, Optional< function_ref< void(CallSite OldCS, CallSite NewCS)>> ReplaceCallSite) |
| DoPromotion - This method actually performs the promotion of the specified arguments, and returns the new function. More... | |
| static bool | allCallersPassInValidPointerForArgument (Argument *Arg) |
| AllCallersPassInValidPointerForArgument - Return true if we can prove that all callees pass in a valid pointer for the specified function argument. More... | |
| static bool | isPrefix (const IndicesVector &Prefix, const IndicesVector &Longer) |
| Returns true if Prefix is a prefix of longer. More... | |
| static bool | prefixIn (const IndicesVector &Indices, std::set< IndicesVector > &Set) |
| Checks if Indices, or a prefix of Indices, is in Set. More... | |
| static void | markIndicesSafe (const IndicesVector &ToMark, std::set< IndicesVector > &Safe) |
| Mark the given indices (ToMark) as safe in the given set of indices (Safe). More... | |
| static bool | isSafeToPromoteArgument (Argument *Arg, bool isByValOrInAlloca, AAResults &AAR, unsigned MaxElements) |
| isSafeToPromoteArgument - As you might guess from the name of this method, it checks to see if it is both safe and useful to promote the argument. More... | |
| static bool | isDenselyPacked (Type *type, const DataLayout &DL) |
| Checks if a type could have padding bytes. More... | |
| static bool | canPaddingBeAccessed (Argument *arg) |
| Checks if the padding bytes of an argument could be accessed. More... | |
| static Function * | promoteArguments (Function *F, function_ref< AAResults &(Function &F)> AARGetter, unsigned MaxElements, Optional< function_ref< void(CallSite OldCS, CallSite NewCS)>> ReplaceCallSite) |
| 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 60 of file ArgumentPromotion.cpp.
| typedef std::vector<uint64_t> IndicesVector |
A vector used to hold the indices of a single GEP instruction.
Definition at line 68 of file ArgumentPromotion.cpp.
AllCallersPassInValidPointerForArgument - Return true if we can prove that all callees pass in a valid pointer for the specified function argument.
Definition at line 453 of file ArgumentPromotion.cpp.
References assert(), llvm::DL, llvm::Argument::getArgNo(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getArgument(), llvm::Module::getDataLayout(), llvm::Argument::getParent(), llvm::GlobalValue::getParent(), llvm::isDereferenceablePointer(), and llvm::Value::users().
Referenced by isSafeToPromoteArgument().
Checks if the padding bytes of an argument could be accessed.
Definition at line 751 of file ArgumentPromotion.cpp.
References assert(), llvm::SmallVectorTemplateCommon< T >::back(), llvm::SmallVectorBase::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::Argument::hasByValAttr(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::insert(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::pop_back(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::SPII::Store, llvm::Value::user_begin(), and llvm::Value::user_end().
Referenced by promoteArguments().
|
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 74 of file ArgumentPromotion.cpp.
References llvm::Function::arg_begin(), llvm::Function::arg_end(), llvm::AMDGPU::CodeObject::Kernel::Key::Args, assert(), llvm::SmallVectorImpl< T >::clear(), llvm::Function::copyAttributesFrom(), llvm::SmallPtrSetImpl< PtrType >::count(), llvm::Function::Create(), llvm::GetElementPtrInst::Create(), llvm::CallInst::Create(), llvm::InvokeInst::Create(), llvm::dbgs(), DEBUG, llvm::DL, llvm::dyn_cast(), E, llvm::StructType::element_begin(), llvm::StructType::element_end(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::Instruction::eraseFromParent(), F, GEP, llvm::ConstantInt::get(), llvm::FunctionType::get(), llvm::AttributeList::get(), llvm::UndefValue::get(), llvm::Instruction::getAAMetadata(), llvm::LoadInst::getAlignment(), llvm::DataLayout::getAllocaAddrSpace(), llvm::Function::getAttributes(), llvm::Function::getBasicBlockList(), llvm::Function::getContext(), llvm::Module::getDataLayout(), llvm::AttributeList::getFnAttributes(), llvm::Module::getFunctionList(), llvm::Function::getFunctionType(), llvm::GetElementPtrInst::getIndexedType(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::Type::getInt32Ty(), llvm::Type::getInt64Ty(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::GlobalValue::getLinkage(), llvm::Value::getName(), llvm::StructType::getName(), llvm::StructType::getNumElements(), llvm::GetElementPtrInst::getNumIndices(), llvm::User::getNumOperands(), llvm::AttributeList::getParamAttributes(), llvm::GlobalValue::getParent(), llvm::AttributeList::getRetAttributes(), llvm::FunctionType::getReturnType(), llvm::Function::getSubprogram(), llvm::Value::getType(), I, llvm::GetElementPtrInst::idx_begin(), llvm::GetElementPtrInst::idx_end(), llvm::ARM_PROC::IE, llvm::iplist_impl< IntrusiveListT, TraitsT >::insert(), llvm::SmallVectorImpl< T >::insert(), llvm::Type::isStructTy(), llvm::FunctionType::isVarArg(), L, llvm::User::op_begin(), llvm::User::op_end(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::Instruction::setAAMetadata(), llvm::LoadInst::setAlignment(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setAttributes(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setCallingConv(), llvm::Value::setName(), llvm::Function::setSubprogram(), llvm::CallInst::setTailCall(), llvm::Value::takeName(), llvm::Value::use_empty(), llvm::Instruction::user_back(), llvm::Value::user_back(), llvm::Value::users(), and llvm::utostr().
Referenced by promoteArguments().
| INITIALIZE_PASS_BEGIN | ( | ArgPromotion | , |
| "argpromotion" | , | ||
| "Promote 'by reference' arguments to scalars" | , | ||
| false | , | ||
| false | |||
| ) |
|
static |
Checks if a type could have padding bytes.
Definition at line 716 of file ArgumentPromotion.cpp.
References llvm::DL, E, llvm::StructType::getElementType(), llvm::StructType::getNumElements(), llvm::DataLayout::getStructLayout(), llvm::DataLayout::getTypeAllocSizeInBits(), llvm::DataLayout::getTypeSizeInBits(), and llvm::Type::isSized().
Referenced by promoteArguments().
|
static |
Returns true if Prefix is a prefix of longer.
That means, Longer has a size that is greater than or equal to the size of prefix, and each of the elements in Prefix is the same as the corresponding elements in Longer.
This means it also returns true when Prefix and Longer are equal!
Definition at line 476 of file ArgumentPromotion.cpp.
References llvm::lltok::equal.
Referenced by markIndicesSafe(), prefixIn(), and readPrefixes().
|
static |
isSafeToPromoteArgument - As you might guess from the name of this method, it checks to see if it is both safe and useful to promote the argument.
This method limits promotion of aggregates to only promote up to three elements of the aggregate in order to avoid exploding the number of arguments passed in.
Definition at line 538 of file ArgumentPromotion.cpp.
References allCallersPassInValidPointerForArgument(), C, llvm::AAResults::canBasicBlockModify(), llvm::AAResults::canInstructionRangeModRef(), llvm::dbgs(), DEBUG, llvm::SmallVectorBase::empty(), llvm::BasicBlock::front(), llvm::Function::front(), GEP, llvm::MemoryLocation::get(), llvm::Value::getName(), llvm::Argument::getParent(), I, llvm::ARM_PROC::IE, llvm::inverse_depth_first_ext(), llvm::SPII::Load, markIndicesSafe(), llvm::MRI_Mod, P, llvm::predecessors(), prefixIn(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::Value::use_empty(), and llvm::Value::uses().
Referenced by promoteArguments().
|
static |
Mark the given indices (ToMark) as safe in the given set of indices (Safe).
Marking safe usually means adding ToMark to Safe. However, if there is already a prefix of Indices in Safe, Indices are implicitely marked safe already. Furthermore, any indices that Indices is itself a prefix of, are removed from Safe (since they are implicitely safe because of Indices now).
Definition at line 502 of file ArgumentPromotion.cpp.
References llvm::WebAssembly::End, and isPrefix().
Referenced by isSafeToPromoteArgument().
|
static |
Checks if Indices, or a prefix of Indices, is in Set.
Definition at line 483 of file ArgumentPromotion.cpp.
References isPrefix().
Referenced by isSafeToPromoteArgument().
|
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 793 of file ArgumentPromotion.cpp.
References llvm::Function::addParamAttr(), llvm::Function::args(), canPaddingBeAccessed(), llvm::dbgs(), DEBUG, llvm::DL, doPromotion(), llvm::SmallVectorBase::empty(), llvm::SmallPtrSetImplBase::empty(), F, llvm::Module::getDataLayout(), llvm::GlobalValue::getParent(), llvm::GlobalValue::hasLocalLinkage(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), isDenselyPacked(), isSafeToPromoteArgument(), llvm::Function::isVarArg(), llvm::NoAlias, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::Function::removeParamAttr(), and llvm::Value::uses().
Referenced by llvm::ArgumentPromotionPass::run().
| STATISTIC | ( | NumArgumentsPromoted | , |
| "Number of pointer arguments promoted" | |||
| ) |
| STATISTIC | ( | NumAggregatesPromoted | , |
| "Number of aggregate arguments promoted" | |||
| ) |
| STATISTIC | ( | NumByValArgsPromoted | , |
| "Number of byval arguments promoted" | |||
| ) |
| STATISTIC | ( | NumArgumentsDead | , |
| "Number of dead pointer args eliminated" | |||
| ) |
| argpromotion |
Definition at line 999 of file ArgumentPromotion.cpp.
| Promote by reference arguments to false |
Definition at line 999 of file ArgumentPromotion.cpp.
| Promote by reference arguments to scalars |
Definition at line 999 of file ArgumentPromotion.cpp.
1.8.6