LLVM  6.0.0svn
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
llvm::DwarfExpression Class Referenceabstract

Base class containing the logic for constructing DWARF expressions independently of whether they are emitted into a DIE or into a .debug_loc entry. More...

#include "CodeGen/AsmPrinter/DwarfExpression.h"

Inheritance diagram for llvm::DwarfExpression:
Inheritance graph
[legend]
Collaboration diagram for llvm::DwarfExpression:
Collaboration graph
[legend]

Classes

struct  Register
 Holds information about all subregisters comprising a register location. More...
 

Public Member Functions

 DwarfExpression (unsigned DwarfVersion)
 
void finalize ()
 This needs to be called last to commit any pending changes. More...
 
void addSignedConstant (int64_t Value)
 Emit a signed constant. More...
 
void addUnsignedConstant (uint64_t Value)
 Emit an unsigned constant. More...
 
void addUnsignedConstant (const APInt &Value)
 Emit an unsigned constant. More...
 
void setMemoryLocationKind ()
 Lock this down to become a memory location description. More...
 
bool addMachineRegExpression (const TargetRegisterInfo &TRI, DIExpressionCursor &Expr, unsigned MachineReg, unsigned FragmentOffsetInBits=0)
 Emit a machine register location. More...
 
void addExpression (DIExpressionCursor &&Expr, unsigned FragmentOffsetInBits=0)
 Emit all remaining operations in the DIExpressionCursor. More...
 
void addFragmentOffset (const DIExpression *Expr)
 If applicable, emit an empty DW_OP_piece / DW_OP_bit_piece to advance to the fragment described by Expr. More...
 

Protected Types

enum  { Unknown = 0, Register, Memory, Implicit }
 The kind of location description being produced. More...
 

Protected Member Functions

void setSubRegisterPiece (unsigned SizeInBits, unsigned OffsetInBits)
 Push a DW_OP_piece / DW_OP_bit_piece for emitting later, if one is needed to represent a subregister. More...
 
void maskSubRegister ()
 Add masking operations to stencil out a subregister. More...
 
virtual void emitOp (uint8_t Op, const char *Comment=nullptr)=0
 Output a dwarf operand and an optional assembler comment. More...
 
virtual void emitSigned (int64_t Value)=0
 Emit a raw signed value. More...
 
virtual void emitUnsigned (uint64_t Value)=0
 Emit a raw unsigned value. More...
 
virtual bool isFrameRegister (const TargetRegisterInfo &TRI, unsigned MachineReg)=0
 Return whether the given machine register is the frame register in the current function. More...
 
void addReg (int DwarfReg, const char *Comment=nullptr)
 Emit a DW_OP_reg operation. More...
 
void addBReg (int DwarfReg, int Offset)
 Emit a DW_OP_breg operation. More...
 
void addFBReg (int Offset)
 Emit DW_OP_fbreg <Offset>. More...
 
bool addMachineReg (const TargetRegisterInfo &TRI, unsigned MachineReg, unsigned MaxSize=~1U)
 Emit a partial DWARF register operation. More...
 
void addOpPiece (unsigned SizeInBits, unsigned OffsetInBits=0)
 Emit a DW_OP_piece or DW_OP_bit_piece operation for a variable fragment. More...
 
void addShr (unsigned ShiftBy)
 Emit a shift-right dwarf operation. More...
 
void addAnd (unsigned Mask)
 Emit a bitwise and dwarf operation. More...
 
void addStackValue ()
 Emit a DW_OP_stack_value, if supported. More...
 
 ~DwarfExpression ()=default
 

Protected Attributes

SmallVector< Register, 2 > DwarfRegs
 The register location, if any. More...
 
uint64_t OffsetInBits = 0
 Current Fragment Offset in Bits. More...
 
unsigned DwarfVersion
 
unsigned SubRegisterSizeInBits = 0
 Sometimes we need to add a DW_OP_bit_piece to describe a subregister. More...
 
unsigned SubRegisterOffsetInBits = 0
 
enum llvm::DwarfExpression:: { ... }  LocationKind = Unknown
 The kind of location description being produced. More...
 

