blob: 987c0955a0b2cde64a0ef1a99b94674bd49a4267 [file] [log] [blame]
Chris Lattner9efd1182010-04-04 19:09:29 +00001//===-- AsmPrinterDwarf.cpp - AsmPrinter Dwarf Support --------------------===//
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 implements the Dwarf emissions parts of AsmPrinter.
11//
12//===----------------------------------------------------------------------===//
13
Eric Christopher29e874d2014-03-07 22:40:37 +000014#include "ByteStreamer.h"
Chris Lattner9efd1182010-04-04 19:09:29 +000015#include "llvm/CodeGen/AsmPrinter.h"
Eric Christopher698a8ab2014-03-07 01:44:14 +000016#include "llvm/ADT/SmallBitVector.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000017#include "llvm/ADT/Twine.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000018#include "llvm/IR/DataLayout.h"
Chris Lattner9efd1182010-04-04 19:09:29 +000019#include "llvm/MC/MCAsmInfo.h"
Chris Lattner70a4fce2010-04-04 23:25:33 +000020#include "llvm/MC/MCSection.h"
Chris Lattner9efd1182010-04-04 19:09:29 +000021#include "llvm/MC/MCStreamer.h"
Chris Lattner70a4fce2010-04-04 23:25:33 +000022#include "llvm/MC/MCSymbol.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000023#include "llvm/MC/MachineLocation.h"
24#include "llvm/Support/Dwarf.h"
25#include "llvm/Support/ErrorHandling.h"
Anton Korobeynikov2f931282011-01-10 12:39:04 +000026#include "llvm/Target/TargetFrameLowering.h"
Chris Lattnere619c0d2010-04-04 20:20:50 +000027#include "llvm/Target/TargetLoweringObjectFile.h"
28#include "llvm/Target/TargetMachine.h"
Chris Lattneraabc6042010-04-04 23:41:46 +000029#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattner9efd1182010-04-04 19:09:29 +000030using namespace llvm;
31
Chandler Carruth1b9dde02014-04-22 02:02:50 +000032#define DEBUG_TYPE "asm-printer"
33
Chris Lattneraabc6042010-04-04 23:41:46 +000034//===----------------------------------------------------------------------===//
35// Dwarf Emission Helper Routines
36//===----------------------------------------------------------------------===//
37
Chris Lattner9efd1182010-04-04 19:09:29 +000038/// EmitSLEB128 - emit the specified signed leb128 value.
David Blaikie5acff7e2013-06-23 18:31:11 +000039void AsmPrinter::EmitSLEB128(int64_t Value, const char *Desc) const {
Chris Lattner9efd1182010-04-04 19:09:29 +000040 if (isVerbose() && Desc)
41 OutStreamer.AddComment(Desc);
Chris Lattner9efd1182010-04-04 19:09:29 +000042
Benjamin Kramerc74798d2011-11-05 11:52:44 +000043 OutStreamer.EmitSLEB128IntValue(Value);
Chris Lattner9efd1182010-04-04 19:09:29 +000044}
45
46/// EmitULEB128 - emit the specified signed leb128 value.
David Blaikie5acff7e2013-06-23 18:31:11 +000047void AsmPrinter::EmitULEB128(uint64_t Value, const char *Desc,
Chris Lattner9efd1182010-04-04 19:09:29 +000048 unsigned PadTo) const {
49 if (isVerbose() && Desc)
50 OutStreamer.AddComment(Desc);
Rafael Espindola38d07562010-11-04 18:17:08 +000051
Eric Christopherbf7bc492013-01-09 03:52:05 +000052 OutStreamer.EmitULEB128IntValue(Value, PadTo);
Chris Lattner9efd1182010-04-04 19:09:29 +000053}
54
Chris Lattnerbaf2be02010-04-04 20:01:25 +000055/// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
56void AsmPrinter::EmitCFAByte(unsigned Val) const {
57 if (isVerbose()) {
Eric Christopher596077b2013-12-04 22:26:43 +000058 if (Val >= dwarf::DW_CFA_offset && Val < dwarf::DW_CFA_offset + 64)
Eric Christopher1d6bd412012-11-20 20:34:47 +000059 OutStreamer.AddComment("DW_CFA_offset + Reg (" +
Eric Christopher596077b2013-12-04 22:26:43 +000060 Twine(Val - dwarf::DW_CFA_offset) + ")");
Chris Lattnerbaf2be02010-04-04 20:01:25 +000061 else
62 OutStreamer.AddComment(dwarf::CallFrameString(Val));
63 }
Eric Christopherce0cfce2013-01-09 01:35:34 +000064 OutStreamer.EmitIntValue(Val, 1);
Chris Lattnerbaf2be02010-04-04 20:01:25 +000065}
66
Chris Lattnerb75af3c2010-04-04 20:04:21 +000067static const char *DecodeDWARFEncoding(unsigned Encoding) {
68 switch (Encoding) {
Eric Christopher596077b2013-12-04 22:26:43 +000069 case dwarf::DW_EH_PE_absptr:
70 return "absptr";
71 case dwarf::DW_EH_PE_omit:
72 return "omit";
73 case dwarf::DW_EH_PE_pcrel:
74 return "pcrel";
75 case dwarf::DW_EH_PE_udata4:
76 return "udata4";
77 case dwarf::DW_EH_PE_udata8:
78 return "udata8";
79 case dwarf::DW_EH_PE_sdata4:
80 return "sdata4";
81 case dwarf::DW_EH_PE_sdata8:
82 return "sdata8";
83 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4:
84 return "pcrel udata4";
85 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4:
86 return "pcrel sdata4";
87 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8:
88 return "pcrel udata8";
89 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8:
90 return "pcrel sdata8";
91 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4
92 :
Chris Lattnerb75af3c2010-04-04 20:04:21 +000093 return "indirect pcrel udata4";
Eric Christopher596077b2013-12-04 22:26:43 +000094 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
95 :
Chris Lattnerb75af3c2010-04-04 20:04:21 +000096 return "indirect pcrel sdata4";
Eric Christopher596077b2013-12-04 22:26:43 +000097 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8
98 :
Chris Lattnerb75af3c2010-04-04 20:04:21 +000099 return "indirect pcrel udata8";
Eric Christopher596077b2013-12-04 22:26:43 +0000100 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8
101 :
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000102 return "indirect pcrel sdata8";
103 }
Eric Christopher1d6bd412012-11-20 20:34:47 +0000104
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000105 return "<unknown encoding>";
106}
107
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000108/// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
109/// encoding. If verbose assembly output is enabled, we output comments
110/// describing the encoding. Desc is an optional string saying what the
111/// encoding is specifying (e.g. "LSDA").
Chris Lattneraabc6042010-04-04 23:41:46 +0000112void AsmPrinter::EmitEncodingByte(unsigned Val, const char *Desc) const {
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000113 if (isVerbose()) {
Eric Christophercb7119e2013-12-04 22:29:02 +0000114 if (Desc)
Eric Christopher596077b2013-12-04 22:26:43 +0000115 OutStreamer.AddComment(Twine(Desc) + " Encoding = " +
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000116 Twine(DecodeDWARFEncoding(Val)));
117 else
Eric Christopher596077b2013-12-04 22:26:43 +0000118 OutStreamer.AddComment(Twine("Encoding = ") + DecodeDWARFEncoding(Val));
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000119 }
Eric Christopher1d6bd412012-11-20 20:34:47 +0000120
Eric Christopherce0cfce2013-01-09 01:35:34 +0000121 OutStreamer.EmitIntValue(Val, 1);
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000122}
123
Chris Lattnere619c0d2010-04-04 20:20:50 +0000124/// GetSizeOfEncodedValue - Return the size of the encoding in bytes.
125unsigned AsmPrinter::GetSizeOfEncodedValue(unsigned Encoding) const {
126 if (Encoding == dwarf::DW_EH_PE_omit)
127 return 0;
Eric Christopher1d6bd412012-11-20 20:34:47 +0000128
Chris Lattnere619c0d2010-04-04 20:20:50 +0000129 switch (Encoding & 0x07) {
Eric Christopher596077b2013-12-04 22:26:43 +0000130 default:
131 llvm_unreachable("Invalid encoded value.");
132 case dwarf::DW_EH_PE_absptr:
133 return TM.getDataLayout()->getPointerSize();
134 case dwarf::DW_EH_PE_udata2:
135 return 2;
136 case dwarf::DW_EH_PE_udata4:
137 return 4;
138 case dwarf::DW_EH_PE_udata8:
139 return 8;
Chris Lattnere619c0d2010-04-04 20:20:50 +0000140 }
141}
142
Eric Christopher1d6bd412012-11-20 20:34:47 +0000143void AsmPrinter::EmitTTypeReference(const GlobalValue *GV,
144 unsigned Encoding) const {
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000145 if (GV) {
146 const TargetLoweringObjectFile &TLOF = getObjFileLowering();
Eric Christopher1d6bd412012-11-20 20:34:47 +0000147
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000148 const MCExpr *Exp =
Rafael Espindoladaeafb42014-02-19 17:23:20 +0000149 TLOF.getTTypeGlobalReference(GV, Encoding, *Mang, TM, MMI, OutStreamer);
Eric Christopherce0cfce2013-01-09 01:35:34 +0000150 OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding));
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000151 } else
Eric Christopherce0cfce2013-01-09 01:35:34 +0000152 OutStreamer.EmitIntValue(0, GetSizeOfEncodedValue(Encoding));
Chris Lattnere619c0d2010-04-04 20:20:50 +0000153}
Chris Lattner70a4fce2010-04-04 23:25:33 +0000154
155/// EmitSectionOffset - Emit the 4-byte offset of Label from the start of its
156/// section. This can be done with a special directive if the target supports
157/// it (e.g. cygwin) or by emitting it as an offset from a label at the start
158/// of the section.
159///
160/// SectionLabel is a temporary label emitted at the start of the section that
161/// Label lives in.
162void AsmPrinter::EmitSectionOffset(const MCSymbol *Label,
163 const MCSymbol *SectionLabel) const {
164 // On COFF targets, we have to emit the special .secrel32 directive.
Matt Arsenault034ca0f2013-04-22 22:49:11 +0000165 if (MAI->needsDwarfSectionOffsetDirective()) {
Rafael Espindolad3df3d32011-12-17 01:14:52 +0000166 OutStreamer.EmitCOFFSecRel32(Label);
Chris Lattner70a4fce2010-04-04 23:25:33 +0000167 return;
168 }
Eric Christopher1d6bd412012-11-20 20:34:47 +0000169
Chris Lattner70a4fce2010-04-04 23:25:33 +0000170 // Get the section that we're referring to, based on SectionLabel.
171 const MCSection &Section = SectionLabel->getSection();
Eric Christopher1d6bd412012-11-20 20:34:47 +0000172
Chris Lattner70a4fce2010-04-04 23:25:33 +0000173 // If Label has already been emitted, verify that it is in the same section as
174 // section label for sanity.
175 assert((!Label->isInSection() || &Label->getSection() == &Section) &&
176 "Section offset using wrong section base for label");
Eric Christopher1d6bd412012-11-20 20:34:47 +0000177
Duncan Sandsb847bf52011-03-12 13:07:37 +0000178 // If the section in question will end up with an address of 0 anyway, we can
179 // just emit an absolute reference to save a relocation.
180 if (Section.isBaseAddressKnownZero()) {
Eric Christopherce0cfce2013-01-09 01:35:34 +0000181 OutStreamer.EmitSymbolValue(Label, 4);
Duncan Sandsb847bf52011-03-12 13:07:37 +0000182 return;
183 }
Eric Christopher1d6bd412012-11-20 20:34:47 +0000184
Chris Lattner70a4fce2010-04-04 23:25:33 +0000185 // Otherwise, emit it as a label difference from the start of the section.
186 EmitLabelDifference(Label, SectionLabel, 4);
187}
188
Eric Christopher698a8ab2014-03-07 01:44:14 +0000189/// Emit a dwarf register operation.
Eric Christopher29e874d2014-03-07 22:40:37 +0000190static void emitDwarfRegOp(ByteStreamer &Streamer, int Reg) {
Eric Christopher698a8ab2014-03-07 01:44:14 +0000191 assert(Reg >= 0);
192 if (Reg < 32) {
Eric Christopher29e874d2014-03-07 22:40:37 +0000193 Streamer.EmitInt8(dwarf::DW_OP_reg0 + Reg,
194 dwarf::OperationEncodingString(dwarf::DW_OP_reg0 + Reg));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000195 } else {
Eric Christopher29e874d2014-03-07 22:40:37 +0000196 Streamer.EmitInt8(dwarf::DW_OP_regx, "DW_OP_regx");
197 Streamer.EmitULEB128(Reg, Twine(Reg));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000198 }
199}
200
201/// Emit an (double-)indirect dwarf register operation.
Eric Christopher29e874d2014-03-07 22:40:37 +0000202static void emitDwarfRegOpIndirect(ByteStreamer &Streamer, int Reg, int Offset,
Eric Christopher5c303202014-03-07 21:27:42 +0000203 bool Deref) {
Eric Christopher698a8ab2014-03-07 01:44:14 +0000204 assert(Reg >= 0);
205 if (Reg < 32) {
Eric Christopher29e874d2014-03-07 22:40:37 +0000206 Streamer.EmitInt8(dwarf::DW_OP_breg0 + Reg,
207 dwarf::OperationEncodingString(dwarf::DW_OP_breg0 + Reg));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000208 } else {
Eric Christopher29e874d2014-03-07 22:40:37 +0000209 Streamer.EmitInt8(dwarf::DW_OP_bregx, "DW_OP_bregx");
210 Streamer.EmitULEB128(Reg, Twine(Reg));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000211 }
Eric Christopher29e874d2014-03-07 22:40:37 +0000212 Streamer.EmitSLEB128(Offset);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000213 if (Deref)
Eric Christopher29e874d2014-03-07 22:40:37 +0000214 Streamer.EmitInt8(dwarf::DW_OP_deref, "DW_OP_deref");
Eric Christopher698a8ab2014-03-07 01:44:14 +0000215}
216
Adrian Prantlb1416832014-08-01 22:11:58 +0000217void AsmPrinter::EmitDwarfOpPiece(ByteStreamer &Streamer, unsigned SizeInBits,
218 unsigned OffsetInBits) const {
219 assert(SizeInBits > 0 && "piece has size zero");
220 const unsigned SizeOfByte = 8;
Adrian Prantld34db652014-04-27 18:25:45 +0000221 if (OffsetInBits > 0 || SizeInBits % SizeOfByte) {
Eric Christopher29e874d2014-03-07 22:40:37 +0000222 Streamer.EmitInt8(dwarf::DW_OP_bit_piece, "DW_OP_bit_piece");
Adrian Prantld34db652014-04-27 18:25:45 +0000223 Streamer.EmitULEB128(SizeInBits, Twine(SizeInBits));
224 Streamer.EmitULEB128(OffsetInBits, Twine(OffsetInBits));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000225 } else {
Eric Christopher29e874d2014-03-07 22:40:37 +0000226 Streamer.EmitInt8(dwarf::DW_OP_piece, "DW_OP_piece");
Adrian Prantld34db652014-04-27 18:25:45 +0000227 unsigned ByteSize = SizeInBits / SizeOfByte;
Eric Christopher29e874d2014-03-07 22:40:37 +0000228 Streamer.EmitULEB128(ByteSize, Twine(ByteSize));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000229 }
230}
231
Adrian Prantld34db652014-04-27 18:25:45 +0000232/// Emit a shift-right dwarf expression.
233static void emitDwarfOpShr(ByteStreamer &Streamer,
234 unsigned ShiftBy) {
235 Streamer.EmitInt8(dwarf::DW_OP_constu, "DW_OP_constu");
236 Streamer.EmitULEB128(ShiftBy);
237 Streamer.EmitInt8(dwarf::DW_OP_shr, "DW_OP_shr");
238}
239
Adrian Prantl42a0d8c2014-04-27 18:50:45 +0000240// Some targets do not provide a DWARF register number for every
241// register. This function attempts to emit a DWARF register by
242// emitting a piece of a super-register or by piecing together
243// multiple subregisters that alias the register.
Adrian Prantld34db652014-04-27 18:25:45 +0000244void AsmPrinter::EmitDwarfRegOpPiece(ByteStreamer &Streamer,
245 const MachineLocation &MLoc,
246 unsigned PieceSizeInBits,
247 unsigned PieceOffsetInBits) const {
Adrian Prantl42a0d8c2014-04-27 18:50:45 +0000248 assert(MLoc.isReg() && "MLoc must be a register");
Adrian Prantld34db652014-04-27 18:25:45 +0000249 const TargetRegisterInfo *TRI = TM.getRegisterInfo();
Eric Christopher698a8ab2014-03-07 01:44:14 +0000250 int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false);
251
Adrian Prantld34db652014-04-27 18:25:45 +0000252 // If this is a valid register number, emit it.
253 if (Reg >= 0) {
254 emitDwarfRegOp(Streamer, Reg);
Adrian Prantlb1416832014-08-01 22:11:58 +0000255 EmitDwarfOpPiece(Streamer, PieceSizeInBits, PieceOffsetInBits);
Adrian Prantld34db652014-04-27 18:25:45 +0000256 return;
257 }
258
Eric Christopher698a8ab2014-03-07 01:44:14 +0000259 // Walk up the super-register chain until we find a valid number.
260 // For example, EAX on x86_64 is a 32-bit piece of RAX with offset 0.
261 for (MCSuperRegIterator SR(MLoc.getReg(), TRI); SR.isValid(); ++SR) {
262 Reg = TRI->getDwarfRegNum(*SR, false);
263 if (Reg >= 0) {
264 unsigned Idx = TRI->getSubRegIndex(*SR, MLoc.getReg());
265 unsigned Size = TRI->getSubRegIdxSize(Idx);
Adrian Prantlb1416832014-08-01 22:11:58 +0000266 unsigned RegOffset = TRI->getSubRegIdxOffset(Idx);
Adrian Prantld34db652014-04-27 18:25:45 +0000267 OutStreamer.AddComment("super-register");
Eric Christopher29e874d2014-03-07 22:40:37 +0000268 emitDwarfRegOp(Streamer, Reg);
Adrian Prantlb1416832014-08-01 22:11:58 +0000269 if (PieceOffsetInBits == RegOffset) {
270 EmitDwarfOpPiece(Streamer, Size, RegOffset);
Adrian Prantld34db652014-04-27 18:25:45 +0000271 } else {
272 // If this is part of a variable in a sub-register at a
273 // non-zero offset, we need to manually shift the value into
274 // place, since the DW_OP_piece describes the part of the
275 // variable, not the position of the subregister.
Adrian Prantlb1416832014-08-01 22:11:58 +0000276 if (RegOffset)
277 emitDwarfOpShr(Streamer, RegOffset);
278 EmitDwarfOpPiece(Streamer, Size, PieceOffsetInBits);
Adrian Prantld34db652014-04-27 18:25:45 +0000279 }
Eric Christopher698a8ab2014-03-07 01:44:14 +0000280 return;
281 }
282 }
283
284 // Otherwise, attempt to find a covering set of sub-register numbers.
285 // For example, Q0 on ARM is a composition of D0+D1.
286 //
287 // Keep track of the current position so we can emit the more
288 // efficient DW_OP_piece.
Adrian Prantld34db652014-04-27 18:25:45 +0000289 unsigned CurPos = PieceOffsetInBits;
Eric Christopher698a8ab2014-03-07 01:44:14 +0000290 // The size of the register in bits, assuming 8 bits per byte.
Eric Christopher5c303202014-03-07 21:27:42 +0000291 unsigned RegSize = TRI->getMinimalPhysRegClass(MLoc.getReg())->getSize() * 8;
Eric Christopher698a8ab2014-03-07 01:44:14 +0000292 // Keep track of the bits in the register we already emitted, so we
293 // can avoid emitting redundant aliasing subregs.
294 SmallBitVector Coverage(RegSize, false);
295 for (MCSubRegIterator SR(MLoc.getReg(), TRI); SR.isValid(); ++SR) {
296 unsigned Idx = TRI->getSubRegIndex(MLoc.getReg(), *SR);
297 unsigned Size = TRI->getSubRegIdxSize(Idx);
298 unsigned Offset = TRI->getSubRegIdxOffset(Idx);
299 Reg = TRI->getDwarfRegNum(*SR, false);
300
301 // Intersection between the bits we already emitted and the bits
302 // covered by this subregister.
303 SmallBitVector Intersection(RegSize, false);
Eric Christopher5c303202014-03-07 21:27:42 +0000304 Intersection.set(Offset, Offset + Size);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000305 Intersection ^= Coverage;
306
307 // If this sub-register has a DWARF number and we haven't covered
308 // its range, emit a DWARF piece for it.
309 if (Reg >= 0 && Intersection.any()) {
Adrian Prantld34db652014-04-27 18:25:45 +0000310 OutStreamer.AddComment("sub-register");
Eric Christopher29e874d2014-03-07 22:40:37 +0000311 emitDwarfRegOp(Streamer, Reg);
Adrian Prantlb1416832014-08-01 22:11:58 +0000312 EmitDwarfOpPiece(Streamer, Size, Offset == CurPos ? 0 : Offset);
Eric Christopher5c303202014-03-07 21:27:42 +0000313 CurPos = Offset + Size;
Eric Christopher698a8ab2014-03-07 01:44:14 +0000314
315 // Mark it as emitted.
Eric Christopher5c303202014-03-07 21:27:42 +0000316 Coverage.set(Offset, Offset + Size);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000317 }
318 }
319
Adrian Prantld34db652014-04-27 18:25:45 +0000320 if (CurPos == PieceOffsetInBits) {
Eric Christopher698a8ab2014-03-07 01:44:14 +0000321 // FIXME: We have no reasonable way of handling errors in here.
Eric Christopher29e874d2014-03-07 22:40:37 +0000322 Streamer.EmitInt8(dwarf::DW_OP_nop,
323 "nop (could not find a dwarf register number)");
Eric Christopher698a8ab2014-03-07 01:44:14 +0000324 }
325}
326
327/// EmitDwarfRegOp - Emit dwarf register operation.
Eric Christopher29e874d2014-03-07 22:40:37 +0000328void AsmPrinter::EmitDwarfRegOp(ByteStreamer &Streamer,
329 const MachineLocation &MLoc,
Eric Christopher698a8ab2014-03-07 01:44:14 +0000330 bool Indirect) const {
331 const TargetRegisterInfo *TRI = TM.getRegisterInfo();
332 int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false);
333 if (Reg < 0) {
334 // We assume that pointers are always in an addressable register.
335 if (Indirect || MLoc.isIndirect()) {
336 // FIXME: We have no reasonable way of handling errors in here. The
337 // caller might be in the middle of a dwarf expression. We should
338 // probably assert that Reg >= 0 once debug info generation is more
339 // mature.
Eric Christopher29e874d2014-03-07 22:40:37 +0000340 Streamer.EmitInt8(dwarf::DW_OP_nop,
341 "nop (invalid dwarf register number for indirect loc)");
Eric Christopher698a8ab2014-03-07 01:44:14 +0000342 return;
343 }
344
345 // Attempt to find a valid super- or sub-register.
Adrian Prantl42a0d8c2014-04-27 18:50:45 +0000346 return EmitDwarfRegOpPiece(Streamer, MLoc);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000347 }
348
349 if (MLoc.isIndirect())
Eric Christopher29e874d2014-03-07 22:40:37 +0000350 emitDwarfRegOpIndirect(Streamer, Reg, MLoc.getOffset(), Indirect);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000351 else if (Indirect)
Eric Christopher29e874d2014-03-07 22:40:37 +0000352 emitDwarfRegOpIndirect(Streamer, Reg, 0, false);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000353 else
Eric Christopher29e874d2014-03-07 22:40:37 +0000354 emitDwarfRegOp(Streamer, Reg);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000355}
356
Chris Lattneraabc6042010-04-04 23:41:46 +0000357//===----------------------------------------------------------------------===//
358// Dwarf Lowering Routines
359//===----------------------------------------------------------------------===//
Chris Lattner70a4fce2010-04-04 23:25:33 +0000360
Rafael Espindola227144c2013-05-13 01:16:13 +0000361void AsmPrinter::emitCFIInstruction(const MCCFIInstruction &Inst) const {
362 switch (Inst.getOperation()) {
363 default:
364 llvm_unreachable("Unexpected instruction");
365 case MCCFIInstruction::OpDefCfaOffset:
366 OutStreamer.EmitCFIDefCfaOffset(Inst.getOffset());
367 break;
368 case MCCFIInstruction::OpDefCfa:
369 OutStreamer.EmitCFIDefCfa(Inst.getRegister(), Inst.getOffset());
370 break;
371 case MCCFIInstruction::OpDefCfaRegister:
372 OutStreamer.EmitCFIDefCfaRegister(Inst.getRegister());
373 break;
374 case MCCFIInstruction::OpOffset:
375 OutStreamer.EmitCFIOffset(Inst.getRegister(), Inst.getOffset());
376 break;
Venkatraman Govindaraju4c0cdd72013-09-26 15:11:00 +0000377 case MCCFIInstruction::OpRegister:
378 OutStreamer.EmitCFIRegister(Inst.getRegister(), Inst.getRegister2());
379 break;
Venkatraman Govindaraju3816d432013-09-26 14:49:40 +0000380 case MCCFIInstruction::OpWindowSave:
381 OutStreamer.EmitCFIWindowSave();
382 break;
Oliver Stannardb14c6252014-04-02 16:10:33 +0000383 case MCCFIInstruction::OpSameValue:
384 OutStreamer.EmitCFISameValue(Inst.getRegister());
385 break;
Rafael Espindolabeb74c32011-04-15 20:32:03 +0000386 }
387}