LLVM  10.0.0
Classes | Public Member Functions | Static 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"

Classes

struct  ArgumentReplacementInfo
 Helper struct used in the communication between an abstract attribute (AA) that wants to change the signature of a function and the Attributor which applies the changes. More...
 

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, DepClassTy DepClass=DepClassTy::REQUIRED)
 Lookup an abstract attribute of type AAType at position IRP. More...
 
void recordDependence (const AbstractAttribute &FromAA, const AbstractAttribute &ToAA, DepClassTy DepClass)
 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...
 
InformationCache & getInfoCache ()
 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...
 
bool changeUseAfterManifest (Use &U, Value &NV)
 Record that U is to be replaces with NV after information was manifested. More...
 
bool changeValueAfterManifest (Value &V, Value &NV)
 Helper function to replace all uses of V with NV. More...
 
void changeToUnreachableAfterManifest (Instruction *I)
 Record that I is to be replaced with unreachable after information was manifested. More...
 
void registerInvokeWithDeadSuccessor (InvokeInst &II)
 Record that II has at least one dead successor block. 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 checkForAllUses (const function_ref< bool(const Use &, bool &)> &Pred, const AbstractAttribute &QueryingAA, const Value &V)
 Check Pred on all (transitive) uses of V. More...
 
bool registerFunctionSignatureRewrite (Argument &Arg, ArrayRef< Type *> ReplacementTypes, ArgumentReplacementInfo::CalleeRepairCBTy &&CalleeRepairCB, ArgumentReplacementInfo::ACSRepairCBTy &&ACSRepairCB)
 Register a rewrite for a function signature. 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 DataLayout & getDataLayout () const
 Return the data layout associated with the anchor scope. More...
 

Static Public Member Functions

static const Value * getPointerOperand (const Instruction *I, bool AllowVolatile)
 Get pointer operand of memory accessing instruction. 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 685 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 693 of file Attributor.h.

◆ ~Attributor()

llvm::Attributor::~Attributor ( )
inline

Definition at line 698 of file Attributor.h.

References llvm::DeleteContainerPointers().

Member Function Documentation

◆ changeToUnreachableAfterManifest()

void llvm::Attributor::changeToUnreachableAfterManifest ( Instruction *  I)
inline

Record that I is to be replaced with unreachable after information was manifested.

Definition at line 865 of file Attributor.h.

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

◆ changeUseAfterManifest()

bool llvm::Attributor::changeUseAfterManifest ( Use &  U,
Value &  NV 
)
inline

Record that U is to be replaces with NV after information was manifested.

This also triggers deletion of trivially dead istructions.

Definition at line 810 of file Attributor.h.

References assert(), and llvm::Value::stripPointerCasts().

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

◆ changeValueAfterManifest()

bool llvm::Attributor::changeValueAfterManifest ( Value &  V,
Value &  NV 
)
inline

Helper function to replace all uses of V with NV.

Return true if there is any change.

Definition at line 823 of file Attributor.h.

References llvm::Value::uses().

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

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

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

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

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

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 5743 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 5720 of file Attributor.cpp.

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

◆ checkForAllUses()

bool Attributor::checkForAllUses ( const function_ref< bool(const Use &, bool &)> &  Pred,
const AbstractAttribute &  QueryingAA,
const Value &  V 
)

◆ deleteAfterManifest() [1/3]

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

Record that I is deleted after information was manifested.

This also triggers deletion of trivially dead istructions.

Definition at line 878 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.

This also triggers deletion of trivially dead istructions.

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

◆ getAAFor()

template<typename AAType >
const AAType& llvm::Attributor::getAAFor ( const AbstractAttribute &  QueryingAA,
const IRPosition &  IRP,
bool  TrackDependence = true,
DepClassTy  DepClass = DepClassTy::REQUIRED 
)
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 733 of file Attributor.h.

Referenced by AAValueConstantRangeFloating::calculateBinaryOperator(), AAValueConstantRangeFloating::calculateCmpInst(), genericValueTraversal(), llvm::IRPosition::getAttrs(), and AAValueConstantRangeFloating::updateImpl().

◆ getDataLayout()

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

◆ getInfoCache()

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

◆ getPointerOperand()

static const Value* llvm::Attributor::getPointerOperand ( const Instruction *  I,
bool  AllowVolatile 
)
inlinestatic

Get pointer operand of memory accessing instruction.

If I is not a memory accessing instruction, return nullptr. If AllowVolatile, is set to false and the instruction is volatile, return nullptr.

Definition at line 834 of file Attributor.h.

References SI.

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

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

References AnnotateDeclarationCallSites, Arg, llvm::Function::args(), llvm::IRPosition::argument(), assert(), llvm::MCID::Call, Callee, llvm::IRPosition::callsite_argument(), llvm::IRPosition::callsite_returned(), 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::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, CallBrTy, IterTy >::getNumArgOperands(), llvm::getPointerOperand(), llvm::Function::getReturnType(), llvm::Value::getType(), I, llvm::GlobalValue::isDeclaration(), 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 6424 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 5565 of file Attributor.cpp.

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

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

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

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

◆ recordDependence()

void Attributor::recordDependence ( const AbstractAttribute &  FromAA,
const AbstractAttribute &  ToAA,
DepClassTy  DepClass 
)

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. The DepClass flag indicates if the dependence is striclty necessary. That means for required dependences, if FromAA changes to an invalid state, ToAA can be moved to a pessimistic fixpoint because it required information from FromAA but none are available anymore.

Definition at line 6469 of file Attributor.cpp.

