LLVM 20.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Friends | List of all members
llvm::AbstractAttribute Struct Referenceabstract

Base struct for all "concrete attribute" deductions. More...

#include "llvm/Transforms/IPO/Attributor.h"

Inheritance diagram for llvm::AbstractAttribute:
Inheritance graph
[legend]

Public Types

using StateType = AbstractState
 
- Public Types inherited from llvm::IRPosition
enum  Kind : char {
  IRP_INVALID , IRP_FLOAT , IRP_RETURNED , IRP_CALL_SITE_RETURNED ,
  IRP_FUNCTION , IRP_CALL_SITE , IRP_ARGUMENT , IRP_CALL_SITE_ARGUMENT
}
 The positions we distinguish in the IR. More...
 
using CallBaseContext = CallBase
 
- Public Types inherited from llvm::AADepGraphNode
using DepTy = PointerIntPair< AADepGraphNode *, 1 >
 
using DepSetTy = SmallSetVector< DepTy, 2 >
 
using iterator = mapped_iterator< DepSetTy::iterator, decltype(&DepGetVal)>
 
using aaiterator = mapped_iterator< DepSetTy::iterator, decltype(&DepGetValAA)>
 

Public Member Functions

 AbstractAttribute (const IRPosition &IRP)
 
virtual ~AbstractAttribute ()=default
 Virtual destructor.
 
virtual void initialize (Attributor &A)
 Initialize the state with the information in the Attributor A.
 
virtual bool isQueryAA () const
 A query AA is always scheduled as long as we do updates because it does lazy computation that cannot be determined to be done from the outside.
 
virtual StateTypegetState ()=0
 Return the internal abstract state for inspection.
 
virtual const StateTypegetState () const =0
 
const IRPositiongetIRPosition () const
 Return an IR position, see struct IRPosition.
 
IRPositiongetIRPosition ()
 
void print (raw_ostream &OS) const
 Helper functions, for debug purposes only.
 
void print (Attributor *, raw_ostream &OS) const override
 
virtual void printWithDeps (raw_ostream &OS) const
 
void dump () const
 
virtual const std::string getAsStr (Attributor *A) const =0
 This function should return the "summarized" assumed state as string.
 
virtual const std::string getName () const =0
 This function should return the name of the AbstractAttribute.
 
virtual const chargetIdAddr () const =0
 This function should return the address of the ID of the AbstractAttribute.
 
- Public Member Functions inherited from llvm::IRPosition
 IRPosition ()
 Default constructor available to create invalid positions implicitly.
 
bool operator== (const IRPosition &RHS) const
 
bool operator!= (const IRPosition &RHS) const
 
ValuegetAnchorValue () const
 Return the value this abstract attribute is anchored with.
 
FunctiongetAssociatedFunction () const
 Return the associated function, if any.
 
ArgumentgetAssociatedArgument () const
 Return the associated argument, if any.
 
bool isFnInterfaceKind () const
 Return true if the position refers to a function interface, that is the function scope, the function return, or an argument.
 
bool isFunctionScope () const
 Return true if this is a function or call site position.
 
FunctiongetAnchorScope () const
 Return the Function surrounding the anchor value.
 
InstructiongetCtxI () const
 Return the context instruction, if any.
 
ValuegetAssociatedValue () const
 Return the value this abstract attribute is associated with.
 
TypegetAssociatedType () const
 Return the type this abstract attribute is associated with.
 
int getCalleeArgNo () const
 Return the callee argument number of the associated value if it is an argument or call site argument, otherwise a negative value.
 
int getCallSiteArgNo () const
 Return the call site argument number of the associated value if it is an argument or call site argument, otherwise a negative value.
 
unsigned getAttrIdx () const
 Return the index in the attribute list for this position.
 
ValuegetAttrListAnchor () const
 Return the value attributes are attached to.
 
AttributeList getAttrList () const
 Return the attributes associated with this function or call site scope.
 
void setAttrList (const AttributeList &AttrList) const
 Update the attributes associated with this function or call site scope.
 
