blob: 66606caa73dd174577220ccfc4c480c288e53b53 [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
217/// Emit a dwarf register operation for describing
218/// - a small value occupying only part of a register or
219/// - a small register representing only part of a value.
Adrian Prantld34db652014-04-27 18:25:45 +0000220static void emitDwarfOpPiece(ByteStreamer &Streamer, unsigned SizeInBits,
221 unsigned OffsetInBits) {
222 assert(SizeInBits > 0 && "zero-sized piece");
223 unsigned SizeOfByte = 8;
224 if (OffsetInBits > 0 || SizeInBits % SizeOfByte) {
Eric Christopher29e874d2014-03-07 22:40:37 +0000225 Streamer.EmitInt8(dwarf::DW_OP_bit_piece, "DW_OP_bit_piece");
Adrian Prantld34db652014-04-27 18:25:45 +0000226 Streamer.EmitULEB128(SizeInBits, Twine(SizeInBits));
227 Streamer.EmitULEB128(OffsetInBits, Twine(OffsetInBits));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000228 } else {
Eric Christopher29e874d2014-03-07 22:40:37 +0000229 Streamer.EmitInt8(dwarf::DW_OP_piece, "DW_OP_piece");
Adrian Prantld34db652014-04-27 18:25:45 +0000230 unsigned ByteSize = SizeInBits / SizeOfByte;
Eric Christopher29e874d2014-03-07 22:40:37 +0000231 Streamer.EmitULEB128(ByteSize, Twine(ByteSize));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000232 }
233}
234
Adrian Prantld34db652014-04-27 18:25:45 +0000235/// Emit a shift-right dwarf expression.
236static void emitDwarfOpShr(ByteStreamer &Streamer,
237 unsigned ShiftBy) {
238 Streamer.EmitInt8(dwarf::DW_OP_constu, "DW_OP_constu");
239 Streamer.EmitULEB128(ShiftBy);
240 Streamer.EmitInt8(dwarf::DW_OP_shr, "DW_OP_shr");
241}
242
Eric Christopher698a8ab2014-03-07 01:44:14 +0000243/// Some targets do not provide a DWARF register number for every
Adrian Prantld34db652014-04-27 18:25:45 +0000244/// register. This function attempts to emit a DWARF register by
Eric Christopher698a8ab2014-03-07 01:44:14 +0000245/// emitting a piece of a super-register or by piecing together
246/// multiple subregisters that alias the register.
Adrian Prantld34db652014-04-27 18:25:45 +0000247void AsmPrinter::EmitDwarfRegOpPiece(ByteStreamer &Streamer,
248 const MachineLocation &MLoc,
249 unsigned PieceSizeInBits,
250 unsigned PieceOffsetInBits) const {
Eric Christopher698a8ab2014-03-07 01:44:14 +0000251 assert(!MLoc.isIndirect());
Adrian Prantld34db652014-04-27 18:25:45 +0000252 const TargetRegisterInfo *TRI = TM.getRegisterInfo();
Eric Christopher698a8ab2014-03-07 01:44:14 +0000253 int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false);
254
Adrian Prantld34db652014-04-27 18:25:45 +0000255 // If this is a valid register number, emit it.
256 if (Reg >= 0) {
257 emitDwarfRegOp(Streamer, Reg);
258 emitDwarfOpPiece(Streamer, PieceSizeInBits, PieceOffsetInBits);
259 return;
260 }
261
Eric Christopher698a8ab2014-03-07 01:44:14 +0000262 // Walk up the super-register chain until we find a valid number.
263 // For example, EAX on x86_64 is a 32-bit piece of RAX with offset 0.
264 for (MCSuperRegIterator SR(MLoc.getReg(), TRI); SR.isValid(); ++SR) {
265 Reg = TRI->getDwarfRegNum(*SR, false);
266 if (Reg >= 0) {
267 unsigned Idx = TRI->getSubRegIndex(*SR, MLoc.getReg());
268 unsigned Size = TRI->getSubRegIdxSize(Idx);
269 unsigned Offset = TRI->getSubRegIdxOffset(Idx);
Adrian Prantld34db652014-04-27 18:25:45 +0000270 OutStreamer.AddComment("super-register");
Eric Christopher29e874d2014-03-07 22:40:37 +0000271 emitDwarfRegOp(Streamer, Reg);
Adrian Prantld34db652014-04-27 18:25:45 +0000272 if (PieceOffsetInBits == Offset) {
273 emitDwarfOpPiece(Streamer, Size, Offset);
274 } else {
275 // If this is part of a variable in a sub-register at a
276 // non-zero offset, we need to manually shift the value into
277 // place, since the DW_OP_piece describes the part of the
278 // variable, not the position of the subregister.
279 emitDwarfOpPiece(Streamer, Size, PieceOffsetInBits);
280 if (Offset)
281 emitDwarfOpShr(Streamer, Offset);
282 }
Eric Christopher698a8ab2014-03-07 01:44:14 +0000283 return;
284 }
285 }
286
287 // Otherwise, attempt to find a covering set of sub-register numbers.
288 // For example, Q0 on ARM is a composition of D0+D1.
289 //
290 // Keep track of the current position so we can emit the more
291 // efficient DW_OP_piece.
Adrian Prantld34db652014-04-27 18:25:45 +0000292 unsigned CurPos = PieceOffsetInBits;
Eric Christopher698a8ab2014-03-07 01:44:14 +0000293 // The size of the register in bits, assuming 8 bits per byte.
Eric Christopher5c303202014-03-07 21:27:42 +0000294 unsigned RegSize = TRI->getMinimalPhysRegClass(MLoc.getReg())->getSize() * 8;
Eric Christopher698a8ab2014-03-07 01:44:14 +0000295 // Keep track of the bits in the register we already emitted, so we
296 // can avoid emitting redundant aliasing subregs.
297 SmallBitVector Coverage(RegSize, false);
298 for (MCSubRegIterator SR(MLoc.getReg(), TRI); SR.isValid(); ++SR) {
299 unsigned Idx = TRI->getSubRegIndex(MLoc.getReg(), *SR);
300 unsigned Size = TRI->getSubRegIdxSize(Idx);
301 unsigned Offset = TRI->getSubRegIdxOffset(Idx);
302 Reg = TRI->getDwarfRegNum(*SR, false);
303
304 // Intersection between the bits we already emitted and the bits
305 // covered by this subregister.
306 SmallBitVector Intersection(RegSize, false);
Eric Christopher5c303202014-03-07 21:27:42 +0000307 Intersection.set(Offset, Offset + Size);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000308 Intersection ^= Coverage;
309
310 // If this sub-register has a DWARF number and we haven't covered
311 // its range, emit a DWARF piece for it.
312 if (Reg >= 0 && Intersection.any()) {
Adrian Prantld34db652014-04-27 18:25:45 +0000313 OutStreamer.AddComment("sub-register");
Eric Christopher29e874d2014-03-07 22:40:37 +0000314 emitDwarfRegOp(Streamer, Reg);
315 emitDwarfOpPiece(Streamer, Size, Offset == CurPos ? 0 : Offset);
Eric Christopher5c303202014-03-07 21:27:42 +0000316 CurPos = Offset + Size;
Eric Christopher698a8ab2014-03-07 01:44:14 +0000317
318 // Mark it as emitted.
Eric Christopher5c303202014-03-07 21:27:42 +0000319 Coverage.set(Offset, Offset + Size);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000320 }
321 }
322
Adrian Prantld34db652014-04-27 18:25:45 +0000323 if (CurPos == PieceOffsetInBits) {
Eric Christopher698a8ab2014-03-07 01:44:14 +0000324 // FIXME: We have no reasonable way of handling errors in here.
Eric Christopher29e874d2014-03-07 22:40:37 +0000325 Streamer.EmitInt8(dwarf::DW_OP_nop,
326 "nop (could not find a dwarf register number)");
Eric Christopher698a8ab2014-03-07 01:44:14 +0000327 }
328}
329
330/// EmitDwarfRegOp - Emit dwarf register operation.
Eric Christopher29e874d2014-03-07 22:40:37 +0000331void AsmPrinter::EmitDwarfRegOp(ByteStreamer &Streamer,
332 const MachineLocation &MLoc,
Eric Christopher698a8ab2014-03-07 01:44:14 +0000333 bool Indirect) const {
334 const TargetRegisterInfo *TRI = TM.getRegisterInfo();
335 int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false);
336 if (Reg < 0) {
337 // We assume that pointers are always in an addressable register.
338 if (Indirect || MLoc.isIndirect()) {
339 // FIXME: We have no reasonable way of handling errors in here. The
340 // caller might be in the middle of a dwarf expression. We should
341 // probably assert that Reg >= 0 once debug info generation is more
342 // mature.
Eric Christopher29e874d2014-03-07 22:40:37 +0000343 Streamer.EmitInt8(dwarf::DW_OP_nop,
344 "nop (invalid dwarf register number for indirect loc)");
Eric Christopher698a8ab2014-03-07 01:44:14 +0000345 return;
346 }
347
348 // Attempt to find a valid super- or sub-register.
Adrian Prantld34db652014-04-27 18:25:45 +0000349 return EmitDwarfRegOpPiece(Streamer, MLoc, 0, 0);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000350 }
351
352 if (MLoc.isIndirect())
Eric Christopher29e874d2014-03-07 22:40:37 +0000353 emitDwarfRegOpIndirect(Streamer, Reg, MLoc.getOffset(), Indirect);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000354 else if (Indirect)
Eric Christopher29e874d2014-03-07 22:40:37 +0000355 emitDwarfRegOpIndirect(Streamer, Reg, 0, false);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000356 else
Eric Christopher29e874d2014-03-07 22:40:37 +0000357 emitDwarfRegOp(Streamer, Reg);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000358}
359
Chris Lattneraabc6042010-04-04 23:41:46 +0000360//===----------------------------------------------------------------------===//
361// Dwarf Lowering Routines
362//===----------------------------------------------------------------------===//
Chris Lattner70a4fce2010-04-04 23:25:33 +0000363
Rafael Espindola227144c2013-05-13 01:16:13 +0000364void AsmPrinter::emitCFIInstruction(const MCCFIInstruction &Inst) const {
365 switch (Inst.getOperation()) {
366 default:
367 llvm_unreachable("Unexpected instruction");
368 case MCCFIInstruction::OpDefCfaOffset:
369 OutStreamer.EmitCFIDefCfaOffset(Inst.getOffset());
370 break;
371 case MCCFIInstruction::OpDefCfa:
372 OutStreamer.EmitCFIDefCfa(Inst.getRegister(), Inst.getOffset());
373 break;
374 case MCCFIInstruction::OpDefCfaRegister:
375 OutStreamer.EmitCFIDefCfaRegister(Inst.getRegister());
376 break;
377 case MCCFIInstruction::OpOffset:
378 OutStreamer.EmitCFIOffset(Inst.getRegister(), Inst.getOffset());
379 break;
Venkatraman Govindaraju4c0cdd72013-09-26 15:11:00 +0000380 case MCCFIInstruction::OpRegister:
381 OutStreamer.EmitCFIRegister(Inst.getRegister(), Inst.getRegister2());
382 break;
Venkatraman Govindaraju3816d432013-09-26 14:49:40 +0000383 case MCCFIInstruction::OpWindowSave:
384 OutStreamer.EmitCFIWindowSave();
385 break;
Oliver Stannardb14c6252014-04-02 16:10:33 +0000386 case MCCFIInstruction::OpSameValue:
387 OutStreamer.EmitCFISameValue(Inst.getRegister());
388 break;
Rafael Espindolabeb74c32011-04-15 20:32:03 +0000389 }
390}