LLVM  3.7.0
DwarfExpression.h
Go to the documentation of this file.
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/IR/DebugInfo.h"
18 #include "llvm/Support/DataTypes.h"
19 
20 namespace llvm {
21 
22 class AsmPrinter;
23 class ByteStreamer;
24 class TargetRegisterInfo;
25 class DwarfUnit;
26 class DIELoc;
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.
32 protected:
33  // Various convenience accessors that extract things out of AsmPrinter.
35  unsigned DwarfVersion;
36 
37 public:
39  unsigned DwarfVersion)
40  : TRI(TRI), DwarfVersion(DwarfVersion) {}
41  virtual ~DwarfExpression() {}
42 
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(int64_t Value) = 0;
47  /// Emit a raw unsigned value.
48  virtual void EmitUnsigned(uint64_t Value) = 0;
49  /// Return whether the given machine register is the frame register in the
50  /// current function.
51  virtual bool isFrameRegister(unsigned MachineReg) = 0;
52 
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);
57 
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);
64 
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);
68 
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.
74  ///
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.
81  ///
82  /// \return false if no DWARF register exists for MachineReg.
83  bool AddMachineRegPiece(unsigned MachineReg, unsigned PieceSizeInBits = 0,
84  unsigned PieceOffsetInBits = 0);
85 
86  /// Emit a signed constant.
87  void AddSignedConstant(int Value);
88  /// Emit an unsigned constant.
89  void AddUnsignedConstant(unsigned Value);
90 
91  /// \brief Emit an entire expression on top of a machine register location.
92  ///
93  /// \param PieceOffsetInBits If this is one piece out of a fragmented
94  /// location, this is the offset of the piece inside the entire variable.
95  /// \return false if no DWARF register exists for MachineReg.
96  bool AddMachineRegExpression(const DIExpression *Expr, unsigned MachineReg,
97  unsigned PieceOffsetInBits = 0);
98  /// Emit a the operations remaining the DIExpressionIterator I.
99  /// \param PieceOffsetInBits If this is one piece out of a fragmented
100  /// location, this is the offset of the piece inside the entire variable.
103  unsigned PieceOffsetInBits = 0);
104 };
105 
106 /// DwarfExpression implementation for .debug_loc entries.
108  ByteStreamer &BS;
109 
110 public:
112  unsigned DwarfVersion, ByteStreamer &BS)
113  : DwarfExpression(TRI, DwarfVersion), BS(BS) {}
114 
115  void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
116  void EmitSigned(int64_t Value) override;
117  void EmitUnsigned(uint64_t Value) override;
118  bool isFrameRegister(unsigned MachineReg) override;
119 };
120 
121 /// DwarfExpression implementation for singular DW_AT_location.
123 const AsmPrinter ≈
124  DwarfUnit &DU;
125  DIELoc ¨
126 
127 public:
129  void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
130  void EmitSigned(int64_t Value) override;
131  void EmitUnsigned(uint64_t Value) override;
132  bool isFrameRegister(unsigned MachineReg) override;
133 };
134 }
135 
136 #endif
DIELoc - Represents an expression location.
Definition: DIE.h:748
Base class containing the logic for constructing DWARF expressions independently of whether they are ...
void EmitSigned(int64_t Value) override
Emit a raw signed value.
Definition: DwarfUnit.cpp:56
void AddShr(unsigned ShiftBy)
Emit a shift-right dwarf expression.
bool AddMachineRegExpression(const DIExpression *Expr, unsigned MachineReg, unsigned PieceOffsetInBits=0)
Emit an entire expression on top of a machine register location.
bool isFrameRegister(unsigned MachineReg) override
Return whether the given machine register is the frame register in the current function.
Definition: DwarfDebug.cpp:124
void AddOpPiece(unsigned SizeInBits, unsigned OffsetInBits=0)
Emit a dwarf register operation for describing.
virtual void EmitOp(uint8_t Op, const char *Comment=nullptr)=0
Output a dwarf operand and an optional assembler comment.
void EmitOp(uint8_t Op, const char *Comment=nullptr) override
Output a dwarf operand and an optional assembler comment.
Definition: DwarfUnit.cpp:53
DwarfExpression implementation for .debug_loc entries.
void EmitSigned(int64_t Value) override
Emit a raw signed value.
Definition: DwarfDebug.cpp:116
DwarfExpression(const TargetRegisterInfo &TRI, unsigned DwarfVersion)
void EmitOp(uint8_t Op, const char *Comment=nullptr) override
Output a dwarf operand and an optional assembler comment.
Definition: DwarfDebug.cpp:110
void AddUnsignedConstant(unsigned Value)
Emit an unsigned constant.
void AddSignedConstant(int Value)
Emit a signed constant.
This dwarf writer support class manages information associated with a source file.
Definition: DwarfUnit.h:68
DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE)
Definition: DwarfUnit.cpp:47
void EmitUnsigned(uint64_t Value) override
Emit a raw unsigned value.
Definition: DwarfUnit.cpp:59
DIE - A structured debug information entry.
Definition: DIE.h:623
DebugLocDwarfExpression(const TargetRegisterInfo &TRI, unsigned DwarfVersion, ByteStreamer &BS)
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:66
void AddRegIndirect(int DwarfReg, int Offset, bool Deref=false)
Emit an (double-)indirect dwarf register operation.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
virtual void EmitUnsigned(uint64_t Value)=0
Emit a raw unsigned value.
bool AddMachineRegIndirect(unsigned MachineReg, int Offset=0)
Emit an indirect dwarf register operation for the given machine register.
DWARF expression.
void EmitUnsigned(uint64_t Value) override
Emit a raw unsigned value.
Definition: DwarfDebug.cpp:120
#define I(x, y, z)
Definition: MD5.cpp:54
DwarfExpression implementation for singular DW_AT_location.
bool isFrameRegister(unsigned MachineReg) override
Return whether the given machine register is the frame register in the current function.
Definition: DwarfUnit.cpp:62
LLVM Value Representation.
Definition: Value.h:69
virtual void EmitSigned(int64_t Value)=0
Emit a raw signed value.
An iterator for expression operands.
void AddReg(int DwarfReg, const char *Comment=nullptr)
Emit a dwarf register operation.
const TargetRegisterInfo & TRI
bool AddMachineRegPiece(unsigned MachineReg, unsigned PieceSizeInBits=0, unsigned PieceOffsetInBits=0)
Emit a partial DWARF register operation.
void AddExpression(DIExpression::expr_op_iterator I, DIExpression::expr_op_iterator E, unsigned PieceOffsetInBits=0)
Emit a the operations remaining the DIExpressionIterator I.
virtual bool isFrameRegister(unsigned MachineReg)=0
Return whether the given machine register is the frame register in the current function.