unsigned getNumArgs () const
 Return the number of arguments associated with this function or call site scope.
 
ValuegetArg (unsigned ArgNo) const
 Return theargument ArgNo associated with this function or call site scope.
 
Kind getPositionKind () const
 Return the associated position kind.
 
bool isAnyCallSitePosition () const
 
bool isArgumentPosition () const
 Return true if the position is an argument or call site argument.
 
IRPosition stripCallBaseContext () const
 Return the same position without the call base context.
 
const CallBaseContextgetCallBaseContext () const
 Get the call base context from the position.
 
bool hasCallBaseContext () const
 Check if the position has any call base context.
 
 operator void * () const
 }
 
- Public Member Functions inherited from llvm::AADepGraphNode
virtual ~AADepGraphNode ()=default
 
aaiterator begin ()
 
aaiterator end ()
 
iterator child_begin ()
 
iterator child_end ()
 
void print (raw_ostream &OS) const
 
virtual void print (Attributor *, raw_ostream &OS) const
 
DepSetTygetDeps ()
 

Static Public Member Functions

static bool classof (const AADepGraphNode *DGN)
 This function is used to identify if an DGN is of type AbstractAttribute so that the dyn_cast and cast can use such information to cast an AADepGraphNode to an AbstractAttribute.
 
static bool hasTrivialInitializer ()
 Return false if this AA does anything non-trivial (hence not done by default) in its initializer.
 
static bool requiresCalleeForCallBase ()
 Return true if this AA requires a "callee" (or an associted function) for a call site positon.
 
static bool requiresNonAsmForCallBase ()
 Return true if this AA requires non-asm "callee" for a call site positon.
 
static bool requiresCallersForArgOrFunction ()
 Return true if this AA requires all callees for an argument or function positon.
 
static bool isValidIRPositionForInit (Attributor &A, const IRPosition &IRP)
 Return false if an AA should not be created for IRP.
 
static bool isValidIRPositionForUpdate (Attributor &A, const IRPosition &IRP)
 Return false if an AA should not be updated for IRP.
 
- Static Public Member Functions inherited from llvm::IRPosition
static const IRPosition value (const Value &V, const CallBaseContext *CBContext=nullptr)
 Create a position describing the value of V.
 
static const IRPosition inst (const Instruction &I, const CallBaseContext *CBContext=nullptr)
 Create a position describing the instruction I.
 
static const IRPosition function (const Function &F, const CallBaseContext *CBContext=nullptr)
 Create a position describing the function scope of F.
 
static const IRPosition returned (const Function &F, const CallBaseContext *CBContext=nullptr)
 Create a position describing the returned value of F.
 
static const IRPosition argument (const Argument &Arg, const CallBaseContext *CBContext=nullptr)
 Create a position describing the argument Arg.
 
static const IRPosition callsite_function (const CallBase &CB)
 Create a position describing the function scope of CB.
 
static const IRPosition callsite_returned (const CallBase &CB)
 Create a position describing the returned value of CB.
 
static const IRPosition callsite_argument (const CallBase &CB, unsigned ArgNo)
 Create a position describing the argument of CB at position ArgNo.
 
static const IRPosition callsite_argument (AbstractCallSite ACS, unsigned ArgNo)
 Create a position describing the argument of ACS at position ArgNo.
 
static const IRPosition function_scope (const IRPosition &IRP, const CallBaseContext *CBContext=nullptr)
 Create a position with function scope matching the "context" of IRP.
 

Static Public Attributes

static constexpr Attribute::AttrKind IRAttributeKind = Attribute::None
 Compile time access to the IR attribute kind.
 
- Static Public Attributes inherited from llvm::IRPosition
static const IRPosition EmptyKey
 Special DenseMap key values.
 
static const IRPosition TombstoneKey
 

Protected Member Functions

ChangeStatus update (Attributor &A)
 Hook for the Attributor to trigger an update of the internal state.
 
