LLVM  10.0.0svn
Classes | Macros | Typedefs | Functions | Variables
Attributor.cpp File Reference
#include "llvm/Transforms/IPO/Attributor.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
Include dependency graph for Attributor.cpp:

Go to the source code of this file.

Classes

struct  AANoUnwindFunction
 --------------------—NoUnwind Function Attribute-----------------------— More...
 
class  AAReturnedValuesImpl
 ---------------—— Function Return Values -------------------------—— More...
 
struct  AANoSyncFunction
 ---------------------— NoSync Function Attribute ----------------------— More...
 
struct  AANoFreeFunction
 ---------------------— No-Free Attributes -------------------------— More...
 
struct  AANonNullImpl
 ---------------------— NonNull Argument Attribute ---------------------— More...
 
struct  AANonNullReturned
 NonNull attribute for function return value. More...
 
struct  AANonNullArgument
 NonNull attribute for function argument. More...
 
struct  AANonNullCallSiteArgument
 NonNull attribute for a call site argument. More...
 
struct  AAWillReturnImpl
 ---------------------— Will-Return Attributes -------------------------— More...
 
struct  AAWillReturnFunction
 

Macros

#define DEBUG_TYPE   "attributor"
 

Typedefs

template<typename StateTy >
using followValueCB_t = std::function< bool(Value *, StateTy &State)>
 
template<typename StateTy >
using visitValueCB_t = std::function< void(Value *, StateTy &State)>
 

Functions

 STATISTIC (NumFnWithExactDefinition, "Number of function with exact definitions")
 
 STATISTIC (NumFnWithoutExactDefinition, "Number of function without exact definitions")
 
 STATISTIC (NumAttributesTimedOut, "Number of abstract attributes timed out before fixpoint")
 
 STATISTIC (NumAttributesValidFixpoint, "Number of abstract attributes in a valid fixpoint state")
 
 STATISTIC (NumAttributesManifested, "Number of abstract attributes manifested in IR")
 
 STATISTIC (NumFnNoUnwind, "Number of functions marked nounwind")
 
 STATISTIC (NumFnUniqueReturned, "Number of function with unique return")
 
 STATISTIC (NumFnKnownReturns, "Number of function with known return values")
 
 STATISTIC (NumFnArgumentReturned, "Number of function arguments marked returned")
 
 STATISTIC (NumFnNoSync, "Number of functions marked nosync")
 
 STATISTIC (NumFnNoFree, "Number of functions marked nofree")
 
 STATISTIC (NumFnReturnedNonNull, "Number of function return values marked nonnull")
 
 STATISTIC (NumFnArgumentNonNull, "Number of function arguments marked nonnull")
 
 STATISTIC (NumCSArgumentNonNull, "Number of call site arguments marked nonnull")
 
 STATISTIC (NumFnWillReturn, "Number of functions marked willreturn")
 
static void bookkeeping (AbstractAttribute::ManifestPosition MP, const Attribute &Attr)
 } More...
 
template<typename StateTy >
static bool genericValueTraversal (Value *InitV, StateTy &State, visitValueCB_t< StateTy > &VisitValueCB, followValueCB_t< StateTy > *FollowValueCB=nullptr, int MaxValues=8)
 Recursively visit all values that might become InitV at some point. More...
 
static unsigned getAttrIndex (AbstractAttribute::ManifestPosition MP, unsigned ArgNo=0)
 Helper to identify the correct offset into an attribute list. More...
 
static bool isEqualOrWorse (const Attribute &New, const Attribute &Old)
 Return true if New is equal or worse than Old. More...
 
static bool addIfNotExistent (LLVMContext &Ctx, const Attribute &Attr, AttributeList &Attrs, AbstractAttribute::ManifestPosition MP, unsigned ArgNo=0)
 Return true if the information provided by Attr was added to the attribute list Attrs. More...
 
bool containsCycle (Function &F)
 
bool containsPossiblyEndlessLoop (Function &F)
 
