LLVM 22.0.0git
llvm::DIExpression Class Reference

DWARF expression. More...

#include "llvm/IR/DebugInfoMetadata.h"

Inheritance diagram for llvm::DIExpression:
[legend]

Classes

class  expr_op_iterator
 An iterator for expression operands. More...
class  ExprOperand
 A lightweight wrapper around an expression operand. More...

Public Types

enum  SignedOrUnsignedConstant { SignedConstant , UnsignedConstant }
enum  PrependOps : uint8_t {
  ApplyOffset = 0 , DerefBefore = 1 << 0 , DerefAfter = 1 << 1 , StackValue = 1 << 2 ,
  EntryValue = 1 << 3
}
 Used for DIExpression::prepend. More...
using element_iterator = ArrayRef<uint64_t>::iterator
using FragmentInfo = DbgVariableFragmentInfo
using ExtOps = std::array<uint64_t, 6>
Public Types inherited from llvm::MDNode
using op_iterator = const MDOperand *
using op_range = iterator_range<op_iterator>

Public Member Functions

 DEFINE_MDNODE_GET (DIExpression,(ArrayRef< uint64_t > Elements),(Elements)) TempDIExpression clone() const
ArrayRef< uint64_tgetElements () const
unsigned getNumElements () const
uint64_t getElement (unsigned I) const
LLVM_ABI std::optional< SignedOrUnsignedConstantisConstant () const
 Determine whether this represents a constant value, if so.
LLVM_ABI uint64_t getNumLocationOperands () const
 Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; this is not necessarily the number of instances of DW_OP_LLVM_arg within the expression.
element_iterator elements_begin () const
element_iterator elements_end () const
LLVM_ABI bool isValid () const
LLVM_ABI bool startsWithDeref () const
 Return whether the first element a DW_OP_deref.
LLVM_ABI bool isDeref () const
 Return whether there is exactly one operator and it is a DW_OP_deref;.
LLVM_ABI std::optional< uint64_tgetActiveBits (DIVariable *Var)
 Return the number of bits that have an active value, i.e.
std::optional< FragmentInfogetFragmentInfo () const
 Retrieve the details of this fragment expression.
bool isFragment () const
 Return whether this is a piece of an aggregate variable.
LLVM_ABI bool isImplicit () const
 Return whether this is an implicit location description.
LLVM_ABI bool isComplex () const
 Return whether the location is computed on the expression stack, meaning it cannot be a simple register location.
LLVM_ABI bool isSingleLocationExpression () const
 Return whether the evaluated expression makes use of a single location at the start of the expression, i.e.
LLVM_ABI std::optional< ArrayRef< uint64_t > > getSingleLocationExpressionElements () const
 Returns a reference to the elements contained in this expression, skipping past the leading DW_OP_LLVM_arg, 0 if one is present.
LLVM_ABI bool extractIfOffset (int64_t &Offset) const
 If this is a constant offset, extract it.
LLVM_ABI bool extractLeadingOffset (int64_t &OffsetInBytes, SmallVectorImpl< uint64_t > &RemainingOps) const
 Assuming that the expression operates on an address, extract a constant offset and the successive ops.
LLVM_ABI bool hasAllLocationOps (unsigned N) const
 Returns true iff this DIExpression contains at least one instance of DW_OP_LLVM_arg, n for all n in [0, N).
int fragmentCmp (const DIExpression *Other) const
 Determine the relative position of the fragments described by this DIExpression and Other.
bool fragmentsOverlap (const DIExpression *Other) const
 Check if fragments overlap between this DIExpression and Other.
LLVM_ABI bool isEntryValue () const
 Check if the expression consists of exactly one entry value operand.
LLVM_ABI std::pair< DIExpression *, const ConstantInt * > constantFold (const ConstantInt *CI)
 Try to shorten an expression with an initial constant operand.
LLVM_ABI DIExpressionfoldConstantMath ()
 Try to shorten an expression with constant math operations that can be evaluated at compile time.
expr_op_iterator expr_op_begin () const
 Visit the elements via ExprOperand wrappers.
expr_op_iterator expr_op_end () const
iterator_range< expr_op_iteratorexpr_ops () const
Public Member Functions inherited from llvm::MDNode
 MDNode (const MDNode &)=delete
void operator= (const MDNode &)=delete
void * operator new (size_t)=delete
LLVM_ABI TempMDNode clone () const
 Create a (temporary) clone of this.
LLVMContextgetContext () const
LLVM_ABI void replaceOperandWith (unsigned I, Metadata *New)
 Replace a specific operand.
bool isResolved () const
 Check if node is fully resolved.
bool isUniqued () const
bool isDistinct () const
bool isTemporary () const
bool isReplaceable () const
bool isAlwaysReplaceable () const
bool hasGeneralizedMDString ()
 Check if this is a valid generalized type metadata node.
unsigned getNumTemporaryUses () const
void replaceAllUsesWith (Metadata *MD)
 RAUW a temporary.
LLVM_ABI void resolveCycles ()
 Resolve cycles.
