30 emitOp(dwarf::DW_OP_lit0 + Value);
37 emitOp(dwarf::DW_OP_constu);
43 assert(DwarfReg >= 0 &&
"invalid negative dwarf register number");
45 "location description already locked down");
48 emitOp(dwarf::DW_OP_reg0 + DwarfReg, Comment);
50 emitOp(dwarf::DW_OP_regx, Comment);
56 assert(DwarfReg >= 0 &&
"invalid negative dwarf register number");
59 emitOp(dwarf::DW_OP_breg0 + DwarfReg);
61 emitOp(dwarf::DW_OP_bregx);
68 emitOp(dwarf::DW_OP_fbreg);
76 const unsigned SizeOfByte = 8;
77 if (OffsetInBits > 0 || SizeInBits % SizeOfByte) {
78 emitOp(dwarf::DW_OP_bit_piece);
82 emitOp(dwarf::DW_OP_piece);
83 unsigned ByteSize = SizeInBits / SizeOfByte;
86 this->OffsetInBits += SizeInBits;
100 unsigned MachineReg,
unsigned MaxSize) {
155 CurSubReg.
set(Offset, Offset + Size);
159 if (Offset < MaxSize && CurSubReg.
test(Coverage)) {
163 {-1, Offset - CurPos,
"no DWARF register encoding"});
165 {
Reg, std::min<unsigned>(
Size, MaxSize -
Offset),
"sub-register"});
168 Coverage.
set(Offset, Offset + Size);
169 CurPos = Offset +
Size;
175 if (CurPos < RegSize)
176 DwarfRegs.push_back({-1, RegSize - CurPos,
"no DWARF register encoding"});
182 emitOp(dwarf::DW_OP_stack_value);
188 emitOp(dwarf::DW_OP_consts);
208 while (Offset < Size) {
210 if (Offset == 0 && Size <= 64)
213 addOpPiece(std::min(Size - Offset, 64u), Offset);
221 unsigned FragmentOffsetInBits) {
223 if (!
addMachineReg(TRI, MachineReg, Fragment ? Fragment->SizeInBits : ~1U)) {
228 bool HasComplexExpression =
false;
229 auto Op = ExprCursor.
peek();
231 HasComplexExpression =
true;
237 if (HasComplexExpression &&
DwarfRegs.size() > 1) {
250 if (
Reg.DwarfRegNo >= 0)
259 emitOp(dwarf::DW_OP_stack_value);
268 return Op.
getOp() == dwarf::DW_OP_stack_value;
278 int SignedOffset = 0;
279 assert(Reg.Size == 0 &&
"subregister has same size as superregister");
283 if (Op && (Op->
getOp() == dwarf::DW_OP_plus_uconst)) {
286 if (Offset <= IntMax) {
295 if (Op && Op->
getOp() == dwarf::DW_OP_constu) {
299 if (
N &&
N->getOp() == dwarf::DW_OP_plus && Offset <= IntMax) {
302 }
else if (
N &&
N->getOp() == dwarf::DW_OP_minus &&
304 SignedOffset = -
static_cast<int64_t
>(
Offset);
312 addBReg(Reg.DwarfRegNo, SignedOffset);
319 auto Op = ExprCursor.
take();
323 "We don't support entry values of memory locations yet");
326 "Can currently only emit entry values covering a single operation");
328 emitOp(
CU.getDwarf5OrGNULocationAtom(dwarf::DW_OP_entry_value));
350 auto Op = ExprCursor.
take();
351 switch (
Op->getOp()) {
352 case dwarf::DW_OP_deref:
363 unsigned FragmentOffsetInBits) {
366 auto N = ExprCursor.peek();
373 auto Op = ExprCursor.take();
374 uint64_t OpNum =
Op->getOp();
376 if (OpNum >= dwarf::DW_OP_reg0 && OpNum <= dwarf::DW_OP_reg31) {
379 }
else if (OpNum >= dwarf::DW_OP_breg0 && OpNum <= dwarf::DW_OP_breg31) {
380 addBReg(OpNum - dwarf::DW_OP_breg0,
Op->getArg(0));
386 unsigned SizeInBits =
Op->getArg(1);
387 unsigned FragmentOffset =
Op->getArg(0);
415 case dwarf::DW_OP_plus_uconst:
417 emitOp(dwarf::DW_OP_plus_uconst);
420 case dwarf::DW_OP_plus:
421 case dwarf::DW_OP_minus:
422 case dwarf::DW_OP_mul:
423 case dwarf::DW_OP_div:
424 case dwarf::DW_OP_mod:
425 case dwarf::DW_OP_or:
426 case dwarf::DW_OP_and:
427 case dwarf::DW_OP_xor:
428 case dwarf::DW_OP_shl:
429 case dwarf::DW_OP_shr:
430 case dwarf::DW_OP_shra:
431 case dwarf::DW_OP_lit0:
432 case dwarf::DW_OP_not:
433 case dwarf::DW_OP_dup:
436 case dwarf::DW_OP_deref:
443 emitOp(dwarf::DW_OP_deref);
445 case dwarf::DW_OP_constu:
450 unsigned BitSize =
Op->getArg(0);
453 emitOp(dwarf::DW_OP_convert);
456 unsigned I = 0,
E =
CU.ExprRefedBaseTypes.size();
458 if (
CU.ExprRefedBaseTypes[I].BitSize == BitSize &&
459 CU.ExprRefedBaseTypes[I].Encoding == Encoding)
463 CU.ExprRefedBaseTypes.emplace_back(BitSize, Encoding);
473 if (PrevConvertOp && PrevConvertOp->
getArg(0) < BitSize) {
474 if (Encoding == dwarf::DW_ATE_signed)
476 else if (Encoding == dwarf::DW_ATE_unsigned)
478 PrevConvertOp =
None;
485 case dwarf::DW_OP_stack_value:
488 case dwarf::DW_OP_swap:
490 emitOp(dwarf::DW_OP_swap);
492 case dwarf::DW_OP_xderef:
494 emitOp(dwarf::DW_OP_xderef);
496 case dwarf::DW_OP_deref_size:
497 emitOp(dwarf::DW_OP_deref_size);
503 case dwarf::DW_OP_regx:
504 emitOp(dwarf::DW_OP_regx);
507 case dwarf::DW_OP_bregx:
508 emitOp(dwarf::DW_OP_bregx);
548 "overlapping or duplicate fragments");
557 emitOp(dwarf::DW_OP_constu);
560 emitOp(dwarf::DW_OP_lit0);
563 emitOp(dwarf::DW_OP_constu);
571 emitOp(dwarf::DW_OP_constu);
579 emitOp(dwarf::DW_OP_WASM_location);
This is a 'bitvector' (really, a variable-sized bit array), optimized for the case when the array is ...
void addShr(unsigned ShiftBy)
Emit a shift-right dwarf operation.
This class represents lattice values for constants.
void addUnsignedConstant(uint64_t Value)
Emit an unsigned constant.
void emitConstu(uint64_t Value)
Emit a normalized unsigned constant.
bool IsEmittingEntryValue
Whether we are currently emitting an entry value operation.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
void beginEntryValueExpression(DIExpressionCursor &ExprCursor)
Begin emission of an entry value dwarf operation.
Only used in LLVM metadata.
unsigned const TargetRegisterInfo * TRI
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool test(unsigned Idx) const
virtual void enableTemporaryBuffer()=0
Start emitting data to the temporary buffer.
virtual void emitData1(uint8_t Value)=0
MCSuperRegIterator enumerates all super-registers of Reg.
void addBReg(int DwarfReg, int Offset)
Emit a DW_OP_breg operation.
void addFBReg(int Offset)
Emit DW_OP_fbreg <Offset>.
Only used in LLVM metadata.
Holds a DIExpression and keeps track of how many operands have been consumed so far.
virtual void commitTemporaryBuffer()=0
Commit the data stored in the temporary buffer to the main output.
This file implements a class to represent arbitrary precision integral constant values and operations...
void addReg(int DwarfReg, const char *Comment=nullptr)
Emit a DW_OP_reg operation.
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...
void addWasmLocation(unsigned Index, int64_t Offset)
Emit location information expressed via WebAssembly location + offset The Index is an identifier for ...
int getDwarfRegNum(MCRegister RegNum, bool isEH) const
Map a target register to an equivalent dwarf register number.
Optional< DIExpression::ExprOperand > peek() const
Return the current operation.
bool isImplicitLocation() const
unsigned getSubRegIndex(MCRegister RegNo, MCRegister SubRegNo) const
For a given register pair, return the sub-register index if the second register is a sub-register of ...
bool isEntryValue() const
static Optional< FragmentInfo > getFragmentInfo(expr_op_iterator Start, expr_op_iterator End)
Retrieve the details of this fragment expression.
void emitLegacyZExt(unsigned FromBits)
void maskSubRegister()
Add masking operations to stencil out a subregister.
uint64_t getArg(unsigned I) const
Get an argument to the operand.
Optional< DIExpression::ExprOperand > peekNext() const
Return the next operation.
virtual void emitUnsigned(uint64_t Value)=0
Emit a raw unsigned value.
Optional< DIExpression::ExprOperand > take()
Consume one operation.
uint64_t getOp() const
Get the operand code.
virtual void emitOp(uint8_t Op, const char *Comment=nullptr)=0
Output a dwarf operand and an optional assembler comment.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Only used in LLVM metadata.
A lightweight wrapper around an expression operand.
uint64_t OffsetInBits
Current Fragment Offset in Bits.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
Only used in LLVM metadata.
virtual void emitSigned(int64_t Value)=0
Emit a raw signed value.
virtual unsigned getTemporaryBufferSize()=0
Return the emitted size, in number of bytes, for the data stored in the temporary buffer...
bool isMemoryLocation() const
unsigned getSubRegIdxOffset(unsigned Idx) const
Get the offset of the bit range covered by a sub-register index.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MCSubRegIterator enumerates all sub-registers of Reg.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned SubRegisterOffsetInBits
void addExpression(DIExpressionCursor &&Expr, unsigned FragmentOffsetInBits=0)
Emit all remaining operations in the DIExpressionCursor.
bool addMachineReg(const TargetRegisterInfo &TRI, unsigned MachineReg, unsigned MaxSize=~1U)
Emit a partial DWARF register operation.
Align max(MaybeAlign Lhs, Align Rhs)
bool isUnknownLocation() const
void addStackValue()
Emit a DW_OP_stack_value, if supported.
virtual void disableTemporaryBuffer()=0
Disable emission to the temporary buffer.
This file contains constants used for implementing Dwarf debug support.
Class for arbitrary precision integers.
void addAnd(unsigned Mask)
Emit a bitwise and dwarf operation.
bool isValid() const
isValid - returns true if this iterator is not yet at the end.
Optional< DIExpression::FragmentInfo > getFragmentInfo() const
Retrieve the fragment information, if any.
Optional< uint8_t > TagOffset
const uint64_t * getRawData() const
This function returns a pointer to the internal storage of the APInt.
unsigned SubRegisterSizeInBits
Sometimes we need to add a DW_OP_bit_piece to describe a subregister.
void consume(unsigned N)
Consume N operations.
virtual void emitBaseTypeRef(uint64_t Idx)=0
void finalize()
This needs to be called last to commit any pending changes.
void emitLegacySExt(unsigned FromBits)
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
void addFragmentOffset(const DIExpression *Expr)
If applicable, emit an empty DW_OP_piece / DW_OP_bit_piece to advance to the fragment described by Ex...
void finalizeEntryValue()
Finalize an entry value by emitting its size operand, and committing the DWARF block which has been e...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
void addOpPiece(unsigned SizeInBits, unsigned OffsetInBits=0)
Emit a DW_OP_piece or DW_OP_bit_piece operation for a variable fragment.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
void addSignedConstant(int64_t Value)
Emit a signed constant.
unsigned getSubRegIdxSize(unsigned Idx) const
Get the size of the bit range covered by a sub-register index.
SmallVector< Register, 2 > DwarfRegs
The register location, if any.
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
bool isFragment() const
Return whether this is a piece of an aggregate variable.
bool isRegisterLocation() const
bool addMachineRegExpression(const TargetRegisterInfo &TRI, DIExpressionCursor &Expr, unsigned MachineReg, unsigned FragmentOffsetInBits=0)
Emit a machine register location.
virtual bool isFrameRegister(const TargetRegisterInfo &TRI, unsigned MachineReg)=0
Return whether the given machine register is the frame register in the current function.