|
LLVM 23.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. | |
| LLVM_ABI 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. | |
| bool | isFunctionScope () const |
| Return true if this is a function or call site position. | |
| 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. | |
| Value * | getAttrListAnchor () const |
| Return the value attributes are attached to. | |
| AttributeList | getAttrList () const |
| Return the attributes associated with this function or call site scope. | |
| void | setAttrList (const AttributeList &AttrList) const |
| Update the attributes associated with this function or call site scope. | |
| unsigned | getNumArgs () const |
| Return the number of arguments associated with this function or call site scope. | |
| Value * | getArg (unsigned ArgNo) const |
Return theargument ArgNo associated with this function or call site scope. | |
| Kind | getPositionKind () const |
| Return the associated position kind. | |
| 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 LLVM_ABI const IRPosition | EmptyKey |
| Special DenseMap key values. | |
| static LLVM_ABI 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 605 of file Attributor.h.
Definition at line 608 of file Attributor.h.
| enum llvm::IRPosition::Kind : char |
The positions we distinguish in the IR.
Definition at line 611 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 626 of file Attributor.h.
References verify.
Referenced by llvm::AbstractAttribute::AbstractAttribute(), argument(), callsite_argument(), callsite_argument(), callsite_function(), callsite_returned(), function(), function_scope(), llvm::AbstractAttribute::getIRPosition(), llvm::AbstractAttribute::getIRPosition(), inst(), llvm::AbstractAttribute::isValidIRPositionForInit(), llvm::AbstractAttribute::isValidIRPositionForUpdate(), operator!=(), operator==(), returned(), stripCallBaseContext(), and value().
|
inlinestatic |
Create a position describing the argument Arg.
CBContext is used for call base specific analysis.
Definition at line 662 of file Attributor.h.
References IRP_ARGUMENT, and IRPosition().
Referenced by llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::AANoCapture::isImpliedByIR(), llvm::SubsumingPositionIterator::SubsumingPositionIterator(), and value().
|
inlinestatic |
Create a position describing the argument of ACS at position ArgNo.
Definition at line 685 of file Attributor.h.
References callsite_argument(), llvm::cast(), 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 678 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 668 of file Attributor.h.
References IRP_CALL_SITE, and IRPosition().
Referenced by llvm::Attributor::checkForAllCallees(), 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 673 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 648 of file Attributor.h.
References F, IRP_FUNCTION, and IRPosition().
Referenced by llvm::Attributor::checkForAllInstructions(), llvm::Attributor::checkForAllReadWriteInstructions(), llvm::Attributor::checkForAllUses(), function_scope(), llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::Attributor::isAssumedDead(), 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 701 of file Attributor.h.
References assert(), callsite_function(), llvm::cast(), function(), getAnchorValue(), getAssociatedFunction(), IRPosition(), and isAnyCallSitePosition().
|
inline |
Return the Function surrounding the anchor value.
Definition at line 777 of file Attributor.h.
References llvm::cast(), getAnchorValue(), and llvm::isa().
Referenced by llvm::AAInterFnReachability::canReach(), llvm::Attributor::checkForAllUses(), getAssociatedFunction(), llvm::Attributor::getAssumedSimplifiedValues(), llvm::Attributor::isAssumedDead(), llvm::Attributor::isAssumedDead(), llvm::Attributor::isAssumedDead(), llvm::AANoAlias::isImpliedByIR(), llvm::AANonNull::isImpliedByIR(), llvm::Attributor::shouldInitialize(), llvm::Attributor::shouldUpdateAA(), 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 722 of file Attributor.h.
References llvm_unreachable.
Referenced by function_scope(), getAnchorScope(), getArg(), getAssociatedArgument(), getAssociatedFunction(), getAssociatedValue(), getAttrList(), getAttrListAnchor(), getCtxI(), getNumArgs(), llvm::Attributor::hasAttr(), llvm::AAWillReturn::isImpliedByIR(), llvm::AAGlobalValueInfo::isValidIRPositionForInit(), llvm::AAIsDead::isValidIRPositionForInit(), llvm::Attributor::manifestAttrs(), llvm::operator<<(), setAttrList(), llvm::Attributor::shouldUpdateAA(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
Return theargument ArgNo associated with this function or call site scope.
Definition at line 891 of file Attributor.h.
References assert(), llvm::dyn_cast(), getAnchorValue(), llvm::Function::getArg(), getAssociatedFunction(), getPositionKind(), IRP_CALL_SITE, and IRP_FUNCTION.
| Argument * IRPosition::getAssociatedArgument | ( | ) | const |
Return the associated argument, if any.
Definition at line 1078 of file Attributor.cpp.
References llvm::Function::arg_size(), assert(), llvm::cast(), llvm::dyn_cast_if_present(), 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(), llvm::AANoCapture::isImpliedByIR(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inline |
Return the associated function, if any.
Definition at line 736 of file Attributor.h.
References llvm::dyn_cast(), llvm::dyn_cast_if_present(), getAnchorScope(), getAnchorValue(), and getAssociatedArgument().
Referenced by llvm::Attributor::checkForAllCallSites(), llvm::Attributor::checkForAllInstructions(), llvm::Attributor::checkForAllReadWriteInstructions(), llvm::Attributor::checkForAllReturnedValues(), function_scope(), getArg(), getAssociatedType(), getAttrList(), getAttrListAnchor(), llvm::DOTGraphTraits< AttributorCallGraph * >::getNodeLabel(), getNumArgs(), llvm::AANoCapture::isImpliedByIR(), llvm::AANonNull::isImpliedByIR(), llvm::AANoSync::isImpliedByIR(), llvm::AAIsDead::isLiveInstSet(), llvm::AbstractAttribute::isValidIRPositionForUpdate(), setAttrList(), and llvm::Attributor::shouldUpdateAA().
|
inline |
Return the type this abstract attribute is associated with.
Definition at line 812 of file Attributor.h.
References getAssociatedFunction(), getAssociatedValue(), getPositionKind(), llvm::Function::getReturnType(), llvm::Value::getType(), and IRP_RETURNED.
Referenced by llvm::AAValueConstantRange::AAValueConstantRange(), llvm::AAValueSimplify::AAValueSimplify(), llvm::AAPotentialValues::getSingleValue(), llvm::AANonNull::isImpliedByIR(), llvm::AAAddressSpace::isValidIRPositionForInit(), llvm::AAAlign::isValidIRPositionForInit(), llvm::AAAllocationInfo::isValidIRPositionForInit(), llvm::AADereferenceable::isValidIRPositionForInit(), llvm::AAInvariantLoadPointer::isValidIRPositionForInit(), llvm::AAMemoryBehavior::isValidIRPositionForInit(), llvm::AAMemoryLocation::isValidIRPositionForInit(), llvm::AANoAlias::isValidIRPositionForInit(), llvm::AANoAliasAddrSpace::isValidIRPositionForInit(), llvm::AANoCapture::isValidIRPositionForInit(), llvm::AANoFPClass::isValidIRPositionForInit(), llvm::AANoFree::isValidIRPositionForInit(), llvm::AANonNull::isValidIRPositionForInit(), llvm::AANoSync::isValidIRPositionForInit(), llvm::AAPointerInfo::isValidIRPositionForInit(), llvm::AAPotentialConstantValues::isValidIRPositionForInit(), llvm::AAPrivatizablePtr::isValidIRPositionForInit(), llvm::AAUnderlyingObjects::isValidIRPositionForInit(), and llvm::AAValueConstantRange::isValidIRPositionForInit().
|
inline |
Return the value this abstract attribute is associated with.
Definition at line 803 of file Attributor.h.
References assert(), llvm::cast(), getAnchorValue(), getCallSiteArgNo(), and llvm::isa().
Referenced by llvm::Attributor::changeAfterManifest(), getAssociatedType(), llvm::AAPotentialConstantValues::getAssumedConstant(), llvm::AAValueConstantRange::getAssumedConstant(), llvm::Attributor::getAssumedConstant(), llvm::Attributor::getAssumedSimplified(), llvm::Attributor::getAssumedSimplifiedValues(), llvm::Attributor::getAttrsFromAssumes(), llvm::Attributor::isAssumedDead(), llvm::AANoAlias::isImpliedByIR(), llvm::AANoCapture::isImpliedByIR(), llvm::AANonNull::isImpliedByIR(), llvm::AANoUndef::isImpliedByIR(), llvm::IRAttribute< AK, BaseType, AAType >::isImpliedByIR(), llvm::operator<<(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inline |
Return the index in the attribute list for this position.
Definition at line 837 of file Attributor.h.
References getCalleeArgNo(), getCallSiteArgNo(), getPositionKind(), IRP_ARGUMENT, IRP_CALL_SITE, IRP_CALL_SITE_ARGUMENT, IRP_CALL_SITE_RETURNED, IRP_FLOAT, IRP_FUNCTION, IRP_INVALID, IRP_RETURNED, and llvm_unreachable.
|
inline |
Return the attributes associated with this function or call site scope.
Definition at line 865 of file Attributor.h.
References llvm::dyn_cast(), getAnchorValue(), getAssociatedFunction(), and llvm::Function::getAttributes().
Referenced by llvm::Attributor::identifyDefaultAbstractAttributes().
|
inline |
Return the value attributes are attached to.
Definition at line 858 of file Attributor.h.
References llvm::dyn_cast(), getAnchorValue(), and getAssociatedFunction().
|
inline |
Get the call base context from the position.
Definition at line 951 of file Attributor.h.
Referenced by 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 823 of file Attributor.h.
Referenced by llvm::AANoCapture::determineFunctionCaptureCapabilities(), and getAttrIdx().
|
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 832 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 789 of file Attributor.h.
References llvm::dyn_cast(), F, getAnchorValue(), and I.
Referenced by llvm::Attributor::changeAfterManifest(), llvm::Attributor::getAssumedSimplifiedValues(), llvm::Attributor::getAttrsFromAssumes(), llvm::Attributor::isAssumedDead(), llvm::AANonNull::isImpliedByIR(), llvm::AAIndirectCallInfo::isValidIRPositionForInit(), and llvm::AbstractAttribute::print().
|
inline |
Return the number of arguments associated with this function or call site scope.
Definition at line 880 of file Attributor.h.
References llvm::Function::arg_size(), assert(), llvm::dyn_cast(), getAnchorValue(), getAssociatedFunction(), getPositionKind(), IRP_CALL_SITE, and IRP_FUNCTION.
|
inline |
Return the associated position kind.
Definition at line 901 of file Attributor.h.
References IRP_ARGUMENT, IRP_CALL_SITE, IRP_CALL_SITE_ARGUMENT, IRP_CALL_SITE_RETURNED, IRP_FLOAT, IRP_FUNCTION, IRP_INVALID, IRP_RETURNED, and llvm::isa().
Referenced by llvm::Attributor::changeAfterManifest(), llvm::AAExecutionDomain::createForPosition(), getArg(), getAssociatedArgument(), getAssociatedType(), llvm::Attributor::getAssumedSimplified(), llvm::Attributor::getAssumedSimplifiedValues(), getAttrIdx(), llvm::Attributor::getAttrsFromAssumes(), getNumArgs(), isAnyCallSitePosition(), isArgumentPosition(), llvm::Attributor::isAssumedDead(), isAssumedReadOnlyOrReadNone(), isFnInterfaceKind(), isFunctionScope(), llvm::AANoAlias::isImpliedByIR(), llvm::AANoCapture::isImpliedByIR(), llvm::AANonNull::isImpliedByIR(), llvm::AANoUndef::isImpliedByIR(), llvm::AAGlobalValueInfo::isValidIRPositionForInit(), llvm::AAIndirectCallInfo::isValidIRPositionForInit(), llvm::AAIsDead::isValidIRPositionForInit(), llvm::operator<<(), llvm::Attributor::shouldUpdateAA(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inline |
Check if the position has any call base context.
Definition at line 954 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 641 of file Attributor.h.
References I, IRP_FLOAT, and IRPosition().
Referenced by checkForAllInstructionsImpl(), llvm::Attributor::checkForAllReadWriteInstructions(), llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::Attributor::isAssumedDead(), and llvm::Attributor::isAssumedDead().
|
inline |
Definition at line 921 of file Attributor.h.
References getPositionKind(), IRP_CALL_SITE, IRP_CALL_SITE_ARGUMENT, and IRP_CALL_SITE_RETURNED.
Referenced by function_scope(), and llvm::Attributor::shouldUpdateAA().
|
inline |
Return true if the position is an argument or call site argument.
Definition at line 933 of file Attributor.h.
References getPositionKind(), IRP_ARGUMENT, and IRP_CALL_SITE_ARGUMENT.
Referenced by llvm::AANoCapture::isImpliedByIR().
|
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 754 of file Attributor.h.
References getPositionKind(), IRP_ARGUMENT, IRP_FUNCTION, and IRP_RETURNED.
Referenced by llvm::AbstractAttribute::isValidIRPositionForUpdate().
|
inline |
Return true if this is a function or call site position.
Definition at line 766 of file Attributor.h.
References getPositionKind(), IRP_CALL_SITE, and IRP_FUNCTION.
Referenced by llvm::AAMemoryBehavior::isValidIRPositionForInit(), llvm::AAMemoryLocation::isValidIRPositionForInit(), llvm::AANoFree::isValidIRPositionForInit(), and llvm::AANoSync::isValidIRPositionForInit().
|
inline |
}
Conversion into a void * to allow reuse of pointer hashing.
Definition at line 964 of file Attributor.h.
|
inline |
Definition at line 714 of file Attributor.h.
References IRPosition(), and RHS.
|
inline |
Definition at line 711 of file Attributor.h.
References IRPosition(), and RHS.
|
inlinestatic |
Create a position describing the returned value of F.
CBContext is used for call base specific analysis.
Definition at line 655 of file Attributor.h.
References F, IRP_RETURNED, and IRPosition().
Referenced by llvm::Attributor::checkForAllReturnedValues(), llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::Attributor::isAssumedDead(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().
|
inline |
Update the attributes associated with this function or call site scope.
Definition at line 872 of file Attributor.h.
References llvm::dyn_cast(), getAnchorValue(), getAssociatedFunction(), and llvm::Function::setAttributes().
|
inline |
Return the same position without the call base context.
Definition at line 944 of file Attributor.h.
References IRPosition().
Referenced by llvm::Attributor::getOrCreateAAFor().
|
inlinestatic |
Create a position describing the value of V.
Definition at line 629 of file Attributor.h.
References argument(), callsite_returned(), llvm::dyn_cast(), IRP_FLOAT, and IRPosition().
Referenced by clampReturnedValueStates(), llvm::Attributor::getAssumedConstant(), llvm::Attributor::getAssumedSimplified(), llvm::Attributor::getAssumedSimplifiedValues(), 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 959 of file Attributor.h.
Referenced by llvm::DenseMapInfo< IRPosition >::getEmptyKey().
|
static |
Definition at line 960 of file Attributor.h.
Referenced by llvm::DenseMapInfo< IRPosition >::getTombstoneKey().