blob: 26f4c5ff91d38719df74dfe76797a4a3286b0148 [file] [log] [blame]
Bill Wendling88423ee2009-05-15 00:11:17 +00001//===--- lib/CodeGen/DwarfPrinter.cpp - Dwarf Printer ---------------------===//
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// Emit general DWARF directives.
Anton Korobeynikov9184b252010-02-15 22:35:59 +000011//
Bill Wendling88423ee2009-05-15 00:11:17 +000012//===----------------------------------------------------------------------===//
13
14#include "DwarfPrinter.h"
15#include "llvm/Module.h"
16#include "llvm/CodeGen/AsmPrinter.h"
17#include "llvm/CodeGen/MachineFrameInfo.h"
David Greeneeea1f4c2009-08-19 21:59:18 +000018#include "llvm/CodeGen/MachineFunction.h"
Bill Wendling88423ee2009-05-15 00:11:17 +000019#include "llvm/CodeGen/MachineModuleInfo.h"
Chris Lattneraf76e592009-08-22 20:48:53 +000020#include "llvm/MC/MCAsmInfo.h"
Anton Korobeynikov9184b252010-02-15 22:35:59 +000021#include "llvm/MC/MCContext.h"
22#include "llvm/MC/MCExpr.h"
Chris Lattnerf61ed8e2010-01-22 22:38:16 +000023#include "llvm/MC/MCStreamer.h"
Chris Lattner858431d2010-01-16 18:50:28 +000024#include "llvm/MC/MCSymbol.h"
Bill Wendling88423ee2009-05-15 00:11:17 +000025#include "llvm/Target/TargetData.h"
26#include "llvm/Target/TargetFrameInfo.h"
Anton Korobeynikov9184b252010-02-15 22:35:59 +000027#include "llvm/Target/TargetLoweringObjectFile.h"
Bill Wendling88423ee2009-05-15 00:11:17 +000028#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattner23132b12009-08-24 03:52:50 +000029#include "llvm/Support/Dwarf.h"
30#include "llvm/Support/ErrorHandling.h"
Anton Korobeynikov9184b252010-02-15 22:35:59 +000031#include "llvm/ADT/SmallString.h"
Bill Wendling88423ee2009-05-15 00:11:17 +000032using namespace llvm;
33
Chris Lattner066c9ac2010-01-22 22:23:57 +000034DwarfPrinter::DwarfPrinter(raw_ostream &OS, AsmPrinter *A, const MCAsmInfo *T,
35 const char *flavor)
Chris Lattner33adcfb2009-08-22 21:43:10 +000036: O(OS), Asm(A), MAI(T), TD(Asm->TM.getTargetData()),
Bill Wendling88423ee2009-05-15 00:11:17 +000037 RI(Asm->TM.getRegisterInfo()), M(NULL), MF(NULL), MMI(NULL),
38 SubprogramCount(0), Flavor(flavor), SetCounter(1) {}
39
Chris Lattnerb98b1bf2010-03-08 22:23:36 +000040
41/// getDWLabel - Return the MCSymbol corresponding to the assembler temporary
42/// label with the specified stem and unique ID.
43MCSymbol *DwarfPrinter::getDWLabel(const char *Name, unsigned ID) const {
44 // FIXME: REMOVE this. However, there is stuff in EH that passes counters in
45 // here that can be zero.
46
47 //assert(ID && "Should use getTempLabel if no ID");
48 if (ID == 0) return getTempLabel(Name);
49 return Asm->OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix())
50 + Twine(Name) + Twine(ID));
51}
52
53/// getTempLabel - Return the MCSymbol corresponding to the assembler temporary
54/// label with the specified name.
55MCSymbol *DwarfPrinter::getTempLabel(const char *Name) const {
56 return Asm->OutContext.GetOrCreateSymbol(Twine(MAI->getPrivateGlobalPrefix())
57 + Name);
58}
59
60
Anton Korobeynikov9184b252010-02-15 22:35:59 +000061/// SizeOfEncodedValue - Return the size of the encoding in bytes.
62unsigned DwarfPrinter::SizeOfEncodedValue(unsigned Encoding) const {
63 if (Encoding == dwarf::DW_EH_PE_omit)
64 return 0;
65
66 switch (Encoding & 0x07) {
67 case dwarf::DW_EH_PE_absptr:
68 return TD->getPointerSize();
69 case dwarf::DW_EH_PE_udata2:
70 return 2;
71 case dwarf::DW_EH_PE_udata4:
72 return 4;
73 case dwarf::DW_EH_PE_udata8:
74 return 8;
75 }
76
77 assert(0 && "Invalid encoded value.");
78 return 0;
79}
80
Chris Lattner066c9ac2010-01-22 22:23:57 +000081void DwarfPrinter::PrintRelDirective(bool Force32Bit, bool isInSection) const {
Chris Lattner33adcfb2009-08-22 21:43:10 +000082 if (isInSection && MAI->getDwarfSectionOffsetDirective())
83 O << MAI->getDwarfSectionOffsetDirective();
Bill Wendling88423ee2009-05-15 00:11:17 +000084 else if (Force32Bit || TD->getPointerSize() == sizeof(int32_t))
Chris Lattner33adcfb2009-08-22 21:43:10 +000085 O << MAI->getData32bitsDirective();
Bill Wendling88423ee2009-05-15 00:11:17 +000086 else
Chris Lattner33adcfb2009-08-22 21:43:10 +000087 O << MAI->getData64bitsDirective();
Bill Wendling88423ee2009-05-15 00:11:17 +000088}
89
Anton Korobeynikov9184b252010-02-15 22:35:59 +000090void DwarfPrinter::PrintRelDirective(unsigned Encoding) const {
91 unsigned Size = SizeOfEncodedValue(Encoding);
92 assert((Size == 4 || Size == 8) && "Do not support other types or rels!");
93
94 O << (Size == 4 ?
95 MAI->getData32bitsDirective() : MAI->getData64bitsDirective());
96}
97
Chris Lattnerfaca5492010-01-22 23:47:11 +000098/// EOL - Print a newline character to asm stream. If a comment is present
99/// then it will be printed first. Comments should not contain '\n'.
100void DwarfPrinter::EOL(const Twine &Comment) const {
101 if (Asm->VerboseAsm && !Comment.isTriviallyEmpty()) {
102 Asm->O.PadToColumn(MAI->getCommentColumn());
103 Asm->O << Asm->MAI->getCommentString() << ' ' << Comment;
104 }
105 Asm->O << '\n';
106}
107
Chris Lattnerf61ed8e2010-01-22 22:38:16 +0000108static const char *DecodeDWARFEncoding(unsigned Encoding) {
109 switch (Encoding) {
110 case dwarf::DW_EH_PE_absptr: return "absptr";
111 case dwarf::DW_EH_PE_omit: return "omit";
112 case dwarf::DW_EH_PE_pcrel: return "pcrel";
113 case dwarf::DW_EH_PE_udata4: return "udata4";
114 case dwarf::DW_EH_PE_udata8: return "udata8";
115 case dwarf::DW_EH_PE_sdata4: return "sdata4";
116 case dwarf::DW_EH_PE_sdata8: return "sdata8";
117 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: return "pcrel udata4";
118 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: return "pcrel sdata4";
119 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: return "pcrel udata8";
120 case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: return "pcrel sdata8";
121 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata4:
122 return "indirect pcrel udata4";
123 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata4:
124 return "indirect pcrel sdata4";
125 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_udata8:
126 return "indirect pcrel udata8";
127 case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |dwarf::DW_EH_PE_sdata8:
128 return "indirect pcrel sdata8";
129 }
130
131 return "<unknown encoding>";
132}
133
134/// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
135/// encoding. If verbose assembly output is enabled, we output comments
136/// describing the encoding. Desc is an optional string saying what the
137/// encoding is specifying (e.g. "LSDA").
138void DwarfPrinter::EmitEncodingByte(unsigned Val, const char *Desc) {
139 if (Asm->VerboseAsm) {
140 if (Desc != 0)
141 Asm->OutStreamer.AddComment(Twine(Desc)+" Encoding = " +
142 Twine(DecodeDWARFEncoding(Val)));
143 else
144 Asm->OutStreamer.AddComment(Twine("Encoding = ") +
145 DecodeDWARFEncoding(Val));
146 }
147
148 Asm->OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/);
149}
150
Chris Lattner245834d2010-01-22 23:40:08 +0000151/// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
152void DwarfPrinter::EmitCFAByte(unsigned Val) {
153 if (Asm->VerboseAsm) {
154 if (Val >= dwarf::DW_CFA_offset && Val < dwarf::DW_CFA_offset+64)
155 Asm->OutStreamer.AddComment("DW_CFA_offset + Reg (" +
156 Twine(Val-dwarf::DW_CFA_offset) + ")");
157 else
158 Asm->OutStreamer.AddComment(dwarf::CallFrameString(Val));
159 }
160 Asm->OutStreamer.EmitIntValue(Val, 1, 0/*addrspace*/);
161}
162
Chris Lattner894d75a2010-01-22 23:18:42 +0000163/// EmitSLEB128 - emit the specified signed leb128 value.
164void DwarfPrinter::EmitSLEB128(int Value, const char *Desc) const {
165 if (Asm->VerboseAsm && Desc)
166 Asm->OutStreamer.AddComment(Desc);
167
168 if (MAI->hasLEB128()) {
169 O << "\t.sleb128\t" << Value;
170 Asm->OutStreamer.AddBlankLine();
171 return;
172 }
173
174 // If we don't have .sleb128, emit as .bytes.
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000175 int Sign = Value >> (8 * sizeof(Value) - 1);
176 bool IsMore;
177
178 do {
179 unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
180 Value >>= 7;
181 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
182 if (IsMore) Byte |= 0x80;
Chris Lattner894d75a2010-01-22 23:18:42 +0000183 Asm->OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0);
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000184 } while (IsMore);
185}
186
Chris Lattner894d75a2010-01-22 23:18:42 +0000187/// EmitULEB128 - emit the specified signed leb128 value.
Bill Wendling3dc9b482010-02-24 23:34:35 +0000188void DwarfPrinter::EmitULEB128(unsigned Value, const char *Desc,
189 unsigned PadTo) const {
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000190 if (Asm->VerboseAsm && Desc)
191 Asm->OutStreamer.AddComment(Desc);
Chris Lattner894d75a2010-01-22 23:18:42 +0000192
Bill Wendling3dc9b482010-02-24 23:34:35 +0000193 if (MAI->hasLEB128() && PadTo == 0) {
Chris Lattner894d75a2010-01-22 23:18:42 +0000194 O << "\t.uleb128\t" << Value;
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000195 Asm->OutStreamer.AddBlankLine();
Chris Lattner894d75a2010-01-22 23:18:42 +0000196 return;
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000197 }
Chris Lattner894d75a2010-01-22 23:18:42 +0000198
Bill Wendling3dc9b482010-02-24 23:34:35 +0000199 // If we don't have .uleb128 or we want to emit padding, emit as .bytes.
Chris Lattner894d75a2010-01-22 23:18:42 +0000200 do {
201 unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
202 Value >>= 7;
Bill Wendling3dc9b482010-02-24 23:34:35 +0000203 if (Value || PadTo != 0) Byte |= 0x80;
Chris Lattner894d75a2010-01-22 23:18:42 +0000204 Asm->OutStreamer.EmitIntValue(Byte, 1, /*addrspace*/0);
205 } while (Value);
Bill Wendling3dc9b482010-02-24 23:34:35 +0000206
Bill Wendlingf0bd4cc2010-02-25 00:24:52 +0000207 if (PadTo) {
208 if (PadTo > 1)
209 Asm->OutStreamer.EmitFill(PadTo - 1, 0x80/*fillval*/, 0/*addrspace*/);
210 Asm->OutStreamer.EmitFill(1, 0/*fillval*/, 0/*addrspace*/);
211 }
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000212}
213
214
Bill Wendling88423ee2009-05-15 00:11:17 +0000215/// PrintLabelName - Print label name in form used by Dwarf writer.
216///
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000217void DwarfPrinter::PrintLabelName(const MCSymbol *Label) const {
218 // FIXME: REMOVE.
219 O << Label->getName();
220}
221
Chris Lattner066c9ac2010-01-22 22:23:57 +0000222void DwarfPrinter::PrintLabelName(const char *Tag, unsigned Number) const {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000223 // FIXME: REMOVE.
Jim Grosbacha01d3462009-09-01 16:43:35 +0000224 O << MAI->getPrivateGlobalPrefix() << Tag;
Bill Wendling88423ee2009-05-15 00:11:17 +0000225 if (Number) O << Number;
226}
Chris Lattner066c9ac2010-01-22 22:23:57 +0000227void DwarfPrinter::PrintLabelName(const char *Tag, unsigned Number,
228 const char *Suffix) const {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000229 // FIXME: REMOVE.
Jim Grosbacha01d3462009-09-01 16:43:35 +0000230 O << MAI->getPrivateGlobalPrefix() << Tag;
Bill Wendling88423ee2009-05-15 00:11:17 +0000231 if (Number) O << Number;
232 O << Suffix;
233}
234
235/// EmitLabel - Emit location label for internal use by Dwarf.
236///
Chris Lattner066c9ac2010-01-22 22:23:57 +0000237void DwarfPrinter::EmitLabel(const char *Tag, unsigned Number) const {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000238 // FIXME: REMOVE.
Jim Grosbacha01d3462009-09-01 16:43:35 +0000239 PrintLabelName(Tag, Number);
Bill Wendling88423ee2009-05-15 00:11:17 +0000240 O << ":\n";
241}
242
243/// EmitReference - Emit a reference to a label.
244///
Chris Lattner066c9ac2010-01-22 22:23:57 +0000245void DwarfPrinter::EmitReference(const char *Tag, unsigned Number,
246 bool IsPCRelative, bool Force32Bit) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000247 PrintRelDirective(Force32Bit);
248 PrintLabelName(Tag, Number);
Chris Lattner33adcfb2009-08-22 21:43:10 +0000249 if (IsPCRelative) O << "-" << MAI->getPCSymbol();
Bill Wendling88423ee2009-05-15 00:11:17 +0000250}
Chris Lattner066c9ac2010-01-22 22:23:57 +0000251void DwarfPrinter::EmitReference(const std::string &Name, bool IsPCRelative,
252 bool Force32Bit) const {
Bill Wendling88423ee2009-05-15 00:11:17 +0000253 PrintRelDirective(Force32Bit);
254 O << Name;
Chris Lattner33adcfb2009-08-22 21:43:10 +0000255 if (IsPCRelative) O << "-" << MAI->getPCSymbol();
Bill Wendling88423ee2009-05-15 00:11:17 +0000256}
257
Chris Lattner066c9ac2010-01-22 22:23:57 +0000258void DwarfPrinter::EmitReference(const MCSymbol *Sym, bool IsPCRelative,
259 bool Force32Bit) const {
Chris Lattner858431d2010-01-16 18:50:28 +0000260 PrintRelDirective(Force32Bit);
Chris Lattner10b318b2010-01-17 21:43:43 +0000261 O << *Sym;
Chris Lattner858431d2010-01-16 18:50:28 +0000262 if (IsPCRelative) O << "-" << MAI->getPCSymbol();
263}
264
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000265void DwarfPrinter::EmitReference(const char *Tag, unsigned Number,
266 unsigned Encoding) const {
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000267 // FIXME: REMOVE.
268 EmitReference(getDWLabel(Tag, Number), Encoding);
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000269}
270
271void DwarfPrinter::EmitReference(const MCSymbol *Sym, unsigned Encoding) const {
272 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
273
274 PrintRelDirective(Encoding);
275 O << *TLOF.getSymbolForDwarfReference(Sym, Asm->MMI, Encoding);;
276}
277
278void DwarfPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const {
279 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
280
281 PrintRelDirective(Encoding);
282 O << *TLOF.getSymbolForDwarfGlobalReference(GV, Asm->Mang,
283 Asm->MMI, Encoding);;
284}
285
Chris Lattner6a315c32010-01-26 20:20:43 +0000286/// EmitDifference - Emit the difference between two labels. If this assembler
287/// supports .set, we emit a .set of a temporary and then use it in the .word.
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000288void DwarfPrinter::EmitDifference(const MCSymbol *TagHi, const MCSymbol *TagLo,
289 bool IsSmall) {
290 if (MAI->hasSetDirective()) {
291 // FIXME: switch to OutStreamer.EmitAssignment.
292 O << "\t.set\t";
293 PrintLabelName("set", SetCounter, Flavor);
294 O << ",";
295 PrintLabelName(TagHi);
296 O << "-";
297 PrintLabelName(TagLo);
298 O << "\n";
299
300 PrintRelDirective(IsSmall);
301 PrintLabelName("set", SetCounter, Flavor);
302 ++SetCounter;
303 } else {
304 PrintRelDirective(IsSmall);
305 PrintLabelName(TagHi);
306 O << "-";
307 PrintLabelName(TagLo);
308 }
309}
310
311/// EmitDifference - Emit the difference between two labels. If this assembler
312/// supports .set, we emit a .set of a temporary and then use it in the .word.
Chris Lattner066c9ac2010-01-22 22:23:57 +0000313void DwarfPrinter::EmitDifference(const char *TagHi, unsigned NumberHi,
314 const char *TagLo, unsigned NumberLo,
315 bool IsSmall) {
Chris Lattnercee63322010-01-26 20:40:54 +0000316 if (MAI->hasSetDirective()) {
Chris Lattnerc618c8a2010-01-26 21:53:08 +0000317 // FIXME: switch to OutStreamer.EmitAssignment.
Bill Wendling88423ee2009-05-15 00:11:17 +0000318 O << "\t.set\t";
319 PrintLabelName("set", SetCounter, Flavor);
320 O << ",";
321 PrintLabelName(TagHi, NumberHi);
322 O << "-";
323 PrintLabelName(TagLo, NumberLo);
324 O << "\n";
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000325
Bill Wendling88423ee2009-05-15 00:11:17 +0000326 PrintRelDirective(IsSmall);
327 PrintLabelName("set", SetCounter, Flavor);
328 ++SetCounter;
329 } else {
330 PrintRelDirective(IsSmall);
331 PrintLabelName(TagHi, NumberHi);
332 O << "-";
333 PrintLabelName(TagLo, NumberLo);
334 }
335}
336
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000337void DwarfPrinter::EmitSectionOffset(const MCSymbol *Label,
338 const MCSymbol *Section,
Chris Lattner066c9ac2010-01-22 22:23:57 +0000339 bool IsSmall, bool isEH,
340 bool useSet) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000341 bool printAbsolute = false;
342 if (isEH)
Chris Lattner33adcfb2009-08-22 21:43:10 +0000343 printAbsolute = MAI->isAbsoluteEHSectionOffsets();
Bill Wendling88423ee2009-05-15 00:11:17 +0000344 else
Chris Lattner33adcfb2009-08-22 21:43:10 +0000345 printAbsolute = MAI->isAbsoluteDebugSectionOffsets();
Bill Wendling88423ee2009-05-15 00:11:17 +0000346
Chris Lattnercee63322010-01-26 20:40:54 +0000347 if (MAI->hasSetDirective() && useSet) {
Chris Lattnerc618c8a2010-01-26 21:53:08 +0000348 // FIXME: switch to OutStreamer.EmitAssignment.
Bill Wendling88423ee2009-05-15 00:11:17 +0000349 O << "\t.set\t";
350 PrintLabelName("set", SetCounter, Flavor);
351 O << ",";
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000352 PrintLabelName(Label);
Bill Wendling88423ee2009-05-15 00:11:17 +0000353
354 if (!printAbsolute) {
355 O << "-";
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000356 PrintLabelName(Section);
Bill Wendling88423ee2009-05-15 00:11:17 +0000357 }
358
359 O << "\n";
360 PrintRelDirective(IsSmall);
361 PrintLabelName("set", SetCounter, Flavor);
362 ++SetCounter;
363 } else {
364 PrintRelDirective(IsSmall, true);
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000365 PrintLabelName(Label);
Bill Wendling88423ee2009-05-15 00:11:17 +0000366
367 if (!printAbsolute) {
368 O << "-";
Chris Lattnerb98b1bf2010-03-08 22:23:36 +0000369 PrintLabelName(Section);
Bill Wendling88423ee2009-05-15 00:11:17 +0000370 }
371 }
372}
373
374/// EmitFrameMoves - Emit frame instructions to describe the layout of the
375/// frame.
Chris Lattner066c9ac2010-01-22 22:23:57 +0000376void DwarfPrinter::EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
377 const std::vector<MachineMove> &Moves,
378 bool isEH) {
Bill Wendling88423ee2009-05-15 00:11:17 +0000379 int stackGrowth =
380 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
381 TargetFrameInfo::StackGrowsUp ?
382 TD->getPointerSize() : -TD->getPointerSize();
383 bool IsLocal = BaseLabel && strcmp(BaseLabel, "label") == 0;
384
385 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
386 const MachineMove &Move = Moves[i];
387 unsigned LabelID = Move.getLabelID();
388
389 if (LabelID) {
390 LabelID = MMI->MappedLabel(LabelID);
391
392 // Throw out move if the label is invalid.
393 if (!LabelID) continue;
394 }
395
396 const MachineLocation &Dst = Move.getDestination();
397 const MachineLocation &Src = Move.getSource();
398
399 // Advance row if new location.
400 if (BaseLabel && LabelID && (BaseLabelID != LabelID || !IsLocal)) {
Chris Lattner245834d2010-01-22 23:40:08 +0000401 EmitCFAByte(dwarf::DW_CFA_advance_loc4);
Bill Wendling88423ee2009-05-15 00:11:17 +0000402 EmitDifference("label", LabelID, BaseLabel, BaseLabelID, true);
Chris Lattner0ad9c912010-01-22 22:09:00 +0000403 Asm->O << '\n';
Bill Wendling88423ee2009-05-15 00:11:17 +0000404
405 BaseLabelID = LabelID;
406 BaseLabel = "label";
407 IsLocal = true;
408 }
409
410 // If advancing cfa.
411 if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) {
412 if (!Src.isReg()) {
413 if (Src.getReg() == MachineLocation::VirtualFP) {
Chris Lattner245834d2010-01-22 23:40:08 +0000414 EmitCFAByte(dwarf::DW_CFA_def_cfa_offset);
Bill Wendling88423ee2009-05-15 00:11:17 +0000415 } else {
Chris Lattner245834d2010-01-22 23:40:08 +0000416 EmitCFAByte(dwarf::DW_CFA_def_cfa);
Chris Lattner894d75a2010-01-22 23:18:42 +0000417 EmitULEB128(RI->getDwarfRegNum(Src.getReg(), isEH), "Register");
Bill Wendling88423ee2009-05-15 00:11:17 +0000418 }
419
420 int Offset = -Src.getOffset();
Chris Lattner894d75a2010-01-22 23:18:42 +0000421 EmitULEB128(Offset, "Offset");
Bill Wendling88423ee2009-05-15 00:11:17 +0000422 } else {
Torok Edwinc23197a2009-07-14 16:55:14 +0000423 llvm_unreachable("Machine move not supported yet.");
Bill Wendling88423ee2009-05-15 00:11:17 +0000424 }
425 } else if (Src.isReg() &&
426 Src.getReg() == MachineLocation::VirtualFP) {
427 if (Dst.isReg()) {
Chris Lattner245834d2010-01-22 23:40:08 +0000428 EmitCFAByte(dwarf::DW_CFA_def_cfa_register);
Chris Lattner894d75a2010-01-22 23:18:42 +0000429 EmitULEB128(RI->getDwarfRegNum(Dst.getReg(), isEH), "Register");
Bill Wendling88423ee2009-05-15 00:11:17 +0000430 } else {
Torok Edwinc23197a2009-07-14 16:55:14 +0000431 llvm_unreachable("Machine move not supported yet.");
Bill Wendling88423ee2009-05-15 00:11:17 +0000432 }
433 } else {
434 unsigned Reg = RI->getDwarfRegNum(Src.getReg(), isEH);
435 int Offset = Dst.getOffset() / stackGrowth;
436
437 if (Offset < 0) {
Chris Lattner245834d2010-01-22 23:40:08 +0000438 EmitCFAByte(dwarf::DW_CFA_offset_extended_sf);
Chris Lattner894d75a2010-01-22 23:18:42 +0000439 EmitULEB128(Reg, "Reg");
Chris Lattnerbb9078a2010-01-22 22:56:55 +0000440 EmitSLEB128(Offset, "Offset");
Bill Wendling88423ee2009-05-15 00:11:17 +0000441 } else if (Reg < 64) {
Chris Lattner245834d2010-01-22 23:40:08 +0000442 EmitCFAByte(dwarf::DW_CFA_offset + Reg);
Chris Lattner894d75a2010-01-22 23:18:42 +0000443 EmitULEB128(Offset, "Offset");
Bill Wendling88423ee2009-05-15 00:11:17 +0000444 } else {
Chris Lattner245834d2010-01-22 23:40:08 +0000445 EmitCFAByte(dwarf::DW_CFA_offset_extended);
Chris Lattner894d75a2010-01-22 23:18:42 +0000446 EmitULEB128(Reg, "Reg");
447 EmitULEB128(Offset, "Offset");
Bill Wendling88423ee2009-05-15 00:11:17 +0000448 }
449 }
450 }
451}