LLVM_ABI void resolve ()
 Resolve a unique, unresolved node.
op_iterator op_begin () const
op_iterator op_end () const
ArrayRef< MDOperandoperands () const
const MDOperandgetOperand (unsigned I) const
unsigned getNumOperands () const
 Return number of MDNode operands.
LLVM_ABI bool isTBAAVtableAccess () const
 Check whether MDNode is a vtable access.
LLVM_ABI void printTree (raw_ostream &OS, const Module *M=nullptr) const
 Print in tree shape.
LLVM_ABI void printTree (raw_ostream &OS, ModuleSlotTracker &MST, const Module *M=nullptr) const
LLVM_ABI void dumpTree () const
 User-friendly dump in tree shape.
LLVM_ABI void dumpTree (const Module *M) const

Static Public Member Functions

static bool classof (const Metadata *MD)
static LLVM_ABI std::optional< FragmentInfogetFragmentInfo (expr_op_iterator Start, expr_op_iterator End)
 Retrieve the details of this fragment expression.
static LLVM_ABI const DIExpressionconvertToUndefExpression (const DIExpression *Expr)
 Removes all elements from Expr that do not apply to an undef debug value, which includes every operator that computes the value/location on the DWARF stack, including any DW_OP_LLVM_arg elements (making the result of this function always a single-location expression) while leaving everything that defines what the computed value applies to, i.e.
