LLVM  15.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
llvm::Attributor Struct Reference

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

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

Collaboration diagram for llvm::Attributor:
Collaboration graph
[legend]

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 Types

using SimplifictionCallbackTy = std::function< Optional< Value * >(const IRPosition &, const AbstractAttribute *, bool &)>
 Register CB as a simplification callback. More...
 

Public Member Functions

 Attributor (SetVector< Function * > &Functions, InformationCache &InfoCache, AttributorConfig Configuration)
 Constructor. More...
 
 ~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, DepClassTy DepClass)
 Lookup an abstract attribute of type AAType at position IRP. More...
 
template<typename AAType >
const AAType & getAndUpdateAAFor (const AbstractAttribute &QueryingAA, const IRPosition &IRP, DepClassTy DepClass)
 Similar to getAAFor but the return abstract attribute will be updated (via AbstractAttribute::update) even if it is found in the cache. More...
 
template<typename AAType >
const AAType & getOrCreateAAFor (IRPosition IRP, const AbstractAttribute *QueryingAA, DepClassTy DepClass, bool ForceUpdate=false, bool UpdateAfterInit=true)
 The version of getAAFor that allows to omit a querying abstract attribute. More...
 
template<typename AAType >
const AAType & getOrCreateAAFor (const IRPosition &IRP)
 
template<typename AAType >
AAType * lookupAAFor (const IRPosition &IRP, const AbstractAttribute *QueryingAA=nullptr, DepClassTy DepClass=DepClassTy::OPTIONAL, bool AllowInvalidState=false)
 Return the attribute of AAType for IRP if existing and valid. More...
 
void registerForUpdate (AbstractAttribute &AA)
 Allows a query AA to request an update if a new query was received. 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...
 
InformationCachegetInfoCache ()
 Return the internal information cache. More...
 
bool isModulePass () const
 Return true if this is a module pass, false otherwise. More...
 
bool isRunOn (Function &Fn) const
 Return true if we derive attributes for Fn. More...
 
void identifyDefaultAbstractAttributes (Function &F)
 Determine opportunities to derive 'default' attributes in F and create abstract attribute objects for them. More...
 
bool isFunctionIPOAmendable (const Function &F)
 Determine whether the function F is IPO amendable. More...
 
void markLiveInternalFunction (const Function &F)
 Mark the internal function F as live. More...
 
void removeCallSite (CallInst *CI)
 Helper function to remove callsite. 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, bool ChangeDroppable=true)
 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 registerManifestAddedBasicBlock (BasicBlock &BB)
 
void deleteAfterManifest (Function &F)
 Record that F is deleted after information was manifested. More...
 
Optional< Constant * > getAssumedConstant (const IRPosition &IRP, const AbstractAttribute &AA, bool &UsedAssumedInformation)
 If IRP is assumed to be a constant, return it, if it is unclear yet, return None, otherwise return nullptr. More...
 
Optional< Constant * > getAssumedConstant (const Value &V, const AbstractAttribute &AA, bool &UsedAssumedInformation)
 
Optional< Value * > getAssumedSimplified (const IRPosition &IRP, const AbstractAttribute &AA, bool &UsedAssumedInformation)
 If V is assumed simplified, return it, if it is unclear yet, return None, otherwise return nullptr. More...
 
Optional< Value * > getAssumedSimplified (const Value &V, const AbstractAttribute &AA, bool &UsedAssumedInformation)
 
Optional< Value * > getAssumedSimplified (const IRPosition &V, const AbstractAttribute *AA, bool &UsedAssumedInformation)
 If V is assumed simplified, return it, if it is unclear yet, return None, otherwise return nullptr. More...
 
void registerSimplificationCallback (const IRPosition &IRP, const SimplifictionCallbackTy &CB)
 
bool hasSimplificationCallback (const IRPosition &IRP)
 Return true if there is a simplification callback for IRP. More...
 
Optional< Value * > translateArgumentToCallSiteContent (Optional< Value * > V, CallBase &CB, const AbstractAttribute &AA, bool &UsedAssumedInformation)
 Translate V from the callee context into the call site context. More...
 
bool isAssumedDead (const AbstractAttribute &AA, const AAIsDead *LivenessAA, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, DepClassTy DepClass=DepClassTy::OPTIONAL)
 Return true if AA (or its context instruction) is assumed dead. More...
 