static bool runAttributorOnModule (Module &M)
 } More...
 
 INITIALIZE_PASS_BEGIN (AttributorLegacyPass, "attributor", "Deduce and propagate attributes", false, false) INITIALIZE_PASS_END(AttributorLegacyPass
 

Variables

static cl::opt< unsignedMaxFixpointIterations ("attributor-max-iterations", cl::Hidden, cl::desc("Maximal number of fixpoint iterations."), cl::init(32))
 
static cl::opt< boolDisableAttributor ("attributor-disable", cl::Hidden, cl::desc("Disable the attributor inter-procedural deduction pass."), cl::init(true))
 
static cl::opt< boolVerifyAttributor ("attributor-verify", cl::Hidden, cl::desc("Verify the Attributor deduction and " "manifestation of attributes -- may issue false-positive errors"), cl::init(false))
 
 attributor
 
Deduce and propagate attributes
 
Deduce and propagate false
 

Macro Definition Documentation

◆ DEBUG_TYPE

#define DEBUG_TYPE   "attributor"

Definition at line 37 of file Attributor.cpp.

Typedef Documentation

◆ followValueCB_t

template<typename StateTy >
using followValueCB_t = std::function<bool(Value *, StateTy &State)>

Definition at line 143 of file Attributor.cpp.

◆ visitValueCB_t

template<typename StateTy >
using visitValueCB_t = std::function<void(Value *, StateTy &State)>

Definition at line 145 of file Attributor.cpp.

Function Documentation

◆ addIfNotExistent()

static bool addIfNotExistent ( LLVMContext Ctx,
const Attribute Attr,
AttributeList Attrs,
AbstractAttribute::ManifestPosition  MP,
unsigned  ArgNo = 0 
)
static

Return true if the information provided by Attr was added to the attribute list Attrs.

This is only the case if it was not already present in Attrs at the position describe by MP and ArgNo.

Definition at line 251 of file Attributor.cpp.

References llvm::AttributeList::addAttribute(), llvm::AttributeList::getAttribute(), getAttrIndex(), llvm::Attribute::getKindAsEnum(), llvm::Attribute::getKindAsString(), llvm::AttributeList::hasAttribute(), llvm::Attribute::isEnumAttribute(), isEqualOrWorse(), llvm::Attribute::isStringAttribute(), and llvm_unreachable.

Referenced by llvm::AbstractAttribute::manifest().

◆ bookkeeping()

static void bookkeeping ( AbstractAttribute::ManifestPosition  MP,
const Attribute Attr 
)
static

◆ containsCycle()

bool containsCycle ( Function F)

◆ containsPossiblyEndlessLoop()

bool containsPossiblyEndlessLoop ( Function F)

Definition at line 1267 of file Attributor.cpp.

References containsCycle().

Referenced by AAWillReturnFunction::initialize().

◆ genericValueTraversal()

template<typename StateTy >
static bool genericValueTraversal ( Value InitV,
StateTy &  State,
visitValueCB_t< StateTy > &  VisitValueCB,
followValueCB_t< StateTy > *  FollowValueCB = nullptr,
int  MaxValues = 8 
)
static

Recursively visit all values that might become InitV at some point.

This will be done by looking through cast instructions, selects, phis, and calls with the "returned" attribute. The callback FollowValueCB is asked before a potential origin value is looked at. If no FollowValueCB is passed, a default one is used that will make sure we visit every value only once. Once we cannot look through the value any further, the callback VisitValueCB is invoked and passed the current value and the State. To limit how much effort is invested, we will never visit more than MaxValues values.

Definition at line 156 of file Attributor.cpp.

References llvm::SmallVectorImpl< T >::append(), Arg, llvm::Function::args(), llvm::SmallVectorBase::empty(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, CallBrTy, IterTy >::getArgOperand(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, CallBrTy, IterTy >::getCalledFunction(), llvm::Value::getType(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::Type::isPointerTy(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T >::push_back(), SI, and llvm::Value::stripPointerCasts().

◆ getAttrIndex()

static unsigned getAttrIndex ( AbstractAttribute::ManifestPosition  MP,
unsigned  ArgNo = 0 
)
static

◆ INITIALIZE_PASS_BEGIN()

INITIALIZE_PASS_BEGIN ( AttributorLegacyPass  ,
"attributor"  ,
"Deduce and propagate attributes ,
false  ,
false   
)

◆ isEqualOrWorse()

static bool isEqualOrWorse ( const Attribute New,
const Attribute Old 
)
static

Return true if New is equal or worse than Old.

Definition at line 241 of file Attributor.cpp.

References llvm::Attribute::getValueAsInt(), and llvm::Attribute::isIntAttribute().

Referenced by addIfNotExistent().

◆ runAttributorOnModule()

static bool runAttributorOnModule ( Module M)
static

◆ STATISTIC() [1/15]

STATISTIC ( NumFnWithExactDefinition  ,
"Number of function with exact definitions"   
)

◆ STATISTIC() [2/15]

STATISTIC ( NumFnWithoutExactDefinition  ,
"Number of function without exact definitions"   
)

◆ STATISTIC() [3/15]

STATISTIC ( NumAttributesTimedOut  ,
"Number of abstract attributes timed out before fixpoint"   
)

◆ STATISTIC() [4/15]

STATISTIC ( NumAttributesValidFixpoint  ,
"Number of abstract attributes in a valid fixpoint state"   
)

◆ STATISTIC() [5/15]

STATISTIC ( NumAttributesManifested  ,
"Number of abstract attributes manifested in IR  
)

◆ STATISTIC() [6/15]

STATISTIC ( NumFnNoUnwind  ,
"Number of functions marked nounwind"   
)

◆ STATISTIC() [7/15]

STATISTIC ( NumFnUniqueReturned  ,
"Number of function with unique return"   
)

◆ STATISTIC() [8/15]

STATISTIC ( NumFnKnownReturns  ,
"Number of function with known return values"   
)

◆ STATISTIC() [9/15]

STATISTIC ( NumFnArgumentReturned  ,
"Number of function arguments marked returned"   
)

◆ STATISTIC() [10/15]

STATISTIC ( NumFnNoSync  ,
"Number of functions marked nosync"   
)

◆ STATISTIC() [11/15]

STATISTIC ( NumFnNoFree  ,
"Number of functions marked nofree"   
)

◆ STATISTIC() [12/15]

STATISTIC ( NumFnReturnedNonNull  ,
"Number of function return values marked nonnull"   
)

◆ STATISTIC() [13/15]

STATISTIC ( NumFnArgumentNonNull  ,
"Number of function arguments marked nonnull"   
)

◆ STATISTIC() [14/15]

STATISTIC ( NumCSArgumentNonNull  ,
"Number of call site arguments marked nonnull"   
)

◆ STATISTIC() [15/15]

STATISTIC ( NumFnWillReturn  ,
"Number of functions marked willreturn"   
)

Variable Documentation

◆ attributes

Deduce and propagate attributes

Definition at line 1689 of file Attributor.cpp.

Referenced by FunctionNumber(), and llvm::LTOModule::getSymbolAttributes().

◆ attributor

attributor

Definition at line 1689 of file Attributor.cpp.

◆ DisableAttributor

cl::opt<bool> DisableAttributor("attributor-disable", cl::Hidden, cl::desc("Disable the attributor inter-procedural deduction pass."), cl::init(true))
static

Referenced by runAttributorOnModule().

◆ false

Deduce and propagate false

Definition at line 1689 of file Attributor.cpp.

◆ MaxFixpointIterations

cl::opt<unsigned> MaxFixpointIterations("attributor-max-iterations", cl::Hidden, cl::desc("Maximal number of fixpoint iterations."), cl::init(32))
static

Referenced by llvm::Attributor::run().

◆ VerifyAttributor

cl::opt<bool> VerifyAttributor("attributor-verify", cl::Hidden, cl::desc("Verify the Attributor deduction and " "manifestation of attributes -- may issue false-positive errors"), cl::init(false))
static

Referenced by llvm::Attributor::run().