static LLVM_ABI const DIExpressionconvertToVariadicExpression (const DIExpression *Expr)
 If Expr is a non-variadic expression (i.e.
static LLVM_ABI std::optional< const DIExpression * > convertToNonVariadicExpression (const DIExpression *Expr)
 If Expr is a valid single-location expression, i.e.
static LLVM_ABI void canonicalizeExpressionOps (SmallVectorImpl< uint64_t > &Ops, const DIExpression *Expr, bool IsIndirect)
 Inserts the elements of Expr into Ops modified to a canonical form, which uses DW_OP_LLVM_arg (i.e.
static LLVM_ABI bool isEqualExpression (const DIExpression *FirstExpr, bool FirstIndirect, const DIExpression *SecondExpr, bool SecondIndirect)
 Determines whether two debug values should produce equivalent DWARF expressions, using their DIExpressions and directness, ignoring the differences between otherwise identical expressions in variadic and non-variadic form and not considering the debug operands.
static LLVM_ABI void appendOffset (SmallVectorImpl< uint64_t > &Ops, int64_t Offset)
 Append Ops with operations to apply the Offset.
static LLVM_ABI const DIExpressionextractAddressClass (const DIExpression *Expr, unsigned &AddrClass)
 Checks if the last 4 elements of the expression are DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address Space>.
static LLVM_ABI DIExpressionprepend (const DIExpression *Expr, uint8_t Flags, int64_t Offset=0)
 Prepend DIExpr with a deref and offset operation and optionally turn it into a stack value or/and an entry value.
static LLVM_ABI DIExpressionprependOpcodes (const DIExpression *Expr, SmallVectorImpl< uint64_t > &Ops, bool StackValue=false, bool EntryValue=false)
 Prepend DIExpr with the given opcodes and optionally turn it into a stack value.
static LLVM_ABI DIExpressionappend (const DIExpression *Expr, ArrayRef< uint64_t > Ops)
 Append the opcodes Ops to DIExpr.
static LLVM_ABI DIExpressionappendToStack (const DIExpression *Expr, ArrayRef< uint64_t > Ops)
 Convert DIExpr into a stack value if it isn't one already by appending DW_OP_deref if needed, and appending Ops to the resulting expression.
static LLVM_ABI DIExpressionappendOpsToArg (const DIExpression *Expr, ArrayRef< uint64_t > Ops, unsigned ArgNo, bool StackValue=false)
 Create a copy of Expr by appending the given list of Ops to each instance of the operand DW_OP_LLVM_arg, \p ArgNo.
static LLVM_ABI DIExpressionreplaceArg (const DIExpression *Expr, uint64_t OldArg, uint64_t NewArg)
 Create a copy of Expr with each instance of DW_OP_LLVM_arg, \p OldArg replaced with DW_OP_LLVM_arg, \p NewArg, and each instance of DW_OP_LLVM_arg, Arg with DW_OP_LLVM_arg, Arg - 1 for all Arg > OldArg.
static LLVM_ABI std::optional< DIExpression * > createFragmentExpression (const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
 Create a DIExpression to describe one part of an aggregate variable that is fragmented across multiple Values.
static int fragmentCmp (const FragmentInfo &A, const FragmentInfo &B)
 Determine the relative position of the fragments passed in.
static LLVM_ABI bool calculateFragmentIntersect (const DataLayout &DL, const Value *SliceStart, uint64_t SliceOffsetInBits, uint64_t SliceSizeInBits, const Value *DbgPtr, int64_t DbgPtrOffsetInBits, int64_t DbgExtractOffsetInBits, DIExpression::FragmentInfo VarFrag, std::optional< DIExpression::FragmentInfo > &Result, int64_t &OffsetFromLocationInBits)
 Computes a fragment, bit-extract operation if needed, and new constant offset to describe a part of a variable covered by some memory.
static LLVM_ABI ExtOps getExtOps (unsigned FromSize, unsigned ToSize, bool Signed)
 Returns the ops for a zero- or sign-extension in a DIExpression.
static LLVM_ABI DIExpressionappendExt (const DIExpression *Expr, unsigned FromSize, unsigned ToSize, bool Signed)
 Append a zero- or sign-extension to Expr.
static bool fragmentsOverlap (const FragmentInfo &A, const FragmentInfo &B)
 Check if fragments overlap between a pair of FragmentInfos.
Static Public Member Functions inherited from llvm::MDNode
static MDTupleget (LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDTuplegetIfExists (LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDTuplegetDistinct (LLVMContext &Context, ArrayRef< Metadata * > MDs)
static TempMDTuple getTemporary (LLVMContext &Context, ArrayRef< Metadata * > MDs)
static LLVM_ABI void deleteTemporary (MDNode *N)
 Deallocate a node created by getTemporary.
template<class T>
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithPermanent (std::unique_ptr< T, TempMDNodeDeleter > N)
 Replace a temporary node with a permanent one.
template<class T>
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithUniqued (std::unique_ptr< T, TempMDNodeDeleter > N)
 Replace a temporary node with a uniqued one.
template<class T>
static std::enable_if_t< std::is_base_of< MDNode, T >::value, T * > replaceWithDistinct (std::unique_ptr< T, TempMDNodeDeleter > N)
 Replace a temporary node with a distinct one.
static bool classof (const Metadata *MD)
 Methods for support type inquiry through isa, cast, and dyn_cast:
static LLVM_ABI MDNodeconcatenate (MDNode *A, MDNode *B)
 Methods for metadata merging.
static LLVM_ABI MDNodeintersect (MDNode *A, MDNode *B)
static LLVM_ABI MDNodegetMostGenericTBAA (MDNode *A, MDNode *B)
static LLVM_ABI MDNodegetMostGenericFPMath (MDNode *A, MDNode *B)
static LLVM_ABI MDNodegetMostGenericRange (MDNode *A, MDNode *B)
static LLVM_ABI MDNodegetMostGenericNoaliasAddrspace (MDNode *A, MDNode *B)
static LLVM_ABI MDNodegetMostGenericAliasScope (MDNode *A, MDNode *B)
static LLVM_ABI MDNodegetMostGenericAlignmentOrDereferenceable (MDNode *A, MDNode *B)
static LLVM_ABI MDNodegetMergedProfMetadata (MDNode *A, MDNode *B, const Instruction *AInstr, const Instruction *BInstr)
 Merge !prof metadata from two instructions.
static LLVM_ABI MDNodegetMergedMemProfMetadata (MDNode *A, MDNode *B)
static LLVM_ABI MDNodegetMergedCallsiteMetadata (MDNode *A, MDNode *B)
static LLVM_ABI MDNodegetMergedCalleeTypeMetadata (const MDNode *A, const MDNode *B)

Friends

class LLVMContextImpl
class MDNode

Additional Inherited Members

Protected Types inherited from llvm::MDNode
using mutable_op_range = iterator_range<MDOperand *>
 Active type of storage. More...
Protected Member Functions inherited from llvm::MDNode
LLVM_ABI MDNode (LLVMContext &Context, unsigned ID, StorageType Storage, ArrayRef< Metadata * > Ops1, ArrayRef< Metadata * > Ops2={})
 ~MDNode ()=default
LLVM_ABI void * operator new (size_t Size, size_t NumOps, StorageType Storage)
LLVM_ABI void operator delete (void *Mem)
void operator delete (void *, unsigned)
 Required by std, but never called.
void operator delete (void *, unsigned, bool)
 Required by std, but never called.
LLVM_ABI void dropAllReferences ()
MDOperandmutable_begin ()
MDOperandmutable_end ()
mutable_op_range mutable_operands ()
LLVM_ABI void setOperand (unsigned I, Metadata *New)
 Set an operand.
unsigned getNumUnresolved () const
void setNumUnresolved (unsigned N)
LLVM_ABI void storeDistinctInContext ()
void resize (size_t NumOps)
 Resize the node to hold NumOps operands.
Static Protected Member Functions inherited from llvm::MDNode
template<class T, class StoreT>
static TstoreImpl (T *N, StorageType Storage, StoreT &Store)
template<class T>
static TstoreImpl (T *N, StorageType Storage)

Detailed Description

DWARF expression.

This is (almost) a DWARF expression that modifies the location of a variable, or the location of a single piece of a variable, or (when using DW_OP_stack_value) is the constant variable value.

TODO: Co-allocate the expression elements. TODO: Separate from MDNode, or otherwise drop Distinct and Temporary storage types.

Definition at line 3299 of file DebugInfoMetadata.h.

Member Typedef Documentation

◆ element_iterator

Definition at line 3348 of file DebugInfoMetadata.h.

◆ ExtOps

using llvm::DIExpression::ExtOps = std::array<uint64_t, 6>

Definition at line 3704 of file DebugInfoMetadata.h.

◆ FragmentInfo

Member Enumeration Documentation

◆ PrependOps

Used for DIExpression::prepend.

Enumerator
ApplyOffset 
DerefBefore 
DerefAfter 
StackValue 
EntryValue 

Definition at line 3584 of file DebugInfoMetadata.h.

◆ SignedOrUnsignedConstant

Enumerator
SignedConstant 
UnsignedConstant 

Definition at line 3333 of file DebugInfoMetadata.h.

Member Function Documentation

◆ append()

DIExpression * DIExpression::append ( const DIExpression * Expr,
ArrayRef< uint64_t > Ops )
static

Append the opcodes Ops to DIExpr.

Unlike appendToStack, the returned expression is a stack value only if DIExpr is a stack value. If DIExpr describes a fragment, the returned expression will describe the same fragment.

Definition at line 2211 of file DebugInfoMetadata.cpp.

References AbstractManglingParser< Derived, Alloc >::Ops, llvm::SmallVectorImpl< T >::append(), assert(), llvm::dwarf::DW_OP_LLVM_fragment, expr_ops(), llvm::MDNode::get(), and llvm::MDNode::getContext().

Referenced by appendToStack(), combineDIExpressions(), llvm::InstrEmitter::EmitDbgInstrRef(), llvm::LowerDbgDeclare(), processIfEntryValueDbgDeclare(), UpdateDbgValue(), upgradeDbgIntrinsicToDbgRecord(), llvm::UpgradeIntrinsicCall(), and walkToAllocaAndPrependOffsetDeref().

◆ appendExt()

DIExpression * DIExpression::appendExt ( const DIExpression * Expr,
unsigned FromSize,
unsigned ToSize,
bool Signed )
static

Append a zero- or sign-extension to Expr.

Converts the expression to a stack value if it isn't one already.

Definition at line 2514 of file DebugInfoMetadata.cpp.

References appendToStack(), getExtOps(), and llvm::Signed.

Referenced by llvm::X86InstrInfo::describeLoadedValue(), and llvm::replaceAllDbgUsesWith().

◆ appendOffset()

◆ appendOpsToArg()

◆ appendToStack()

DIExpression * DIExpression::appendToStack ( const DIExpression * Expr,
ArrayRef< uint64_t > Ops )
static

Convert DIExpr into a stack value if it isn't one already by appending DW_OP_deref if needed, and appending Ops to the resulting expression.

If DIExpr describes a fragment, the returned expression will describe the same fragment.

Definition at line 2235 of file DebugInfoMetadata.cpp.

References AbstractManglingParser< Derived, Alloc >::Ops, append(), llvm::SmallVectorImpl< T >::append(), assert(), llvm::ArrayRef< T >::back(), llvm::ArrayRef< T >::drop_back(), llvm::ArrayRef< T >::empty(), getElements(), getFragmentInfo(), getNumElements(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().

Referenced by appendExt().

◆ calculateFragmentIntersect()

bool DIExpression::calculateFragmentIntersect ( const DataLayout & DL,
const Value * SliceStart,
uint64_t SliceOffsetInBits,
uint64_t SliceSizeInBits,
const Value * DbgPtr,
int64_t DbgPtrOffsetInBits,
int64_t DbgExtractOffsetInBits,
DIExpression::FragmentInfo VarFrag,
std::optional< DIExpression::FragmentInfo > & Result,
int64_t & OffsetFromLocationInBits )
static

Computes a fragment, bit-extract operation if needed, and new constant offset to describe a part of a variable covered by some memory.

See declaration for more info.

The memory region starts at: SliceStart + SliceOffsetInBits And is size: SliceSizeInBits

The location of the existing variable fragment VarFrag is: DbgPtr + DbgPtrOffsetInBits + DbgExtractOffsetInBits.

It is intended that these arguments are derived from a debug record:

  • DbgPtr is the (single) DIExpression operand.
  • DbgPtrOffsetInBits is the constant offset applied to DbgPtr.
  • DbgExtractOffsetInBits is the offset from a DW_OP_LLVM_bit_extract_[sz]ext operation.

Results and return value:

  • Return false if the result can't be calculated for any reason.
  • Result is set to nullopt if the intersect equals VarFarg.
  • Result contains a zero-sized fragment if there's no intersect.
  • OffsetFromLocationInBits is set to the difference between the first bit of the variable location and the first bit of the slice. The magnitude of a negative value therefore indicates the number of bits into the variable fragment that the memory region begins.

We don't pass in a debug record directly to get the constituent parts and offsets because different debug records store the information in different places (dbg_assign has two DIExpressions - one contains the fragment info for the entire intrinsic).

Definition at line 2362 of file DebugInfoMetadata.cpp.

References DL, llvm::Value::getPointerOffsetFrom(), llvm::DbgVariableFragmentInfo::intersect(), llvm::DbgVariableFragmentInfo::OffsetInBits, and llvm::DbgVariableFragmentInfo::SizeInBits.

Referenced by llvm::at::calculateFragmentIntersect().

◆ canonicalizeExpressionOps()

void DIExpression::canonicalizeExpressionOps ( SmallVectorImpl< uint64_t > & Ops,
const DIExpression * Expr,
bool IsIndirect )
static

Inserts the elements of Expr into Ops modified to a canonical form, which uses DW_OP_LLVM_arg (i.e.

is a variadic expression) and folds the implied derefence from the IsIndirect flag into the expression. This allows us to check equivalence between expressions with differing directness or variadicness.

Definition at line 1897 of file DebugInfoMetadata.cpp.

References AbstractManglingParser< Derived, Alloc >::Ops, llvm::dwarf::DW_OP_LLVM_arg, llvm::dwarf::DW_OP_LLVM_fragment, elements_begin(), elements_end(), expr_ops(), and llvm::none_of().

Referenced by isEqualExpression().

◆ classof()

bool llvm::DIExpression::classof ( const Metadata * MD)
inlinestatic

Definition at line 3454 of file DebugInfoMetadata.h.

References llvm::Metadata::getMetadataID().

◆ constantFold()

std::pair< DIExpression *, const ConstantInt * > DIExpression::constantFold ( const ConstantInt * CI)

Try to shorten an expression with an initial constant operand.

Returns a new expression and constant on success, or the original expression and constant on failure.

Definition at line 2431 of file DebugInfoMetadata.cpp.

References AbstractManglingParser< Derived, Alloc >::Ops, assert(), Changed, llvm::dwarf::DW_OP_LLVM_convert, expr_ops(), llvm::First, llvm::MDNode::get(), llvm::MDNode::getContext(), llvm::ConstantInt::getValue(), llvm::APInt::sextOrTrunc(), and llvm::APInt::zextOrTrunc().

Referenced by llvm::InstrEmitter::EmitDbgValueFromSingleOp(), and llvm::FastISel::lowerDbgValue().

◆ convertToNonVariadicExpression()

std::optional< const DIExpression * > DIExpression::convertToNonVariadicExpression ( const DIExpression * Expr)
static

If Expr is a valid single-location expression, i.e.

it refers to only a single debug operand at the start of the expression, then return that expression in a non-variadic form by removing DW_OP_LLVM_arg from the expression if it is present; otherwise returns std::nullopt. See also getSingleLocationExpressionElements above, which skips checking isSingleLocationExpression and returns a list of elements rather than a DIExpression.

Definition at line 1887 of file DebugInfoMetadata.cpp.

References llvm::MDNode::get(), llvm::MDNode::getContext(), and getSingleLocationExpressionElements().

Referenced by llvm::Loc::EntryValue::addExpr(), emitDebugValueComment(), getDebugLocValue(), and TransferTracker::recoverAsEntryValue().

◆ convertToUndefExpression()

const DIExpression * DIExpression::convertToUndefExpression ( const DIExpression * Expr)
static

Removes all elements from Expr that do not apply to an undef debug value, which includes every operator that computes the value/location on the DWARF stack, including any DW_OP_LLVM_arg elements (making the result of this function always a single-location expression) while leaving everything that defines what the computed value applies to, i.e.

the fragment information.

Definition at line 1864 of file DebugInfoMetadata.cpp.

References llvm::SmallVectorImpl< T >::append(), llvm::dwarf::DW_OP_LLVM_fragment, llvm::MDNode::get(), llvm::MDNode::getContext(), and getFragmentInfo().

Referenced by llvm::InstrEmitter::EmitDbgNoLocation(), and llvm::SelectionDAGBuilder::handleKillDebugValue().

◆ convertToVariadicExpression()

const DIExpression * DIExpression::convertToVariadicExpression ( const DIExpression * Expr)
static

If Expr is a non-variadic expression (i.e.

one that does not contain DW_OP_LLVM_arg), returns Expr converted to variadic form by adding a leading [DW_OP_LLVM_arg, 0] to the expression; otherwise returns Expr.

Definition at line 1874 of file DebugInfoMetadata.cpp.

References llvm::any_of(), llvm::SmallVectorImpl< T >::append(), llvm::dwarf::DW_OP_LLVM_arg, elements_begin(), elements_end(), expr_ops(), llvm::MDNode::get(), llvm::MDNode::getContext(), getNumElements(), and llvm::SmallVectorImpl< T >::reserve().

Referenced by llvm::InstrEmitter::EmitDbgInstrRef(), and llvm::SelectionDAG::salvageDebugInfo().

◆ createFragmentExpression()

std::optional< DIExpression * > DIExpression::createFragmentExpression ( const DIExpression * Expr,
unsigned OffsetInBits,
unsigned SizeInBits )
static

Create a DIExpression to describe one part of an aggregate variable that is fragmented across multiple Values.

The DW_OP_LLVM_fragment operation will be appended to the elements of Expr. If Expr already contains a DW_OP_LLVM_fragment OffsetInBits is interpreted as an offset into the existing fragment.

Parameters
OffsetInBitsOffset of the piece in bits.
SizeInBitsSize of the piece in bits.
Returns
Creating a fragment expression may fail if Expr contains arithmetic operations that would be truncated.

Definition at line 2269 of file DebugInfoMetadata.cpp.

References AbstractManglingParser< Derived, Alloc >::Ops, assert(), llvm::dwarf::DW_OP_LLVM_extract_bits_sext, llvm::dwarf::DW_OP_LLVM_extract_bits_zext, llvm::dwarf::DW_OP_LLVM_fragment, expr_ops(), llvm::MDNode::get(), llvm::MDNode::getContext(), and isImplicit().

Referenced by emitDbgAssign(), llvm::SelectionDAGBuilder::handleDebugValue(), migrateDebugInfo(), shortenAssignment(), llvm::SelectionDAG::transferDbgValues(), and transferSRADebugInfo().

◆ DEFINE_MDNODE_GET()

llvm::DIExpression::DEFINE_MDNODE_GET ( DIExpression ,
(ArrayRef< uint64_t > Elements) ,
(Elements)  ) const
inline

Definition at line 3320 of file DebugInfoMetadata.h.

◆ elements_begin()

element_iterator llvm::DIExpression::elements_begin ( ) const
inline

◆ elements_end()

element_iterator llvm::DIExpression::elements_end ( ) const
inline

◆ expr_op_begin()

expr_op_iterator llvm::DIExpression::expr_op_begin ( ) const
inline

Visit the elements via ExprOperand wrappers.

These range iterators visit elements through ExprOperand wrappers. This is not guaranteed to be a valid range unless isValid() gives true.

Precondition
isValid() gives true.

Definition at line 3441 of file DebugInfoMetadata.h.

References elements_begin().

Referenced by llvm::DIExpressionCursor::DIExpressionCursor(), expr_ops(), llvm::DbgVariableLocation::extractFromMachineInstruction(), getFragmentInfo(), and isValid().

◆ expr_op_end()

◆ expr_ops()

◆ extractAddressClass()

const DIExpression * DIExpression::extractAddressClass ( const DIExpression * Expr,
unsigned & AddrClass )
static

Checks if the last 4 elements of the expression are DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef and extracts the <DWARF Address Space>.

Definition at line 2080 of file DebugInfoMetadata.cpp.

References llvm::MDNode::get(), llvm::MDNode::getContext(), and getSingleLocationExpressionElements().

Referenced by llvm::DwarfCompileUnit::addLocationAttribute().

◆ extractIfOffset()

bool DIExpression::extractIfOffset ( int64_t & Offset) const

If this is a constant offset, extract it.

If there is no expression, return true with an offset of zero.

Definition at line 1999 of file DebugInfoMetadata.cpp.

References getSingleLocationExpressionElements(), and llvm::Offset.

Referenced by transferSRADebugInfo().

◆ extractLeadingOffset()

bool DIExpression::extractLeadingOffset ( int64_t & OffsetInBytes,
SmallVectorImpl< uint64_t > & RemainingOps ) const

Assuming that the expression operates on an address, extract a constant offset and the successive ops.

Return false if the expression contains any incompatible ops (including non-zero DW_OP_LLVM_args - only a single address operand to the expression is permitted).

We don't try very hard to interpret the expression because we assume that foldConstantMath has canonicalized the expression.

Definition at line 2030 of file DebugInfoMetadata.cpp.

References llvm::SmallVectorImpl< T >::append(), llvm::SmallVectorImpl< T >::clear(), llvm::dwarf::DW_OP_LLVM_extract_bits_sext, llvm::dwarf::DW_OP_LLVM_extract_bits_zext, llvm::dwarf::DW_OP_LLVM_fragment, and getSingleLocationExpressionElements().

Referenced by llvm::at::calculateFragmentIntersect().

◆ foldConstantMath()

DIExpression * DIExpression::foldConstantMath ( )

◆ fragmentCmp() [1/2]

int llvm::DIExpression::fragmentCmp ( const DIExpression * Other) const
inline

Determine the relative position of the fragments described by this DIExpression and Other.

Calls static fragmentCmp implementation.

Definition at line 3723 of file DebugInfoMetadata.h.

References fragmentCmp(), getFragmentInfo(), and llvm::Other.

◆ fragmentCmp() [2/2]

int llvm::DIExpression::fragmentCmp ( const FragmentInfo & A,
const FragmentInfo & B )
inlinestatic

Determine the relative position of the fragments passed in.

Returns -1 if this is entirely before Other, 0 if this and Other overlap, 1 if this is entirely after Other.

Definition at line 3654 of file DebugInfoMetadata.h.

References A(), B(), r1(), and r2().

Referenced by fragmentCmp(), fragmentsOverlap(), and fragmentsOverlap().

◆ fragmentsOverlap() [1/2]

bool llvm::DIExpression::fragmentsOverlap ( const DIExpression * Other) const
inline

Check if fragments overlap between this DIExpression and Other.

Definition at line 3730 of file DebugInfoMetadata.h.

References fragmentCmp(), isFragment(), and llvm::Other.

◆ fragmentsOverlap() [2/2]

bool llvm::DIExpression::fragmentsOverlap ( const FragmentInfo & A,
const FragmentInfo & B )
inlinestatic

Check if fragments overlap between a pair of FragmentInfos.

Definition at line 3717 of file DebugInfoMetadata.h.

References A(), B(), and fragmentCmp().

Referenced by llvm::SelectionDAGBuilder::dropDanglingDebugInfo(), handleNewDebugValue(), and stashEntryDbgValues().

◆ getActiveBits()

std::optional< uint64_t > DIExpression::getActiveBits ( DIVariable * Var)

Return the number of bits that have an active value, i.e.

those that aren't known to be zero/sign (depending on the type of Var) and which are within the size of this fragment (if it is one). If we can't deduce anything from the expression this will return the size of Var.

Definition at line 1949 of file DebugInfoMetadata.cpp.

References llvm::dwarf::DW_OP_LLVM_extract_bits_sext, llvm::dwarf::DW_OP_LLVM_extract_bits_zext, llvm::dwarf::DW_OP_LLVM_fragment, expr_ops(), llvm::DIVariable::getSignedness(), llvm::DIVariable::getSizeInBits(), and llvm::DIBasicType::Signed.

Referenced by valueCoversEntireFragment().

◆ getElement()

uint64_t llvm::DIExpression::getElement ( unsigned I) const
inline

◆ getElements()

◆ getExtOps()

DIExpression::ExtOps DIExpression::getExtOps ( unsigned FromSize,
unsigned ToSize,
bool Signed )
static

◆ getFragmentInfo() [1/2]

std::optional< FragmentInfo > llvm::DIExpression::getFragmentInfo ( ) const
inline

Retrieve the details of this fragment expression.

Definition at line 3477 of file DebugInfoMetadata.h.

References expr_op_begin(), expr_op_end(), and getFragmentInfo().

Referenced by fragmentCmp(), getFragmentInfo(), llvm::DIExpressionCursor::getFragmentInfo(), and isFragment().

◆ getFragmentInfo() [2/2]

◆ getNumElements()

◆ getNumLocationOperands()

uint64_t DIExpression::getNumLocationOperands ( ) const

Return the number of unique location operands referred to (via DW_OP_LLVM_arg) in this expression; this is not necessarily the number of instances of DW_OP_LLVM_arg within the expression.

For example, for the expression: (DW_OP_LLVM_arg 0, DW_OP_LLVM_arg 1, DW_OP_plus, DW_OP_LLVM_arg 0, DW_OP_mul) This function would return 2, as there are two unique location operands (0 and 1).

Definition at line 2469 of file DebugInfoMetadata.cpp.

References assert(), llvm::dwarf::DW_OP_LLVM_arg, expr_ops(), and hasAllLocationOps().

Referenced by llvm::salvageDebugInfoForDbgValues(), salvageDebugInfoImpl(), and llvm::SelectionDAGBuilder::salvageUnresolvedDbgValue().

◆ getSingleLocationExpressionElements()

std::optional< ArrayRef< uint64_t > > DIExpression::getSingleLocationExpressionElements ( ) const

Returns a reference to the elements contained in this expression, skipping past the leading DW_OP_LLVM_arg, 0 if one is present.

Similar to convertToNonVariadicExpression, but faster and cheaper - it does not check whether the expression is a single-location expression, and it returns elements rather than creating a new DIExpression.

Definition at line 1847 of file DebugInfoMetadata.cpp.

References llvm::ArrayRef< T >::drop_front(), llvm::dwarf::DW_OP_LLVM_arg, getElements(), getNumElements(), and isSingleLocationExpression().

Referenced by convertToNonVariadicExpression(), extractAddressClass(), extractIfOffset(), extractLeadingOffset(), isDeref(), isEntryValue(), and startsWithDeref().

◆ hasAllLocationOps()

bool DIExpression::hasAllLocationOps ( unsigned N) const

Returns true iff this DIExpression contains at least one instance of DW_OP_LLVM_arg, n for all n in [0, N).

Definition at line 2069 of file DebugInfoMetadata.cpp.

References llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::contains(), llvm::dwarf::DW_OP_LLVM_arg, expr_ops(), llvm::detail::DenseSetImpl< ValueT, MapTy, ValueInfoT >::insert(), and N.

Referenced by getNumLocationOperands().

◆ isComplex()

bool DIExpression::isComplex ( ) const

Return whether the location is computed on the expression stack, meaning it cannot be a simple register location.

Definition at line 1803 of file DebugInfoMetadata.cpp.

References llvm::dwarf::DW_OP_LLVM_arg, llvm::dwarf::DW_OP_LLVM_fragment, llvm::dwarf::DW_OP_LLVM_tag_offset, expr_ops(), getNumElements(), and isValid().

Referenced by LiveDebugValues::MLocTracker::emitLoc(), llvm::DbgVariableRecord::isKillLocation(), and UpdateDbgValue().

◆ isConstant()

std::optional< DIExpression::SignedOrUnsignedConstant > DIExpression::isConstant ( ) const

Determine whether this represents a constant value, if so.

Definition at line 2480 of file DebugInfoMetadata.cpp.

References llvm::dwarf::DW_OP_LLVM_fragment, getElement(), getNumElements(), SignedConstant, and UnsignedConstant.

Referenced by llvm::DwarfCompileUnit::addLocationAttribute().

◆ isDeref()

bool DIExpression::isDeref ( ) const

Return whether there is exactly one operator and it is a DW_OP_deref;.

Definition at line 1651 of file DebugInfoMetadata.cpp.

References getSingleLocationExpressionElements().

Referenced by TransferTracker::isEntryValueVariable().

◆ isEntryValue()

◆ isEqualExpression()

bool DIExpression::isEqualExpression ( const DIExpression * FirstExpr,
bool FirstIndirect,
const DIExpression * SecondExpr,
bool SecondIndirect )
static

Determines whether two debug values should produce equivalent DWARF expressions, using their DIExpressions and directness, ignoring the differences between otherwise identical expressions in variadic and non-variadic form and not considering the debug operands.

FirstExpr is the DIExpression for the first debug value. FirstIndirect should be true if the first debug value is indirect; in IR this should be true for dbg.declare intrinsics and false for dbg.values, and in MIR this should be true only for DBG_VALUE instructions whose second operand is an immediate value. SecondExpr and SecondIndirect have the same meaning as the prior arguments, but apply to the second debug value.

Definition at line 1927 of file DebugInfoMetadata.cpp.

References canonicalizeExpressionOps().

Referenced by llvm::DbgValueLoc::isEquivalent(), llvm::MachineInstr::isEquivalentDbgInstr(), and LiveDebugValues::DbgValueProperties::isJoinable().

◆ isFragment()

bool llvm::DIExpression::isFragment ( ) const
inline

Return whether this is a piece of an aggregate variable.

Definition at line 3482 of file DebugInfoMetadata.h.

References getFragmentInfo().

Referenced by llvm::DwarfExpression::addFragmentOffset(), fragmentsOverlap(), and llvm::DbgValueLoc::isFragment().

◆ isImplicit()

bool DIExpression::isImplicit ( ) const

Return whether this is an implicit location description.

Definition at line 1784 of file DebugInfoMetadata.cpp.

References expr_ops(), getNumElements(), and isValid().

Referenced by combineDIExpressions(), createFragmentExpression(), and LiveDebugValues::MLocTracker::emitLoc().

◆ isSingleLocationExpression()

bool DIExpression::isSingleLocationExpression ( ) const

Return whether the evaluated expression makes use of a single location at the start of the expression, i.e.

if it contains only a single DW_OP_LLVM_arg op as its first operand, or if it contains none.

Definition at line 1826 of file DebugInfoMetadata.cpp.

References llvm::dwarf::DW_OP_LLVM_arg, expr_ops(), getNumElements(), and isValid().

Referenced by LiveDebugValues::MLocTracker::emitLoc(), getSingleLocationExpressionElements(), and salvageDebugInfoImpl().

◆ isValid()

◆ prepend()

◆ prependOpcodes()

◆ replaceArg()

DIExpression * DIExpression::replaceArg ( const DIExpression * Expr,
uint64_t OldArg,
uint64_t NewArg )
static

Create a copy of Expr with each instance of DW_OP_LLVM_arg, \p OldArg replaced with DW_OP_LLVM_arg, \p NewArg, and each instance of DW_OP_LLVM_arg, Arg with DW_OP_LLVM_arg, Arg - 1 for all Arg > OldArg.

This is used when replacing one of the operands of a debug value list with another operand in the same list and deleting the old operand.

Definition at line 2156 of file DebugInfoMetadata.cpp.

References assert(), llvm::dwarf::DW_OP_LLVM_arg, expr_ops(), llvm::MDNode::get(), llvm::MDNode::getContext(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().

◆ startsWithDeref()

bool DIExpression::startsWithDeref ( ) const

Return whether the first element a DW_OP_deref.

Definition at line 1645 of file DebugInfoMetadata.cpp.

References getSingleLocationExpressionElements().

Referenced by insertNewDbgInst(), promoteSingleBlockAlloca(), and rewriteSingleStoreAlloca().

◆ LLVMContextImpl

friend class LLVMContextImpl
friend

Definition at line 3300 of file DebugInfoMetadata.h.

References LLVMContextImpl.

Referenced by LLVMContextImpl.

◆ MDNode

friend class MDNode
friend

Definition at line 3301 of file DebugInfoMetadata.h.

References llvm::CallingConv::C, MDNode, and llvm::Metadata::Storage.

Referenced by MDNode.


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