|
LLVM
4.0.0
|
This file implements interprocedural passes which walk the call-graph deducing and/or propagating function attributes. More...
#include "llvm/Transforms/IPO/FunctionAttrs.h"#include "llvm/Transforms/IPO.h"#include "llvm/ADT/SCCIterator.h"#include "llvm/ADT/SetVector.h"#include "llvm/ADT/SmallSet.h"#include "llvm/ADT/Statistic.h"#include "llvm/ADT/StringSwitch.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/CaptureTracking.h"#include "llvm/Analysis/TargetLibraryInfo.h"#include "llvm/Analysis/ValueTracking.h"#include "llvm/IR/GlobalVariable.h"#include "llvm/IR/InstIterator.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/LLVMContext.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"Go to the source code of this file.
Classes | |
| struct | llvm::GraphTraits< ArgumentGraphNode * > |
| struct | llvm::GraphTraits< ArgumentGraph * > |
Namespaces | |
| llvm | |
| Compute iterated dominance frontiers using a linear time algorithm. | |
Macros | |
| #define | DEBUG_TYPE "functionattrs" |
Enumerations | |
| enum | MemoryAccessKind |
| The three kinds of memory access relevant to 'readonly' and 'readnone' attributes. More... | |
Functions | |
| STATISTIC (NumReadNone,"Number of functions marked readnone") | |
| STATISTIC (NumReadOnly,"Number of functions marked readonly") | |
| STATISTIC (NumNoCapture,"Number of arguments marked nocapture") | |
| STATISTIC (NumReturned,"Number of arguments marked returned") | |
| STATISTIC (NumReadNoneArg,"Number of arguments marked readnone") | |
| STATISTIC (NumReadOnlyArg,"Number of arguments marked readonly") | |
| STATISTIC (NumNoAlias,"Number of function returns marked noalias") | |
| STATISTIC (NumNonNullReturn,"Number of function returns marked nonnull") | |
| STATISTIC (NumNoRecurse,"Number of functions marked as norecurse") | |
| static MemoryAccessKind | checkFunctionMemoryAccess (Function &F, AAResults &AAR, const SCCNodeSet &SCCNodes) |
| template<typename AARGetterT > | |
| static bool | addReadAttrs (const SCCNodeSet &SCCNodes, AARGetterT AARGetter) |
| Deduce readonly/readnone attributes for the SCC. More... | |
| static Attribute::AttrKind | determinePointerReadAttrs (Argument *A, const SmallPtrSet< Argument *, 8 > &SCCNodes) |
| Returns Attribute::None, Attribute::ReadOnly or Attribute::ReadNone. More... | |
| static bool | addArgumentReturnedAttrs (const SCCNodeSet &SCCNodes) |
| Deduce returned attributes for the SCC. More... | |
| static bool | addArgumentAttrs (const SCCNodeSet &SCCNodes) |
| Deduce nocapture attributes for the SCC. More... | |
| static bool | isFunctionMallocLike (Function *F, const SCCNodeSet &SCCNodes) |
| Tests whether a function is "malloc-like". More... | |
| static bool | addNoAliasAttrs (const SCCNodeSet &SCCNodes) |
| Deduce noalias attributes for the SCC. More... | |
| static bool | isReturnNonNull (Function *F, const SCCNodeSet &SCCNodes, bool &Speculative) |
| Tests whether this function is known to not return null. More... | |
| static bool | addNonNullAttrs (const SCCNodeSet &SCCNodes) |
| Deduce nonnull attributes for the SCC. More... | |
| static bool | removeConvergentAttrs (const SCCNodeSet &SCCNodes) |
| Remove the convergent attribute from all functions in the SCC if every callsite within the SCC is not convergent (except for calls to functions within the SCC). More... | |
| static bool | setDoesNotRecurse (Function &F) |
| static bool | addNoRecurseAttrs (const SCCNodeSet &SCCNodes) |
| INITIALIZE_PASS_BEGIN (PostOrderFunctionAttrsLegacyPass,"functionattrs","Deduce function attributes", false, false) INITIALIZE_PASS_END(PostOrderFunctionAttrsLegacyPass | |
| template<typename AARGetterT > | |
| static bool | runImpl (CallGraphSCC &SCC, AARGetterT AARGetter) |
| INITIALIZE_PASS_BEGIN (ReversePostOrderFunctionAttrsLegacyPass,"rpo-functionattrs","Deduce function attributes in RPO", false, false) INITIALIZE_PASS_END(ReversePostOrderFunctionAttrsLegacyPass | |
| static bool | addNoRecurseAttrsTopDown (Function &F) |
| static bool | deduceFunctionAttributeInRPO (Module &M, CallGraph &CG) |
Variables | |
| functionattrs | |
| Deduce function | attributes |
| Deduce function | false |
| rpo Deduce function attributes in | RPO |
This file implements interprocedural passes which walk the call-graph deducing and/or propagating function attributes.
Definition in file FunctionAttrs.cpp.
| #define DEBUG_TYPE "functionattrs" |
Definition at line 40 of file FunctionAttrs.cpp.
| enum MemoryAccessKind |
The three kinds of memory access relevant to 'readonly' and 'readnone' attributes.
Definition at line 59 of file FunctionAttrs.cpp.
Deduce nocapture attributes for the SCC.
Definition at line 535 of file FunctionAttrs.cpp.
References A, llvm::Argument::addAttr(), llvm::AttrBuilder::addAttribute(), llvm::Function::arg_begin(), llvm::Function::arg_end(), B, llvm::SmallPtrSetImpl< PtrType >::count(), determinePointerReadAttrs(), llvm::Function::doesNotThrow(), E, llvm::Argument::getArgNo(), llvm::Function::getContext(), llvm::Value::getContext(), llvm::Function::getReturnType(), llvm::GlobalValue::hasExactDefinition(), llvm::Argument::hasNoCaptureAttr(), I, i, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Type::isVoidTy(), N, llvm::Attribute::None, llvm::Function::onlyReadsMemory(), llvm::PointerMayBeCaptured(), AMDGPU::RuntimeMD::KernelArg::ReadOnly, llvm::Argument::removeAttr(), and llvm::scc_begin().
Referenced by llvm::PostOrderFunctionAttrsPass::run(), and runImpl().
Deduce returned attributes for the SCC.
Definition at line 482 of file FunctionAttrs.cpp.
References A, llvm::AttrBuilder::addAttribute(), llvm::any_of(), llvm::Function::args(), B, llvm::Function::getContext(), llvm::Function::getReturnType(), llvm::Value::getType(), llvm::GlobalValue::hasExactDefinition(), llvm::Type::isVoidTy(), and llvm::MipsISD::Ret.
Referenced by llvm::PostOrderFunctionAttrsPass::run(), and runImpl().
Deduce noalias attributes for the SCC.
Definition at line 790 of file FunctionAttrs.cpp.
References llvm::Function::doesNotAlias(), llvm::Function::getReturnType(), llvm::GlobalValue::hasExactDefinition(), isFunctionMallocLike(), llvm::Type::isPointerTy(), and llvm::Function::setDoesNotAlias().
Referenced by llvm::PostOrderFunctionAttrsPass::run(), and runImpl().
Deduce nonnull attributes for the SCC.
Definition at line 897 of file FunctionAttrs.cpp.
References llvm::Function::addAttribute(), llvm::dbgs(), DEBUG, llvm::Function::getAttributes(), llvm::Value::getName(), llvm::Function::getReturnType(), llvm::AttributeSet::hasAttribute(), llvm::GlobalValue::hasExactDefinition(), llvm::Type::isPointerTy(), isReturnNonNull(), and llvm::AttributeSet::ReturnIndex.
Referenced by llvm::PostOrderFunctionAttrsPass::run(), and runImpl().
Definition at line 1008 of file FunctionAttrs.cpp.
References llvm::Function::begin(), llvm::Function::doesNotRecurse(), I, llvm::instructions(), llvm::GlobalValue::isDeclaration(), and setDoesNotRecurse().
Referenced by llvm::PostOrderFunctionAttrsPass::run(), and runImpl().
Definition at line 1210 of file FunctionAttrs.cpp.
References assert(), llvm::Function::doesNotRecurse(), llvm::dyn_cast(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getParent(), llvm::BasicBlock::getParent(), llvm::GlobalValue::hasInternalLinkage(), I, llvm::GlobalValue::isDeclaration(), setDoesNotRecurse(), and llvm::Value::users().
Referenced by deduceFunctionAttributeInRPO().
|
static |
Deduce readonly/readnone attributes for the SCC.
Definition at line 177 of file FunctionAttrs.cpp.
References llvm::AttrBuilder::addAttribute(), B, checkFunctionMemoryAccess(), F, llvm::AttributeSet::FunctionIndex, and AMDGPU::RuntimeMD::KernelArg::ReadOnly.
Referenced by llvm::PostOrderFunctionAttrsPass::run(), and runImpl().
|
static |
Definition at line 66 of file FunctionAttrs.cpp.
References llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_begin(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_end(), E, llvm::FMRB_DoesNotAccessMemory, llvm::MemoryLocation::get(), llvm::Instruction::getAAMetadata(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledFunction(), llvm::AAResults::getModRefBehavior(), llvm::Value::getType(), llvm::GlobalValue::hasExactDefinition(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::hasOperandBundles(), I, llvm::inst_begin(), llvm::inst_end(), llvm::Type::isPtrOrPtrVectorTy(), llvm::Instruction::mayReadFromMemory(), llvm::Instruction::mayWriteToMemory(), llvm::MRI_Mod, llvm::MRI_ModRef, llvm::MRI_Ref, llvm::AAResults::onlyAccessesArgPointees(), llvm::AAResults::onlyReadsMemory(), llvm::AAResults::pointsToConstantMemory(), SI, llvm::MemoryLocation::UnknownSize, and VI.
Referenced by addReadAttrs().
Definition at line 1239 of file FunctionAttrs.cpp.
References addNoRecurseAttrsTopDown(), llvm::Function::doesNotRecurse(), llvm::GlobalValue::hasInternalLinkage(), I, llvm::GlobalValue::isDeclaration(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::reverse(), and llvm::scc_begin().
Referenced by llvm::ReversePostOrderFunctionAttrsPass::run().
|
static |
Returns Attribute::None, Attribute::ReadOnly or Attribute::ReadNone.
Definition at line 354 of file FunctionAttrs.cpp.
References llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_begin(), llvm::Function::arg_begin(), llvm::Function::arg_size(), assert(), llvm::Call, llvm::SmallPtrSetImpl< PtrType >::count(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::data_operands_size(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::doesNotAccessMemory(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::doesNotCapture(), llvm::SmallVectorBase::empty(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledFunction(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getNumArgOperands(), llvm::Instruction::getOpcode(), llvm::Value::getType(), llvm::Argument::hasInAllocaAttr(), I, llvm::SmallSet< T, N, C >::insert(), llvm::Function::isVarArg(), llvm::Type::isVoidTy(), isVolatile(), llvm::SPII::Load, llvm::Attribute::None, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::onlyReadsMemory(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), AMDGPU::RuntimeMD::KernelArg::ReadOnly, llvm::MipsISD::Ret, llvm::MCID::Select, and llvm::Value::uses().
Referenced by addArgumentAttrs().
| INITIALIZE_PASS_BEGIN | ( | PostOrderFunctionAttrsLegacyPass | , |
| "functionattrs" | , | ||
| "Deduce function attributes" | , | ||
| false | , | ||
| false | |||
| ) |
| INITIALIZE_PASS_BEGIN | ( | ReversePostOrderFunctionAttrsLegacyPass | , |
| "rpo-functionattrs" | , | ||
| "Deduce function attributes in RPO" | , | ||
| false | , | ||
| false | |||
| ) |
Tests whether a function is "malloc-like".
A function is "malloc-like" if it returns either null or a pointer that doesn't alias any other pointer visible to the caller.
Definition at line 726 of file FunctionAttrs.cpp.
References C, llvm::Call, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledFunction(), llvm::SelectInst::getFalseValue(), llvm::SelectInst::getTrueValue(), i, llvm::PHINode::incoming_values(), llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::insert(), LLVM_FALLTHROUGH, llvm::NoAlias, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::paramHasAttr(), llvm::PointerMayBeCaptured(), llvm::MipsISD::Ret, llvm::MCID::Select, SI, and llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::size().
Referenced by addNoAliasAttrs().
|
static |
Tests whether this function is known to not return null.
Requires that the function returns a pointer.
Returns true if it believes the function will not return a null, and sets Speculative based on whether the returned conclusion is a speculative conclusion due to SCC calls.
Definition at line 833 of file FunctionAttrs.cpp.
References assert(), llvm::Call, llvm::dyn_cast(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledFunction(), llvm::SelectInst::getFalseValue(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Function::getReturnType(), llvm::SelectInst::getTrueValue(), i, llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::insert(), llvm::isKnownNonNull(), llvm::Type::isPointerTy(), llvm_unreachable, llvm::MipsISD::Ret, llvm::MCID::Select, SI, and llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::size().
Referenced by addNonNullAttrs().
Remove the convergent attribute from all functions in the SCC if every callsite within the SCC is not convergent (except for calls to functions within the SCC).
Returns true if changes were made.
Definition at line 960 of file FunctionAttrs.cpp.
References llvm::dbgs(), DEBUG, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getCalledFunction(), llvm::Value::getName(), I, llvm::instructions(), llvm::Function::isConvergent(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::isConvergent(), llvm::GlobalValue::isDeclaration(), and llvm::Function::setNotConvergent().
Referenced by llvm::PostOrderFunctionAttrsPass::run(), and runImpl().
|
static |
Definition at line 1126 of file FunctionAttrs.cpp.
References addArgumentAttrs(), addArgumentReturnedAttrs(), addNoAliasAttrs(), addNonNullAttrs(), addNoRecurseAttrs(), addReadAttrs(), llvm::Function::hasFnAttribute(), I, and removeConvergentAttrs().
Definition at line 1000 of file FunctionAttrs.cpp.
References llvm::Function::doesNotRecurse(), and llvm::Function::setDoesNotRecurse().
Referenced by addNoRecurseAttrs(), and addNoRecurseAttrsTopDown().
| STATISTIC | ( | NumReadNone | , |
| "Number of functions marked readnone" | |||
| ) |
| STATISTIC | ( | NumReadOnly | , |
| "Number of functions marked readonly" | |||
| ) |
| STATISTIC | ( | NumNoCapture | , |
| "Number of arguments marked nocapture" | |||
| ) |
| STATISTIC | ( | NumReturned | , |
| "Number of arguments marked returned" | |||
| ) |
| STATISTIC | ( | NumReadNoneArg | , |
| "Number of arguments marked readnone" | |||
| ) |
| STATISTIC | ( | NumReadOnlyArg | , |
| "Number of arguments marked readonly" | |||
| ) |
| STATISTIC | ( | NumNoAlias | , |
| "Number of function returns marked noalias" | |||
| ) |
| STATISTIC | ( | NumNonNullReturn | , |
| "Number of function returns marked nonnull" | |||
| ) |
| STATISTIC | ( | NumNoRecurse | , |
| "Number of functions marked as norecurse" | |||
| ) |
| Deduce function attributes |
Definition at line 1118 of file FunctionAttrs.cpp.
Referenced by llvm::LTOModule::getSymbolAttributes().
| rpo Deduce function attributes in false |
Definition at line 1118 of file FunctionAttrs.cpp.
| rpo functionattrs |
Definition at line 1118 of file FunctionAttrs.cpp.
| rpo Deduce function attributes in RPO |
Definition at line 1203 of file FunctionAttrs.cpp.
1.8.6