LLVM  10.0.0svn
Public Member Functions | List of all members
llvm::Attributor Struct Reference

The fixpoint analysis framework that orchestrates the attribute deduction. More...

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

Public Member Functions

 Attributor (InformationCache &InfoCache, unsigned DepRecomputeInterval, DenseSet< const char *> *Whitelist=nullptr)
 Constructor. More...
 
 ~Attributor ()
 
ChangeStatus run (Module &M)
 Run the analyses until a fixpoint is reached or enforced (timeout). More...
 
template<typename AAType >
const AAType & getAAFor (const AbstractAttribute &QueryingAA, const IRPosition &IRP, bool TrackDependence=true)
 Lookup an abstract attribute of type AAType at position IRP. More...
 
void recordDependence (const AbstractAttribute &FromAA, const AbstractAttribute &ToAA)
 Explicitly record a dependence from FromAA to ToAA, that is if FromAA changes ToAA should be updated as well. More...
 
template<typename AAType >
AAType & registerAA (AAType &AA)
 Introduce a new abstract attribute into the fixpoint analysis. More...
 
InformationCachegetInfoCache ()
 Return the internal information cache. More...
 
void identifyDefaultAbstractAttributes (Function &F)
 Determine opportunities to derive 'default' attributes in F and create abstract attribute objects for them. More...
 
void initializeInformationCache (Function &F)
 Initialize the information cache for queries regarding function F. More...
 
void markLiveInternalFunction (const Function &F)
 Mark the internal function F as live. More...
 
void deleteAfterManifest (Instruction &I)
 Record that I is deleted after information was manifested. More...
 
void deleteAfterManifest (BasicBlock &BB)
 Record that BB is deleted after information was manifested. More...
 
void deleteAfterManifest (Function &F)
 Record that F is deleted after information was manifested. More...
 
bool isAssumedDead (const AbstractAttribute &AA, const AAIsDead *LivenessAA)
 Return true if AA (or its context instruction) is assumed dead. More...
 
bool checkForAllCallSites (const function_ref< bool(AbstractCallSite)> &Pred, const AbstractAttribute &QueryingAA, bool RequireAllCallSites)
 Check Pred on all function call sites. More...
 
bool checkForAllReturnedValuesAndReturnInsts (const function_ref< bool(Value &, const SmallSetVector< ReturnInst *, 4 > &)> &Pred, const AbstractAttribute &QueryingAA)
 Check Pred on all values potentially returned by F. More...
 
bool checkForAllReturnedValues (const function_ref< bool(Value &)> &Pred, const AbstractAttribute &QueryingAA)
 Check Pred on all values potentially returned by the function associated with QueryingAA. More...
 
bool checkForAllInstructions (const function_ref< bool(Instruction &)> &Pred, const AbstractAttribute &QueryingAA, const ArrayRef< unsigned > &Opcodes)
 Check Pred on all instructions with an opcode present in Opcodes. More...
 
bool checkForAllCallLikeInstructions (const function_ref< bool(Instruction &)> &Pred, const AbstractAttribute &QueryingAA)
 Check Pred on all call-like instructions (=CallBased derived). More...
 
bool checkForAllReadWriteInstructions (const llvm::function_ref< bool(Instruction &)> &Pred, AbstractAttribute &QueryingAA)
 Check Pred on all Read/Write instructions. More...
 
const DataLayoutgetDataLayout () const
 Return the data layout associated with the anchor scope. More...
 

Detailed Description

The fixpoint analysis framework that orchestrates the attribute deduction.

The Attributor provides a general abstract analysis framework (guided fixpoint iteration) as well as helper functions for the deduction of (LLVM-IR) attributes. However, also other code properties can be deduced, propagated, and ultimately manifested through the Attributor framework. This is particularly useful if these properties interact with attributes and a co-scheduled deduction allows to improve the solution. Even if not, thus if attributes/properties are completely isolated, they should use the Attributor framework to reduce the number of fixpoint iteration frameworks in the code base. Note that the Attributor design makes sure that isolated attributes are not impacted, in any way, by others derived at the same time if there is no cross-reasoning performed.

The public facing interface of the Attributor is kept simple and basically allows abstract attributes to one thing, query abstract attributes in-flight. There are two reasons to do this: a) The optimistic state of one abstract attribute can justify an optimistic state of another, allowing to framework to end up with an optimistic (=best possible) fixpoint instead of one based solely on information in the IR. b) This avoids reimplementing various kinds of lookups, e.g., to check for existing IR attributes, in favor of a single lookups interface provided by an abstract attribute subclass.

NOTE: The mechanics of adding a new "concrete" abstract attribute are described in the file comment.

Definition at line 713 of file Attributor.h.

Constructor & Destructor Documentation

◆ Attributor()

llvm::Attributor::Attributor ( InformationCache InfoCache,
unsigned  DepRecomputeInterval,
DenseSet< const char *> *  Whitelist = nullptr 
)
inline

