LLVM  14.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]
Collaboration diagram for llvm::IRPosition:
Collaboration 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. More...
 
bool operator== (const IRPosition &RHS) const
 
bool operator!= (const IRPosition &RHS) const
 
ValuegetAnchorValue () const
 Return the value this abstract attribute is anchored with. More...
 
FunctiongetAssociatedFunction () const
 Return the associated function, if any. More...
 
ArgumentgetAssociatedArgument () const
 Return the associated argument, if any. More...
 
bool isFnInterfaceKind () const
 Return true if the position refers to a function interface, that is the function scope, the function return, or an argument. More...
 
FunctiongetAnchorScope () const
 Return the Function surrounding the anchor value. More...
 
InstructiongetCtxI () const
 Return the context instruction, if any. More...
 
ValuegetAssociatedValue () const
 Return the value this abstract attribute is associated with. More...
 
TypegetAssociatedType () const
 Return the type this abstract attribute is associated with. More...
 
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. More...
 
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. More...
 
unsigned getAttrIdx () const
 Return the index in the attribute list for this position. More...
 
Kind getPositionKind () const
 Return the associated position kind. More...
 
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. More...
 
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. More...
 
void removeAttrs (ArrayRef< Attribute::AttrKind > AKs) const
 Remove the attribute of kind AKs existing in the IR at this position. More...
 
bool isAnyCallSitePosition () const
 
bool isArgumentPosition () const
 Return true if the position is an argument or call site argument. More...
 
IRPosition stripCallBaseContext () const
 Return the same position without the call base context. More...
 
const CallBaseContextgetCallBaseContext () const
 Get the call base context from the position. More...
 
bool hasCallBaseContext () const
 Check if the position has any call base context. More...
 
 operator void * () const
 } More...
 

Static Public Member Functions

static const IRPosition value (const Value &V, const CallBaseContext *CBContext=nullptr)
 Create a position describing the value of V. More...
 
static const IRPosition function (const Function &F, const CallBaseContext *CBContext=nullptr)
 Create a position describing the function scope of F. More...
 
static const IRPosition returned (const Function &F, const CallBaseContext *CBContext=nullptr)
 Create a position describing the returned value of F. More...
 
static const IRPosition argument (const Argument &Arg, const CallBaseContext *CBContext=nullptr)
 Create a position describing the argument Arg. More...
 
static const IRPosition callsite_function (const CallBase &CB)
 Create a position describing the function scope of CB. More...
 
static const IRPosition callsite_returned (const CallBase &CB)
 Create a position describing the returned value of CB. More...
 
static const IRPosition callsite_argument (const CallBase &CB, unsigned ArgNo)
 Create a position describing the argument of CB at position ArgNo. More...
 
static const IRPosition callsite_argument (AbstractCallSite ACS, unsigned ArgNo)
 Create a position describing the argument of ACS at position ArgNo. More...
 
static const IRPosition function_scope (const IRPosition &IRP, const CallBaseContext *CBContext=nullptr)
 Create a position with function scope matching the "context" of IRP. More...
 

Static Public Attributes

static const IRPosition EmptyKey
 Special DenseMap key values. More...
 
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 304 of file Attributor.h.

Member Typedef Documentation

◆ CallBaseContext

Definition at line 307 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 310 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 325 of file Attributor.h.

Referenced by argument(), callsite_argument(), callsite_function(), callsite_returned(), function(), 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 353 of file Attributor.h.

References Arg, IRP_ARGUMENT, and IRPosition().

Referenced by llvm::Attributor::identifyDefaultAbstractAttributes(), 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 376 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

Create a position describing the function scope of CB.

Definition at line 359 of file Attributor.h.

References IRP_CALL_SITE, and IRPosition().

Referenced by function_scope(), llvm::Attributor::identifyDefaultAbstractAttributes(), and llvm::SubsumingPositionIterator::SubsumingPositionIterator().

◆ 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 364 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 392 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 413 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().

◆ 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

◆ getAttrs()

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.

Parameters
IgnoreSubsumingPositionsFlag to determine if subsuming positions, e.g., the function position if this is an argument position, should be ignored.

Definition at line 633 of file Attributor.cpp.

References Attrs.

◆ getCallBaseContext()

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

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

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

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

◆ getCtxI()

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

Return the context instruction, if any.

Definition at line 468 of file Attributor.h.

References Arg, F, getAnchorValue(), and I.

Referenced by llvm::Attributor::isAssumedDead(), and llvm::AbstractAttribute::print().

◆ getPositionKind()

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

◆ hasAttr()

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

Parameters
IgnoreSubsumingPositionsFlag to determine if subsuming positions, e.g., the function position if this is an argument position, should be ignored.

Definition at line 613 of file Attributor.cpp.

References Attrs.

◆ hasCallBaseContext()

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

Check if the position has any call base context.

Definition at line 636 of file Attributor.h.

Referenced by llvm::operator<<().

◆ isAnyCallSitePosition()

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

Definition at line 603 of file Attributor.h.

References getPositionKind(), IRP_CALL_SITE, IRP_CALL_SITE_ARGUMENT, and IRP_CALL_SITE_RETURNED.

Referenced by function_scope().

◆ isArgumentPosition()

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

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

Definition at line 615 of file Attributor.h.

References getPositionKind(), IRP_ARGUMENT, and IRP_CALL_SITE_ARGUMENT.

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

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

Referenced by llvm::IRAttribute< Attribute::Returned, AbstractAttribute >::initialize().

◆ operator void *()

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

}

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

Definition at line 646 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 405 of file Attributor.h.

◆ operator==()

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

Definition at line 402 of file Attributor.h.

◆ removeAttrs()

void llvm::IRPosition::removeAttrs ( ArrayRef< Attribute::AttrKind AKs) const
inline

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

References F, IRP_RETURNED, and IRPosition().

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

◆ stripCallBaseContext()

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

Return the same position without the call base context.

Definition at line 626 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 641 of file Attributor.h.

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

◆ TombstoneKey

const IRPosition IRPosition::TombstoneKey
static

Definition at line 642 of file Attributor.h.

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


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