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 {
34 // Various convenience accessors that extract things out of AsmPrinter.
35 const TargetRegisterInfo *getTRI() const;
36 unsigned getDwarfVersion() const;
39 DwarfExpression(const AsmPrinter &AP) : AP(AP) {}
40 virtual ~DwarfExpression() {}
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.
45 virtual void EmitSigned(int Value) = 0;
46 /// Emit a raw unsigned value.
47 virtual void EmitUnsigned(unsigned Value) = 0;
48 /// Return whether the given machine register is the frame register in the
50 virtual bool isFrameRegister(unsigned MachineReg) = 0;
52 /// Emit a dwarf register operation.
53 void AddReg(int DwarfReg, const char *Comment = nullptr);
54 /// Emit an (double-)indirect dwarf register operation.
55 void AddRegIndirect(int DwarfReg, int Offset, bool Deref = false);
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);
64 /// Emit an indirect dwarf register operation for the given machine register.
65 /// \return false if no DWARF register exists for MachineReg.
66 bool AddMachineRegIndirect(unsigned MachineReg, int Offset = 0);
68 /// \brief Emit a partial DWARF register operation.
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.
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.
81 /// \return false if no DWARF register exists for MachineReg.
82 bool AddMachineRegPiece(unsigned MachineReg, unsigned PieceSizeInBits = 0,
83 unsigned PieceOffsetInBits = 0);
85 /// Emit a signed constant.
86 void AddSignedConstant(int Value);
87 /// Emit an unsigned constant.
88 void AddUnsignedConstant(unsigned Value);
90 /// Emit an entire DIExpression on top of a machine register location.
91 /// \param PieceOffsetInBits If this is one piece out of a fragmented
92 /// location, this is the offset of the piece inside the entire variable.
93 /// \return false if no DWARF register exists for MachineReg.
94 bool AddMachineRegExpression(DIExpression Expr, unsigned MachineReg,
95 unsigned PieceOffsetInBits = 0);
96 /// Emit a the operations remaining the DIExpressionIterator I.
97 /// \param PieceOffsetInBits If this is one piece out of a fragmented
98 /// location, this is the offset of the piece inside the entire variable.
99 void AddExpression(DIExpression::iterator I, unsigned PieceOffsetInBits = 0);
102 /// DwarfExpression implementation for .debug_loc entries.
103 class DebugLocDwarfExpression : public DwarfExpression {
107 DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
108 : DwarfExpression(AP), BS(BS) {}
110 void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
111 void EmitSigned(int Value) override;
112 void EmitUnsigned(unsigned Value) override;
113 bool isFrameRegister(unsigned MachineReg) override;
116 /// DwarfExpression implementation for singular DW_AT_location.
117 class DIEDwarfExpression : public DwarfExpression {
122 DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE)
123 : DwarfExpression(AP), DU(DU), DIE(DIE) {}
125 void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
126 void EmitSigned(int Value) override;
127 void EmitUnsigned(unsigned Value) override;
128 bool isFrameRegister(unsigned MachineReg) override;