Constructor.

Parameters
InfoCacheCache to hold various information accessible for the abstract attributes.
DepRecomputeIntervalNumber of iterations until the dependences between abstract attributes are recomputed.
WhitelistIf not null, a set limiting the attribute opportunities.

Definition at line 721 of file Attributor.h.

◆ ~Attributor()

llvm::Attributor::~Attributor ( )
inline

Definition at line 726 of file Attributor.h.

References llvm::DeleteContainerPointers().

Member Function Documentation

◆ checkForAllCallLikeInstructions()

bool llvm::Attributor::checkForAllCallLikeInstructions ( const function_ref< bool(Instruction &)> &  Pred,
const AbstractAttribute QueryingAA 
)
inline

Check Pred on all call-like instructions (=CallBased derived).

See checkForAllCallLikeInstructions(...) for more information.

Definition at line 881 of file Attributor.h.

References llvm::MCID::Call.

Referenced by llvm::IRPosition::getAttrs().

◆ checkForAllCallSites()

bool Attributor::checkForAllCallSites ( const function_ref< bool(AbstractCallSite)> &  Pred,
const AbstractAttribute QueryingAA,
bool  RequireAllCallSites 
)

◆ checkForAllInstructions()

bool Attributor::checkForAllInstructions ( const function_ref< bool(Instruction &)> &  Pred,
const AbstractAttribute QueryingAA,
const ArrayRef< unsigned > &  Opcodes 
)

Check Pred on all instructions with an opcode present in Opcodes.

This method will evaluate Pred on all instructions with an opcode present in Opcode and return true if Pred holds on all of them.

Definition at line 4396 of file Attributor.cpp.

References checkForAllInstructionsImpl(), llvm::IRPosition::function(), llvm::IRPosition::getAssociatedFunction(), and llvm::AbstractAttribute::getIRPosition().

Referenced by llvm::IRPosition::getAttrs().

◆ checkForAllReadWriteInstructions()

bool Attributor::checkForAllReadWriteInstructions ( const llvm::function_ref< bool(Instruction &)> &  Pred,
AbstractAttribute QueryingAA 
)

Check Pred on all Read/Write instructions.

This method will evaluate Pred on all instructions that read or write to memory present in the information cache and return true if Pred holds on all of them.

Definition at line 4425 of file Attributor.cpp.

References llvm::IRPosition::function(), llvm::IRPosition::getAssociatedFunction(), llvm::AbstractAttribute::getIRPosition(), and I.

Referenced by llvm::IRPosition::getAttrs().

◆ checkForAllReturnedValues()

bool Attributor::checkForAllReturnedValues ( const function_ref< bool(Value &)> &  Pred,
const AbstractAttribute QueryingAA 
)

Check Pred on all values potentially returned by the function associated with QueryingAA.

This is the context insensitive version of the method above.

Definition at line 4355 of file Attributor.cpp.

References llvm::IRPosition::function(), llvm::IRPosition::getAssociatedFunction(), and llvm::AbstractAttribute::getIRPosition().

Referenced by llvm::IRPosition::getAttrs().

◆ checkForAllReturnedValuesAndReturnInsts()

bool Attributor::checkForAllReturnedValuesAndReturnInsts ( const function_ref< bool(Value &, const SmallSetVector< ReturnInst *, 4 > &)> &  Pred,
const AbstractAttribute QueryingAA 
)

Check Pred on all values potentially returned by F.

This method will evaluate Pred on all values potentially returned by the function associated with QueryingAA. The returned values are matched with their respective return instructions. Returns true if Pred holds on all of them.

Definition at line 4332 of file Attributor.cpp.

References llvm::IRPosition::function(), llvm::IRPosition::getAssociatedFunction(), and llvm::AbstractAttribute::getIRPosition().

◆ deleteAfterManifest() [1/3]

void llvm::Attributor::deleteAfterManifest ( Instruction I)
inline

Record that I is deleted after information was manifested.

Definition at line 829 of file Attributor.h.

Referenced by llvm::IRPosition::getAttrs().

◆ deleteAfterManifest() [2/3]

void llvm::Attributor::deleteAfterManifest ( BasicBlock BB)
inline

Record that BB is deleted after information was manifested.

Definition at line 832 of file Attributor.h.

◆ deleteAfterManifest() [3/3]

void llvm::Attributor::deleteAfterManifest ( Function F)
inline

Record that F is deleted after information was manifested.

Definition at line 835 of file Attributor.h.

◆ getAAFor()

template<typename AAType >
const AAType& llvm::Attributor::getAAFor ( const AbstractAttribute QueryingAA,
const IRPosition IRP,
bool  TrackDependence = true 
)
inline

Lookup an abstract attribute of type AAType at position IRP.

While no abstract attribute is found equivalent positions are checked, see SubsumingPositionIterator. Thus, the returned abstract attribute might be anchored at a different position, e.g., the callee if IRP is a call base.