Detailed Description

Base class containing the logic for constructing DWARF expressions independently of whether they are emitted into a DIE or into a .debug_loc entry.

Definition at line 99 of file DwarfExpression.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected

The kind of location description being produced.

Enumerator
Unknown 
Register 
Memory 
Implicit 

Definition at line 120 of file DwarfExpression.h.

Constructor & Destructor Documentation

◆ ~DwarfExpression()

llvm::DwarfExpression::~DwarfExpression ( )
protecteddefault

◆ DwarfExpression()

llvm::DwarfExpression::DwarfExpression ( unsigned  DwarfVersion)
inline

Definition at line 200 of file DwarfExpression.h.

References finalize.

Member Function Documentation

◆ addAnd()

void DwarfExpression::addAnd ( unsigned  Mask)
protected

Emit a bitwise and dwarf operation.

Definition at line 80 of file DwarfExpression.cpp.

References emitOp(), and emitUnsigned().

Referenced by maskSubRegister().

◆ addBReg()

void DwarfExpression::addBReg ( int  DwarfReg,
int  Offset 
)
protected

Emit a DW_OP_breg operation.

Definition at line 40 of file DwarfExpression.cpp.

References assert(), emitOp(), emitSigned(), emitUnsigned(), and LocationKind.

Referenced by addMachineRegExpression().

◆ addExpression()

void DwarfExpression::addExpression ( DIExpressionCursor &&  Expr,
unsigned  FragmentOffsetInBits = 0 
)

◆ addFBReg()

void DwarfExpression::addFBReg ( int  Offset)
protected

Emit DW_OP_fbreg <Offset>.

Definition at line 52 of file DwarfExpression.cpp.

References emitOp(), and emitSigned().

Referenced by addMachineRegExpression().

◆ addFragmentOffset()

void DwarfExpression::addFragmentOffset ( const DIExpression Expr)

If applicable, emit an empty DW_OP_piece / DW_OP_bit_piece to advance to the fragment described by Expr.

Definition at line 401 of file DwarfExpression.cpp.

References addOpPiece(), assert(), llvm::DIExpression::getFragmentInfo(), llvm::DIExpression::isFragment(), and OffsetInBits.

Referenced by llvm::DwarfCompileUnit::addComplexAddress(), llvm::DwarfCompileUnit::constructVariableDIE(), and emitDebugLocValue().

◆ addMachineReg()

bool DwarfExpression::addMachineReg ( const TargetRegisterInfo TRI,
unsigned  MachineReg,
unsigned  MaxSize = ~1U 
)
protected

Emit a partial DWARF register operation.

Parameters
MachineRegThe register number.
MaxSizeIf the register must be composed from sub-registers this is an upper bound for how many bits the emitted DW_OP_piece may cover.

If size and offset is zero an operation for the entire register is emitted: Some targets do not provide a DWARF register number for every register. If this is the case, this function will attempt to emit a DWARF register by emitting a fragment of a super-register or by piecing together multiple subregisters that alias the register.

Returns
false if no DWARF register exists for MachineReg.

Definition at line 86 of file DwarfExpression.cpp.

References DwarfRegs, llvm::MCRegisterInfo::getDwarfRegNum(), llvm::TargetRegisterInfo::getMinimalPhysRegClass(), llvm::TargetRegisterInfo::getRegSizeInBits(), llvm::MCRegisterInfo::getSubRegIdxOffset(), llvm::MCRegisterInfo::getSubRegIdxSize(), llvm::MCRegisterInfo::getSubRegIndex(), isFrameRegister(), llvm::TargetRegisterInfo::isPhysicalRegister(), llvm::MCRegisterInfo::DiffListIterator::isValid(), llvm::SmallBitVector::set(), setSubRegisterPiece(), llvm::AMDGPU::HSAMD::Kernel::Arg::Key::Size, and llvm::SmallBitVector::test().

Referenced by addMachineRegExpression().

◆ addMachineRegExpression()

bool DwarfExpression::addMachineRegExpression ( const TargetRegisterInfo TRI,
DIExpressionCursor Expr,
unsigned  MachineReg,
unsigned  FragmentOffsetInBits = 0 
)

