struct Attributor

Declaration

struct Attributor { /* full declaration omitted */ };

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.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:685

Method Overview

Methods

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

Description

Constructor

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:693

Parameters

llvm::InformationCache& InfoCache
Cache to hold various information accessible for the abstract attributes.
unsigned int DepRecomputeInterval
Number of iterations until the dependences between abstract attributes are recomputed.
DenseSet<const char*>* Whitelist = nullptr
If not null, a set limiting the attribute opportunities.

void changeToUnreachableAfterManifest(
    llvm::Instruction* I)

Description

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

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:865

Parameters

llvm::Instruction* I

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

Description

Record that \p U is to be replaces with \p NV after information was manifested. This also triggers deletion of trivially dead istructions.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:810

Parameters

llvm::Use& U
llvm::Value& NV

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

Description

Helper function to replace all uses of \p V with \p NV. Return true if there is any change.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:823

Parameters

llvm::Value& V
llvm::Value& NV

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

Description

Check \p Pred on all call-like instructions (=CallBased derived). See checkForAllCallLikeInstructions(...) for more information.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:1029

Parameters

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

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

Description

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

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:995

Parameters

const function_ref<bool(llvm::AbstractCallSite)>& Pred
const llvm::AbstractAttribute& QueryingAA
bool RequireAllCallSites

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

Description

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

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:1021

Parameters

const function_ref<bool(llvm::Instruction&)>& Pred
const llvm::AbstractAttribute& QueryingAA
const ArrayRef<unsigned int>& Opcodes

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

Description

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

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:1042

Parameters

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

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

Description

Check \p Pred on all values potentially returned by the function associated with \p QueryingAA. This is the context insensitive version of the method above.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:1014

Parameters

const function_ref<bool(llvm::Value&)>& Pred
const llvm::AbstractAttribute& QueryingAA

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

Description

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

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:1005

Parameters

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

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

Description

Check \p Pred on all (transitive) uses of \p V. This method will evaluate \p Pred on all (transitive) uses of the associated value and return true if \p Pred holds every time.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:896

Parameters

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

void deleteAfterManifest(llvm::Instruction& I)

Description

Record that \p I is deleted after information was manifested. This also triggers deletion of trivially dead istructions.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:878

Parameters

llvm::Instruction& I

void deleteAfterManifest(llvm::BasicBlock& BB)

Description

Record that \p BB is deleted after information was manifested. This also triggers deletion of trivially dead istructions.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:882

Parameters

llvm::BasicBlock& BB

void deleteAfterManifest(llvm::Function& F)

Description

Record that \p F is deleted after information was manifested.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:885

Parameters

llvm::Function& F

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

Description

Lookup an abstract attribute of type \p AAType at position \p 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 \p 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 \p TrackDependence is set to false the dependence from\p 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.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:733

Templates

AAType

Parameters

const llvm::AbstractAttribute& QueryingAA
const llvm::IRPosition& IRP
bool TrackDependence = true
llvm::DepClassTy DepClass = DepClassTy::REQUIRED

const llvm::DataLayout& getDataLayout() const

Description

Return the data layout associated with the anchor scope.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:1047

llvm::InformationCache& getInfoCache()

Description

Return the internal information cache.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:777

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

Description

Get pointer operand of memory accessing instruction. If \p I is not a memory accessing instruction, return nullptr. If \p AllowVolatile, is set to false and the instruction is volatile, return nullptr.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:834

Parameters

const llvm::Instruction* I
bool AllowVolatile

void identifyDefaultAbstractAttributes(
    llvm::Function& F)

Description

Determine opportunities to derive 'default' attributes in \p F and create abstract attribute objects for them. 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.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:789

Parameters

llvm::Function& F
The function that is checked for attribute opportunities.

void initializeInformationCache(llvm::Function& F)

Description

Initialize the information cache for queries regarding function \p 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.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:795

Parameters

llvm::Function& F

bool isAssumedDead(
    const llvm::AbstractAttribute& AA,
    const llvm::AAIsDead* LivenessAA)

Description

Return true if \p AA (or its context instruction) is assumed dead. If \p LivenessAA is not provided it is queried.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:890

Parameters

const llvm::AbstractAttribute& AA
const llvm::AAIsDead* LivenessAA

void markLiveInternalFunction(
    const llvm::Function& F)

Description

Mark the internal function \p F as live. This will trigger the identification and initialization of attributes for\p F.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:801

Parameters

const llvm::Function& F

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

Description

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

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:751

Parameters

const llvm::AbstractAttribute& FromAA
const llvm::AbstractAttribute& ToAA
llvm::DepClassTy DepClass

template <typename AAType>
AAType& registerAA(AAType& AA)

Description

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

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:761

Templates

AAType

Parameters

AAType& AA

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

Description

Register a rewrite for a function signature. The argument \p Arg is replaced with new ones defined by the number, order, and types in \p ReplacementTypes. The rewiring at the call sites is done through \p ACSRepairCB and at the callee site through\p CalleeRepairCB.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:985

Parameters

llvm::Argument& Arg
ArrayRef<llvm::Type*> ReplacementTypes
ArgumentReplacementInfo::CalleeRepairCBTy&& CalleeRepairCB
ArgumentReplacementInfo::ACSRepairCBTy&& ACSRepairCB

Returns

True, if the replacement was registered, false otherwise.

void registerInvokeWithDeadSuccessor(
    llvm::InvokeInst& II)

Description

Record that \p II has at least one dead successor block. This information is used, e.g., to replace \p II with a call, after information was manifested.

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:872

Parameters

llvm::InvokeInst& II

llvm::ChangeStatus run(llvm::Module& M)

Description

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

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:710

Parameters

llvm::Module& M

Returns

CHANGED if the IR was changed, otherwise UNCHANGED.

~Attributor()

Declared at: llvm/include/llvm/Transforms/IPO/Attributor.h:698