LLVM  10.0.0svn
llvm::AbstractAttribute Struct Referenceabstract

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

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

Inheritance diagram for llvm::AbstractAttribute:
[legend]

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

## Friends

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

## ◆ StateType

Definition at line 1225 of file Attributor.h.

## ◆ ~AbstractAttribute()

 virtual llvm::AbstractAttribute::~AbstractAttribute ( )
inlinevirtual

Virtual destructor.

Definition at line 1228 of file Attributor.h.

## ◆ dump()

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

Definition at line 1250 of file Attributor.h.

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

## ◆ getAsStr()

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

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

Referenced by AAReturnedValuesImpl::getNumReturnValues(), and print().

## ◆ 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 )
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 1238 of file Attributor.h.

References print().

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

## ◆ manifest()

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

## ◆ print()

 void AbstractAttribute::print ( raw_ostream & OS ) const
virtual

Helper functions, for debug purposes only.

{

Definition at line 4059 of file Attributor.cpp.

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

Referenced by llvm::operator<<().

## ◆ 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.

CHANGED if the internal state changed, otherwise UNCHANGED.

Definition at line 292 of file Attributor.cpp.

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

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

## ◆ 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.

## ◆ Attributor

 friend struct Attributor
friend

}