LLVM  10.0.0svn
Public Types | Public Member Functions | 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

Public Types

using StateType = AbstractState

Public Member Functions

virtual ~AbstractAttribute ()
 Virtual destructor. More...
virtual void initialize (Attributor &A)
 Initialize the state with the information in the Attributor A. More...
virtual StateTypegetState ()=0
 Return the internal abstract state for inspection. More...
virtual const StateTypegetState () const =0
virtual const IRPositiongetIRPosition () const =0
 Return an IR position, see struct IRPosition. More...
virtual void print (raw_ostream &OS) const
 Helper functions, for debug purposes only. More...
void dump () const
virtual const std::string getAsStr () const =0
 This function should return the "summarized" assumed state as string. More...

Protected Member Functions

ChangeStatus update (Attributor &A)
 Hook for the Attributor to trigger an update of the internal state. More...
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. More...
virtual void trackStatistics () const =0
 Hook to enable custom statistic tracking, called after manifest that resulted in a change if statistics are enabled. More...
virtual IRPositiongetIRPosition ()=0
 Return an IR position, see struct IRPosition. More...
virtual ChangeStatus updateImpl (Attributor &A)=0
 The actual update/transfer function which has to be implemented by the derived classes. More...


struct Attributor
 } More...

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 1025 of file Attributor.h.

Member Typedef Documentation

◆ StateType

Definition at line 1026 of file Attributor.h.

Constructor & Destructor Documentation

◆ ~AbstractAttribute()

virtual llvm::AbstractAttribute::~AbstractAttribute ( )

Virtual destructor.

Definition at line 1029 of file Attributor.h.

Member Function Documentation

◆ dump()

void llvm::AbstractAttribute::dump ( ) const

Definition at line 1051 of file Attributor.h.

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

◆ getAsStr()

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

◆ getIRPosition() [1/2]

virtual const IRPosition& llvm::AbstractAttribute::getIRPosition ( ) const
pure virtual

Return an IR position, see struct IRPosition.

Implemented in llvm::AAIsDead, llvm::IRAttribute< Attribute::NonNull, StateWrapper< BooleanState, AbstractAttribute > >, llvm::IRAttribute< Attribute::NoSync, StateWrapper< BooleanState, AbstractAttribute > >, llvm::IRAttribute< Attribute::Alignment, StateWrapper< IntegerState, AbstractAttribute > >, llvm::IRAttribute< Attribute::NoRecurse, StateWrapper< BooleanState, AbstractAttribute > >, llvm::IRAttribute< Attribute::NoFree, StateWrapper< BooleanState, AbstractAttribute > >, llvm::IRAttribute< Attribute::Dereferenceable, StateWrapper< DerefState, AbstractAttribute > >, llvm::IRAttribute< Attribute::NoReturn, StateWrapper< BooleanState, AbstractAttribute > >, llvm::IRAttribute< Attribute::NoAlias, StateWrapper< BooleanState, AbstractAttribute > >, llvm::IRAttribute< Attribute::WillReturn, StateWrapper< BooleanState, AbstractAttribute > >, llvm::IRAttribute< Attribute::NoUnwind, StateWrapper< BooleanState, AbstractAttribute > >, and llvm::IRAttribute< Attribute::Returned, AbstractAttribute >.

Referenced by llvm::Attributor::checkForAllCallSites(), llvm::Attributor::checkForAllInstructions(), llvm::Attributor::checkForAllReadWriteInstructions(), llvm::Attributor::checkForAllReturnedValues(), llvm::Attributor::checkForAllReturnedValuesAndReturnInsts(), AANonNullFloating::initialize(), AADereferenceableImpl::initialize(), llvm::Attributor::isAssumedDead(), AAReturnedValuesImpl::manifest(), AAAlignFloating::manifest(), print(), AACallSiteReturnedFromReturned< AANonNull, AANonNullImpl >::updateImpl(), AANonNullFloating::updateImpl(), AADereferenceableFloating::updateImpl(), and AAAlignFloating::updateImpl().

◆ getIRPosition() [2/2]

virtual IRPosition& llvm::AbstractAttribute::getIRPosition ( )
protectedpure virtual

◆ getState() [1/2]

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

◆ getState() [2/2]

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

◆ initialize()

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

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.

Reimplemented in AANoReturnImpl, AAAlignImpl, AADereferenceableImpl, AAIsDeadImpl, AANoAliasImpl, AAWillReturnImpl, AANoRecurseImpl, AANonNullFloating, AANonNullImpl, AANoFreeImpl, AANoSyncImpl, AAReturnedValuesImpl, and AANoUnwindImpl.

Definition at line 1039 of file Attributor.h.

References print().

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

◆ manifest()

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

◆ print()

void AbstractAttribute::print ( raw_ostream OS) const

Helper functions, for debug purposes only.


Definition at line 2803 of file Attributor.cpp.

References getAsStr(), getIRPosition(), and getState().

Referenced by llvm::operator<<().

◆ trackStatistics()

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

◆ update()

ChangeStatus AbstractAttribute::update ( Attributor A)

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.

CHANGED if the internal state changed, otherwise UNCHANGED.

Definition at line 260 of file Attributor.cpp.

References 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.

CHANGED if the internal state changed, otherwise UNCHANGED.

Implemented in AANoReturnImpl, AAAlignFloating, AADereferenceableFloating, AAIsDeadImpl, AANoAliasReturned, AANoAliasCallSiteArgument, AANoAliasArgument, AANoAliasFloating, AAWillReturnImpl, AANoRecurseFunction, AANonNullFloating, AANoFreeImpl, AANoSyncImpl, AAReturnedValuesImpl, and AANoUnwindImpl.

Referenced by AANoSyncImpl::getAsStr(), AAReturnedValuesImpl::getState(), AAIsDeadImpl::manifest(), and update().

Friends And Related Function Documentation

◆ Attributor

friend struct Attributor


Allow the Attributor access to the protected methods.

Definition at line 1058 of file Attributor.h.

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