blob: 92e4d5d8a2905b9d0f4a528a937b02a9d3950da8 [file] [log] [blame]
Adrian Prantlb16d9eb2015-01-12 22:19:22 +00001//===-- 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
Adrian Prantl092d9482015-01-13 23:39:11 +000017#include "llvm/IR/DebugInfo.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000018#include "llvm/Support/DataTypes.h"
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000019
20namespace llvm {
21
Adrian Prantla4c30d62015-01-12 23:36:56 +000022class AsmPrinter;
Adrian Prantl66f25952015-01-13 00:04:06 +000023class ByteStreamer;
Adrian Prantla4c30d62015-01-12 23:36:56 +000024class TargetRegisterInfo;
Adrian Prantl658676c2015-01-14 01:01:22 +000025class DwarfUnit;
26class DIELoc;
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000027
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.
31class DwarfExpression {
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000032protected:
Adrian Prantla4c30d62015-01-12 23:36:56 +000033 const AsmPrinter ≈
34 // Various convenience accessors that extract things out of AsmPrinter.
35 const TargetRegisterInfo *getTRI() const;
Adrian Prantl66f25952015-01-13 00:04:06 +000036 unsigned getDwarfVersion() const;
Adrian Prantla4c30d62015-01-12 23:36:56 +000037
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000038public:
Adrian Prantla4c30d62015-01-12 23:36:56 +000039 DwarfExpression(const AsmPrinter &AP) : AP(AP) {}
Adrian Prantl9cffbd82015-01-12 23:36:50 +000040 virtual ~DwarfExpression() {}
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000041
Adrian Prantl172ab662015-01-13 23:11:07 +000042 /// 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 Prantlb16d9eb2015-01-12 22:19:22 +000045 virtual void EmitSigned(int Value) = 0;
Adrian Prantl172ab662015-01-13 23:11:07 +000046 /// Emit a raw unsigned value.
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000047 virtual void EmitUnsigned(unsigned Value) = 0;
Adrian Prantl172ab662015-01-13 23:11:07 +000048 /// Return whether the given machine register is the frame register in the
49 /// current function.
Adrian Prantl8995f5c2015-01-13 23:10:43 +000050 virtual bool isFrameRegister(unsigned MachineReg) = 0;
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000051
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000052 /// Emit a dwarf register operation.
Adrian Prantl172ab662015-01-13 23:11:07 +000053 void AddReg(int DwarfReg, const char *Comment = nullptr);
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000054 /// 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 Prantl00dbc2a2015-01-12 22:19:26 +000064 /// Emit an indirect dwarf register operation for the given machine register.
Adrian Prantlad768c32015-01-14 01:01:28 +000065 /// \return false if no DWARF register exists for MachineReg.
Adrian Prantl172ab662015-01-13 23:11:07 +000066 bool AddMachineRegIndirect(unsigned MachineReg, int Offset = 0);
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000067
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000068 /// \brief Emit a partial DWARF register operation.
Adrian Prantl172ab662015-01-13 23:11:07 +000069 /// \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 Prantlb16d9eb2015-01-12 22:19:22 +000073 ///
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 Prantlad768c32015-01-14 01:01:28 +000080 ///
81 /// \return false if no DWARF register exists for MachineReg.
82 bool AddMachineRegPiece(unsigned MachineReg, unsigned PieceSizeInBits = 0,
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000083 unsigned PieceOffsetInBits = 0);
Adrian Prantl66f25952015-01-13 00:04:06 +000084
85 /// Emit a signed constant.
86 void AddSignedConstant(int Value);
87 /// Emit an unsigned constant.
88 void AddUnsignedConstant(unsigned Value);
Adrian Prantl66f25952015-01-13 00:04:06 +000089
Adrian Prantl092d9482015-01-13 23:39:11 +000090 /// 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.
Adrian Prantlad768c32015-01-14 01:01:28 +000093 /// \return false if no DWARF register exists for MachineReg.
94 bool AddMachineRegExpression(DIExpression Expr, unsigned MachineReg,
Adrian Prantl092d9482015-01-13 23:39:11 +000095 unsigned PieceOffsetInBits = 0);
96 /// Emit a the operations in a DIExpression, starting from element 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 Expr, unsigned PieceOffsetInBits = 0,
100 unsigned I = 0);
101};
Adrian Prantl66f25952015-01-13 00:04:06 +0000102
103/// DwarfExpression implementation for .debug_loc entries.
104class DebugLocDwarfExpression : public DwarfExpression {
105 ByteStreamer &BS;
106
107public:
108 DebugLocDwarfExpression(const AsmPrinter &AP, ByteStreamer &BS)
109 : DwarfExpression(AP), BS(BS) {}
110
Adrian Prantl172ab662015-01-13 23:11:07 +0000111 void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
Adrian Prantl66f25952015-01-13 00:04:06 +0000112 void EmitSigned(int Value) override;
113 void EmitUnsigned(unsigned Value) override;
Adrian Prantl8995f5c2015-01-13 23:10:43 +0000114 bool isFrameRegister(unsigned MachineReg) override;
Adrian Prantlb16d9eb2015-01-12 22:19:22 +0000115};
Adrian Prantl658676c2015-01-14 01:01:22 +0000116
117/// DwarfExpression implementation for singular DW_AT_location.
118class DIEDwarfExpression : public DwarfExpression {
119 DwarfUnit &DU;
120 DIELoc ¨
121
122public:
123 DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE)
124 : DwarfExpression(AP), DU(DU), DIE(DIE) {}
125
126 void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
127 void EmitSigned(int Value) override;
128 void EmitUnsigned(unsigned Value) override;
129 bool isFrameRegister(unsigned MachineReg) override;
130};
Adrian Prantlb16d9eb2015-01-12 22:19:22 +0000131}
132
133#endif