LLVM 17.0.0git
|
Helper to describe and deal with positions in the LLVM-IR. More...
#include "llvm/Transforms/IPO/Attributor.h"
Public Types | |
enum | Kind : char { IRP_INVALID , IRP_FLOAT , IRP_RETURNED , IRP_CALL_SITE_RETURNED , IRP_FUNCTION , IRP_CALL_SITE , IRP_ARGUMENT , IRP_CALL_SITE_ARGUMENT } |
The positions we distinguish in the IR. More... | |
using | CallBaseContext = CallBase |
Public Member Functions | |
IRPosition () | |
Default constructor available to create invalid positions implicitly. | |
bool | operator== (const IRPosition &RHS) const |
bool | operator!= (const IRPosition &RHS) const |
Value & | getAnchorValue () const |
Return the value this abstract attribute is anchored with. | |
Function * | getAssociatedFunction () const |
Return the associated function, if any. | |
Argument * | getAssociatedArgument () const |
Return the associated argument, if any. | |
bool | isFnInterfaceKind () const |
Return true if the position refers to a function interface, that is the function scope, the function return, or an argument. | |
Function * | getAnchorScope () const |
Return the Function surrounding the anchor value. | |
Instruction * | getCtxI () const |
Return the context instruction, if any. | |
Value & | getAssociatedValue () const |
Return the value this abstract attribute is associated with. | |
Type * | getAssociatedType () const |
Return the type this abstract attribute is associated with. | |
int | getCalleeArgNo () const |
Return the callee argument number of the associated value if it is an argument or call site argument, otherwise a negative value. | |
int | getCallSiteArgNo () const |
Return the call site argument number of the associated value if it is an argument or call site argument, otherwise a negative value. | |
unsigned | getAttrIdx () const |
Return the index in the attribute list for this position. | |
Kind | getPositionKind () const |
Return the associated position kind. | |
bool | hasAttr (ArrayRef< Attribute::AttrKind > AKs, bool IgnoreSubsumingPositions=false, Attributor *A=nullptr) const |
TODO: Figure out if the attribute related helper functions should live here or somewhere else. | |
void | getAttrs (ArrayRef< Attribute::AttrKind > AKs, SmallVectorImpl< Attribute > &Attrs, bool IgnoreSubsumingPositions=false, Attributor *A=nullptr) const |
Return the attributes of any kind in AKs existing in the IR at a position that will affect this one. | |
void | removeAttrs (ArrayRef< Attribute::AttrKind > AKs) const |
Remove the attribute of kind AKs existing in the IR at this position. | |
bool | isAnyCallSitePosition () const |
bool | isArgumentPosition () const |
Return true if the position is an argument or call site argument. | |
IRPosition | stripCallBaseContext () const |
Return the same position without the call base context. | |
const CallBaseContext * | getCallBaseContext () const |
Get the call base context from the position. | |
bool | hasCallBaseContext () const |
Check if the position has any call base context. | |
operator void * () const | |
} | |
Static Public Member Functions | |
static const IRPosition | value (const Value &V, const CallBaseContext *CBContext=nullptr) |
Create a position describing the value of V . | |
static const IRPosition | inst (const Instruction &I, const CallBaseContext *CBContext=nullptr) |
Create a position describing the instruction I . | |
static const IRPosition | function (const Function &F, const CallBaseContext *CBContext=nullptr) |
Create a position describing the function scope of F . | |
static const IRPosition | returned (const Function &F, const CallBaseContext *CBContext=nullptr) |
Create a position describing the returned value of F . | |
static const IRPosition | argument (const Argument &Arg, const CallBaseContext *CBContext=nullptr) |
Create a position describing the argument Arg . | |
static const IRPosition | callsite_function (const CallBase &CB) |
Create a position describing the function scope of CB . | |
static const IRPosition | callsite_returned (const CallBase &CB) |
Create a position describing the returned value of CB . | |
static const IRPosition | callsite_argument (const CallBase &CB, unsigned ArgNo) |
Create a position describing the argument of CB at position ArgNo . | |
static const IRPosition | callsite_argument (AbstractCallSite ACS, unsigned ArgNo) |
Create a position describing the argument of ACS at position ArgNo . | |
static const IRPosition | function_scope (const IRPosition &IRP, const CallBaseContext *CBContext=nullptr) |
Create a position with function scope matching the "context" of IRP . | |
Static Public Attributes | |
static const IRPosition | EmptyKey |
Special DenseMap key values. | |
static const IRPosition | TombstoneKey |
Helper to describe and deal with positions in the LLVM-IR.
A position in the IR is described by an anchor value and an "offset" that could be the argument number, for call sites and arguments, or an indicator of the "position kind". The kinds, specified in the Kind enum below, include the locations in the attribute list, i.a., function scope and return value, as well as a distinction between call sites and functions. Finally, there are floating values that do not have a corresponding attribute list position.
Definition at line 558 of file Attributor.h.
Definition at line 561 of file Attributor.h.
enum llvm::IRPosition::Kind : char |
The positions we distinguish in the IR.
Definition at line 564 of file Attributor.h.
|
inline |
Default constructor available to create invalid positions implicitly.
All other positions need to be created explicitly through the appropriate static member function.
Definition at line 579 of file Attributor.h.
Referenced by argument(), callsite_argument(), callsite_function(), callsite_returned(), function(), inst(), returned(), and value().
|
inlinestatic |
Create a position describing the argument Arg
.
CBContext
is used for call base specific analysis.
Definition at line 615 of file Attributor.h.
References Arg, IRP_ARGUMENT, and IRPosition().
Referenced by llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::SubsumingPositionIterator::SubsumingPositionIterator(), and value().
|
inlinestatic |
Create a position describing the argument of ACS
at position ArgNo
.
Definition at line 638 of file Attributor.h.
References callsite_argument(), llvm::AbstractCallSite::getCallArgOperandNo(), llvm::AbstractCallSite::getInstruction(), llvm::AbstractCallSite::getNumArgOperands(), and IRPosition().
|
inlinestatic |
Create a position describing the argument of CB
at position ArgNo
.
Definition at line 631 of file Attributor.h.
References llvm::CallBase::getArgOperandUse(), IRP_CALL_SITE_ARGUMENT, and IRPosition().
Referenced by callsite_argument(), llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::Attributor::isAssumedDead(), llvm::SubsumingPositionIterator::SubsumingPositionIterator(), and llvm::Attributor::translateArgumentToCallSiteContent().
|
inlinestatic |
Create a position describing the function scope of CB
.
Definition at line 621 of file Attributor.h.
References IRP_CALL_SITE, and IRPosition().
Referenced by function_scope(), llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::AA::isNoSyncInst(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inlinestatic |
Create a position describing the returned value of CB
.
Definition at line 626 of file Attributor.h.
References IRP_CALL_SITE_RETURNED, and IRPosition().
Referenced by llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::Attributor::isAssumedDead(), and value().
|
inlinestatic |
Create a position describing the function scope of F
.
CBContext
is used for call base specific analysis.
Definition at line 601 of file Attributor.h.
References F, IRP_FUNCTION, and IRPosition().
Referenced by llvm::Attributor::checkForAllInstructions(), llvm::Attributor::checkForAllReadWriteInstructions(), llvm::Attributor::checkForAllReturnedValues(), llvm::Attributor::checkForAllReturnedValuesAndReturnInsts(), llvm::Attributor::checkForAllUses(), function_scope(), llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::Attributor::isAssumedDead(), isPotentiallyReachable(), llvm::AACallEdgeIterator::operator*(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inlinestatic |
Create a position with function scope matching the "context" of IRP
.
If IRP
is a call site (see isAnyCallSitePosition()) then the result will be a call site position, otherwise the function position of the associated function.
Definition at line 654 of file Attributor.h.
References assert(), callsite_function(), function(), getAnchorValue(), getAssociatedFunction(), and isAnyCallSitePosition().
|
inline |
Return the Function surrounding the anchor value.
Definition at line 718 of file Attributor.h.
References getAnchorValue().
Referenced by llvm::AAInterFnReachability::canReach(), llvm::Attributor::checkForAllUses(), getAssociatedFunction(), llvm::Attributor::getAssumedSimplifiedValues(), llvm::Attributor::getOrCreateAAFor(), llvm::IRAttribute< AK, BaseType >::initialize(), llvm::Attributor::isAssumedDead(), llvm::IRAttributeManifest::manifestAttrs(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inline |
Return the value this abstract attribute is anchored with.
The anchor value might not be the associated value if the latter is not sufficient to determine where arguments will be manifested. This is, so far, only the case for call site arguments as the value is not sufficient to pinpoint them. Instead, we can use the call site as an anchor.
Definition at line 675 of file Attributor.h.
References llvm_unreachable.
Referenced by function_scope(), getAnchorScope(), getAssociatedArgument(), getAssociatedFunction(), getAssociatedValue(), getCtxI(), llvm::IRAttributeManifest::manifestAttrs(), llvm::operator<<(), removeAttrs(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
Argument * IRPosition::getAssociatedArgument | ( | ) | const |
Return the associated argument, if any.
Definition at line 904 of file Attributor.cpp.
References llvm::Function::arg_size(), assert(), Callee, getAnchorValue(), llvm::Function::getArg(), llvm::AbstractCallSite::getCallArgOperandNo(), llvm::AbstractCallSite::getCallbackUses(), llvm::AbstractCallSite::getCalledFunction(), getCallSiteArgNo(), llvm::AbstractCallSite::getNumArgOperands(), getPositionKind(), IRP_ARGUMENT, and llvm::AbstractCallSite::isCallbackCall().
Referenced by getAssociatedFunction(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inline |
Return the associated function, if any.
Definition at line 689 of file Attributor.h.
References Arg, getAnchorScope(), getAnchorValue(), and getAssociatedArgument().
Referenced by llvm::Attributor::checkForAllCallSites(), llvm::Attributor::checkForAllInstructions(), llvm::Attributor::checkForAllReadWriteInstructions(), llvm::Attributor::checkForAllReturnedValues(), llvm::Attributor::checkForAllReturnedValuesAndReturnInsts(), function_scope(), getAssociatedType(), llvm::DOTGraphTraits< AttributorCallGraph * >::getNodeLabel(), llvm::Attributor::getOrCreateAAFor(), llvm::AAIsDead::isLiveInstSet(), and removeAttrs().
|
inline |
Return the type this abstract attribute is associated with.
Definition at line 753 of file Attributor.h.
References getAssociatedFunction(), getAssociatedValue(), getPositionKind(), llvm::Function::getReturnType(), llvm::Value::getType(), and IRP_RETURNED.
Referenced by llvm::AAPotentialValues::getSingleValue().
|
inline |
Return the value this abstract attribute is associated with.
Definition at line 744 of file Attributor.h.
References assert(), getAnchorValue(), and getCallSiteArgNo().
Referenced by llvm::Attributor::changeAfterManifest(), getAssociatedType(), llvm::AAValueConstantRange::getAssumedConstant(), llvm::AAPotentialConstantValues::getAssumedConstant(), llvm::Attributor::getAssumedConstant(), llvm::Attributor::getAssumedSimplified(), llvm::IRAttribute< AK, BaseType >::initialize(), llvm::Attributor::isAssumedDead(), llvm::operator<<(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inline |
Return the index in the attribute list for this position.
Definition at line 778 of file Attributor.h.
References llvm::AttributeList::FirstArgIndex, llvm::AttributeList::FunctionIndex, getCallSiteArgNo(), getPositionKind(), IRP_ARGUMENT, IRP_CALL_SITE, IRP_CALL_SITE_ARGUMENT, IRP_CALL_SITE_RETURNED, IRP_FLOAT, IRP_FUNCTION, IRP_INVALID, IRP_RETURNED, llvm_unreachable, and llvm::AttributeList::ReturnIndex.
Referenced by llvm::IRAttributeManifest::manifestAttrs(), and removeAttrs().
void IRPosition::getAttrs | ( | ArrayRef< Attribute::AttrKind > | AKs, |
SmallVectorImpl< Attribute > & | Attrs, | ||
bool | IgnoreSubsumingPositions = false , |
||
Attributor * | A = nullptr |
||
) | const |
Return the attributes of any kind in AKs
existing in the IR at a position that will affect this one.
While each position can only have a single attribute of any kind in AKs
, there are "subsuming" positions that could have an attribute as well. This method returns all attributes found in Attrs
.
IgnoreSubsumingPositions | Flag to determine if subsuming positions, e.g., the function position if this is an argument position, should be ignored. |
Definition at line 1122 of file Attributor.cpp.
References A.
|
inline |
Get the call base context from the position.
Definition at line 895 of file Attributor.h.
Referenced by llvm::Attributor::checkForAllReturnedValues(), llvm::DenseMapInfo< IRPosition >::getHashValue(), llvm::Attributor::isAssumedDead(), and llvm::operator<<().
|
inline |
Return the callee argument number of the associated value if it is an argument or call site argument, otherwise a negative value.
In contrast to getCallSiteArgNo
this method will always return the "argument number" from the perspective of the callee. This may not the same as the call site if this is a callback call.
Definition at line 764 of file Attributor.h.
|
inline |
Return the call site argument number of the associated value if it is an argument or call site argument, otherwise a negative value.
In contrast to getCalleArgNo
this method will always return the "operand number" from the perspective of the call site. This may not the same as the callee perspective if this is a callback call.
Definition at line 773 of file Attributor.h.
Referenced by llvm::Attributor::changeAfterManifest(), getAssociatedArgument(), getAssociatedValue(), getAttrIdx(), and llvm::operator<<().
|
inline |
Return the context instruction, if any.
Definition at line 730 of file Attributor.h.
References Arg, F, getAnchorValue(), and I.
Referenced by llvm::Attributor::changeAfterManifest(), llvm::Attributor::isAssumedDead(), and llvm::AbstractAttribute::print().
|
inline |
Return the associated position kind.
Definition at line 798 of file Attributor.h.
References IRP_ARGUMENT, IRP_CALL_SITE, IRP_CALL_SITE_ARGUMENT, IRP_CALL_SITE_RETURNED, IRP_FLOAT, IRP_FUNCTION, IRP_INVALID, and IRP_RETURNED.
Referenced by llvm::Attributor::changeAfterManifest(), llvm::AAExecutionDomain::createForPosition(), getAssociatedArgument(), getAssociatedType(), llvm::Attributor::getAssumedSimplified(), getAttrIdx(), isAnyCallSitePosition(), isArgumentPosition(), llvm::Attributor::isAssumedDead(), isAssumedReadOnlyOrReadNone(), isFnInterfaceKind(), llvm::IRAttributeManifest::manifestAttrs(), llvm::operator<<(), removeAttrs(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
bool IRPosition::hasAttr | ( | ArrayRef< Attribute::AttrKind > | AKs, |
bool | IgnoreSubsumingPositions = false , |
||
Attributor * | A = nullptr |
||
) | const |
TODO: Figure out if the attribute related helper functions should live here or somewhere else.
Return true if any kind in AKs
existing in the IR at a position that will affect this one. See also getAttrs(...).
IgnoreSubsumingPositions | Flag to determine if subsuming positions, e.g., the function position if this is an argument position, should be ignored. |
Definition at line 1102 of file Attributor.cpp.
References A.
|
inline |
Check if the position has any call base context.
Definition at line 898 of file Attributor.h.
Referenced by llvm::operator<<().
|
inlinestatic |
Create a position describing the instruction I
.
This is different from the value version because call sites are treated as intrusctions rather than their return value in this function.
Definition at line 594 of file Attributor.h.
References I, IRP_FLOAT, and IRPosition().
Referenced by checkForAllInstructionsImpl(), llvm::Attributor::checkForAllReadWriteInstructions(), llvm::Attributor::identifyDefaultAbstractAttributes(), and llvm::Attributor::isAssumedDead().
|
inline |
Definition at line 865 of file Attributor.h.
References getPositionKind(), IRP_CALL_SITE, IRP_CALL_SITE_ARGUMENT, and IRP_CALL_SITE_RETURNED.
Referenced by function_scope().
|
inline |
Return true if the position is an argument or call site argument.
Definition at line 877 of file Attributor.h.
References getPositionKind(), IRP_ARGUMENT, and IRP_CALL_SITE_ARGUMENT.
|
inline |
Return true if the position refers to a function interface, that is the function scope, the function return, or an argument.
Definition at line 706 of file Attributor.h.
References getPositionKind(), IRP_ARGUMENT, IRP_FUNCTION, and IRP_RETURNED.
Referenced by llvm::IRAttribute< AK, BaseType >::initialize().
|
inline |
}
Conversion into a void * to allow reuse of pointer hashing.
Definition at line 908 of file Attributor.h.
References llvm::PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info >::getOpaqueValue().
|
inline |
Definition at line 667 of file Attributor.h.
References RHS.
|
inline |
Definition at line 664 of file Attributor.h.
References RHS.
|
inline |
Remove the attribute of kind AKs
existing in the IR at this position.
Definition at line 844 of file Attributor.h.
References getAnchorValue(), getAssociatedFunction(), llvm::Function::getAttributes(), llvm::AttributeList::getAttributes(), getAttrIdx(), llvm::Value::getContext(), getPositionKind(), IRP_FLOAT, IRP_INVALID, llvm::AttributeList::removeAttributeAtIndex(), and llvm::Function::setAttributes().
|
inlinestatic |
Create a position describing the returned value of F
.
CBContext
is used for call base specific analysis.
Definition at line 608 of file Attributor.h.
References F, IRP_RETURNED, and IRPosition().
Referenced by llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::Attributor::isAssumedDead(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inline |
Return the same position without the call base context.
Definition at line 888 of file Attributor.h.
Referenced by llvm::Attributor::getOrCreateAAFor().
|
inlinestatic |
Create a position describing the value of V
.
Definition at line 582 of file Attributor.h.
References Arg, argument(), callsite_returned(), IRP_FLOAT, and IRPosition().
Referenced by clampReturnedValueStates(), llvm::Attributor::getAssumedConstant(), llvm::Attributor::getAssumedSimplified(), getPotentialCopiesOfMemoryValue(), llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::Attributor::isAssumedDead(), llvm::AA::isAssumedThreadLocalObject(), llvm::AA::isDynamicallyUnique(), llvm::AA::isPotentiallyAffectedByBarrier(), stripAndAccumulateOffsets(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
static |
Special DenseMap key values.
{
Definition at line 903 of file Attributor.h.
Referenced by llvm::DenseMapInfo< IRPosition >::getEmptyKey().
|
static |
Definition at line 904 of file Attributor.h.
Referenced by llvm::DenseMapInfo< IRPosition >::getTombstoneKey().