bool isAssumedDead (const Instruction &I, const AbstractAttribute *QueryingAA, const AAIsDead *LivenessAA, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, DepClassTy DepClass=DepClassTy::OPTIONAL)
 Return true if I is assumed dead. More...
 
bool isAssumedDead (const Use &U, const AbstractAttribute *QueryingAA, const AAIsDead *FnLivenessAA, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, DepClassTy DepClass=DepClassTy::OPTIONAL)
 Return true if U is assumed dead. More...
 
bool isAssumedDead (const IRPosition &IRP, const AbstractAttribute *QueryingAA, const AAIsDead *FnLivenessAA, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, DepClassTy DepClass=DepClassTy::OPTIONAL)
 Return true if IRP is assumed dead. More...
 
bool isAssumedDead (const BasicBlock &BB, const AbstractAttribute *QueryingAA, const AAIsDead *FnLivenessAA, DepClassTy DepClass=DepClassTy::OPTIONAL)
 Return true if BB is assumed dead. More...
 
bool checkForAllUses (function_ref< bool(const Use &, bool &)> Pred, const AbstractAttribute &QueryingAA, const Value &V, bool CheckBBLivenessOnly=false, DepClassTy LivenessDepClass=DepClassTy::OPTIONAL, bool IgnoreDroppableUses=true, function_ref< bool(const Use &OldU, const Use &NewU)> EquivalentUseCB=nullptr)
 Check Pred on all (transitive) uses of V. More...
 
template<typename RemarkKind , typename RemarkCallBack >
void emitRemark (Instruction *I, StringRef RemarkName, RemarkCallBack &&RemarkCB) const
 Emit a remark generically. More...
 
template<typename RemarkKind , typename RemarkCallBack >
void emitRemark (Function *F, StringRef RemarkName, RemarkCallBack &&RemarkCB) const
 Emit a remark on a function. More...
 
bool isValidFunctionSignatureRewrite (Argument &Arg, ArrayRef< Type * > ReplacementTypes)
 Check if we can rewrite a function signature. More...
 
bool registerFunctionSignatureRewrite (Argument &Arg, ArrayRef< Type * > ReplacementTypes, ArgumentReplacementInfo::CalleeRepairCBTy &&CalleeRepairCB, ArgumentReplacementInfo::ACSRepairCBTy &&ACSRepairCB)
 Register a rewrite for a function signature. More...
 
bool checkForAllCallSites (function_ref< bool(AbstractCallSite)> Pred, const AbstractAttribute &QueryingAA, bool RequireAllCallSites, bool &UsedAssumedInformation)
 Check Pred on all function call sites. More...
 
bool checkForAllCallSites (function_ref< bool(AbstractCallSite)> Pred, const Function &Fn, bool RequireAllCallSites, const AbstractAttribute *QueryingAA, bool &UsedAssumedInformation)
 Check Pred on all call sites of Fn. More...
 
bool checkForAllReturnedValuesAndReturnInsts (function_ref< bool(Value &, const SmallSetVector< ReturnInst *, 4 > &)> Pred, const AbstractAttribute &QueryingAA)
 Check Pred on all values potentially returned by F. More...
 
bool checkForAllReturnedValues (function_ref< bool(Value &)> Pred, const AbstractAttribute &QueryingAA)
 Check Pred on all values potentially returned by the function associated with QueryingAA. More...
 
bool checkForAllInstructions (function_ref< bool(Instruction &)> Pred, const Function *Fn, const AbstractAttribute &QueryingAA, const ArrayRef< unsigned > &Opcodes, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, bool CheckPotentiallyDead=false)
 Check Pred on all instructions in Fn with an opcode present in Opcodes. More...
 
bool checkForAllInstructions (function_ref< bool(Instruction &)> Pred, const AbstractAttribute &QueryingAA, const ArrayRef< unsigned > &Opcodes, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, bool CheckPotentiallyDead=false)
 Check Pred on all instructions with an opcode present in Opcodes. More...
 
bool checkForAllCallLikeInstructions (function_ref< bool(Instruction &)> Pred, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool CheckBBLivenessOnly=false, bool CheckPotentiallyDead=false)
 Check Pred on all call-like instructions (=CallBased derived). More...
 