virtual ChangeStatus manifest (Attributor &A)
 Hook for the Attributor to trigger the manifestation of the information represented by the abstract attribute in the LLVM-IR.
 
virtual void trackStatistics () const =0
 Hook to enable custom statistic tracking, called after manifest that resulted in a change if statistics are enabled.
 
virtual ChangeStatus updateImpl (Attributor &A)=0
 The actual update/transfer function which has to be implemented by the derived classes.
 
- Protected Member Functions inherited from llvm::AADepGraphNode
 operator AbstractAttribute * ()
 

Friends

struct Attributor
 }
 

Additional Inherited Members

- Static Protected Member Functions inherited from llvm::AADepGraphNode
static AADepGraphNodeDepGetVal (const DepTy &DT)
 
static AbstractAttributeDepGetValAA (const DepTy &DT)
 
- Protected Attributes inherited from llvm::AADepGraphNode
DepSetTy Deps
 Set of dependency graph nodes which should be updated if this one is updated.
 

Detailed Description

Base struct for all "concrete attribute" deductions.

The abstract attribute is a minimal interface that allows the Attributor to orchestrate the abstract/fixpoint analysis. The design allows to hide away implementation choices made for the subclasses but also to structure their implementation and simplify the use of other abstract attributes in-flight.

To allow easy creation of new attributes, most methods have default implementations. The ones that do not are generally straight forward, except AbstractAttribute::updateImpl which is the location of most reasoning associated with the abstract attribute. The update is invoked by the Attributor in case the situation used to justify the current optimistic state might have changed. The Attributor determines this automatically by monitoring the Attributor::getAAFor calls made by abstract attributes.

The updateImpl method should inspect the IR and other abstract attributes in-flight to justify the best possible (=optimistic) state. The actual implementation is, similar to the underlying abstract state encoding, not exposed. In the most common case, the updateImpl will go through a list of reasons why its optimistic state is valid given the current information. If any combination of them holds and is sufficient to justify the current optimistic state, the method shall return UNCHAGED. If not, the optimistic state is adjusted to the situation and the method shall return CHANGED.

If the manifestation of the "concrete attribute" deduced by the subclass differs from the "default" behavior, which is a (set of) LLVM-IR attribute(s) for an argument, call site argument, function return value, or function, the AbstractAttribute::manifest method should be overloaded.

NOTE: If the state obtained via getState() is INVALID, thus if AbstractAttribute::getState().isValidState() returns false, no information provided by the methods of this class should be used. NOTE: The Attributor currently has certain limitations to what we can do. As a general rule of thumb, "concrete" abstract attributes should for now only perform "backward" information propagation. That means optimistic information obtained through abstract attributes should only be used at positions that precede the origin of the information with regards to the program flow. More practically, information can now be propagated from instructions to their enclosing function, but not from call sites to the called function. The mechanisms to allow both directions will be added in the future. NOTE: The mechanics of adding a new "concrete" abstract attribute are described in the file comment.

Definition at line 3284 of file Attributor.h.

Member Typedef Documentation

◆ StateType

Definition at line 3285 of file Attributor.h.

Constructor & Destructor Documentation

◆ AbstractAttribute()

llvm::AbstractAttribute::AbstractAttribute ( const IRPosition IRP)
inline

Definition at line 3287 of file Attributor.h.

◆ ~AbstractAttribute()

virtual llvm::AbstractAttribute::~AbstractAttribute ( )
virtualdefault

Virtual destructor.

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

Member Function Documentation

◆ classof()

static bool llvm::AbstractAttribute::classof ( const AADepGraphNode DGN)
inlinestatic

This function is used to identify if an DGN is of type AbstractAttribute so that the dyn_cast and cast can use such information to cast an AADepGraphNode to an AbstractAttribute.

We eagerly return true here because all AADepGraphNodes except for the Synthethis Node are of type AbstractAttribute

Definition at line 3301 of file Attributor.h.

◆ dump()

void llvm::AbstractAttribute::dump ( ) const
inline

