blob: a8b65f504346ea2f63063cc1a0dc9ab8b347c771 [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 // Various convenience accessors that extract things out of AsmPrinter.
Adrian Prantl92da14b2015-03-02 22:02:33 +000034 const TargetRegisterInfo &TRI;
35 unsigned DwarfVersion;
Adrian Prantla4c30d62015-01-12 23:36:56 +000036
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000037public:
Adrian Prantl92da14b2015-03-02 22:02:33 +000038 DwarfExpression(const TargetRegisterInfo &TRI,
39 unsigned DwarfVersion)
40 : TRI(TRI), DwarfVersion(DwarfVersion) {}
Adrian Prantl9cffbd82015-01-12 23:36:50 +000041 virtual ~DwarfExpression() {}
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000042
Adrian Prantl172ab662015-01-13 23:11:07 +000043 /// 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.
Adrian Prantl51233682015-03-10 19:23:37 +000046 virtual void EmitSigned(int64_t Value) = 0;
Adrian Prantl172ab662015-01-13 23:11:07 +000047 /// Emit a raw unsigned value.
Adrian Prantl51233682015-03-10 19:23:37 +000048 virtual void EmitUnsigned(uint64_t Value) = 0;
Adrian Prantl172ab662015-01-13 23:11:07 +000049 /// Return whether the given machine register is the frame register in the
50 /// current function.
Adrian Prantl8995f5c2015-01-13 23:10:43 +000051 virtual bool isFrameRegister(unsigned MachineReg) = 0;
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000052
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000053 /// Emit a dwarf register operation.
Adrian Prantl172ab662015-01-13 23:11:07 +000054 void AddReg(int DwarfReg, const char *Comment = nullptr);
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000055 /// 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
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000065 /// Emit an indirect dwarf register operation for the given machine register.
Adrian Prantlad768c32015-01-14 01:01:28 +000066 /// \return false if no DWARF register exists for MachineReg.
Adrian Prantl172ab662015-01-13 23:11:07 +000067 bool AddMachineRegIndirect(unsigned MachineReg, int Offset = 0);
Adrian Prantl00dbc2a2015-01-12 22:19:26 +000068
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000069 /// \brief Emit a partial DWARF register operation.
Adrian Prantl172ab662015-01-13 23:11:07 +000070 /// \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.
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000074 ///
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.
Adrian Prantlad768c32015-01-14 01:01:28 +000081 ///
82 /// \return false if no DWARF register exists for MachineReg.
83 bool AddMachineRegPiece(unsigned MachineReg, unsigned PieceSizeInBits = 0,
Adrian Prantlb16d9eb2015-01-12 22:19:22 +000084 unsigned PieceOffsetInBits = 0);
Adrian Prantl66f25952015-01-13 00:04:06 +000085
86 /// Emit a signed constant.
87 void AddSignedConstant(int Value);
88 /// Emit an unsigned constant.
89 void AddUnsignedConstant(unsigned Value);
Adrian Prantl66f25952015-01-13 00:04:06 +000090
Adrian Prantl092d9482015-01-13 23:39:11 +000091 /// 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.
Adrian Prantlad768c32015-01-14 01:01:28 +000094 /// \return false if no DWARF register exists for MachineReg.
95 bool AddMachineRegExpression(DIExpression Expr, unsigned MachineReg,
Adrian Prantl092d9482015-01-13 23:39:11 +000096 unsigned PieceOffsetInBits = 0);
Adrian Prantl531641a2015-01-22 00:00:59 +000097 /// Emit a the operations remaining the DIExpressionIterator I.
Adrian Prantl092d9482015-01-13 23:39:11 +000098 /// \param PieceOffsetInBits If this is one piece out of a fragmented
99 /// location, this is the offset of the piece inside the entire variable.
Duncan P. N. Exon Smith76c91842015-04-07 03:45:57 +0000100 void AddExpression(MDExpression::expr_op_iterator I,
101 MDExpression::expr_op_iterator E,
Duncan P. N. Exon Smith57bab0b2015-02-17 22:30:56 +0000102 unsigned PieceOffsetInBits = 0);
Adrian Prantl092d9482015-01-13 23:39:11 +0000103};
Adrian Prantl66f25952015-01-13 00:04:06 +0000104
105/// DwarfExpression implementation for .debug_loc entries.
106class DebugLocDwarfExpression : public DwarfExpression {
107 ByteStreamer &BS;
108
109public:
Adrian Prantl92da14b2015-03-02 22:02:33 +0000110 DebugLocDwarfExpression(const TargetRegisterInfo &TRI,
111 unsigned DwarfVersion, ByteStreamer &BS)
112 : DwarfExpression(TRI, DwarfVersion), BS(BS) {}
Adrian Prantl66f25952015-01-13 00:04:06 +0000113
Adrian Prantl172ab662015-01-13 23:11:07 +0000114 void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
Adrian Prantl51233682015-03-10 19:23:37 +0000115 void EmitSigned(int64_t Value) override;
116 void EmitUnsigned(uint64_t Value) override;
Adrian Prantl8995f5c2015-01-13 23:10:43 +0000117 bool isFrameRegister(unsigned MachineReg) override;
Adrian Prantlb16d9eb2015-01-12 22:19:22 +0000118};
Adrian Prantl658676c2015-01-14 01:01:22 +0000119
120/// DwarfExpression implementation for singular DW_AT_location.
121class DIEDwarfExpression : public DwarfExpression {
Adrian Prantl92da14b2015-03-02 22:02:33 +0000122const AsmPrinter ≈
Adrian Prantl658676c2015-01-14 01:01:22 +0000123 DwarfUnit &DU;
124 DIELoc ¨
125
126public:
Adrian Prantl92da14b2015-03-02 22:02:33 +0000127 DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU, DIELoc &DIE);
Adrian Prantl658676c2015-01-14 01:01:22 +0000128 void EmitOp(uint8_t Op, const char *Comment = nullptr) override;
Adrian Prantl51233682015-03-10 19:23:37 +0000129 void EmitSigned(int64_t Value) override;
130 void EmitUnsigned(uint64_t Value) override;
Adrian Prantl658676c2015-01-14 01:01:22 +0000131 bool isFrameRegister(unsigned MachineReg) override;
132};
Adrian Prantlb16d9eb2015-01-12 22:19:22 +0000133}
134
135#endif