Emit a machine register location.

As an optimization this may also consume the prefix of a DwarfExpression if a more efficient representation for combining the register location and the first operation exists.

Parameters
FragmentOffsetInBitsIf this is one fragment out of a fragmented location, this is the offset of the fragment inside the entire variable.
Returns
false if no DWARF register exists for MachineReg.

Definition at line 200 of file DwarfExpression.cpp.

References addBReg(), addFBReg(), addMachineReg(), addOpPiece(), addReg(), llvm::any_of(), assert(), llvm::DIExpressionCursor::begin(), llvm::DIExpressionCursor::consume(), llvm::dwarf::DW_OP_LLVM_fragment, DwarfRegs, DwarfVersion, llvm::DIExpressionCursor::end(), llvm::DIExpressionCursor::getFragmentInfo(), isFrameRegister(), LocationKind, N, llvm::DIExpressionCursor::peek(), llvm::DIExpressionCursor::peekNext(), SubRegisterSizeInBits, llvm::DIExpressionCursor::take(), and Unknown.

Referenced by llvm::DwarfCompileUnit::addAddress(), llvm::DwarfUnit::addBlockByrefAddress(), llvm::DwarfCompileUnit::addComplexAddress(), llvm::DwarfCompileUnit::constructVariableDIE(), and emitDebugLocValue().

◆ addOpPiece()

void DwarfExpression::addOpPiece ( unsigned  SizeInBits,
unsigned  OffsetInBits = 0 
)
protected

Emit a DW_OP_piece or DW_OP_bit_piece operation for a variable fragment.

Parameters
OffsetInBitsThis is an optional offset into the location that is at the top of the DWARF stack.

Definition at line 57 of file DwarfExpression.cpp.

References emitOp(), and emitUnsigned().

Referenced by addExpression(), addFragmentOffset(), addMachineRegExpression(), addUnsignedConstant(), and finalize().

◆ addReg()

void DwarfExpression::addReg ( int  DwarfReg,
const char Comment = nullptr 
)
protected

Emit a DW_OP_reg operation.

Note that this is only legal inside a DWARF register location description.

Definition at line 27 of file DwarfExpression.cpp.

References assert(), emitOp(), emitUnsigned(), LocationKind, Register, and Unknown.

Referenced by addMachineRegExpression().

◆ addShr()

void DwarfExpression::addShr ( unsigned  ShiftBy)
protected

Emit a shift-right dwarf operation.

Definition at line 74 of file DwarfExpression.cpp.

References emitOp(), and emitUnsigned().

Referenced by maskSubRegister().

◆ addSignedConstant()

void DwarfExpression::addSignedConstant ( int64_t  Value)

Emit a signed constant.

Definition at line 166 of file DwarfExpression.cpp.

References assert(), emitOp(), emitSigned(), Implicit, LocationKind, and Unknown.

Referenced by emitDebugLocValue().

◆ addStackValue()

void DwarfExpression::addStackValue ( )
protected

Emit a DW_OP_stack_value, if supported.

The proper way to describe a constant value is DW_OP_constu <const>, DW_OP_stack_value. Unfortunately, DW_OP_stack_value was not available until DWARF 4, so we will continue to generate DW_OP_constu <const> for DWARF 2 and DWARF 3. Technically, this is incorrect since DW_OP_const <const> actually describes a value at a constant addess, not a constant value. However, in the past there was no better way to describe a constant value, so the producers and consumers started to rely on heuristics to disambiguate the value vs. location status of the expression. See PR21176 for more details.

Definition at line 161 of file DwarfExpression.cpp.

References DwarfVersion, and emitOp().

Referenced by addExpression(), and addUnsignedConstant().

◆ addUnsignedConstant() [1/2]

void DwarfExpression::addUnsignedConstant ( uint64_t  Value)

◆ addUnsignedConstant() [2/2]

void DwarfExpression::addUnsignedConstant ( const APInt Value)

◆ emitOp()

virtual void llvm::DwarfExpression::emitOp ( uint8_t  Op,
const char Comment = nullptr 
)
protectedpure virtual