Definition at line 3371 of file Attributor.h.

References llvm::dbgs(), and print().

◆ getAsStr()

virtual const std::string llvm::AbstractAttribute::getAsStr ( Attributor A) const
pure virtual

This function should return the "summarized" assumed state as string.

Implemented in llvm::AAMemoryLocation.

Referenced by print().

◆ getIdAddr()

virtual const char * llvm::AbstractAttribute::getIdAddr ( ) const
pure virtual

This function should return the address of the ID of the AbstractAttribute.

Implemented in llvm::AANoUnwind, llvm::AANoSync, llvm::AAMustProgress, llvm::AANonNull, llvm::AANoRecurse, llvm::AAWillReturn, llvm::AAUndefinedBehavior, llvm::AAIntraFnReachability, llvm::AANoAlias, llvm::AANoFree, llvm::AANoReturn, llvm::AAIsDead, llvm::AADereferenceable, llvm::AAAlign, llvm::AAInstanceInfo, llvm::AANoCapture, llvm::AAValueSimplify, llvm::AAHeapToStack, llvm::AAPrivatizablePtr, llvm::AAMemoryBehavior, llvm::AAMemoryLocation, llvm::AAValueConstantRange, llvm::AAPotentialConstantValues, llvm::AAPotentialValues, llvm::AANoUndef, llvm::AANoFPClass, llvm::AACallEdges, llvm::AAExecutionDomain, llvm::AAInterFnReachability, llvm::AANonConvergent, llvm::AAPointerInfo, llvm::AAAssumptionInfo, llvm::AAUnderlyingObjects, llvm::AAAddressSpace, llvm::AAAllocationInfo, llvm::AAGlobalValueInfo, llvm::AAIndirectCallInfo, and llvm::AADenormalFPMath.

Referenced by llvm::AANoUnwind::classof(), llvm::AANoSync::classof(), llvm::AAMustProgress::classof(), llvm::AANonNull::classof(), llvm::AANoRecurse::classof(), llvm::AAWillReturn::classof(), llvm::AAUndefinedBehavior::classof(), llvm::AAIntraFnReachability::classof(), llvm::AANoAlias::classof(), llvm::AANoFree::classof(), llvm::AANoReturn::classof(), llvm::AAIsDead::classof(), llvm::AADereferenceable::classof(), llvm::AAAlign::classof(), llvm::AAInstanceInfo::classof(), llvm::AANoCapture::classof(), llvm::AAValueSimplify::classof(), llvm::AAHeapToStack::classof(), llvm::AAPrivatizablePtr::classof(), llvm::AAMemoryBehavior::classof(), llvm::AAMemoryLocation::classof(), llvm::AAValueConstantRange::classof(), llvm::AAPotentialConstantValues::classof(), llvm::AAPotentialValues::classof(), llvm::AANoUndef::classof(), llvm::AANoFPClass::classof(), llvm::AACallEdges::classof(), llvm::AAExecutionDomain::classof(), llvm::AAInterFnReachability::classof(), llvm::AANonConvergent::classof(), llvm::AAPointerInfo::classof(), llvm::AAAssumptionInfo::classof(), llvm::AAUnderlyingObjects::classof(), llvm::AAAddressSpace::classof(), llvm::AAAllocationInfo::classof(), llvm::AAGlobalValueInfo::classof(), llvm::AAIndirectCallInfo::classof(), and llvm::AADenormalFPMath::classof().

◆ getIRPosition() [1/2]

IRPosition & llvm::AbstractAttribute::getIRPosition ( )
inline

Definition at line 3364 of file Attributor.h.

◆ getIRPosition() [2/2]

const IRPosition & llvm::AbstractAttribute::getIRPosition ( ) const
inline

◆ getName()

virtual const std::string llvm::AbstractAttribute::getName ( ) const
pure virtual

◆ getState() [1/2]

virtual const StateType & llvm::AbstractAttribute::getState ( ) const
pure virtual

◆ getState() [2/2]