bool checkForAllReadWriteInstructions (function_ref< bool(Instruction &)> Pred, AbstractAttribute &QueryingAA, bool &UsedAssumedInformation)
 Check Pred on all Read/Write instructions. More...
 
const DataLayoutgetDataLayout () const
 Return the data layout associated with the anchor scope. More...
 

Static Public Member Functions

static void createShallowWrapper (Function &F)
 Create a shallow wrapper for F such that F has internal linkage afterwards. More...
 
static bool isInternalizable (Function &F)
 Returns true if the function F can be internalized. More...
 
static FunctioninternalizeFunction (Function &F, bool Force=false)
 Make another copy of the function F such that the copied version has internal linkage afterwards and can be analysed. More...
 
static bool internalizeFunctions (SmallPtrSetImpl< Function * > &FnSet, DenseMap< Function *, Function * > &FnMap)
 Make copies of each function in the set FnSet such that the copied version has internal linkage afterwards and can be analysed. More...
 

Public Attributes

BumpPtrAllocatorAllocator
 The allocator used to allocate memory, e.g. for AbstractAttributes. 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 1264 of file Attributor.h.

Member Typedef Documentation

◆ SimplifictionCallbackTy

Register CB as a simplification callback.

Attributor::getAssumedSimplified will use these callbacks before we it will ask AAValueSimplify. It is important to ensure this is called before identifyDefaultAbstractAttributes, assuming the latter is called at all.

Definition at line 1653 of file Attributor.h.

Constructor & Destructor Documentation

◆ Attributor()

llvm::Attributor::Attributor ( SetVector< Function * > &  Functions,
InformationCache InfoCache,
AttributorConfig  Configuration 
)
inline

Constructor.

Parameters
FunctionsThe set of functions we are deriving attributes for.
InfoCacheCache to hold various information accessible for the abstract attributes.
ConfigurationThe Attributor configuration which determines what generic features to use.

Definition at line 1273 of file Attributor.h.

◆ ~Attributor()

Attributor::~Attributor ( )

Definition at line 1105 of file Attributor.cpp.

References llvm::AADepGraphNode::Deps, and llvm::AADepGraph::SyntheticRoot.

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

References I.

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

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

◆ changeValueAfterManifest()

bool llvm::Attributor::changeValueAfterManifest ( Value V,
Value NV,
bool  ChangeDroppable = true 
)
inline

Helper function to replace all uses of V with NV.

Return true if there is any change. The flag ChangeDroppable indicates if dropppable uses should be changed too.

Definition at line 1566 of file Attributor.h.

◆ checkForAllCallLikeInstructions()

bool llvm::Attributor::checkForAllCallLikeInstructions ( function_ref< bool(Instruction &)>  Pred,
const AbstractAttribute QueryingAA,
bool &  UsedAssumedInformation,
bool  CheckBBLivenessOnly = false,
bool  CheckPotentiallyDead = false 
)
inline

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

See checkForAllCallLikeInstructions(...) for more information.

Definition at line 1952 of file Attributor.h.

References llvm::MCID::Call, and checkForAllInstructions().

◆ checkForAllCallSites() [1/2]

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

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. If true is returned, UsedAssumedInformation is set if assumed information was used to skip or simplify potential call sites.

Definition at line 1363 of file Attributor.cpp.

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

Referenced by isValidFunctionSignatureRewrite().

◆ checkForAllCallSites() [2/2]

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

Check Pred on all call sites of Fn.

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. If true is returned, UsedAssumedInformation is set if assumed information was used to skip or simplify potential call sites.

Definition at line 1382 of file Attributor.cpp.

References llvm::Function::arg_size(), assert(), llvm::dbgs(), llvm::Use::get(), llvm::Function::getArg(), llvm::AbstractCallSite::getCallArgOperand(), llvm::AbstractCallSite::getCalledFunction(), llvm::AbstractCallSite::getCalleeUseForCallback(), llvm::AbstractCallSite::getInstruction(), llvm::Value::getName(), llvm::AbstractCallSite::getNumArgOperands(), llvm::Value::getType(), llvm::Use::getUser(), llvm::GlobalValue::hasLocalLinkage(), isAssumedDead(), llvm::AbstractCallSite::isCallbackCall(), llvm::AbstractCallSite::isCallee(), LLVM_DEBUG, llvm::make_pointer_range(), llvm::min(), llvm::Value::uses(), and Uses.

