Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 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 | |
| 14 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXPRESSION_H |
| 15 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXPRESSION_H |
| 16 | |
| 17 | #include "llvm/Support/DataTypes.h" |
Adrian Prantl | 092d948 | 2015-01-13 23:39:11 +0000 | [diff] [blame] | 18 | #include "llvm/IR/DebugInfo.h" |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | |
Adrian Prantl | a4c30d6 | 2015-01-12 23:36:56 +0000 | [diff] [blame] | 22 | class AsmPrinter; |
Adrian Prantl | 66f2595 | 2015-01-13 00:04:06 +0000 | [diff] [blame] | 23 | class ByteStreamer; |
Adrian Prantl | a4c30d6 | 2015-01-12 23:36:56 +0000 | [diff] [blame] | 24 | class TargetRegisterInfo; |
Adrian Prantl | 658676c | 2015-01-14 01:01:22 +0000 | [diff] [blame^] | 25 | class DwarfUnit; |
| 26 | class DIELoc; |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 27 | |
| 28 | /// Base class containing the logic for constructing DWARF expressions |
| 29 | /// independently of whether they are emitted into a DIE or into a .debug_loc |
| 30 | /// entry. |
| 31 | class DwarfExpression { |
Adrian Prantl | 00dbc2a | 2015-01-12 22:19:26 +0000 | [diff] [blame] | 32 | protected: |
Adrian Prantl | a4c30d6 | 2015-01-12 23:36:56 +0000 | [diff] [blame] | 33 | const AsmPrinter ≈ |
| 34 | // Various convenience accessors that extract things out of AsmPrinter. |
| 35 | const TargetRegisterInfo *getTRI() const; |
Adrian Prantl | 66f2595 | 2015-01-13 00:04:06 +0000 | [diff] [blame] | 36 | unsigned getDwarfVersion() const; |
Adrian Prantl | a4c30d6 | 2015-01-12 23:36:56 +0000 | [diff] [blame] | 37 | |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 38 | public: |
Adrian Prantl | a4c30d6 | 2015-01-12 23:36:56 +0000 | [diff] [blame] | 39 | DwarfExpression(const AsmPrinter &AP) : AP(AP) {} |
Adrian Prantl | 9cffbd8 | 2015-01-12 23:36:50 +0000 | [diff] [blame] | 40 | virtual ~DwarfExpression() {} |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 41 | |
Adrian Prantl | 172ab66 | 2015-01-13 23:11:07 +0000 | [diff] [blame] | 42 | /// Output a dwarf operand and an optional assembler comment. |
| 43 | virtual void EmitOp(uint8_t Op, const char *Comment = nullptr) = 0; |
| 44 | /// Emit a raw signed value. |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 45 | virtual void EmitSigned(int Value) = 0; |
Adrian Prantl | 172ab66 | 2015-01-13 23:11:07 +0000 | [diff] [blame] | 46 | /// Emit a raw unsigned value. |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 47 | virtual void EmitUnsigned(unsigned Value) = 0; |
Adrian Prantl | 172ab66 | 2015-01-13 23:11:07 +0000 | [diff] [blame] | 48 | /// Return whether the given machine register is the frame register in the |
| 49 | /// current function. |
Adrian Prantl | 8995f5c | 2015-01-13 23:10:43 +0000 | [diff] [blame] | 50 | virtual bool isFrameRegister(unsigned MachineReg) = 0; |
Adrian Prantl | 00dbc2a | 2015-01-12 22:19:26 +0000 | [diff] [blame] | 51 | |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 52 | /// Emit a dwarf register operation. |
Adrian Prantl | 172ab66 | 2015-01-13 23:11:07 +0000 | [diff] [blame] | 53 | void AddReg(int DwarfReg, const char *Comment = nullptr); |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 54 | /// Emit an (double-)indirect dwarf register operation. |
| 55 | void AddRegIndirect(int DwarfReg, int Offset, bool Deref = false); |
| 56 | |
| 57 | /// Emit a dwarf register operation for describing |
| 58 | /// - a small value occupying only part of a register or |
| 59 | /// - a register representing only part of a value. |
| 60 | void AddOpPiece(unsigned SizeInBits, unsigned OffsetInBits = 0); |
| 61 | /// Emit a shift-right dwarf expression. |
| 62 | void AddShr(unsigned ShiftBy); |
| 63 | |
Adrian Prantl | 00dbc2a | 2015-01-12 22:19:26 +0000 | [diff] [blame] | 64 | /// Emit an indirect dwarf register operation for the given machine register. |
| 65 | /// Returns false if no DWARF register exists for MachineReg. |
Adrian Prantl | 172ab66 | 2015-01-13 23:11:07 +0000 | [diff] [blame] | 66 | bool AddMachineRegIndirect(unsigned MachineReg, int Offset = 0); |
Adrian Prantl | 00dbc2a | 2015-01-12 22:19:26 +0000 | [diff] [blame] | 67 | |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 68 | /// \brief Emit a partial DWARF register operation. |
Adrian Prantl | 172ab66 | 2015-01-13 23:11:07 +0000 | [diff] [blame] | 69 | /// \param MachineReg the register |
| 70 | /// \param PieceSizeInBits size and |
| 71 | /// \param PieceOffsetInBits offset of the piece in bits, if this is one |
| 72 | /// piece of an aggregate value. |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 73 | /// |
| 74 | /// If size and offset is zero an operation for the entire |
| 75 | /// register is emitted: Some targets do not provide a DWARF |
| 76 | /// register number for every register. If this is the case, this |
| 77 | /// function will attempt to emit a DWARF register by emitting a |
| 78 | /// piece of a super-register or by piecing together multiple |
| 79 | /// subregisters that alias the register. |
Adrian Prantl | 172ab66 | 2015-01-13 23:11:07 +0000 | [diff] [blame] | 80 | void AddMachineRegPiece(unsigned MachineReg, unsigned PieceSizeInBits = 0, |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 81 | unsigned PieceOffsetInBits = 0); |
Adrian Prantl | 66f2595 | 2015-01-13 00:04:06 +0000 | [diff] [blame] | 82 | |
| 83 | /// Emit a signed constant. |
| 84 | void AddSignedConstant(int Value); |
| 85 | /// Emit an unsigned constant. |
| 86 | void AddUnsignedConstant(unsigned Value); |
Adrian Prantl | 66f2595 | 2015-01-13 00:04:06 +0000 | [diff] [blame] | 87 | |
Adrian Prantl | 092d948 | 2015-01-13 23:39:11 +0000 | [diff] [blame] | 88 | /// Emit an entire DIExpression on top of a machine register location. |
| 89 | /// \param PieceOffsetInBits If this is one piece out of a fragmented |
| 90 | /// location, this is the offset of the piece inside the entire variable. |
| 91 | void AddMachineRegExpression(DIExpression Expr, unsigned MachineReg, |
| 92 | unsigned PieceOffsetInBits = 0); |
| 93 | /// Emit a the operations in a DIExpression, starting from element I. |
| 94 | /// \param PieceOffsetInBits If this is one piece out of a fragmented |
| 95 | /// location, this is the offset of the piece inside the entire variable. |
| 96 | void AddExpression(DIExpression Expr, unsigned PieceOffsetInBits = 0, |
| 97 | unsigned I = 0); |
| 98 | }; |
Adrian Prantl | 66f2595 | 2015-01-13 00:04:06 +0000 | [diff] [blame] | 99 | |
| 100 | /// DwarfExpression implementation for .debug_loc entries. |
| 101 | class DebugLocDwarfExpression : public DwarfExpression { |
| 102 | ByteStreamer &BS; |
| 103 | |
| 104 | public: |
| 105 | DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS) |
| 106 | : DwarfExpression(AP), BS(BS) {} |
| 107 | |
Adrian Prantl | 172ab66 | 2015-01-13 23:11:07 +0000 | [diff] [blame] | 108 | void EmitOp(uint8_t Op, const char *Comment = nullptr) override; |
Adrian Prantl | 66f2595 | 2015-01-13 00:04:06 +0000 | [diff] [blame] | 109 | void EmitSigned(int Value) override; |
| 110 | void EmitUnsigned(unsigned Value) override; |
Adrian Prantl | 8995f5c | 2015-01-13 23:10:43 +0000 | [diff] [blame] | 111 | bool isFrameRegister(unsigned MachineReg) override; |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 112 | }; |
Adrian Prantl | 658676c | 2015-01-14 01:01:22 +0000 | [diff] [blame^] | 113 | |
| 114 | /// DwarfExpression implementation for singular DW_AT_location. |
| 115 | class DIEDwarfExpression : public DwarfExpression { |
| 116 | DwarfUnit &DU; |
| 117 | DIELoc ¨ |
| 118 | |
| 119 | public: |
| 120 | DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE) |
| 121 | : DwarfExpression(AP), DU(DU), DIE(DIE) {} |
| 122 | |
| 123 | void EmitOp(uint8_t Op, const char *Comment = nullptr) override; |
| 124 | void EmitSigned(int Value) override; |
| 125 | void EmitUnsigned(unsigned Value) override; |
| 126 | bool isFrameRegister(unsigned MachineReg) override; |
| 127 | }; |
Adrian Prantl | b16d9eb | 2015-01-12 22:19:22 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | #endif |