References llvm::AbstractAttribute::getState(), llvm::AbstractState::isAtFixpoint(), and llvm::REQUIRED.

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

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

◆ registerFunctionSignatureRewrite()

bool Attributor::registerFunctionSignatureRewrite ( Argument &  Arg,
ArrayRef< Type *>  ReplacementTypes,
ArgumentReplacementInfo::CalleeRepairCBTy &&  CalleeRepairCB,
ArgumentReplacementInfo::ACSRepairCBTy &&  ACSRepairCB 
)

Register a rewrite for a function signature.

The argument Arg is replaced with new ones defined by the number, order, and types in ReplacementTypes. The rewiring at the call sites is done through ACSRepairCB and at the callee site through CalleeRepairCB.

Returns
True, if the replacement was registered, false otherwise.

Definition at line 6178 of file Attributor.cpp.

References llvm::SmallVectorImpl< T >::append(), Arg, llvm::Function::arg_begin(), llvm::Function::arg_size(), llvm::Function::args(), assert(), llvm::MCID::Call, llvm::CHANGED, checkForAllInstructionsImpl(), llvm::Function::Create(), llvm::CallInst::Create(), llvm::InvokeInst::Create(), llvm::dbgs(), llvm::Instruction::eraseFromParent(), llvm::Instruction::extractProfTotalWeight(), llvm::FunctionType::get(), llvm::AttributeList::get(), llvm::GlobalValue::getAddressSpace(), llvm::Argument::getArgNo(), llvm::Function::getAttributes(), llvm::CallBase::getAttributes(), llvm::Function::getBasicBlockList(), llvm::CallBase::getCallingConv(), llvm::Function::getContext(), llvm::Instruction::getDebugLoc(), llvm::AttributeList::getFnAttributes(), llvm::Module::getFunctionList(), llvm::Function::getFunctionType(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::GlobalValue::getLinkage(), llvm::Value::getName(), llvm::Attributor::ArgumentReplacementInfo::getNumReplacementArgs(), llvm::CallBase::getOperandBundlesAsDefs(), llvm::AttributeList::getParamAttributes(), llvm::Argument::getParent(), llvm::GlobalValue::getParent(), llvm::AttributeList::getRetAttributes(), llvm::FunctionType::getReturnType(), llvm::Function::getSubprogram(), llvm::AttributeList::hasAttrSomewhere(), I, llvm::iplist_impl< IntrusiveListT, TraitsT >::insert(), llvm::FunctionType::isVarArg(), llvm::Function::isVarArg(), LLVM_DEBUG, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::Value::replaceAllUsesWith(), llvm::SmallVectorImpl< T >::resize(), llvm::CallBase::setAttributes(), llvm::CallBase::setCallingConv(), llvm::Instruction::setDebugLoc(), llvm::Instruction::setProfWeight(), llvm::Function::setSubprogram(), llvm::SmallVectorBase::size(), llvm::ArrayRef< T >::size(), Success, llvm::Value::takeName(), llvm::UNCHANGED, and llvm::RISCVFenceField::W.

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

◆ registerInvokeWithDeadSuccessor()

void llvm::Attributor::registerInvokeWithDeadSuccessor ( InvokeInst &  II)
inline

Record that II has at least one dead successor block.

This information is used, e.g., to replace II with a call, after information was manifested.

Definition at line 872 of file Attributor.h.

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

◆ run()

ChangeStatus Attributor::run ( Module &  M)

Run the analyses until a fixpoint is reached or enforced (timeout).

The attributes registered with this Attributor can be used after as long as the Attributor is not destroyed (it owns the attributes now).

CHANGED if the IR was changed, otherwise UNCHANGED.

Definition at line 5847 of file Attributor.cpp.

References llvm::SmallVectorImpl< T >::append(), llvm::AreStatisticsEnabled(), assert(), BUILD_STAT_NAME, llvm::CHANGED, llvm::changeToCall(), llvm::changeToUnreachable(), llvm::SetVector< T, Vector, Set >::clear(), llvm::SmallVectorImpl< T >::clear(), llvm::ConstantFoldTerminator(), llvm::dbgs(), llvm::Function::deleteBody(), llvm::DetatchDeadBlocks(), llvm::numbers::e, llvm::SetVector< T, Vector, Set >::empty(), llvm::SmallPtrSetImplBase::empty(), llvm::Function::eraseFromParent(), llvm::errs(), F(), llvm::BasicBlock::front(), llvm::UndefValue::get(), llvm::Instruction::getFunction(), llvm::AbstractCallSite::getInstruction(), llvm::BasicBlock::getParent(), llvm::AbstractAttribute::getState(), llvm::BasicBlock::getTerminator(), llvm::GlobalValue::getType(), llvm::BasicBlock::getUniquePredecessor(), I, llvm::AbstractState::indicateOptimisticFixpoint(), llvm::AbstractState::indicatePessimisticFixpoint(), llvm::SetVector< T, Vector, Set >::insert(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::insert(), llvm::AbstractState::isAtFixpoint(), llvm::isInstructionTriviallyDead(), llvm::AbstractState::isValidState(), LLVM_DEBUG, llvm_unreachable, MaxFixpointIterations, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::RecursivelyDeleteTriviallyDeadInstructions(), llvm::Value::replaceAllUsesWith(), llvm::SmallVectorImpl< T >::reserve(), llvm::SmallVectorBase::size(), llvm::SetVector< T, Vector, Set >::size(), llvm::SmallPtrSetImplBase::size(), llvm::SplitBlockPredecessors(), STATS_DECL, llvm::UNCHANGED, and VerifyMaxFixpointIterations.

Referenced by runAttributorOnModule().


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