◆ checkForAllInstructions() [1/2]

bool Attributor::checkForAllInstructions ( function_ref< bool(Instruction &)>  Pred,
const AbstractAttribute QueryingAA,
const ArrayRef< unsigned > &  Opcodes,
bool &  UsedAssumedInformation,
bool  CheckBBLivenessOnly = false,
bool  CheckPotentiallyDead = false 
)

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

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

◆ checkForAllInstructions() [2/2]

bool Attributor::checkForAllInstructions ( function_ref< bool(Instruction &)>  Pred,
const Function Fn,
const AbstractAttribute QueryingAA,
const ArrayRef< unsigned > &  Opcodes,
bool &  UsedAssumedInformation,
bool  CheckBBLivenessOnly = false,
bool  CheckPotentiallyDead = false 
)

Check Pred on all instructions in Fn 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 1558 of file Attributor.cpp.

References checkForAllInstructionsImpl(), llvm::IRPosition::function(), llvm::InformationCache::getOpcodeInstMapForFunction(), llvm::GlobalValue::isDeclaration(), and llvm::NONE.

Referenced by checkForAllCallLikeInstructions(), and checkForAllInstructions().

◆ checkForAllReadWriteInstructions()

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

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

References llvm::IRPosition::function(), llvm::IRPosition::getAssociatedFunction(), llvm::AbstractAttribute::getIRPosition(), llvm::InformationCache::getReadOrWriteInstsForFunction(), I, llvm::IRPosition::inst(), isAssumedDead(), and llvm::NONE.

◆ checkForAllReturnedValues()