virtual StateType & llvm::AbstractAttribute::getState ( )
pure virtual

◆ hasTrivialInitializer()

static bool llvm::AbstractAttribute::hasTrivialInitializer ( )
inlinestatic

Return false if this AA does anything non-trivial (hence not done by default) in its initializer.

Definition at line 3305 of file Attributor.h.

◆ initialize()

virtual void llvm::AbstractAttribute::initialize ( Attributor A)
inlinevirtual

Initialize the state with the information in the Attributor A.

This function is called by the Attributor once all abstract attributes have been identified. It can and shall be used for task like:

  • identify existing knowledge in the IR and use it for the "known state"
  • perform any work that is not going to change over time, e.g., determine a subset of the IR, or attributes in-flight, that have to be looked at in the updateImpl method.

Definition at line 3348 of file Attributor.h.

◆ isQueryAA()

virtual bool llvm::AbstractAttribute::isQueryAA ( ) const
inlinevirtual

A query AA is always scheduled as long as we do updates because it does lazy computation that cannot be determined to be done from the outside.

However, while query AAs will not be fixed if they do not have outstanding dependences, we will only schedule them like other AAs. If a query AA that received a new query it needs to request an update via Attributor::requestUpdateForAA.

Definition at line 3356 of file Attributor.h.

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

◆ isValidIRPositionForInit()

static bool llvm::AbstractAttribute::isValidIRPositionForInit ( Attributor A,
const IRPosition IRP 
)
inlinestatic

◆ isValidIRPositionForUpdate()

static bool llvm::AbstractAttribute::isValidIRPositionForUpdate ( Attributor A,
const IRPosition IRP 
)
inlinestatic

Return false if an AA should not be updated for IRP.

Definition at line 3324 of file Attributor.h.

References A, assert(), llvm::IRPosition::getAssociatedFunction(), and llvm::IRPosition::isFnInterfaceKind().

◆ manifest()

virtual ChangeStatus llvm::AbstractAttribute::manifest ( Attributor A)
inlineprotectedvirtual

Hook for the Attributor to trigger the manifestation of the information represented by the abstract attribute in the LLVM-IR.

\Return CHANGED if the IR was altered, otherwise UNCHANGED.

Reimplemented in llvm::IRAttribute< Attribute::Alignment, StateWrapper< AAAlignmentStateType, AbstractAttribute >, AAAlign >, llvm::IRAttribute< Attribute::Dereferenceable, StateWrapper< DerefState, AbstractAttribute >, AADereferenceable >, llvm::IRAttribute< Attribute::None, StateWrapper< BitIntegerState< uint8_t, 3 >, AbstractAttribute >, AAMemoryBehavior >, llvm::IRAttribute< Attribute::None, StateWrapper< BitIntegerState< uint32_t, 511 >, AbstractAttribute >, AAMemoryLocation >, llvm::IRAttribute< Attribute::MustProgress, StateWrapper< BooleanState, AbstractAttribute >, AAMustProgress >, llvm::IRAttribute< Attribute::NoAlias, StateWrapper< BooleanState, AbstractAttribute >, AANoAlias >, llvm::IRAttribute< Attribute::NoCapture, StateWrapper< BitIntegerState< uint16_t, 7, 0 >, AbstractAttribute >, AANoCapture >, llvm::IRAttribute< Attribute::NoFPClass, StateWrapper< BitIntegerState< uint32_t, fcAllFlags, fcNone >, AbstractAttribute >, AANoFPClass >, llvm::IRAttribute< Attribute::NoFree, StateWrapper< BooleanState, AbstractAttribute >, AANoFree >, llvm::IRAttribute< Attribute::NoRecurse, StateWrapper< BooleanState, AbstractAttribute >, AANoRecurse >, llvm::IRAttribute< Attribute::NoReturn, StateWrapper< BooleanState, AbstractAttribute >, AANoReturn >, llvm::IRAttribute< Attribute::NoSync, StateWrapper< BooleanState, AbstractAttribute >, AANoSync >, llvm::IRAttribute< Attribute::NoUndef, StateWrapper< BooleanState, AbstractAttribute >, AANoUndef >, llvm::IRAttribute< Attribute::NoUnwind, StateWrapper< BooleanState, AbstractAttribute >, AANoUnwind >, llvm::IRAttribute< Attribute::NonNull, StateWrapper< BooleanState, AbstractAttribute >, AANonNull >, and llvm::IRAttribute< Attribute::WillReturn, StateWrapper< BooleanState, AbstractAttribute >, AAWillReturn >.

