LLVM 20.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
llvm::IRPosition Struct Reference

Helper to describe and deal with positions in the LLVM-IR. More...

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

Inheritance diagram for llvm::IRPosition:
Inheritance graph
[legend]

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
 
ValuegetAnchorValue () const
 Return the value this abstract attribute is anchored with.
 
FunctiongetAssociatedFunction () const
 Return the associated function, if any.
 
ArgumentgetAssociatedArgument () 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.
 
FunctiongetAnchorScope () const
 Return the Function surrounding the anchor value.
 
InstructiongetCtxI () const
 Return the context instruction, if any.
 
ValuegetAssociatedValue () const
 Return the value this abstract attribute is associated with.
 
TypegetAssociatedType () 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.
 
ValuegetAttrListAnchor () 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.
 
ValuegetArg (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 CallBaseContextgetCallBaseContext () 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
 

Detailed Description

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

Member Typedef Documentation

◆ CallBaseContext

Definition at line 584 of file Attributor.h.

Member Enumeration Documentation

◆ Kind

The positions we distinguish in the IR.

Enumerator
IRP_INVALID 

An invalid position.

IRP_FLOAT 

A position that is not associated with a spot suitable for attributes.

This could be any value or instruction.

IRP_RETURNED 

An attribute for the function return value.

IRP_CALL_SITE_RETURNED 

An attribute for a call site return value.

IRP_FUNCTION 

An attribute for a function (scope).

IRP_CALL_SITE 

An attribute for a call site (function scope).

IRP_ARGUMENT 

An attribute for a function argument.

IRP_CALL_SITE_ARGUMENT 

An attribute for a call site argument.

Definition at line 587 of file Attributor.h.

Constructor & Destructor Documentation

◆ IRPosition()

llvm::IRPosition::IRPosition ( )
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 602 of file Attributor.h.

Referenced by argument(), callsite_argument(), callsite_function(), callsite_returned(), function(), inst(), returned(), and value().

Member Function Documentation

◆ argument()

static const IRPosition llvm::IRPosition::argument ( const Argument Arg,
const CallBaseContext CBContext = nullptr 
)
inlinestatic

Create a position describing the argument Arg.

CBContext is used for call base specific analysis.

Definition at line 638 of file Attributor.h.

References IRP_ARGUMENT, and IRPosition().

Referenced by llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::AANoCapture::isImpliedByIR(), llvm::SubsumingPositionIterator::SubsumingPositionIterator(), and value().

◆ callsite_argument() [1/2]

static const IRPosition llvm::IRPosition::callsite_argument ( AbstractCallSite  ACS,
unsigned  ArgNo 
)
inlinestatic

Create a position describing the argument of ACS at position ArgNo.

Definition at line 661 of file Attributor.h.

References callsite_argument(), llvm::AbstractCallSite::getCallArgOperandNo(), llvm::AbstractCallSite::getInstruction(), llvm::AbstractCallSite::getNumArgOperands(), and IRPosition().

◆ callsite_argument() [2/2]

static const IRPosition llvm::IRPosition::callsite_argument ( const CallBase CB,
unsigned  ArgNo 
)
inlinestatic

◆ callsite_function()

static const IRPosition llvm::IRPosition::callsite_function ( const CallBase CB)
inlinestatic

◆ callsite_returned()

static const IRPosition llvm::IRPosition::callsite_returned ( const CallBase CB)
inlinestatic

Create a position describing the returned value of CB.

Definition at line 649 of file Attributor.h.

References IRP_CALL_SITE_RETURNED, and IRPosition().

Referenced by llvm::Attributor::identifyDefaultAbstractAttributes(), llvm::Attributor::isAssumedDead(), and value().

◆ function()

static const IRPosition llvm::IRPosition::function ( const Function F,
const CallBaseContext CBContext = nullptr 
)
inlinestatic

◆ function_scope()

static const IRPosition llvm::IRPosition::function_scope ( const IRPosition IRP,
const CallBaseContext CBContext = nullptr 
)
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 677 of file Attributor.h.

References assert(), callsite_function(), function(), getAnchorValue(), getAssociatedFunction(), and isAnyCallSitePosition().

◆ getAnchorScope()

Function * llvm::IRPosition::getAnchorScope ( ) const
inline

◆ getAnchorValue()

Value & llvm::IRPosition::getAnchorValue ( ) const
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 698 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::AAIsDead::isValidIRPositionForInit(), llvm::AAGlobalValueInfo::isValidIRPositionForInit(), llvm::Attributor::manifestAttrs(), llvm::operator<<(), setAttrList(), llvm::Attributor::shouldUpdateAA(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().

◆ getArg()

Value * llvm::IRPosition::getArg ( unsigned  ArgNo) const
inline

Return theargument ArgNo associated with this function or call site scope.

Definition at line 867 of file Attributor.h.

References assert(), getAnchorValue(), llvm::Function::getArg(), getAssociatedFunction(), getPositionKind(), IRP_CALL_SITE, and IRP_FUNCTION.

◆ getAssociatedArgument()

Argument * IRPosition::getAssociatedArgument ( ) const

◆ getAssociatedFunction()

Function * llvm::IRPosition::getAssociatedFunction ( ) const
inline

◆ getAssociatedType()

Type * llvm::IRPosition::getAssociatedType ( ) const
inline

◆ getAssociatedValue()

Value & llvm::IRPosition::getAssociatedValue ( ) const
inline

◆ getAttrIdx()

unsigned llvm::IRPosition::getAttrIdx ( ) const
inline

◆ getAttrList()

AttributeList llvm::IRPosition::getAttrList ( ) const
inline

Return the attributes associated with this function or call site scope.

Definition at line 841 of file Attributor.h.

References getAnchorValue(), getAssociatedFunction(), llvm::Function::getAttributes(), and llvm::AttributeList::getAttributes().

Referenced by llvm::Attributor::identifyDefaultAbstractAttributes().

◆ getAttrListAnchor()

Value * llvm::IRPosition::getAttrListAnchor ( ) const
inline

Return the value attributes are attached to.

Definition at line 834 of file Attributor.h.

References getAnchorValue(), and getAssociatedFunction().

◆ getCallBaseContext()

const CallBaseContext * llvm::IRPosition::getCallBaseContext ( ) const
inline

Get the call base context from the position.

Definition at line 927 of file Attributor.h.

Referenced by llvm::DenseMapInfo< IRPosition >::getHashValue(), llvm::Attributor::isAssumedDead(), and llvm::operator<<().

◆ getCalleeArgNo()

int llvm::IRPosition::getCalleeArgNo ( ) const
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 799 of file Attributor.h.

Referenced by llvm::AANoCapture::determineFunctionCaptureCapabilities(), and getAttrIdx().

◆ getCallSiteArgNo()

int llvm::IRPosition::getCallSiteArgNo ( ) const
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 808 of file Attributor.h.

Referenced by llvm::Attributor::changeAfterManifest(), getAssociatedArgument(), getAssociatedValue(), getAttrIdx(), and llvm::operator<<().

◆ getCtxI()

Instruction * llvm::IRPosition::getCtxI ( ) const
inline

◆ getNumArgs()

unsigned llvm::IRPosition::getNumArgs ( ) const
inline

Return the number of arguments associated with this function or call site scope.

Definition at line 856 of file Attributor.h.

References llvm::Function::arg_size(), assert(), getAnchorValue(), getAssociatedFunction(), getPositionKind(), IRP_CALL_SITE, and IRP_FUNCTION.

◆ getPositionKind()

Kind llvm::IRPosition::getPositionKind ( ) const
inline

◆ hasCallBaseContext()

bool llvm::IRPosition::hasCallBaseContext ( ) const
inline

Check if the position has any call base context.

Definition at line 930 of file Attributor.h.

Referenced by llvm::operator<<().

◆ inst()

static const IRPosition llvm::IRPosition::inst ( const Instruction I,
const CallBaseContext CBContext = nullptr 
)
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 617 of file Attributor.h.

References I, IRP_FLOAT, and IRPosition().

Referenced by checkForAllInstructionsImpl(), llvm::Attributor::checkForAllReadWriteInstructions(), llvm::Attributor::identifyDefaultAbstractAttributes(), and llvm::Attributor::isAssumedDead().

◆ isAnyCallSitePosition()

bool llvm::IRPosition::isAnyCallSitePosition ( ) const
inline

◆ isArgumentPosition()

bool llvm::IRPosition::isArgumentPosition ( ) const
inline

Return true if the position is an argument or call site argument.

Definition at line 909 of file Attributor.h.

References getPositionKind(), IRP_ARGUMENT, and IRP_CALL_SITE_ARGUMENT.

Referenced by llvm::AANoCapture::isImpliedByIR().

◆ isFnInterfaceKind()

bool llvm::IRPosition::isFnInterfaceKind ( ) const
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 730 of file Attributor.h.

References getPositionKind(), IRP_ARGUMENT, IRP_FUNCTION, and IRP_RETURNED.

Referenced by llvm::AbstractAttribute::isValidIRPositionForUpdate().

◆ isFunctionScope()

bool llvm::IRPosition::isFunctionScope ( ) const
inline

◆ operator void *()

llvm::IRPosition::operator void * ( ) const
inline

}

Conversion into a void * to allow reuse of pointer hashing.

Definition at line 940 of file Attributor.h.

References llvm::PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info >::getOpaqueValue().

◆ operator!=()

bool llvm::IRPosition::operator!= ( const IRPosition RHS) const
inline

Definition at line 690 of file Attributor.h.

References RHS.

◆ operator==()

bool llvm::IRPosition::operator== ( const IRPosition RHS) const
inline

Definition at line 687 of file Attributor.h.

References RHS.

◆ returned()

static const IRPosition llvm::IRPosition::returned ( const Function F,
const CallBaseContext CBContext = nullptr 
)
inlinestatic

Create a position describing the returned value of F.

CBContext is used for call base specific analysis.

Definition at line 631 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().

◆ setAttrList()

void llvm::IRPosition::setAttrList ( const AttributeList AttrList) const
inline

Update the attributes associated with this function or call site scope.

Definition at line 848 of file Attributor.h.

References getAnchorValue(), getAssociatedFunction(), and llvm::Function::setAttributes().

◆ stripCallBaseContext()

IRPosition llvm::IRPosition::stripCallBaseContext ( ) const
inline

Return the same position without the call base context.

Definition at line 920 of file Attributor.h.

Referenced by llvm::Attributor::getOrCreateAAFor().

◆ value()

static const IRPosition llvm::IRPosition::value ( const Value V,
const CallBaseContext CBContext = nullptr 
)
inlinestatic

Member Data Documentation

◆ EmptyKey

const IRPosition IRPosition::EmptyKey
static

Special DenseMap key values.

{

Definition at line 935 of file Attributor.h.

Referenced by llvm::DenseMapInfo< IRPosition >::getEmptyKey().

◆ TombstoneKey

const IRPosition IRPosition::TombstoneKey
static

Definition at line 936 of file Attributor.h.

Referenced by llvm::DenseMapInfo< IRPosition >::getTombstoneKey().


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