bool Attributor::checkForAllReturnedValues ( 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 1507 of file Attributor.cpp.

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

◆ checkForAllReturnedValuesAndReturnInsts()

bool Attributor::checkForAllReturnedValuesAndReturnInsts ( 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 1484 of file Attributor.cpp.

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

◆ checkForAllUses()

bool Attributor::checkForAllUses ( function_ref< bool(const Use &, bool &)>  Pred,
const AbstractAttribute QueryingAA,
const Value V,
bool  CheckBBLivenessOnly = false,
DepClassTy  LivenessDepClass = DepClassTy::OPTIONAL,
bool  IgnoreDroppableUses = true,
function_ref< bool(const Use &OldU, const Use &NewU)>  EquivalentUseCB = nullptr 
)

Check Pred on all (transitive) uses of V.

This method will evaluate Pred on all (transitive) uses of the associated value and return true if Pred holds every time. If uses are skipped in favor of equivalent ones, e.g., if we look through memory, the EquivalentUseCB will be used to give the caller an idea what original used was replaced by a new one (or new ones). The visit is cut short if EquivalentUseCB returns false and the function will return false as well.

Definition at line 1275 of file Attributor.cpp.

References llvm::dbgs(), llvm::IRPosition::function(), llvm::IRPosition::getAnchorScope(), llvm::AbstractAttribute::getIRPosition(), llvm::Value::getName(), llvm::AA::getPotentialCopiesOfStoredValue(), llvm::SmallPtrSetImpl< PtrType >::insert(), isAssumedDead(), LLVM_DEBUG, llvm::NONE, llvm::SmallVectorImpl< T >::pop_back_val(), SI, llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::size(), llvm::Value::use_empty(), and llvm::Value::uses().

◆ createShallowWrapper()

void Attributor::createShallowWrapper ( Function F)
static

Create a shallow wrapper for F such that F has internal linkage afterwards.

It also sets the original F 's name to anonymous

A wrapper is a function with the same type (and attributes) as F that will only call F and return the result, if any.

Assuming the declaration of looks like: rty F(aty0 arg0, ..., atyN argN);

The wrapper will then look as follows: rty wrapper(aty0 arg0, ..., atyN argN) { return F(arg0, ..., argN); }

Definition at line 2210 of file Attributor.cpp.

References llvm::CallBase::addFnAttr(), Arg, llvm::AMDGPU::HSAMD::Kernel::Key::Args, assert(), llvm::BasicBlock::Create(), llvm::Function::Create(), llvm::CallInst::Create(), llvm::ReturnInst::Create(), F, getName(), llvm::Value::getType(), llvm::GlobalValue::InternalLinkage, llvm::Type::isVoidTy(), M, llvm::CallInst::setTailCall(), and Wrapper.

Referenced by runAttributorOnFunctions().

◆ deleteAfterManifest() [1/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 1599 of file Attributor.h.

References BB.

◆ deleteAfterManifest() [2/3]

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

Record that F is deleted after information was manifested.

Definition at line 1608 of file Attributor.h.

References llvm::AttributorConfig::DeleteFns, llvm::errs(), and F.

◆ deleteAfterManifest() [3/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 1595 of file Attributor.h.

References I.

◆ emitRemark() [1/2]

template<typename RemarkKind , typename RemarkCallBack >
void llvm::Attributor::emitRemark ( Function F,
StringRef  RemarkName,
RemarkCallBack &&  RemarkCB 
) const
inline

Emit a remark on a function.

Definition at line 1765 of file Attributor.h.

References F, llvm::AttributorConfig::OREGetter, llvm::AttributorConfig::PassName, and llvm::StringRef::startswith().

◆ emitRemark() [2/2]

template<typename RemarkKind , typename RemarkCallBack >
void llvm::Attributor::emitRemark ( Instruction I,
StringRef  RemarkName,
RemarkCallBack &&  RemarkCB 
) const
inline

Emit a remark generically.

This template function can be used to generically emit a remark. The RemarkKind should be one of the following:

The remark is built using a callback function RemarkCB that takes a RemarkKind as input and returns a RemarkKind.

Definition at line 1744 of file Attributor.h.

References F, I, llvm::AttributorConfig::OREGetter, llvm::AttributorConfig::PassName, and llvm::StringRef::startswith().

◆ getAAFor()

template<typename AAType >
const AAType& llvm::Attributor::getAAFor ( const AbstractAttribute QueryingAA,
const IRPosition IRP,
DepClassTy  DepClass 
)
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 DepClass enum is set to DepClassTy::None 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 1309 of file Attributor.h.

◆ getAndUpdateAAFor()

template<typename AAType >
const AAType& llvm::Attributor::getAndUpdateAAFor ( const AbstractAttribute QueryingAA,
const IRPosition IRP,
DepClassTy  DepClass 
)
inline

Similar to getAAFor but the return abstract attribute will be updated (via AbstractAttribute::update) even if it is found in the cache.

This is especially useful for AAIsDead as changes in liveness can make updates possible/useful that were not happening before as the abstract attribute was assumed dead.

Definition at line 1321 of file Attributor.h.

◆ getAssumedConstant() [1/2]

Optional< Constant * > Attributor::getAssumedConstant ( const IRPosition IRP,
const AbstractAttribute AA,
bool &  UsedAssumedInformation 
)

If IRP is assumed to be a constant, return it, if it is unclear yet, return None, otherwise return nullptr.

Definition at line 1019 of file Attributor.cpp.

References llvm::UndefValue::get(), llvm::IRPosition::getAssociatedType(), llvm::Optional< T >::getValue(), llvm::AA::getWithType(), llvm::Optional< T >::hasValue(), llvm::None, llvm::NONE, llvm::OPTIONAL, and recordDependence().

Referenced by getAssumedConstant().

◆ getAssumedConstant() [2/2]

Optional<Constant *> llvm::Attributor::getAssumedConstant ( const Value V,
const AbstractAttribute AA,
bool &  UsedAssumedInformation 
)
inline

Definition at line 1620 of file Attributor.h.

References getAssumedConstant(), and llvm::IRPosition::value().

◆ getAssumedSimplified() [1/3]

Optional<Value *> llvm::Attributor::getAssumedSimplified ( const IRPosition IRP,
const AbstractAttribute AA,
bool &  UsedAssumedInformation 
)
inline

If V is assumed simplified, return it, if it is unclear yet, return None, otherwise return nullptr.

Definition at line 1628 of file Attributor.h.

Referenced by getAssumedSimplified(), identifyDefaultAbstractAttributes(), and translateArgumentToCallSiteContent().

◆ getAssumedSimplified() [2/3]

Optional< Value * > Attributor::getAssumedSimplified ( const IRPosition V,
const AbstractAttribute AA,
bool &  UsedAssumedInformation 
)

If V is assumed simplified, return it, if it is unclear yet, return None, otherwise return nullptr.

Same as the public version except that it can be used without recording dependences on any AA.

Definition at line 1057 of file Attributor.cpp.

References llvm::IRPosition::getAssociatedType(), llvm::IRPosition::getAssociatedValue(), llvm::AA::getWithType(), llvm::Optional< T >::hasValue(), llvm::None, llvm::NONE, llvm::OPTIONAL, and recordDependence().

◆ getAssumedSimplified() [3/3]

Optional<Value *> llvm::Attributor::getAssumedSimplified ( const Value V,
const AbstractAttribute AA,
bool &  UsedAssumedInformation 
)
inline

Definition at line 1633 of file Attributor.h.

References getAssumedSimplified(), and llvm::IRPosition::value().

◆ getDataLayout()

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

Return the data layout associated with the anchor scope.

Definition at line 2025 of file Attributor.h.

◆ getInfoCache()

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

Return the internal information cache.

Definition at line 1500 of file Attributor.h.

Referenced by getOrCreateAAFor().

◆ getOrCreateAAFor() [1/2]

template<typename AAType >
const AAType& llvm::Attributor::getOrCreateAAFor ( const IRPosition IRP)
inline

Definition at line 1420 of file Attributor.h.

References llvm::NONE.

◆ getOrCreateAAFor() [2/2]

template<typename AAType >
const AAType& llvm::Attributor::getOrCreateAAFor ( IRPosition  IRP,
const AbstractAttribute QueryingAA,
DepClassTy  DepClass,
bool  ForceUpdate = false,
bool  UpdateAfterInit = true 
)
inline

The version of getAAFor that allows to omit a querying abstract attribute.

Using this after Attributor started running is restricted to only the Attributor itself. Initial seeding of AAs can be done via this function. NOTE: ForceUpdate is ignored in any stage other than the update stage.

Definition at line 1333 of file Attributor.h.

References llvm::AttributorConfig::Allowed, llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::count(), llvm::SetVector< T, Vector, Set >::count(), llvm::IRPosition::getAnchorScope(), llvm::IRPosition::getAssociatedFunction(), getInfoCache(), llvm::Function::hasFnAttribute(), llvm::InformationCache::isInModuleSlice(), isModulePass(), llvm::MaxInitializationChainLength, recordDependence(), registerAA(), and llvm::IRPosition::stripCallBaseContext().

◆ hasSimplificationCallback()

bool llvm::Attributor::hasSimplificationCallback ( const IRPosition IRP)
inline

Return true if there is a simplification callback for IRP.

Definition at line 1660 of file Attributor.h.

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

References AnnotateDeclarationCallSites, Arg, llvm::IRPosition::argument(), assert(), llvm::MCID::Call, Callee, llvm::IRPosition::callsite_argument(), llvm::IRPosition::callsite_function(), llvm::IRPosition::callsite_returned(), checkForAllInstructionsImpl(), E, EnableHeapToStack, F, llvm::IRPosition::function(), getAssumedSimplified(), llvm::InformationCache::getOpcodeInstMapForFunction(), llvm::getPointerOperand(), llvm::Use::getUser(), I, llvm::IRPosition::inst(), isModulePass(), llvm::SPII::Load, llvm::IRPosition::returned(), SimplifyAllLoads, llvm::SPII::Store, Success, and llvm::IRPosition::value().

Referenced by markLiveInternalFunction().

◆ internalizeFunction()

Function * Attributor::internalizeFunction ( Function F,
bool  Force = false 
)
static

Make another copy of the function F such that the copied version has internal linkage afterwards and can be analysed.

Then we replace all uses of the original function to the copied one

Only non-locally linked functions that have linkonce_odr or weak_odr linkage can be internalized because these linkages guarantee that other definitions with the same name have the same semantics as this one.

This will only be run if the attributor-allow-deep-wrappers option is set, or if the function is called with Force set to true.

If the function F failed to be internalized the return value will be a null pointer.

Definition at line 2264 of file Attributor.cpp.

References AllowDeepWrapper, F, internalizeFunctions(), and isInternalizable().

Referenced by runAttributorOnFunctions().

◆ internalizeFunctions()

bool Attributor::internalizeFunctions ( SmallPtrSetImpl< Function * > &  FnSet,
DenseMap< Function *, Function * > &  FnMap 
)
static

Make copies of each function in the set FnSet such that the copied version has internal linkage afterwards and can be analysed.

Then we replace all uses of the original function to the copied one. The map FnMap contains a mapping of functions to their internalized versions.

Only non-locally linked functions that have linkonce_odr or weak_odr linkage can be internalized because these linkages guarantee that other definitions with the same name have the same semantics as this one.

This version will internalize all the functions in the set FnSet at once and then replace the uses. This prevents internalized functions being called by external functions when there is an internalized version in the module.

Definition at line 2277 of file Attributor.cpp.

References llvm::GlobalObject::addMetadata(), Arg, llvm::Function::arg_begin(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::clear(), llvm::CloneFunctionInto(), llvm::Function::Create(), llvm::GlobalValue::DefaultVisibility, F, llvm::Use::getUser(), llvm::GlobalObject::hasMetadata(), isInternalizable(), llvm::LocalChangesOnly, llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::lookup(), M, llvm::GlobalValue::PrivateLinkage, llvm::GlobalValue::setDSOLocal(), llvm::GlobalValue::setLinkage(), and llvm::GlobalValue::setVisibility().

Referenced by internalizeFunction(), and llvm::OpenMPOptPass::run().

◆ isAssumedDead() [1/5]

bool Attributor::isAssumedDead ( const AbstractAttribute AA,
const AAIsDead LivenessAA,
bool &  UsedAssumedInformation,
bool  CheckBBLivenessOnly = false,
DepClassTy  DepClass = DepClassTy::OPTIONAL 
)

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

If LivenessAA is not provided it is queried.

Definition at line 1114 of file Attributor.cpp.

References llvm::SetVector< T, Vector, Set >::count(), and llvm::IRPosition::getAnchorScope().

Referenced by checkForAllCallSites(), checkForAllReadWriteInstructions(), checkForAllUses(), and isAssumedDead().

◆ isAssumedDead() [2/5]

bool Attributor::isAssumedDead ( const BasicBlock BB,
const AbstractAttribute QueryingAA,
const AAIsDead FnLivenessAA,
DepClassTy  DepClass = DepClassTy::OPTIONAL 
)

Return true if BB is assumed dead.

If LivenessAA is not provided it is queried.

Definition at line 1259 of file Attributor.cpp.

References BB, llvm::IRPosition::function(), llvm::AAIsDead::isAssumedDead(), llvm::NONE, and recordDependence().

◆ isAssumedDead() [3/5]

bool Attributor::isAssumedDead ( const Instruction I,
const AbstractAttribute QueryingAA,
const AAIsDead LivenessAA,
bool &  UsedAssumedInformation,
bool  CheckBBLivenessOnly = false,
DepClassTy  DepClass = DepClassTy::OPTIONAL 
)

◆ isAssumedDead() [4/5]

bool Attributor::isAssumedDead ( const IRPosition IRP,
const AbstractAttribute QueryingAA,
const AAIsDead FnLivenessAA,
bool &  UsedAssumedInformation,
bool  CheckBBLivenessOnly = false,
DepClassTy  DepClass = DepClassTy::OPTIONAL 
)

◆ isAssumedDead() [5/5]

bool Attributor::isAssumedDead ( const Use U,
const AbstractAttribute QueryingAA,
const AAIsDead FnLivenessAA,
bool &  UsedAssumedInformation,
bool  CheckBBLivenessOnly = false,
DepClassTy  DepClass = DepClassTy::OPTIONAL 
)

◆ isFunctionIPOAmendable()

bool llvm::Attributor::isFunctionIPOAmendable ( const Function F)
inline

Determine whether the function F is IPO amendable.

If a function is exactly defined or it has alwaysinline attribute and is viable to be inlined, we say it is IPO amendable

Definition at line 1526 of file Attributor.h.

References F.

◆ isInternalizable()

bool Attributor::isInternalizable ( Function F)
static

Returns true if the function F can be internalized.

i.e. it has a compatible linkage.

Definition at line 2257 of file Attributor.cpp.

References F, and llvm::GlobalValue::isInterposableLinkage().

Referenced by internalizeFunction(), internalizeFunctions(), and llvm::OpenMPOptPass::run().

◆ isModulePass()

bool llvm::Attributor::isModulePass ( ) const
inline

Return true if this is a module pass, false otherwise.

Definition at line 1503 of file Attributor.h.

References llvm::AttributorConfig::IsModulePass.

Referenced by getOrCreateAAFor(), and identifyDefaultAbstractAttributes().

◆ isRunOn()

bool llvm::Attributor::isRunOn ( Function Fn) const
inline

Return true if we derive attributes for Fn.

Definition at line 1506 of file Attributor.h.

References llvm::SetVector< T, Vector, Set >::count(), and llvm::SetVector< T, Vector, Set >::empty().

◆ isValidFunctionSignatureRewrite()

bool Attributor::isValidFunctionSignatureRewrite ( Argument Arg,
ArrayRef< Type * >  ReplacementTypes 
)

◆ lookupAAFor()

template<typename AAType >
AAType* llvm::Attributor::lookupAAFor ( const IRPosition IRP,
const AbstractAttribute QueryingAA = nullptr,
DepClassTy  DepClass = DepClassTy::OPTIONAL,
bool  AllowInvalidState = false 
)
inline

Return the attribute of AAType for IRP if existing and valid.

This also allows non-AA users lookup.

Definition at line 1428 of file Attributor.h.

References llvm::NONE, and recordDependence().

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

References assert(), llvm::AttributorConfig::DefaultInitializeLiveInternals, F, and identifyDefaultAbstractAttributes().

◆ 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 DepClass enum passed to the method set to None. 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 2767 of file Attributor.cpp.

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

Referenced by getAssumedConstant(), getAssumedSimplified(), getOrCreateAAFor(), isAssumedDead(), and lookupAAFor().

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

References assert(), llvm::AADepGraphNode::Deps, llvm::REQUIRED, and llvm::AADepGraph::SyntheticRoot.

Referenced by getOrCreateAAFor().

◆ registerForUpdate()

void Attributor::registerForUpdate ( AbstractAttribute AA)

Allows a query AA to request an update if a new query was received.

Definition at line 1777 of file Attributor.cpp.

References assert().

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

References Arg, llvm::Function::arg_size(), assert(), llvm::dbgs(), isValidFunctionSignatureRewrite(), LLVM_DEBUG, move, llvm::SmallVectorImpl< T >::resize(), and llvm::ArrayRef< T >::size().

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

◆ registerManifestAddedBasicBlock()

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

Definition at line 1603 of file Attributor.h.

References BB.

◆ registerSimplificationCallback()

void llvm::Attributor::registerSimplificationCallback ( const IRPosition IRP,
const SimplifictionCallbackTy CB 
)
inline

Definition at line 1654 of file Attributor.h.

◆ removeCallSite()

void llvm::Attributor::removeCallSite ( CallInst CI)
inline

Helper function to remove callsite.

Definition at line 1543 of file Attributor.h.

References llvm::AttributorConfig::CGUpdater, and llvm::CallGraphUpdater::removeCallSite().

◆ run()

ChangeStatus Attributor::run ( )

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

\Returns CHANGED if the IR was changed, otherwise UNCHANGED.

Definition at line 2142 of file Attributor.cpp.

References DumpDepGraph, llvm::AADepGraph::dumpGraph(), llvm::AttributorCallGraph::populateAll(), llvm::AADepGraph::print(), llvm::AttributorCallGraph::print(), PrintCallGraph, PrintDependencies, ViewDepGraph, and llvm::AADepGraph::viewGraph().

◆ translateArgumentToCallSiteContent()

Optional< Value * > Attributor::translateArgumentToCallSiteContent ( Optional< Value * >  V,
CallBase CB,
const AbstractAttribute AA,
bool &  UsedAssumedInformation 
)

Translate V from the callee context into the call site context.

Definition at line 1089 of file Attributor.cpp.

References Arg, llvm::IRPosition::callsite_argument(), getAssumedSimplified(), llvm::CallBase::getCalledFunction(), and llvm::Optional< T >::hasValue().

Member Data Documentation

◆ Allocator

BumpPtrAllocator& llvm::Attributor::Allocator

The allocator used to allocate memory, e.g. for AbstractAttributes.

Definition at line 2028 of file Attributor.h.


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