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