Definition at line 3399 of file Attributor.h.

References llvm::UNCHANGED.

◆ print() [1/2]

void AbstractAttribute::print ( Attributor A,
raw_ostream OS 
) const
overridevirtual

Reimplemented from llvm::AADepGraphNode.

Definition at line 3754 of file Attributor.cpp.

References A, getAsStr(), llvm::IRPosition::getCtxI(), getIRPosition(), getName(), I, and OS.

◆ print() [2/2]

void llvm::AbstractAttribute::print ( raw_ostream OS) const
inline

Helper functions, for debug purposes only.

{

Definition at line 3368 of file Attributor.h.

References OS, and print().

Referenced by dump(), llvm::operator<<(), print(), and printWithDeps().

◆ printWithDeps()

void AbstractAttribute::printWithDeps ( raw_ostream OS) const
virtual

Definition at line 3770 of file Attributor.cpp.

References llvm::AADepGraphNode::Deps, OS, and print().

◆ requiresCalleeForCallBase()

static bool llvm::AbstractAttribute::requiresCalleeForCallBase ( )
inlinestatic

Return true if this AA requires a "callee" (or an associted function) for a call site positon.

Default is optimistic to minimize AAs.

Definition at line 3309 of file Attributor.h.

◆ requiresCallersForArgOrFunction()

static bool llvm::AbstractAttribute::requiresCallersForArgOrFunction ( )
inlinestatic

Return true if this AA requires all callees for an argument or function positon.

Definition at line 3316 of file Attributor.h.

◆ requiresNonAsmForCallBase()

static bool llvm::AbstractAttribute::requiresNonAsmForCallBase ( )
inlinestatic

Return true if this AA requires non-asm "callee" for a call site positon.

Definition at line 3312 of file Attributor.h.

◆ trackStatistics()

virtual void llvm::AbstractAttribute::trackStatistics ( ) const
protectedpure virtual

Hook to enable custom statistic tracking, called after manifest that resulted in a change if statistics are enabled.

We require subclasses to provide an implementation so we remember to add statistics for them.

◆ update()

ChangeStatus AbstractAttribute::update ( Attributor A)
protected

Hook for the Attributor to trigger an update of the internal state.

If this attribute is already fixed, this method will return UNCHANGED, otherwise it delegates to AbstractAttribute::updateImpl.

\Return CHANGED if the internal state changed, otherwise UNCHANGED.

Definition at line 1049 of file Attributor.cpp.

References A, llvm::dbgs(), getState(), LLVM_DEBUG, llvm::UNCHANGED, and updateImpl().

◆ updateImpl()

virtual ChangeStatus llvm::AbstractAttribute::updateImpl ( Attributor A)
protectedpure virtual

The actual update/transfer function which has to be implemented by the derived classes.

If it is called, the environment has changed and we have to determine if the current information is still valid or adjust it otherwise.

\Return CHANGED if the internal state changed, otherwise UNCHANGED.

Referenced by update().

Friends And Related Function Documentation

◆ Attributor

friend struct Attributor
friend

}

Allow the Attributor access to the protected methods.

Definition at line 3384 of file Attributor.h.

Member Data Documentation

◆ IRAttributeKind

constexpr Attribute::AttrKind llvm::AbstractAttribute::IRAttributeKind = Attribute::None
staticconstexpr

Compile time access to the IR attribute kind.

Definition at line 3293 of file Attributor.h.


The documentation for this struct was generated from the following files: