blob: 05f6a68375b067e8053ce8925c01b84a031c0d3b [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"
Eric Christopherd9134482014-08-04 21:25:23 +000030#include "llvm/Target/TargetSubtargetInfo.h"
Chris Lattner9efd1182010-04-04 19:09:29 +000031using namespace llvm;
32
Chandler Carruth1b9dde02014-04-22 02:02:50 +000033#define DEBUG_TYPE "asm-printer"
34
Chris Lattneraabc6042010-04-04 23:41:46 +000035//===----------------------------------------------------------------------===//
36// Dwarf Emission Helper Routines
37//===----------------------------------------------------------------------===//
38
Chris Lattner9efd1182010-04-04 19:09:29 +000039/// EmitSLEB128 - emit the specified signed leb128 value.
David Blaikie5acff7e2013-06-23 18:31:11 +000040void AsmPrinter::EmitSLEB128(int64_t Value, const char *Desc) const {
Chris Lattner9efd1182010-04-04 19:09:29 +000041 if (isVerbose() && Desc)
42 OutStreamer.AddComment(Desc);
Chris Lattner9efd1182010-04-04 19:09:29 +000043
Benjamin Kramerc74798d2011-11-05 11:52:44 +000044 OutStreamer.EmitSLEB128IntValue(Value);
Chris Lattner9efd1182010-04-04 19:09:29 +000045}
46
47/// EmitULEB128 - emit the specified signed leb128 value.
David Blaikie5acff7e2013-06-23 18:31:11 +000048void AsmPrinter::EmitULEB128(uint64_t Value, const char *Desc,
Chris Lattner9efd1182010-04-04 19:09:29 +000049 unsigned PadTo) const {
50 if (isVerbose() && Desc)
51 OutStreamer.AddComment(Desc);
Rafael Espindola38d07562010-11-04 18:17:08 +000052
Eric Christopherbf7bc492013-01-09 03:52:05 +000053 OutStreamer.EmitULEB128IntValue(Value, PadTo);
Chris Lattner9efd1182010-04-04 19:09:29 +000054}
55
Chris Lattnerbaf2be02010-04-04 20:01:25 +000056/// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
57void AsmPrinter::EmitCFAByte(unsigned Val) const {
58 if (isVerbose()) {
Eric Christopher596077b2013-12-04 22:26:43 +000059 if (Val >= dwarf::DW_CFA_offset && Val < dwarf::DW_CFA_offset + 64)
Eric Christopher1d6bd412012-11-20 20:34:47 +000060 OutStreamer.AddComment("DW_CFA_offset + Reg (" +
Eric Christopher596077b2013-12-04 22:26:43 +000061 Twine(Val - dwarf::DW_CFA_offset) + ")");
Chris Lattnerbaf2be02010-04-04 20:01:25 +000062 else
63 OutStreamer.AddComment(dwarf::CallFrameString(Val));
64 }
Eric Christopherce0cfce2013-01-09 01:35:34 +000065 OutStreamer.EmitIntValue(Val, 1);
Chris Lattnerbaf2be02010-04-04 20:01:25 +000066}
67
Chris Lattnerb75af3c2010-04-04 20:04:21 +000068static const char *DecodeDWARFEncoding(unsigned Encoding) {
69 switch (Encoding) {
Eric Christopher596077b2013-12-04 22:26:43 +000070 case dwarf::DW_EH_PE_absptr:
71 return "absptr";
72 case dwarf::DW_EH_PE_omit:
73 return "omit";
74 case dwarf::DW_EH_PE_pcrel:
75 return "pcrel";
76 case dwarf::DW_EH_PE_udata4:
77 return "udata4";
78 case dwarf::DW_EH_PE_udata8:
79 return "udata8";
80 case dwarf::DW_EH_PE_sdata4:
81 return "sdata4";
82 case dwarf::DW_EH_PE_sdata8:
83 return "sdata8";
84 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4:
85 return "pcrel udata4";
86 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4:
87 return "pcrel sdata4";
88 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8:
89 return "pcrel udata8";
90 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8:
91 return "pcrel sdata8";
92 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4
93 :
Chris Lattnerb75af3c2010-04-04 20:04:21 +000094 return "indirect pcrel udata4";
Eric Christopher596077b2013-12-04 22:26:43 +000095 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
96 :
Chris Lattnerb75af3c2010-04-04 20:04:21 +000097 return "indirect pcrel sdata4";
Eric Christopher596077b2013-12-04 22:26:43 +000098 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8
99 :
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000100 return "indirect pcrel udata8";
Eric Christopher596077b2013-12-04 22:26:43 +0000101 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8
102 :
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000103 return "indirect pcrel sdata8";
104 }
Eric Christopher1d6bd412012-11-20 20:34:47 +0000105
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000106 return "<unknown encoding>";
107}
108
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000109/// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
110/// encoding. If verbose assembly output is enabled, we output comments
111/// describing the encoding. Desc is an optional string saying what the
112/// encoding is specifying (e.g. "LSDA").
Chris Lattneraabc6042010-04-04 23:41:46 +0000113void AsmPrinter::EmitEncodingByte(unsigned Val, const char *Desc) const {
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000114 if (isVerbose()) {
Eric Christophercb7119e2013-12-04 22:29:02 +0000115 if (Desc)
Eric Christopher596077b2013-12-04 22:26:43 +0000116 OutStreamer.AddComment(Twine(Desc) + " Encoding = " +
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000117 Twine(DecodeDWARFEncoding(Val)));
118 else
Eric Christopher596077b2013-12-04 22:26:43 +0000119 OutStreamer.AddComment(Twine("Encoding = ") + DecodeDWARFEncoding(Val));
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000120 }
Eric Christopher1d6bd412012-11-20 20:34:47 +0000121
Eric Christopherce0cfce2013-01-09 01:35:34 +0000122 OutStreamer.EmitIntValue(Val, 1);
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000123}
124
Chris Lattnere619c0d2010-04-04 20:20:50 +0000125/// GetSizeOfEncodedValue - Return the size of the encoding in bytes.
126unsigned AsmPrinter::GetSizeOfEncodedValue(unsigned Encoding) const {
127 if (Encoding == dwarf::DW_EH_PE_omit)
128 return 0;
Eric Christopher1d6bd412012-11-20 20:34:47 +0000129
Chris Lattnere619c0d2010-04-04 20:20:50 +0000130 switch (Encoding & 0x07) {
Eric Christopher596077b2013-12-04 22:26:43 +0000131 default:
132 llvm_unreachable("Invalid encoded value.");
133 case dwarf::DW_EH_PE_absptr:
Eric Christopherd9134482014-08-04 21:25:23 +0000134 return TM.getSubtargetImpl()->getDataLayout()->getPointerSize();
Eric Christopher596077b2013-12-04 22:26:43 +0000135 case dwarf::DW_EH_PE_udata2:
136 return 2;
137 case dwarf::DW_EH_PE_udata4:
138 return 4;
139 case dwarf::DW_EH_PE_udata8:
140 return 8;
Chris Lattnere619c0d2010-04-04 20:20:50 +0000141 }
142}
143
Eric Christopher1d6bd412012-11-20 20:34:47 +0000144void AsmPrinter::EmitTTypeReference(const GlobalValue *GV,
145 unsigned Encoding) const {
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000146 if (GV) {
147 const TargetLoweringObjectFile &TLOF = getObjFileLowering();
Eric Christopher1d6bd412012-11-20 20:34:47 +0000148
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000149 const MCExpr *Exp =
Rafael Espindoladaeafb42014-02-19 17:23:20 +0000150 TLOF.getTTypeGlobalReference(GV, Encoding, *Mang, TM, MMI, OutStreamer);
Eric Christopherce0cfce2013-01-09 01:35:34 +0000151 OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding));
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000152 } else
Eric Christopherce0cfce2013-01-09 01:35:34 +0000153 OutStreamer.EmitIntValue(0, GetSizeOfEncodedValue(Encoding));
Chris Lattnere619c0d2010-04-04 20:20:50 +0000154}
Chris Lattner70a4fce2010-04-04 23:25:33 +0000155
156/// EmitSectionOffset - Emit the 4-byte offset of Label from the start of its
157/// section. This can be done with a special directive if the target supports
158/// it (e.g. cygwin) or by emitting it as an offset from a label at the start
159/// of the section.
160///
161/// SectionLabel is a temporary label emitted at the start of the section that
162/// Label lives in.
163void AsmPrinter::EmitSectionOffset(const MCSymbol *Label,
164 const MCSymbol *SectionLabel) const {
165 // On COFF targets, we have to emit the special .secrel32 directive.
Matt Arsenault034ca0f2013-04-22 22:49:11 +0000166 if (MAI->needsDwarfSectionOffsetDirective()) {
Rafael Espindolad3df3d32011-12-17 01:14:52 +0000167 OutStreamer.EmitCOFFSecRel32(Label);
Chris Lattner70a4fce2010-04-04 23:25:33 +0000168 return;
169 }
Eric Christopher1d6bd412012-11-20 20:34:47 +0000170
Chris Lattner70a4fce2010-04-04 23:25:33 +0000171 // Get the section that we're referring to, based on SectionLabel.
172 const MCSection &Section = SectionLabel->getSection();
Eric Christopher1d6bd412012-11-20 20:34:47 +0000173
Chris Lattner70a4fce2010-04-04 23:25:33 +0000174 // If Label has already been emitted, verify that it is in the same section as
175 // section label for sanity.
176 assert((!Label->isInSection() || &Label->getSection() == &Section) &&
177 "Section offset using wrong section base for label");
Eric Christopher1d6bd412012-11-20 20:34:47 +0000178
Duncan Sandsb847bf52011-03-12 13:07:37 +0000179 // If the section in question will end up with an address of 0 anyway, we can
180 // just emit an absolute reference to save a relocation.
181 if (Section.isBaseAddressKnownZero()) {
Eric Christopherce0cfce2013-01-09 01:35:34 +0000182 OutStreamer.EmitSymbolValue(Label, 4);
Duncan Sandsb847bf52011-03-12 13:07:37 +0000183 return;
184 }
Eric Christopher1d6bd412012-11-20 20:34:47 +0000185
Chris Lattner70a4fce2010-04-04 23:25:33 +0000186 // Otherwise, emit it as a label difference from the start of the section.
187 EmitLabelDifference(Label, SectionLabel, 4);
188}
189
Eric Christopher698a8ab2014-03-07 01:44:14 +0000190/// Emit a dwarf register operation.
Eric Christopher29e874d2014-03-07 22:40:37 +0000191static void emitDwarfRegOp(ByteStreamer &Streamer, int Reg) {
Eric Christopher698a8ab2014-03-07 01:44:14 +0000192 assert(Reg >= 0);
193 if (Reg < 32) {
Eric Christopher29e874d2014-03-07 22:40:37 +0000194 Streamer.EmitInt8(dwarf::DW_OP_reg0 + Reg,
195 dwarf::OperationEncodingString(dwarf::DW_OP_reg0 + Reg));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000196 } else {
Eric Christopher29e874d2014-03-07 22:40:37 +0000197 Streamer.EmitInt8(dwarf::DW_OP_regx, "DW_OP_regx");
198 Streamer.EmitULEB128(Reg, Twine(Reg));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000199 }
200}
201
202/// Emit an (double-)indirect dwarf register operation.
Eric Christopher29e874d2014-03-07 22:40:37 +0000203static void emitDwarfRegOpIndirect(ByteStreamer &Streamer, int Reg, int Offset,
Eric Christopher5c303202014-03-07 21:27:42 +0000204 bool Deref) {
Eric Christopher698a8ab2014-03-07 01:44:14 +0000205 assert(Reg >= 0);
206 if (Reg < 32) {
Eric Christopher29e874d2014-03-07 22:40:37 +0000207 Streamer.EmitInt8(dwarf::DW_OP_breg0 + Reg,
208 dwarf::OperationEncodingString(dwarf::DW_OP_breg0 + Reg));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000209 } else {
Eric Christopher29e874d2014-03-07 22:40:37 +0000210 Streamer.EmitInt8(dwarf::DW_OP_bregx, "DW_OP_bregx");
211 Streamer.EmitULEB128(Reg, Twine(Reg));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000212 }
Eric Christopher29e874d2014-03-07 22:40:37 +0000213 Streamer.EmitSLEB128(Offset);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000214 if (Deref)
Eric Christopher29e874d2014-03-07 22:40:37 +0000215 Streamer.EmitInt8(dwarf::DW_OP_deref, "DW_OP_deref");
Eric Christopher698a8ab2014-03-07 01:44:14 +0000216}
217
Adrian Prantlb1416832014-08-01 22:11:58 +0000218void AsmPrinter::EmitDwarfOpPiece(ByteStreamer &Streamer, unsigned SizeInBits,
219 unsigned OffsetInBits) const {
220 assert(SizeInBits > 0 && "piece has size zero");
221 const unsigned SizeOfByte = 8;
Adrian Prantld34db652014-04-27 18:25:45 +0000222 if (OffsetInBits > 0 || SizeInBits % SizeOfByte) {
Eric Christopher29e874d2014-03-07 22:40:37 +0000223 Streamer.EmitInt8(dwarf::DW_OP_bit_piece, "DW_OP_bit_piece");
Adrian Prantld34db652014-04-27 18:25:45 +0000224 Streamer.EmitULEB128(SizeInBits, Twine(SizeInBits));
225 Streamer.EmitULEB128(OffsetInBits, Twine(OffsetInBits));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000226 } else {
Eric Christopher29e874d2014-03-07 22:40:37 +0000227 Streamer.EmitInt8(dwarf::DW_OP_piece, "DW_OP_piece");
Adrian Prantld34db652014-04-27 18:25:45 +0000228 unsigned ByteSize = SizeInBits / SizeOfByte;
Eric Christopher29e874d2014-03-07 22:40:37 +0000229 Streamer.EmitULEB128(ByteSize, Twine(ByteSize));
Eric Christopher698a8ab2014-03-07 01:44:14 +0000230 }
231}
232
Adrian Prantld34db652014-04-27 18:25:45 +0000233/// Emit a shift-right dwarf expression.
234static void emitDwarfOpShr(ByteStreamer &Streamer,
235 unsigned ShiftBy) {
236 Streamer.EmitInt8(dwarf::DW_OP_constu, "DW_OP_constu");
237 Streamer.EmitULEB128(ShiftBy);
238 Streamer.EmitInt8(dwarf::DW_OP_shr, "DW_OP_shr");
239}
240
Adrian Prantl42a0d8c2014-04-27 18:50:45 +0000241// Some targets do not provide a DWARF register number for every
242// register. This function attempts to emit a DWARF register by
243// emitting a piece of a super-register or by piecing together
244// multiple subregisters that alias the register.
Adrian Prantld34db652014-04-27 18:25:45 +0000245void AsmPrinter::EmitDwarfRegOpPiece(ByteStreamer &Streamer,
246 const MachineLocation &MLoc,
247 unsigned PieceSizeInBits,
248 unsigned PieceOffsetInBits) const {
Adrian Prantl42a0d8c2014-04-27 18:50:45 +0000249 assert(MLoc.isReg() && "MLoc must be a register");
Eric Christopherd9134482014-08-04 21:25:23 +0000250 const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
Eric Christopher698a8ab2014-03-07 01:44:14 +0000251 int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false);
252
Adrian Prantld34db652014-04-27 18:25:45 +0000253 // If this is a valid register number, emit it.
254 if (Reg >= 0) {
255 emitDwarfRegOp(Streamer, Reg);
Adrian Prantlb1416832014-08-01 22:11:58 +0000256 EmitDwarfOpPiece(Streamer, PieceSizeInBits, PieceOffsetInBits);
Adrian Prantld34db652014-04-27 18:25:45 +0000257 return;
258 }
259
Eric Christopher698a8ab2014-03-07 01:44:14 +0000260 // Walk up the super-register chain until we find a valid number.
261 // For example, EAX on x86_64 is a 32-bit piece of RAX with offset 0.
262 for (MCSuperRegIterator SR(MLoc.getReg(), TRI); SR.isValid(); ++SR) {
263 Reg = TRI->getDwarfRegNum(*SR, false);
264 if (Reg >= 0) {
265 unsigned Idx = TRI->getSubRegIndex(*SR, MLoc.getReg());
266 unsigned Size = TRI->getSubRegIdxSize(Idx);
Adrian Prantlb1416832014-08-01 22:11:58 +0000267 unsigned RegOffset = TRI->getSubRegIdxOffset(Idx);
Adrian Prantld34db652014-04-27 18:25:45 +0000268 OutStreamer.AddComment("super-register");
Eric Christopher29e874d2014-03-07 22:40:37 +0000269 emitDwarfRegOp(Streamer, Reg);
Adrian Prantlb1416832014-08-01 22:11:58 +0000270 if (PieceOffsetInBits == RegOffset) {
271 EmitDwarfOpPiece(Streamer, Size, RegOffset);
Adrian Prantld34db652014-04-27 18:25:45 +0000272 } else {
273 // If this is part of a variable in a sub-register at a
274 // non-zero offset, we need to manually shift the value into
275 // place, since the DW_OP_piece describes the part of the
276 // variable, not the position of the subregister.
Adrian Prantlb1416832014-08-01 22:11:58 +0000277 if (RegOffset)
278 emitDwarfOpShr(Streamer, RegOffset);
279 EmitDwarfOpPiece(Streamer, Size, PieceOffsetInBits);
Adrian Prantld34db652014-04-27 18:25:45 +0000280 }
Eric Christopher698a8ab2014-03-07 01:44:14 +0000281 return;
282 }
283 }
284
285 // Otherwise, attempt to find a covering set of sub-register numbers.
286 // For example, Q0 on ARM is a composition of D0+D1.
287 //
288 // Keep track of the current position so we can emit the more
289 // efficient DW_OP_piece.
Adrian Prantld34db652014-04-27 18:25:45 +0000290 unsigned CurPos = PieceOffsetInBits;
Eric Christopher698a8ab2014-03-07 01:44:14 +0000291 // The size of the register in bits, assuming 8 bits per byte.
Eric Christopher5c303202014-03-07 21:27:42 +0000292 unsigned RegSize = TRI->getMinimalPhysRegClass(MLoc.getReg())->getSize() * 8;
Eric Christopher698a8ab2014-03-07 01:44:14 +0000293 // Keep track of the bits in the register we already emitted, so we
294 // can avoid emitting redundant aliasing subregs.
295 SmallBitVector Coverage(RegSize, false);
296 for (MCSubRegIterator SR(MLoc.getReg(), TRI); SR.isValid(); ++SR) {
297 unsigned Idx = TRI->getSubRegIndex(MLoc.getReg(), *SR);
298 unsigned Size = TRI->getSubRegIdxSize(Idx);
299 unsigned Offset = TRI->getSubRegIdxOffset(Idx);
300 Reg = TRI->getDwarfRegNum(*SR, false);
301
302 // Intersection between the bits we already emitted and the bits
303 // covered by this subregister.
304 SmallBitVector Intersection(RegSize, false);
Eric Christopher5c303202014-03-07 21:27:42 +0000305 Intersection.set(Offset, Offset + Size);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000306 Intersection ^= Coverage;
307
308 // If this sub-register has a DWARF number and we haven't covered
309 // its range, emit a DWARF piece for it.
310 if (Reg >= 0 && Intersection.any()) {
Adrian Prantld34db652014-04-27 18:25:45 +0000311 OutStreamer.AddComment("sub-register");
Eric Christopher29e874d2014-03-07 22:40:37 +0000312 emitDwarfRegOp(Streamer, Reg);
Adrian Prantlb1416832014-08-01 22:11:58 +0000313 EmitDwarfOpPiece(Streamer, Size, Offset == CurPos ? 0 : Offset);
Eric Christopher5c303202014-03-07 21:27:42 +0000314 CurPos = Offset + Size;
Eric Christopher698a8ab2014-03-07 01:44:14 +0000315
316 // Mark it as emitted.
Eric Christopher5c303202014-03-07 21:27:42 +0000317 Coverage.set(Offset, Offset + Size);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000318 }
319 }
320
Adrian Prantld34db652014-04-27 18:25:45 +0000321 if (CurPos == PieceOffsetInBits) {
Eric Christopher698a8ab2014-03-07 01:44:14 +0000322 // FIXME: We have no reasonable way of handling errors in here.
Eric Christopher29e874d2014-03-07 22:40:37 +0000323 Streamer.EmitInt8(dwarf::DW_OP_nop,
324 "nop (could not find a dwarf register number)");
Eric Christopher698a8ab2014-03-07 01:44:14 +0000325 }
326}
327
328/// EmitDwarfRegOp - Emit dwarf register operation.
Eric Christopher29e874d2014-03-07 22:40:37 +0000329void AsmPrinter::EmitDwarfRegOp(ByteStreamer &Streamer,
330 const MachineLocation &MLoc,
Eric Christopher698a8ab2014-03-07 01:44:14 +0000331 bool Indirect) const {
Eric Christopherd9134482014-08-04 21:25:23 +0000332 const TargetRegisterInfo *TRI = TM.getSubtargetImpl()->getRegisterInfo();
Eric Christopher698a8ab2014-03-07 01:44:14 +0000333 int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false);
334 if (Reg < 0) {
335 // We assume that pointers are always in an addressable register.
336 if (Indirect || MLoc.isIndirect()) {
337 // FIXME: We have no reasonable way of handling errors in here. The
338 // caller might be in the middle of a dwarf expression. We should
339 // probably assert that Reg >= 0 once debug info generation is more
340 // mature.
Eric Christopher29e874d2014-03-07 22:40:37 +0000341 Streamer.EmitInt8(dwarf::DW_OP_nop,
342 "nop (invalid dwarf register number for indirect loc)");
Eric Christopher698a8ab2014-03-07 01:44:14 +0000343 return;
344 }
345
346 // Attempt to find a valid super- or sub-register.
Adrian Prantl42a0d8c2014-04-27 18:50:45 +0000347 return EmitDwarfRegOpPiece(Streamer, MLoc);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000348 }
349
350 if (MLoc.isIndirect())
Eric Christopher29e874d2014-03-07 22:40:37 +0000351 emitDwarfRegOpIndirect(Streamer, Reg, MLoc.getOffset(), Indirect);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000352 else if (Indirect)
Eric Christopher29e874d2014-03-07 22:40:37 +0000353 emitDwarfRegOpIndirect(Streamer, Reg, 0, false);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000354 else
Eric Christopher29e874d2014-03-07 22:40:37 +0000355 emitDwarfRegOp(Streamer, Reg);
Eric Christopher698a8ab2014-03-07 01:44:14 +0000356}
357
Chris Lattneraabc6042010-04-04 23:41:46 +0000358//===----------------------------------------------------------------------===//
359// Dwarf Lowering Routines
360//===----------------------------------------------------------------------===//
Chris Lattner70a4fce2010-04-04 23:25:33 +0000361
Rafael Espindola227144c2013-05-13 01:16:13 +0000362void AsmPrinter::emitCFIInstruction(const MCCFIInstruction &Inst) const {
363 switch (Inst.getOperation()) {
364 default:
365 llvm_unreachable("Unexpected instruction");
366 case MCCFIInstruction::OpDefCfaOffset:
367 OutStreamer.EmitCFIDefCfaOffset(Inst.getOffset());
368 break;
369 case MCCFIInstruction::OpDefCfa:
370 OutStreamer.EmitCFIDefCfa(Inst.getRegister(), Inst.getOffset());
371 break;
372 case MCCFIInstruction::OpDefCfaRegister:
373 OutStreamer.EmitCFIDefCfaRegister(Inst.getRegister());
374 break;
375 case MCCFIInstruction::OpOffset:
376 OutStreamer.EmitCFIOffset(Inst.getRegister(), Inst.getOffset());
377 break;
Venkatraman Govindaraju4c0cdd72013-09-26 15:11:00 +0000378 case MCCFIInstruction::OpRegister:
379 OutStreamer.EmitCFIRegister(Inst.getRegister(), Inst.getRegister2());
380 break;
Venkatraman Govindaraju3816d432013-09-26 14:49:40 +0000381 case MCCFIInstruction::OpWindowSave:
382 OutStreamer.EmitCFIWindowSave();
383 break;
Oliver Stannardb14c6252014-04-02 16:10:33 +0000384 case MCCFIInstruction::OpSameValue:
385 OutStreamer.EmitCFISameValue(Inst.getRegister());
386 break;
Rafael Espindolabeb74c32011-04-15 20:32:03 +0000387 }
388}