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)
 
 ~Attributor ()
 
ChangeStatus run ()
 Run the analyses until a fixpoint is reached or enforced (timeout). More...
 
template<typename AAType >
const AAType & getAAFor (const AbstractAttribute &QueryingAA, const IRPosition &IRP)
 Lookup an abstract attribute of type AAType at position IRP. 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, DenseSet< const char *> *Whitelist=nullptr)
 Determine opportunities to derive 'default' attributes in F and create abstract attribute objects for them. 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(CallSite)> &Pred, const AbstractAttribute &QueryingAA, bool RequireAllCallSites)
 Check Pred on all function call sites. More...
 
bool checkForAllReturnedValuesAndReturnInsts (const function_ref< bool(Value &, const SmallPtrSetImpl< ReturnInst *> &)> &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 566 of file Attributor.h.

Constructor & Destructor Documentation

◆ Attributor()

llvm::Attributor::Attributor ( InformationCache InfoCache)
inline

Definition at line 567 of file Attributor.h.

◆ ~Attributor()

llvm::Attributor::~Attributor ( )
inline

Definition at line 568 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 698 of file Attributor.h.

References llvm::MCID::Call.

Referenced by AANoSyncImpl::updateImpl(), AANoFreeImpl::updateImpl(), and AAWillReturnImpl::updateImpl().

◆ checkForAllCallSites()

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

Check Pred on all function call sites.

This method will evaluate Pred on call sites and return true if Pred holds in every call sites. However, this is only possible all call sites are known, hence the function has internal linkage.

Definition at line 2260 of file Attributor.cpp.

References llvm::dbgs(), llvm::IRPosition::function(), llvm::IRPosition::getAssociatedFunction(), llvm::Instruction::getFunction(), llvm::AbstractAttribute::getIRPosition(), llvm::Value::getName(), llvm::GlobalValue::hasInternalLinkage(), I, LLVM_DEBUG, and llvm::Value::uses().

Referenced by clampCallSiteArgumentStates().

◆ 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 2354 of file Attributor.cpp.

References llvm::IRPosition::function_scope(), llvm::IRPosition::getAssociatedFunction(), llvm::AbstractAttribute::getIRPosition(), llvm::GlobalValue::hasExactDefinition(), and I.

Referenced by AANoUnwindImpl::updateImpl(), AAReturnedValuesImpl::updateImpl(), and AANoReturnImpl::updateImpl().

◆ 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 2383 of file Attributor.cpp.

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

Referenced by AANoSyncImpl::updateImpl().

◆ 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 2334 of file Attributor.cpp.

References llvm::IRPosition::function_scope(), llvm::IRPosition::getAssociatedFunction(), llvm::AbstractAttribute::getIRPosition(), and llvm::GlobalValue::hasExactDefinition().

Referenced by clampReturnedValueStates(), AAReturnedValuesImpl::getAssumedUniqueReturnValue(), and AANoAliasReturned::updateImpl().

◆ checkForAllReturnedValuesAndReturnInsts()

bool Attributor::checkForAllReturnedValuesAndReturnInsts ( const function_ref< bool(Value &, const SmallPtrSetImpl< ReturnInst *> &)> &  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 2312 of file Attributor.cpp.

References llvm::IRPosition::function_scope(), llvm::IRPosition::getAssociatedFunction(), llvm::AbstractAttribute::getIRPosition(), and llvm::GlobalValue::hasExactDefinition().

◆ getAAFor()

template<typename AAType >
const AAType& llvm::Attributor::getAAFor ( const AbstractAttribute QueryingAA,
const IRPosition IRP 
)
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.

Definition at line 592 of file Attributor.h.

References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup().

Referenced by clampCallSiteArgumentStates(), clampReturnedValueStates(), AAIsDeadImpl::findNextNoReturn(), genericValueTraversal(), AADereferenceableImpl::initialize(), AAIsDeadImpl::manifest(), AACallSiteReturnedFromReturned< AANonNull, AANonNullImpl >::updateImpl(), AANoUnwindImpl::updateImpl(), AAReturnedValuesImpl::updateImpl(), AANoSyncImpl::updateImpl(), AANoFreeImpl::updateImpl(), AANonNullFloating::updateImpl(), AAWillReturnImpl::updateImpl(), AANoAliasReturned::updateImpl(), AADereferenceableFloating::updateImpl(), and AAAlignFloating::updateImpl().

◆ getDataLayout()

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

Return the data layout associated with the anchor scope.

Definition at line 716 of file Attributor.h.

Referenced by AANonNullFloating::initialize(), AANonNullFloating::updateImpl(), AADereferenceableFloating::updateImpl(), and AAAlignFloating::updateImpl().

◆ getInfoCache()

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

Return the internal information cache.

Definition at line 638 of file Attributor.h.

References F().

Referenced by AAReturnedValuesImpl::initialize().

◆ identifyDefaultAbstractAttributes()

void Attributor::identifyDefaultAbstractAttributes ( Function F,
DenseSet< const char *> *  Whitelist = nullptr 
)

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

Parameters
FThe function that is checked for attribute opportunities.
WhitelistIf not null, a set limiting the 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 2579 of file Attributor.cpp.

References Arg, llvm::Function::arg_size(), llvm::Function::args(), llvm::IRPosition::argument(), assert(), llvm::MCID::Call, llvm::IRPosition::callsite_argument(), F(), 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::Function::getReturnType(), llvm::Value::getType(), I, llvm::instructions(), llvm::Type::isPointerTy(), llvm::MipsISD::Ret, and llvm::IRPosition::returned().

◆ 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 2243 of file Attributor.cpp.

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

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

Referenced by checkAndRegisterAA().

◆ run()

ChangeStatus Attributor::run ( )

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