This method is the only (supported) way an abstract attribute can retrieve information from another abstract attribute. As an example, take an abstract attribute that determines the memory access behavior for a argument (readnone, readonly, ...). It should use getAAFor to get the most optimistic information for other abstract attributes in-flight, e.g. the one reasoning about the "captured" state for the argument or the one reasoning on the memory access behavior of the function as a whole.

If the flag TrackDependence is set to false the dependence from QueryingAA to the return abstract attribute is not automatically recorded. This should only be used if the caller will record the dependence explicitly if necessary, thus if it the returned abstract attribute is used for reasoning. To record the dependences explicitly use the Attributor::recordDependence method.

Definition at line 757 of file Attributor.h.

Referenced by genericValueTraversal(), and llvm::IRPosition::getAttrs().

◆ getDataLayout()

const DataLayout& llvm::Attributor::getDataLayout ( ) const
inline

◆ getInfoCache()

InformationCache& llvm::Attributor::getInfoCache ( )
inline

Return the internal information cache.

Definition at line 797 of file Attributor.h.

References F().

Referenced by llvm::IRPosition::getAttrs().

◆ identifyDefaultAbstractAttributes()

void Attributor::identifyDefaultAbstractAttributes ( Function F)

Determine opportunities to derive 'default' attributes in F and create abstract attribute objects for them.

Parameters
FThe function that is checked for attribute opportunities.

Note that abstract attribute instances are generally created even if the IR already contains the information they would deduce. The most important reason for this is the single interface, the one of the abstract attribute instance, which can be queried without the need to look at the IR in various places.

Definition at line 4724 of file Attributor.cpp.

References Arg, llvm::Function::arg_size(), llvm::Function::args(), llvm::IRPosition::argument(), assert(), llvm::MCID::Call, llvm::IRPosition::callsite_argument(), checkForAllInstructionsImpl(), llvm::numbers::e, EnableHeapToStack, llvm::IRPosition::function(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, CallBrTy, IterTy >::getArgument(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, CallBrTy, IterTy >::getCalledFunction(), llvm::getPointerOperand(), llvm::Function::getReturnType(), llvm::Value::getType(), I, llvm::Type::isPointerTy(), llvm::SPII::Load, llvm::IRPosition::returned(), llvm::SPII::Store, Success, and llvm::IRPosition::value().

Referenced by runAttributorOnModule().

◆ initializeInformationCache()

void Attributor::initializeInformationCache ( Function F)

Initialize the information cache for queries regarding function F.

This method needs to be called for all function that might be looked at through the information cache interface prior to looking at them.

Definition at line 4682 of file Attributor.cpp.

References assert(), llvm::MCID::Call, F(), I, llvm::instructions(), llvm::SPII::Load, llvm::MipsISD::Ret, and llvm::SPII::Store.

Referenced by runAttributorOnModule().

◆ isAssumedDead()

bool Attributor::isAssumedDead ( const AbstractAttribute AA,
const AAIsDead LivenessAA 
)

Return true if AA (or its context instruction) is assumed dead.


Attributor

If LivenessAA is not provided it is queried.

Definition at line 4231 of file Attributor.cpp.

References llvm::IRPosition::function(), llvm::IRPosition::getCtxI(), llvm::Instruction::getFunction(), llvm::AbstractAttribute::getIRPosition(), and llvm::AAIsDead::isAssumedDead().

◆ markLiveInternalFunction()

void llvm::Attributor::markLiveInternalFunction ( const Function F)
inline

Mark the internal function F as live.

This will trigger the identification and initialization of attributes for F.

Definition at line 821 of file Attributor.h.

References assert(), and llvm::GlobalValue::hasLocalLinkage().

Referenced by llvm::IRPosition::getAttrs().

◆ recordDependence()

void llvm::Attributor::recordDependence ( const AbstractAttribute FromAA,
const AbstractAttribute ToAA 
)
inline

Explicitly record a dependence from FromAA to ToAA, that is if FromAA changes ToAA should be updated as well.

This method should be used in conjunction with the getAAFor method and with the TrackDependence flag passed to the method set to false. This can be beneficial to avoid false dependences but it requires the users of getAAFor to explicitly record true dependences through this method.

Definition at line 769 of file Attributor.h.

Referenced by genericValueTraversal().

◆ registerAA()

template<typename AAType >
AAType& llvm::Attributor::registerAA ( AAType &  AA)
inline

Introduce a new abstract attribute into the fixpoint analysis.

Note that ownership of the attribute is given to the Attributor. It will invoke delete for the Attributor on destruction of the Attributor.

Attributes are identified by their IR position (AAType::getIRPosition()) and the address of their static member (see AAType::ID).

Definition at line 781 of file Attributor.h.

References assert(), and llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::count().

◆ run()

ChangeStatus Attributor::run ( Module M)

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