DwarfExpression.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //===-- llvm/CodeGen/DwarfExpression.h - Dwarf Compile Unit ---*- C++ -*--===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file contains support for writing dwarf compile unit.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXPRESSION_H
  14. #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXPRESSION_H
  15. #include "llvm/IR/DebugInfo.h"
  16. #include "llvm/Support/DataTypes.h"
  17. namespace llvm {
  18. class AsmPrinter;
  19. class ByteStreamer;
  20. class TargetRegisterInfo;
  21. class DwarfUnit;
  22. class DIELoc;
  23. /// Base class containing the logic for constructing DWARF expressions
  24. /// independently of whether they are emitted into a DIE or into a .debug_loc
  25. /// entry.
  26. class DwarfExpression {
  27. protected:
  28. // Various convenience accessors that extract things out of AsmPrinter.
  29. const TargetRegisterInfo &TRI;
  30. unsigned DwarfVersion;
  31. public:
  32. DwarfExpression(const TargetRegisterInfo &TRI,
  33. unsigned DwarfVersion)
  34. : TRI(TRI), DwarfVersion(DwarfVersion) {}
  35. virtual ~DwarfExpression() {}
  36. /// Output a dwarf operand and an optional assembler comment.
  37. virtual void EmitOp(uint8_t Op, const char *Comment = nullptr) = 0;
  38. /// Emit a raw signed value.
  39. virtual void EmitSigned(int64_t Value) = 0;
  40. /// Emit a raw unsigned value.
  41. virtual void EmitUnsigned(uint64_t Value) = 0;
  42. /// Return whether the given machine register is the frame register in the
  43. /// current function.
  44. virtual bool isFrameRegister(unsigned MachineReg) = 0;
  45. /// Emit a dwarf register operation.
  46. void AddReg(int DwarfReg, const char *Comment = nullptr);
  47. /// Emit an (double-)indirect dwarf register operation.
  48. void AddRegIndirect(int DwarfReg, int Offset, bool Deref = false);
  49. /// Emit a dwarf register operation for describing
  50. /// - a small value occupying only part of a register or
  51. /// - a register representing only part of a value.
  52. void AddOpPiece(unsigned SizeInBits, unsigned OffsetInBits = 0);
  53. /// Emit a shift-right dwarf expression.
  54. void AddShr(unsigned ShiftBy);
  55. /// Emit an indirect dwarf register operation for the given machine register.
  56. /// \return false if no DWARF register exists for MachineReg.
  57. bool AddMachineRegIndirect(unsigned MachineReg, int Offset = 0);
  58. /// \brief Emit a partial DWARF register operation.
  59. /// \param MachineReg the register
  60. /// \param PieceSizeInBits size and
  61. /// \param PieceOffsetInBits offset of the piece in bits, if this is one
  62. /// piece of an aggregate value.
  63. ///
  64. /// If size and offset is zero an operation for the entire
  65. /// register is emitted: Some targets do not provide a DWARF
  66. /// register number for every register. If this is the case, this
  67. /// function will attempt to emit a DWARF register by emitting a
  68. /// piece of a super-register or by piecing together multiple
  69. /// subregisters that alias the register.
  70. ///
  71. /// \return false if no DWARF register exists for MachineReg.
  72. bool AddMachineRegPiece(unsigned MachineReg, unsigned PieceSizeInBits = 0,
  73. unsigned PieceOffsetInBits = 0);
  74. /// Emit a signed constant.
  75. void AddSignedConstant(int Value);
  76. /// Emit an unsigned constant.
  77. void AddUnsignedConstant(unsigned Value);
  78. /// \brief Emit an entire expression on top of a machine register location.
  79. ///
  80. /// \param PieceOffsetInBits If this is one piece out of a fragmented
  81. /// location, this is the offset of the piece inside the entire variable.
  82. /// \return false if no DWARF register exists for MachineReg.
  83. bool AddMachineRegExpression(const DIExpression *Expr, unsigned MachineReg,
  84. unsigned PieceOffsetInBits = 0);
  85. /// Emit a the operations remaining the DIExpressionIterator I.
  86. /// \param PieceOffsetInBits If this is one piece out of a fragmented
  87. /// location, this is the offset of the piece inside the entire variable.
  88. void AddExpression(DIExpression::expr_op_iterator I,
  89. DIExpression::expr_op_iterator E,
  90. unsigned PieceOffsetInBits = 0);
  91. };
  92. /// DwarfExpression implementation for .debug_loc entries.
  93. class DebugLocDwarfExpression : public DwarfExpression {
  94. ByteStreamer &BS;
  95. public:
  96. DebugLocDwarfExpression(const TargetRegisterInfo &TRI,
  97. unsigned DwarfVersion, ByteStreamer &BS)
  98. : DwarfExpression(TRI, DwarfVersion), BS(BS) {}
  99. void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
  100. void EmitSigned(int64_t Value) override;
  101. void EmitUnsigned(uint64_t Value) override;
  102. bool isFrameRegister(unsigned MachineReg) override;
  103. };
  104. /// DwarfExpression implementation for singular DW_AT_location.
  105. class DIEDwarfExpression : public DwarfExpression {
  106. const AsmPrinter ≈
  107. DwarfUnit &DU;
  108. DIELoc ¨
  109. public:
  110. DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE);
  111. void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
  112. void EmitSigned(int64_t Value) override;
  113. void EmitUnsigned(uint64_t Value) override;
  114. bool isFrameRegister(unsigned MachineReg) override;
  115. };
  116. }
  117. #endif