Output a dwarf operand and an optional assembler comment.

Referenced by addAnd(), addBReg(), addExpression(), addFBReg(), addOpPiece(), addReg(), addShr(), addSignedConstant(), addStackValue(), and addUnsignedConstant().

◆ emitSigned()

virtual void llvm::DwarfExpression::emitSigned ( int64_t  Value)
protectedpure virtual

Emit a raw signed value.

Referenced by addBReg(), addFBReg(), and addSignedConstant().

◆ emitUnsigned()

virtual void llvm::DwarfExpression::emitUnsigned ( uint64_t  Value)
protectedpure virtual

Emit a raw unsigned value.

Referenced by addAnd(), addBReg(), addExpression(), addOpPiece(), addReg(), addShr(), and addUnsignedConstant().

◆ finalize()

void DwarfExpression::finalize ( )

This needs to be called last to commit any pending changes.

Definition at line 390 of file DwarfExpression.cpp.

References addOpPiece(), assert(), DwarfRegs, SubRegisterOffsetInBits, and SubRegisterSizeInBits.

Referenced by llvm::DIEDwarfExpression::finalize().

◆ isFrameRegister()

virtual bool llvm::DwarfExpression::isFrameRegister ( const TargetRegisterInfo TRI,
unsigned  MachineReg 
)
protectedpure virtual

Return whether the given machine register is the frame register in the current function.

Referenced by addMachineReg(), and addMachineRegExpression().

◆ maskSubRegister()

void DwarfExpression::maskSubRegister ( )
protected

Add masking operations to stencil out a subregister.

add masking operations to stencil out a subregister.

Definition at line 382 of file DwarfExpression.cpp.

References addAnd(), addShr(), assert(), llvm::BitmaskEnumDetail::Mask(), SubRegisterOffsetInBits, and SubRegisterSizeInBits.

Referenced by addExpression().

◆ setMemoryLocationKind()

void llvm::DwarfExpression::setMemoryLocationKind ( )
inline

◆ setSubRegisterPiece()

void llvm::DwarfExpression::setSubRegisterPiece ( unsigned  SizeInBits,
unsigned  OffsetInBits 
)
inlineprotected

Push a DW_OP_piece / DW_OP_bit_piece for emitting later, if one is needed to represent a subregister.

Definition at line 124 of file DwarfExpression.h.

References llvm::BitmaskEnumDetail::Mask().

Referenced by addExpression(), and addMachineReg().

Member Data Documentation

◆ DwarfRegs

SmallVector<Register, 2> llvm::DwarfExpression::DwarfRegs
protected

The register location, if any.

Definition at line 109 of file DwarfExpression.h.

Referenced by addMachineReg(), addMachineRegExpression(), and finalize().

◆ DwarfVersion

unsigned llvm::DwarfExpression::DwarfVersion
protected

Definition at line 113 of file DwarfExpression.h.

Referenced by addMachineRegExpression(), and addStackValue().

◆ LocationKind

enum { ... } llvm::DwarfExpression::LocationKind

The kind of location description being produced.

Referenced by addBReg(), addExpression(), addMachineRegExpression(), addReg(), addSignedConstant(), and addUnsignedConstant().

◆ OffsetInBits

uint64_t llvm::DwarfExpression::OffsetInBits = 0
protected

Current Fragment Offset in Bits.

Definition at line 112 of file DwarfExpression.h.

Referenced by addExpression(), and addFragmentOffset().

◆ SubRegisterOffsetInBits

unsigned llvm::DwarfExpression::SubRegisterOffsetInBits = 0
protected

Definition at line 117 of file DwarfExpression.h.

Referenced by addExpression(), finalize(), and maskSubRegister().

◆ SubRegisterSizeInBits

unsigned llvm::DwarfExpression::SubRegisterSizeInBits = 0
protected

Sometimes we need to add a DW_OP_bit_piece to describe a subregister.

Definition at line 116 of file DwarfExpression.h.

Referenced by addExpression(), addMachineRegExpression(), finalize(), and maskSubRegister().


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