AsmPrinter.cpp revision a87dea4f8c546ca748f1777a8d1cabcc06515d91
1//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
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 AsmPrinter class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/CodeGen/AsmPrinter.h"
15#include "llvm/Assembly/Writer.h"
16#include "llvm/DerivedTypes.h"
17#include "llvm/Constants.h"
18#include "llvm/Module.h"
19#include "llvm/CodeGen/GCMetadataPrinter.h"
20#include "llvm/CodeGen/MachineConstantPool.h"
21#include "llvm/CodeGen/MachineJumpTableInfo.h"
22#include "llvm/CodeGen/MachineModuleInfo.h"
23#include "llvm/CodeGen/DwarfWriter.h"
24#include "llvm/Analysis/DebugInfo.h"
25#include "llvm/MC/MCContext.h"
26#include "llvm/MC/MCInst.h"
27#include "llvm/MC/MCSection.h"
28#include "llvm/MC/MCStreamer.h"
29#include "llvm/Support/CommandLine.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/FormattedStream.h"
32#include "llvm/Support/Mangler.h"
33#include "llvm/Target/TargetAsmInfo.h"
34#include "llvm/Target/TargetData.h"
35#include "llvm/Target/TargetLowering.h"
36#include "llvm/Target/TargetLoweringObjectFile.h"
37#include "llvm/Target/TargetOptions.h"
38#include "llvm/Target/TargetRegisterInfo.h"
39#include "llvm/ADT/SmallPtrSet.h"
40#include "llvm/ADT/SmallString.h"
41#include "llvm/ADT/StringExtras.h"
42#include <cerrno>
43using namespace llvm;
44
45static cl::opt<cl::boolOrDefault>
46AsmVerbose("asm-verbose", cl::desc("Add comments to directives."),
47           cl::init(cl::BOU_UNSET));
48
49char AsmPrinter::ID = 0;
50AsmPrinter::AsmPrinter(formatted_raw_ostream &o, TargetMachine &tm,
51                       const TargetAsmInfo *T, bool VDef)
52  : MachineFunctionPass(&ID), FunctionNumber(0), O(o),
53    TM(tm), TAI(T), TRI(tm.getRegisterInfo()),
54
55    OutContext(*new MCContext()),
56    OutStreamer(*createAsmStreamer(OutContext, O)),
57
58    IsInTextSection(false), LastMI(0), LastFn(0), Counter(~0U),
59    PrevDLT(0, ~0U, ~0U) {
60  DW = 0; MMI = 0;
61  switch (AsmVerbose) {
62  case cl::BOU_UNSET: VerboseAsm = VDef;  break;
63  case cl::BOU_TRUE:  VerboseAsm = true;  break;
64  case cl::BOU_FALSE: VerboseAsm = false; break;
65  }
66}
67
68AsmPrinter::~AsmPrinter() {
69  for (gcp_iterator I = GCMetadataPrinters.begin(),
70                    E = GCMetadataPrinters.end(); I != E; ++I)
71    delete I->second;
72
73  delete &OutStreamer;
74  delete &OutContext;
75}
76
77const TargetLoweringObjectFile &AsmPrinter::getObjFileLowering() const {
78  return TM.getTargetLowering()->getObjFileLowering();
79}
80
81
82/// SwitchToTextSection - Switch to the specified text section of the executable
83/// if we are not already in it!
84///
85void AsmPrinter::SwitchToTextSection(const char *NewSection,
86                                     const GlobalValue *GV) {
87  std::string NS;
88  if (GV && GV->hasSection())
89    NS = TAI->getSwitchToSectionDirective() + GV->getSection();
90  else
91    NS = NewSection;
92
93  // If we're already in this section, we're done.
94  if (CurrentSection == NS) return;
95
96  // Close the current section, if applicable.
97  if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
98    O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << '\n';
99
100  CurrentSection = NS;
101
102  if (!CurrentSection.empty())
103    O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
104
105  IsInTextSection = true;
106}
107
108/// SwitchToDataSection - Switch to the specified data section of the executable
109/// if we are not already in it!
110///
111void AsmPrinter::SwitchToDataSection(const char *NewSection,
112                                     const GlobalValue *GV) {
113  std::string NS;
114  if (GV && GV->hasSection())
115    NS = TAI->getSwitchToSectionDirective() + GV->getSection();
116  else
117    NS = NewSection;
118
119  // If we're already in this section, we're done.
120  if (CurrentSection == NS) return;
121
122  // Close the current section, if applicable.
123  if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
124    O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << '\n';
125
126  CurrentSection = NS;
127
128  if (!CurrentSection.empty())
129    O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
130
131  IsInTextSection = false;
132}
133
134/// SwitchToSection - Switch to the specified section of the executable if we
135/// are not already in it!
136void AsmPrinter::SwitchToSection(const MCSection *NS) {
137  const std::string &NewSection = NS->getName();
138
139  // If we're already in this section, we're done.
140  if (CurrentSection == NewSection) return;
141
142  // Close the current section, if applicable.
143  if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
144    O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << '\n';
145
146  // FIXME: Make CurrentSection a Section* in the future
147  CurrentSection = NewSection;
148  CurrentSection_ = NS;
149
150  if (!CurrentSection.empty()) {
151    // If section is named we need to switch into it via special '.section'
152    // directive and also append funky flags. Otherwise - section name is just
153    // some magic assembler directive.
154    if (NS->getKind().hasExplicitSection()) {
155      SmallString<32> FlagsStr;
156
157      getObjFileLowering().getSectionFlagsAsString(NS->getKind(), FlagsStr);
158
159      O << TAI->getSwitchToSectionDirective()
160        << CurrentSection
161        << FlagsStr.c_str();
162    } else {
163      O << CurrentSection;
164    }
165    O << TAI->getDataSectionStartSuffix() << '\n';
166  }
167
168  IsInTextSection = NS->getKind().isText();
169}
170
171void AsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
172  MachineFunctionPass::getAnalysisUsage(AU);
173  AU.addRequired<GCModuleInfo>();
174}
175
176bool AsmPrinter::doInitialization(Module &M) {
177  // Initialize TargetLoweringObjectFile.
178  const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
179    .Initialize(OutContext, TM);
180
181  Mang = new Mangler(M, TAI->getGlobalPrefix(), TAI->getPrivateGlobalPrefix(),
182                     TAI->getLinkerPrivateGlobalPrefix());
183
184  if (TAI->doesAllowQuotesInName())
185    Mang->setUseQuotes(true);
186
187  GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
188  assert(MI && "AsmPrinter didn't require GCModuleInfo?");
189
190  if (TAI->hasSingleParameterDotFile()) {
191    /* Very minimal debug info. It is ignored if we emit actual
192       debug info. If we don't, this at helps the user find where
193       a function came from. */
194    O << "\t.file\t\"" << M.getModuleIdentifier() << "\"\n";
195  }
196
197  for (GCModuleInfo::iterator I = MI->begin(), E = MI->end(); I != E; ++I)
198    if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
199      MP->beginAssembly(O, *this, *TAI);
200
201  if (!M.getModuleInlineAsm().empty())
202    O << TAI->getCommentString() << " Start of file scope inline assembly\n"
203      << M.getModuleInlineAsm()
204      << '\n' << TAI->getCommentString()
205      << " End of file scope inline assembly\n";
206
207  SwitchToDataSection("");   // Reset back to no section.
208
209  if (TAI->doesSupportDebugInformation() ||
210      TAI->doesSupportExceptionHandling()) {
211    MMI = getAnalysisIfAvailable<MachineModuleInfo>();
212    if (MMI)
213      MMI->AnalyzeModule(M);
214    DW = getAnalysisIfAvailable<DwarfWriter>();
215    if (DW)
216      DW->BeginModule(&M, MMI, O, this, TAI);
217  }
218
219  return false;
220}
221
222bool AsmPrinter::doFinalization(Module &M) {
223  // Emit global variables.
224  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
225       I != E; ++I)
226    PrintGlobalVariable(I);
227
228  // Emit final debug information.
229  if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
230    DW->EndModule();
231
232  // If the target wants to know about weak references, print them all.
233  if (TAI->getWeakRefDirective()) {
234    // FIXME: This is not lazy, it would be nice to only print weak references
235    // to stuff that is actually used.  Note that doing so would require targets
236    // to notice uses in operands (due to constant exprs etc).  This should
237    // happen with the MC stuff eventually.
238    SwitchToDataSection("");
239
240    // Print out module-level global variables here.
241    for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
242         I != E; ++I) {
243      if (I->hasExternalWeakLinkage())
244        O << TAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
245    }
246
247    for (Module::const_iterator I = M.begin(), E = M.end();
248         I != E; ++I) {
249      if (I->hasExternalWeakLinkage())
250        O << TAI->getWeakRefDirective() << Mang->getMangledName(I) << '\n';
251    }
252  }
253
254  if (TAI->getSetDirective()) {
255    O << '\n';
256    for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
257         I != E; ++I) {
258      std::string Name = Mang->getMangledName(I);
259
260      const GlobalValue *GV = cast<GlobalValue>(I->getAliasedGlobal());
261      std::string Target = Mang->getMangledName(GV);
262
263      if (I->hasExternalLinkage() || !TAI->getWeakRefDirective())
264        O << "\t.globl\t" << Name << '\n';
265      else if (I->hasWeakLinkage())
266        O << TAI->getWeakRefDirective() << Name << '\n';
267      else if (!I->hasLocalLinkage())
268        llvm_unreachable("Invalid alias linkage");
269
270      printVisibility(Name, I->getVisibility());
271
272      O << TAI->getSetDirective() << ' ' << Name << ", " << Target << '\n';
273    }
274  }
275
276  GCModuleInfo *MI = getAnalysisIfAvailable<GCModuleInfo>();
277  assert(MI && "AsmPrinter didn't require GCModuleInfo?");
278  for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
279    if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*--I))
280      MP->finishAssembly(O, *this, *TAI);
281
282  // If we don't have any trampolines, then we don't require stack memory
283  // to be executable. Some targets have a directive to declare this.
284  Function *InitTrampolineIntrinsic = M.getFunction("llvm.init.trampoline");
285  if (!InitTrampolineIntrinsic || InitTrampolineIntrinsic->use_empty())
286    if (TAI->getNonexecutableStackDirective())
287      O << TAI->getNonexecutableStackDirective() << '\n';
288
289  delete Mang; Mang = 0;
290  DW = 0; MMI = 0;
291
292  OutStreamer.Finish();
293  return false;
294}
295
296std::string
297AsmPrinter::getCurrentFunctionEHName(const MachineFunction *MF) const {
298  assert(MF && "No machine function?");
299  return Mang->getMangledName(MF->getFunction(), ".eh",
300                              TAI->is_EHSymbolPrivate());
301}
302
303void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
304  // What's my mangled name?
305  CurrentFnName = Mang->getMangledName(MF.getFunction());
306  IncrementFunctionNumber();
307}
308
309namespace {
310  // SectionCPs - Keep track the alignment, constpool entries per Section.
311  struct SectionCPs {
312    const MCSection *S;
313    unsigned Alignment;
314    SmallVector<unsigned, 4> CPEs;
315    SectionCPs(const MCSection *s, unsigned a) : S(s), Alignment(a) {};
316  };
317}
318
319/// EmitConstantPool - Print to the current output stream assembly
320/// representations of the constants in the constant pool MCP. This is
321/// used to print out constants which have been "spilled to memory" by
322/// the code generator.
323///
324void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
325  const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
326  if (CP.empty()) return;
327
328  // Calculate sections for constant pool entries. We collect entries to go into
329  // the same section together to reduce amount of section switch statements.
330  SmallVector<SectionCPs, 4> CPSections;
331  for (unsigned i = 0, e = CP.size(); i != e; ++i) {
332    const MachineConstantPoolEntry &CPE = CP[i];
333    unsigned Align = CPE.getAlignment();
334
335    SectionKind Kind;
336    switch (CPE.getRelocationInfo()) {
337    default: llvm_unreachable("Unknown section kind");
338    case 2: Kind = SectionKind::get(SectionKind::ReadOnlyWithRel, false); break;
339    case 1:
340      Kind = SectionKind::get(SectionKind::ReadOnlyWithRelLocal,false);
341      break;
342    case 0:
343    switch (TM.getTargetData()->getTypeAllocSize(CPE.getType())) {
344    case 4:  Kind = SectionKind::get(SectionKind::MergeableConst4,false); break;
345    case 8:  Kind = SectionKind::get(SectionKind::MergeableConst8,false); break;
346    case 16: Kind = SectionKind::get(SectionKind::MergeableConst16,false);break;
347    default: Kind = SectionKind::get(SectionKind::MergeableConst,false); break;
348    }
349    }
350
351    const MCSection *S =
352      getObjFileLowering().getSectionForMergeableConstant(Kind);
353
354    // The number of sections are small, just do a linear search from the
355    // last section to the first.
356    bool Found = false;
357    unsigned SecIdx = CPSections.size();
358    while (SecIdx != 0) {
359      if (CPSections[--SecIdx].S == S) {
360        Found = true;
361        break;
362      }
363    }
364    if (!Found) {
365      SecIdx = CPSections.size();
366      CPSections.push_back(SectionCPs(S, Align));
367    }
368
369    if (Align > CPSections[SecIdx].Alignment)
370      CPSections[SecIdx].Alignment = Align;
371    CPSections[SecIdx].CPEs.push_back(i);
372  }
373
374  // Now print stuff into the calculated sections.
375  for (unsigned i = 0, e = CPSections.size(); i != e; ++i) {
376    SwitchToSection(CPSections[i].S);
377    EmitAlignment(Log2_32(CPSections[i].Alignment));
378
379    unsigned Offset = 0;
380    for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) {
381      unsigned CPI = CPSections[i].CPEs[j];
382      MachineConstantPoolEntry CPE = CP[CPI];
383
384      // Emit inter-object padding for alignment.
385      unsigned AlignMask = CPE.getAlignment() - 1;
386      unsigned NewOffset = (Offset + AlignMask) & ~AlignMask;
387      EmitZeros(NewOffset - Offset);
388
389      const Type *Ty = CPE.getType();
390      Offset = NewOffset + TM.getTargetData()->getTypeAllocSize(Ty);
391
392      O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
393        << CPI << ":\t\t\t\t\t";
394      if (VerboseAsm) {
395        O << TAI->getCommentString() << ' ';
396        WriteTypeSymbolic(O, CPE.getType(), 0);
397      }
398      O << '\n';
399      if (CPE.isMachineConstantPoolEntry())
400        EmitMachineConstantPoolValue(CPE.Val.MachineCPVal);
401      else
402        EmitGlobalConstant(CPE.Val.ConstVal);
403    }
404  }
405}
406
407/// EmitJumpTableInfo - Print assembly representations of the jump tables used
408/// by the current function to the current output stream.
409///
410void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
411                                   MachineFunction &MF) {
412  const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
413  if (JT.empty()) return;
414
415  bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
416
417  // Pick the directive to use to print the jump table entries, and switch to
418  // the appropriate section.
419  TargetLowering *LoweringInfo = TM.getTargetLowering();
420
421  const char *JumpTableDataSection = TAI->getJumpTableDataSection();
422  const Function *F = MF.getFunction();
423
424  const MCSection *FuncSection =
425    getObjFileLowering().SectionForGlobal(F, Mang, TM);
426
427  bool JTInDiffSection = false;
428  if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
429      !JumpTableDataSection ||
430      FuncSection->getKind().isWeak()) {
431    // In PIC mode, we need to emit the jump table to the same section as the
432    // function body itself, otherwise the label differences won't make sense.
433    // We should also do if the section name is NULL or function is declared in
434    // discardable section.
435    SwitchToSection(FuncSection);
436  } else {
437    SwitchToDataSection(JumpTableDataSection);
438    JTInDiffSection = true;
439  }
440
441  EmitAlignment(Log2_32(MJTI->getAlignment()));
442
443  for (unsigned i = 0, e = JT.size(); i != e; ++i) {
444    const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
445
446    // If this jump table was deleted, ignore it.
447    if (JTBBs.empty()) continue;
448
449    // For PIC codegen, if possible we want to use the SetDirective to reduce
450    // the number of relocations the assembler will generate for the jump table.
451    // Set directives are all printed before the jump table itself.
452    SmallPtrSet<MachineBasicBlock*, 16> EmittedSets;
453    if (TAI->getSetDirective() && IsPic)
454      for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
455        if (EmittedSets.insert(JTBBs[ii]))
456          printPICJumpTableSetLabel(i, JTBBs[ii]);
457
458    // On some targets (e.g. darwin) we want to emit two consequtive labels
459    // before each jump table.  The first label is never referenced, but tells
460    // the assembler and linker the extents of the jump table object.  The
461    // second label is actually referenced by the code.
462    if (JTInDiffSection) {
463      if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
464        O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
465    }
466
467    O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
468      << '_' << i << ":\n";
469
470    for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
471      printPICJumpTableEntry(MJTI, JTBBs[ii], i);
472      O << '\n';
473    }
474  }
475}
476
477void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
478                                        const MachineBasicBlock *MBB,
479                                        unsigned uid)  const {
480  bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
481
482  // Use JumpTableDirective otherwise honor the entry size from the jump table
483  // info.
484  const char *JTEntryDirective = TAI->getJumpTableDirective();
485  bool HadJTEntryDirective = JTEntryDirective != NULL;
486  if (!HadJTEntryDirective) {
487    JTEntryDirective = MJTI->getEntrySize() == 4 ?
488      TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
489  }
490
491  O << JTEntryDirective << ' ';
492
493  // If we have emitted set directives for the jump table entries, print
494  // them rather than the entries themselves.  If we're emitting PIC, then
495  // emit the table entries as differences between two text section labels.
496  // If we're emitting non-PIC code, then emit the entries as direct
497  // references to the target basic blocks.
498  if (IsPic) {
499    if (TAI->getSetDirective()) {
500      O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
501        << '_' << uid << "_set_" << MBB->getNumber();
502    } else {
503      printBasicBlockLabel(MBB, false, false, false);
504      // If the arch uses custom Jump Table directives, don't calc relative to
505      // JT
506      if (!HadJTEntryDirective)
507        O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
508          << getFunctionNumber() << '_' << uid;
509    }
510  } else {
511    printBasicBlockLabel(MBB, false, false, false);
512  }
513}
514
515
516/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
517/// special global used by LLVM.  If so, emit it and return true, otherwise
518/// do nothing and return false.
519bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
520  if (GV->getName() == "llvm.used") {
521    if (TAI->getUsedDirective() != 0)    // No need to emit this at all.
522      EmitLLVMUsedList(GV->getInitializer());
523    return true;
524  }
525
526  // Ignore debug and non-emitted data.  This handles llvm.compiler.used.
527  if (GV->getSection() == "llvm.metadata" ||
528      GV->hasAvailableExternallyLinkage())
529    return true;
530
531  if (!GV->hasAppendingLinkage()) return false;
532
533  assert(GV->hasInitializer() && "Not a special LLVM global!");
534
535  const TargetData *TD = TM.getTargetData();
536  unsigned Align = Log2_32(TD->getPointerPrefAlignment());
537  if (GV->getName() == "llvm.global_ctors") {
538    SwitchToDataSection(TAI->getStaticCtorsSection());
539    EmitAlignment(Align, 0);
540    EmitXXStructorList(GV->getInitializer());
541    return true;
542  }
543
544  if (GV->getName() == "llvm.global_dtors") {
545    SwitchToDataSection(TAI->getStaticDtorsSection());
546    EmitAlignment(Align, 0);
547    EmitXXStructorList(GV->getInitializer());
548    return true;
549  }
550
551  return false;
552}
553
554/// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
555/// global in the specified llvm.used list for which emitUsedDirectiveFor
556/// is true, as being used with this directive.
557void AsmPrinter::EmitLLVMUsedList(Constant *List) {
558  const char *Directive = TAI->getUsedDirective();
559
560  // Should be an array of 'i8*'.
561  ConstantArray *InitList = dyn_cast<ConstantArray>(List);
562  if (InitList == 0) return;
563
564  for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
565    const GlobalValue *GV =
566      dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
567    if (GV && TAI->emitUsedDirectiveFor(GV, Mang)) {
568      O << Directive;
569      EmitConstantValueOnly(InitList->getOperand(i));
570      O << '\n';
571    }
572  }
573}
574
575/// EmitXXStructorList - Emit the ctor or dtor list.  This just prints out the
576/// function pointers, ignoring the init priority.
577void AsmPrinter::EmitXXStructorList(Constant *List) {
578  // Should be an array of '{ int, void ()* }' structs.  The first value is the
579  // init priority, which we ignore.
580  if (!isa<ConstantArray>(List)) return;
581  ConstantArray *InitList = cast<ConstantArray>(List);
582  for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
583    if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
584      if (CS->getNumOperands() != 2) return;  // Not array of 2-element structs.
585
586      if (CS->getOperand(1)->isNullValue())
587        return;  // Found a null terminator, exit printing.
588      // Emit the function pointer.
589      EmitGlobalConstant(CS->getOperand(1));
590    }
591}
592
593/// getGlobalLinkName - Returns the asm/link name of of the specified
594/// global variable.  Should be overridden by each target asm printer to
595/// generate the appropriate value.
596const std::string &AsmPrinter::getGlobalLinkName(const GlobalVariable *GV,
597                                                 std::string &LinkName) const {
598  if (isa<Function>(GV)) {
599    LinkName += TAI->getFunctionAddrPrefix();
600    LinkName += Mang->getMangledName(GV);
601    LinkName += TAI->getFunctionAddrSuffix();
602  } else {
603    LinkName += TAI->getGlobalVarAddrPrefix();
604    LinkName += Mang->getMangledName(GV);
605    LinkName += TAI->getGlobalVarAddrSuffix();
606  }
607
608  return LinkName;
609}
610
611/// EmitExternalGlobal - Emit the external reference to a global variable.
612/// Should be overridden if an indirect reference should be used.
613void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
614  std::string GLN;
615  O << getGlobalLinkName(GV, GLN);
616}
617
618
619
620//===----------------------------------------------------------------------===//
621/// LEB 128 number encoding.
622
623/// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
624/// representing an unsigned leb128 value.
625void AsmPrinter::PrintULEB128(unsigned Value) const {
626  char Buffer[20];
627  do {
628    unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
629    Value >>= 7;
630    if (Value) Byte |= 0x80;
631    O << "0x" << utohex_buffer(Byte, Buffer+20);
632    if (Value) O << ", ";
633  } while (Value);
634}
635
636/// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
637/// representing a signed leb128 value.
638void AsmPrinter::PrintSLEB128(int Value) const {
639  int Sign = Value >> (8 * sizeof(Value) - 1);
640  bool IsMore;
641  char Buffer[20];
642
643  do {
644    unsigned char Byte = static_cast<unsigned char>(Value & 0x7f);
645    Value >>= 7;
646    IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
647    if (IsMore) Byte |= 0x80;
648    O << "0x" << utohex_buffer(Byte, Buffer+20);
649    if (IsMore) O << ", ";
650  } while (IsMore);
651}
652
653//===--------------------------------------------------------------------===//
654// Emission and print routines
655//
656
657/// PrintHex - Print a value as a hexidecimal value.
658///
659void AsmPrinter::PrintHex(int Value) const {
660  char Buffer[20];
661  O << "0x" << utohex_buffer(static_cast<unsigned>(Value), Buffer+20);
662}
663
664/// EOL - Print a newline character to asm stream.  If a comment is present
665/// then it will be printed first.  Comments should not contain '\n'.
666void AsmPrinter::EOL() const {
667  O << '\n';
668}
669
670void AsmPrinter::EOL(const std::string &Comment) const {
671  if (VerboseAsm && !Comment.empty()) {
672    O << '\t'
673      << TAI->getCommentString()
674      << ' '
675      << Comment;
676  }
677  O << '\n';
678}
679
680void AsmPrinter::EOL(const char* Comment) const {
681  if (VerboseAsm && *Comment) {
682    O << '\t'
683      << TAI->getCommentString()
684      << ' '
685      << Comment;
686  }
687  O << '\n';
688}
689
690/// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
691/// unsigned leb128 value.
692void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
693  if (TAI->hasLEB128()) {
694    O << "\t.uleb128\t"
695      << Value;
696  } else {
697    O << TAI->getData8bitsDirective();
698    PrintULEB128(Value);
699  }
700}
701
702/// EmitSLEB128Bytes - print an assembler byte data directive to compose a
703/// signed leb128 value.
704void AsmPrinter::EmitSLEB128Bytes(int Value) const {
705  if (TAI->hasLEB128()) {
706    O << "\t.sleb128\t"
707      << Value;
708  } else {
709    O << TAI->getData8bitsDirective();
710    PrintSLEB128(Value);
711  }
712}
713
714/// EmitInt8 - Emit a byte directive and value.
715///
716void AsmPrinter::EmitInt8(int Value) const {
717  O << TAI->getData8bitsDirective();
718  PrintHex(Value & 0xFF);
719}
720
721/// EmitInt16 - Emit a short directive and value.
722///
723void AsmPrinter::EmitInt16(int Value) const {
724  O << TAI->getData16bitsDirective();
725  PrintHex(Value & 0xFFFF);
726}
727
728/// EmitInt32 - Emit a long directive and value.
729///
730void AsmPrinter::EmitInt32(int Value) const {
731  O << TAI->getData32bitsDirective();
732  PrintHex(Value);
733}
734
735/// EmitInt64 - Emit a long long directive and value.
736///
737void AsmPrinter::EmitInt64(uint64_t Value) const {
738  if (TAI->getData64bitsDirective()) {
739    O << TAI->getData64bitsDirective();
740    PrintHex(Value);
741  } else {
742    if (TM.getTargetData()->isBigEndian()) {
743      EmitInt32(unsigned(Value >> 32)); O << '\n';
744      EmitInt32(unsigned(Value));
745    } else {
746      EmitInt32(unsigned(Value)); O << '\n';
747      EmitInt32(unsigned(Value >> 32));
748    }
749  }
750}
751
752/// toOctal - Convert the low order bits of X into an octal digit.
753///
754static inline char toOctal(int X) {
755  return (X&7)+'0';
756}
757
758/// printStringChar - Print a char, escaped if necessary.
759///
760static void printStringChar(formatted_raw_ostream &O, unsigned char C) {
761  if (C == '"') {
762    O << "\\\"";
763  } else if (C == '\\') {
764    O << "\\\\";
765  } else if (isprint((unsigned char)C)) {
766    O << C;
767  } else {
768    switch(C) {
769    case '\b': O << "\\b"; break;
770    case '\f': O << "\\f"; break;
771    case '\n': O << "\\n"; break;
772    case '\r': O << "\\r"; break;
773    case '\t': O << "\\t"; break;
774    default:
775      O << '\\';
776      O << toOctal(C >> 6);
777      O << toOctal(C >> 3);
778      O << toOctal(C >> 0);
779      break;
780    }
781  }
782}
783
784/// EmitString - Emit a string with quotes and a null terminator.
785/// Special characters are emitted properly.
786/// \literal (Eg. '\t') \endliteral
787void AsmPrinter::EmitString(const std::string &String) const {
788  EmitString(String.c_str(), String.size());
789}
790
791void AsmPrinter::EmitString(const char *String, unsigned Size) const {
792  const char* AscizDirective = TAI->getAscizDirective();
793  if (AscizDirective)
794    O << AscizDirective;
795  else
796    O << TAI->getAsciiDirective();
797  O << '\"';
798  for (unsigned i = 0; i < Size; ++i)
799    printStringChar(O, String[i]);
800  if (AscizDirective)
801    O << '\"';
802  else
803    O << "\\0\"";
804}
805
806
807/// EmitFile - Emit a .file directive.
808void AsmPrinter::EmitFile(unsigned Number, const std::string &Name) const {
809  O << "\t.file\t" << Number << " \"";
810  for (unsigned i = 0, N = Name.size(); i < N; ++i)
811    printStringChar(O, Name[i]);
812  O << '\"';
813}
814
815
816//===----------------------------------------------------------------------===//
817
818// EmitAlignment - Emit an alignment directive to the specified power of
819// two boundary.  For example, if you pass in 3 here, you will get an 8
820// byte alignment.  If a global value is specified, and if that global has
821// an explicit alignment requested, it will unconditionally override the
822// alignment request.  However, if ForcedAlignBits is specified, this value
823// has final say: the ultimate alignment will be the max of ForcedAlignBits
824// and the alignment computed with NumBits and the global.
825//
826// The algorithm is:
827//     Align = NumBits;
828//     if (GV && GV->hasalignment) Align = GV->getalignment();
829//     Align = std::max(Align, ForcedAlignBits);
830//
831void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
832                               unsigned ForcedAlignBits,
833                               bool UseFillExpr) const {
834  if (GV && GV->getAlignment())
835    NumBits = Log2_32(GV->getAlignment());
836  NumBits = std::max(NumBits, ForcedAlignBits);
837
838  if (NumBits == 0) return;   // No need to emit alignment.
839  if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
840  O << TAI->getAlignDirective() << NumBits;
841
842  unsigned FillValue = TAI->getTextAlignFillValue();
843  UseFillExpr &= IsInTextSection && FillValue;
844  if (UseFillExpr) {
845    O << ',';
846    PrintHex(FillValue);
847  }
848  O << '\n';
849}
850
851
852/// EmitZeros - Emit a block of zeros.
853///
854void AsmPrinter::EmitZeros(uint64_t NumZeros, unsigned AddrSpace) const {
855  if (NumZeros) {
856    if (TAI->getZeroDirective()) {
857      O << TAI->getZeroDirective() << NumZeros;
858      if (TAI->getZeroDirectiveSuffix())
859        O << TAI->getZeroDirectiveSuffix();
860      O << '\n';
861    } else {
862      for (; NumZeros; --NumZeros)
863        O << TAI->getData8bitsDirective(AddrSpace) << "0\n";
864    }
865  }
866}
867
868// Print out the specified constant, without a storage class.  Only the
869// constants valid in constant expressions can occur here.
870void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
871  if (CV->isNullValue() || isa<UndefValue>(CV))
872    O << '0';
873  else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
874    O << CI->getZExtValue();
875  } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
876    // This is a constant address for a global variable or function. Use the
877    // name of the variable or function as the address value, possibly
878    // decorating it with GlobalVarAddrPrefix/Suffix or
879    // FunctionAddrPrefix/Suffix (these all default to "" )
880    if (isa<Function>(GV)) {
881      O << TAI->getFunctionAddrPrefix()
882        << Mang->getMangledName(GV)
883        << TAI->getFunctionAddrSuffix();
884    } else {
885      O << TAI->getGlobalVarAddrPrefix()
886        << Mang->getMangledName(GV)
887        << TAI->getGlobalVarAddrSuffix();
888    }
889  } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
890    const TargetData *TD = TM.getTargetData();
891    unsigned Opcode = CE->getOpcode();
892    switch (Opcode) {
893    case Instruction::GetElementPtr: {
894      // generate a symbolic expression for the byte address
895      const Constant *ptrVal = CE->getOperand(0);
896      SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
897      if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
898                                                idxVec.size())) {
899        // Truncate/sext the offset to the pointer size.
900        if (TD->getPointerSizeInBits() != 64) {
901          int SExtAmount = 64-TD->getPointerSizeInBits();
902          Offset = (Offset << SExtAmount) >> SExtAmount;
903        }
904
905        if (Offset)
906          O << '(';
907        EmitConstantValueOnly(ptrVal);
908        if (Offset > 0)
909          O << ") + " << Offset;
910        else if (Offset < 0)
911          O << ") - " << -Offset;
912      } else {
913        EmitConstantValueOnly(ptrVal);
914      }
915      break;
916    }
917    case Instruction::Trunc:
918    case Instruction::ZExt:
919    case Instruction::SExt:
920    case Instruction::FPTrunc:
921    case Instruction::FPExt:
922    case Instruction::UIToFP:
923    case Instruction::SIToFP:
924    case Instruction::FPToUI:
925    case Instruction::FPToSI:
926      llvm_unreachable("FIXME: Don't yet support this kind of constant cast expr");
927      break;
928    case Instruction::BitCast:
929      return EmitConstantValueOnly(CE->getOperand(0));
930
931    case Instruction::IntToPtr: {
932      // Handle casts to pointers by changing them into casts to the appropriate
933      // integer type.  This promotes constant folding and simplifies this code.
934      Constant *Op = CE->getOperand(0);
935      Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/);
936      return EmitConstantValueOnly(Op);
937    }
938
939
940    case Instruction::PtrToInt: {
941      // Support only foldable casts to/from pointers that can be eliminated by
942      // changing the pointer to the appropriately sized integer type.
943      Constant *Op = CE->getOperand(0);
944      const Type *Ty = CE->getType();
945
946      // We can emit the pointer value into this slot if the slot is an
947      // integer slot greater or equal to the size of the pointer.
948      if (TD->getTypeAllocSize(Ty) >= TD->getTypeAllocSize(Op->getType()))
949        return EmitConstantValueOnly(Op);
950
951      O << "((";
952      EmitConstantValueOnly(Op);
953      APInt ptrMask = APInt::getAllOnesValue(TD->getTypeAllocSizeInBits(Ty));
954
955      SmallString<40> S;
956      ptrMask.toStringUnsigned(S);
957      O << ") & " << S.c_str() << ')';
958      break;
959    }
960    case Instruction::Add:
961    case Instruction::Sub:
962    case Instruction::And:
963    case Instruction::Or:
964    case Instruction::Xor:
965      O << '(';
966      EmitConstantValueOnly(CE->getOperand(0));
967      O << ')';
968      switch (Opcode) {
969      case Instruction::Add:
970       O << " + ";
971       break;
972      case Instruction::Sub:
973       O << " - ";
974       break;
975      case Instruction::And:
976       O << " & ";
977       break;
978      case Instruction::Or:
979       O << " | ";
980       break;
981      case Instruction::Xor:
982       O << " ^ ";
983       break;
984      default:
985       break;
986      }
987      O << '(';
988      EmitConstantValueOnly(CE->getOperand(1));
989      O << ')';
990      break;
991    default:
992      llvm_unreachable("Unsupported operator!");
993    }
994  } else {
995    llvm_unreachable("Unknown constant value!");
996  }
997}
998
999/// printAsCString - Print the specified array as a C compatible string, only if
1000/// the predicate isString is true.
1001///
1002static void printAsCString(formatted_raw_ostream &O, const ConstantArray *CVA,
1003                           unsigned LastElt) {
1004  assert(CVA->isString() && "Array is not string compatible!");
1005
1006  O << '\"';
1007  for (unsigned i = 0; i != LastElt; ++i) {
1008    unsigned char C =
1009        (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
1010    printStringChar(O, C);
1011  }
1012  O << '\"';
1013}
1014
1015/// EmitString - Emit a zero-byte-terminated string constant.
1016///
1017void AsmPrinter::EmitString(const ConstantArray *CVA) const {
1018  unsigned NumElts = CVA->getNumOperands();
1019  if (TAI->getAscizDirective() && NumElts &&
1020      cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
1021    O << TAI->getAscizDirective();
1022    printAsCString(O, CVA, NumElts-1);
1023  } else {
1024    O << TAI->getAsciiDirective();
1025    printAsCString(O, CVA, NumElts);
1026  }
1027  O << '\n';
1028}
1029
1030void AsmPrinter::EmitGlobalConstantArray(const ConstantArray *CVA,
1031                                         unsigned AddrSpace) {
1032  if (CVA->isString()) {
1033    EmitString(CVA);
1034  } else { // Not a string.  Print the values in successive locations
1035    for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
1036      EmitGlobalConstant(CVA->getOperand(i), AddrSpace);
1037  }
1038}
1039
1040void AsmPrinter::EmitGlobalConstantVector(const ConstantVector *CP) {
1041  const VectorType *PTy = CP->getType();
1042
1043  for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
1044    EmitGlobalConstant(CP->getOperand(I));
1045}
1046
1047void AsmPrinter::EmitGlobalConstantStruct(const ConstantStruct *CVS,
1048                                          unsigned AddrSpace) {
1049  // Print the fields in successive locations. Pad to align if needed!
1050  const TargetData *TD = TM.getTargetData();
1051  unsigned Size = TD->getTypeAllocSize(CVS->getType());
1052  const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
1053  uint64_t sizeSoFar = 0;
1054  for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
1055    const Constant* field = CVS->getOperand(i);
1056
1057    // Check if padding is needed and insert one or more 0s.
1058    uint64_t fieldSize = TD->getTypeAllocSize(field->getType());
1059    uint64_t padSize = ((i == e-1 ? Size : cvsLayout->getElementOffset(i+1))
1060                        - cvsLayout->getElementOffset(i)) - fieldSize;
1061    sizeSoFar += fieldSize + padSize;
1062
1063    // Now print the actual field value.
1064    EmitGlobalConstant(field, AddrSpace);
1065
1066    // Insert padding - this may include padding to increase the size of the
1067    // current field up to the ABI size (if the struct is not packed) as well
1068    // as padding to ensure that the next field starts at the right offset.
1069    EmitZeros(padSize, AddrSpace);
1070  }
1071  assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
1072         "Layout of constant struct may be incorrect!");
1073}
1074
1075void AsmPrinter::EmitGlobalConstantFP(const ConstantFP *CFP,
1076                                      unsigned AddrSpace) {
1077  // FP Constants are printed as integer constants to avoid losing
1078  // precision...
1079  const TargetData *TD = TM.getTargetData();
1080  if (CFP->getType() == Type::DoubleTy) {
1081    double Val = CFP->getValueAPF().convertToDouble();  // for comment only
1082    uint64_t i = CFP->getValueAPF().bitcastToAPInt().getZExtValue();
1083    if (TAI->getData64bitsDirective(AddrSpace)) {
1084      O << TAI->getData64bitsDirective(AddrSpace) << i;
1085      if (VerboseAsm)
1086        O << '\t' << TAI->getCommentString() << " double value: " << Val;
1087      O << '\n';
1088    } else if (TD->isBigEndian()) {
1089      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
1090      if (VerboseAsm)
1091        O << '\t' << TAI->getCommentString()
1092          << " double most significant word " << Val;
1093      O << '\n';
1094      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i);
1095      if (VerboseAsm)
1096        O << '\t' << TAI->getCommentString()
1097          << " double least significant word " << Val;
1098      O << '\n';
1099    } else {
1100      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i);
1101      if (VerboseAsm)
1102        O << '\t' << TAI->getCommentString()
1103          << " double least significant word " << Val;
1104      O << '\n';
1105      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(i >> 32);
1106      if (VerboseAsm)
1107        O << '\t' << TAI->getCommentString()
1108          << " double most significant word " << Val;
1109      O << '\n';
1110    }
1111    return;
1112  } else if (CFP->getType() == Type::FloatTy) {
1113    float Val = CFP->getValueAPF().convertToFloat();  // for comment only
1114    O << TAI->getData32bitsDirective(AddrSpace)
1115      << CFP->getValueAPF().bitcastToAPInt().getZExtValue();
1116    if (VerboseAsm)
1117      O << '\t' << TAI->getCommentString() << " float " << Val;
1118    O << '\n';
1119    return;
1120  } else if (CFP->getType() == Type::X86_FP80Ty) {
1121    // all long double variants are printed as hex
1122    // api needed to prevent premature destruction
1123    APInt api = CFP->getValueAPF().bitcastToAPInt();
1124    const uint64_t *p = api.getRawData();
1125    // Convert to double so we can print the approximate val as a comment.
1126    APFloat DoubleVal = CFP->getValueAPF();
1127    bool ignored;
1128    DoubleVal.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven,
1129                      &ignored);
1130    if (TD->isBigEndian()) {
1131      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
1132      if (VerboseAsm)
1133        O << '\t' << TAI->getCommentString()
1134          << " long double most significant halfword of ~"
1135          << DoubleVal.convertToDouble();
1136      O << '\n';
1137      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
1138      if (VerboseAsm)
1139        O << '\t' << TAI->getCommentString() << " long double next halfword";
1140      O << '\n';
1141      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
1142      if (VerboseAsm)
1143        O << '\t' << TAI->getCommentString() << " long double next halfword";
1144      O << '\n';
1145      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
1146      if (VerboseAsm)
1147        O << '\t' << TAI->getCommentString() << " long double next halfword";
1148      O << '\n';
1149      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
1150      if (VerboseAsm)
1151        O << '\t' << TAI->getCommentString()
1152          << " long double least significant halfword";
1153      O << '\n';
1154     } else {
1155      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0]);
1156      if (VerboseAsm)
1157        O << '\t' << TAI->getCommentString()
1158          << " long double least significant halfword of ~"
1159          << DoubleVal.convertToDouble();
1160      O << '\n';
1161      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 16);
1162      if (VerboseAsm)
1163        O << '\t' << TAI->getCommentString()
1164          << " long double next halfword";
1165      O << '\n';
1166      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 32);
1167      if (VerboseAsm)
1168        O << '\t' << TAI->getCommentString()
1169          << " long double next halfword";
1170      O << '\n';
1171      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[0] >> 48);
1172      if (VerboseAsm)
1173        O << '\t' << TAI->getCommentString()
1174          << " long double next halfword";
1175      O << '\n';
1176      O << TAI->getData16bitsDirective(AddrSpace) << uint16_t(p[1]);
1177      if (VerboseAsm)
1178        O << '\t' << TAI->getCommentString()
1179          << " long double most significant halfword";
1180      O << '\n';
1181    }
1182    EmitZeros(TD->getTypeAllocSize(Type::X86_FP80Ty) -
1183              TD->getTypeStoreSize(Type::X86_FP80Ty), AddrSpace);
1184    return;
1185  } else if (CFP->getType() == Type::PPC_FP128Ty) {
1186    // all long double variants are printed as hex
1187    // api needed to prevent premature destruction
1188    APInt api = CFP->getValueAPF().bitcastToAPInt();
1189    const uint64_t *p = api.getRawData();
1190    if (TD->isBigEndian()) {
1191      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
1192      if (VerboseAsm)
1193        O << '\t' << TAI->getCommentString()
1194          << " long double most significant word";
1195      O << '\n';
1196      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
1197      if (VerboseAsm)
1198        O << '\t' << TAI->getCommentString()
1199        << " long double next word";
1200      O << '\n';
1201      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
1202      if (VerboseAsm)
1203        O << '\t' << TAI->getCommentString()
1204          << " long double next word";
1205      O << '\n';
1206      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
1207      if (VerboseAsm)
1208        O << '\t' << TAI->getCommentString()
1209          << " long double least significant word";
1210      O << '\n';
1211     } else {
1212      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1]);
1213      if (VerboseAsm)
1214        O << '\t' << TAI->getCommentString()
1215          << " long double least significant word";
1216      O << '\n';
1217      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[1] >> 32);
1218      if (VerboseAsm)
1219        O << '\t' << TAI->getCommentString()
1220          << " long double next word";
1221      O << '\n';
1222      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0]);
1223      if (VerboseAsm)
1224        O << '\t' << TAI->getCommentString()
1225          << " long double next word";
1226      O << '\n';
1227      O << TAI->getData32bitsDirective(AddrSpace) << uint32_t(p[0] >> 32);
1228      if (VerboseAsm)
1229        O << '\t' << TAI->getCommentString()
1230          << " long double most significant word";
1231      O << '\n';
1232    }
1233    return;
1234  } else llvm_unreachable("Floating point constant type not handled");
1235}
1236
1237void AsmPrinter::EmitGlobalConstantLargeInt(const ConstantInt *CI,
1238                                            unsigned AddrSpace) {
1239  const TargetData *TD = TM.getTargetData();
1240  unsigned BitWidth = CI->getBitWidth();
1241  assert(isPowerOf2_32(BitWidth) &&
1242         "Non-power-of-2-sized integers not handled!");
1243
1244  // We don't expect assemblers to support integer data directives
1245  // for more than 64 bits, so we emit the data in at most 64-bit
1246  // quantities at a time.
1247  const uint64_t *RawData = CI->getValue().getRawData();
1248  for (unsigned i = 0, e = BitWidth / 64; i != e; ++i) {
1249    uint64_t Val;
1250    if (TD->isBigEndian())
1251      Val = RawData[e - i - 1];
1252    else
1253      Val = RawData[i];
1254
1255    if (TAI->getData64bitsDirective(AddrSpace))
1256      O << TAI->getData64bitsDirective(AddrSpace) << Val << '\n';
1257    else if (TD->isBigEndian()) {
1258      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32);
1259      if (VerboseAsm)
1260        O << '\t' << TAI->getCommentString()
1261          << " Double-word most significant word " << Val;
1262      O << '\n';
1263      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val);
1264      if (VerboseAsm)
1265        O << '\t' << TAI->getCommentString()
1266          << " Double-word least significant word " << Val;
1267      O << '\n';
1268    } else {
1269      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val);
1270      if (VerboseAsm)
1271        O << '\t' << TAI->getCommentString()
1272          << " Double-word least significant word " << Val;
1273      O << '\n';
1274      O << TAI->getData32bitsDirective(AddrSpace) << unsigned(Val >> 32);
1275      if (VerboseAsm)
1276        O << '\t' << TAI->getCommentString()
1277          << " Double-word most significant word " << Val;
1278      O << '\n';
1279    }
1280  }
1281}
1282
1283/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
1284void AsmPrinter::EmitGlobalConstant(const Constant *CV, unsigned AddrSpace) {
1285  const TargetData *TD = TM.getTargetData();
1286  const Type *type = CV->getType();
1287  unsigned Size = TD->getTypeAllocSize(type);
1288
1289  if (CV->isNullValue() || isa<UndefValue>(CV)) {
1290    EmitZeros(Size, AddrSpace);
1291    return;
1292  } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
1293    EmitGlobalConstantArray(CVA , AddrSpace);
1294    return;
1295  } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
1296    EmitGlobalConstantStruct(CVS, AddrSpace);
1297    return;
1298  } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
1299    EmitGlobalConstantFP(CFP, AddrSpace);
1300    return;
1301  } else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1302    // Small integers are handled below; large integers are handled here.
1303    if (Size > 4) {
1304      EmitGlobalConstantLargeInt(CI, AddrSpace);
1305      return;
1306    }
1307  } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
1308    EmitGlobalConstantVector(CP);
1309    return;
1310  }
1311
1312  printDataDirective(type, AddrSpace);
1313  EmitConstantValueOnly(CV);
1314  if (VerboseAsm) {
1315    if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
1316      SmallString<40> S;
1317      CI->getValue().toStringUnsigned(S, 16);
1318      O << "\t\t\t" << TAI->getCommentString() << " 0x" << S.c_str();
1319    }
1320  }
1321  O << '\n';
1322}
1323
1324void AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
1325  // Target doesn't support this yet!
1326  llvm_unreachable("Target does not support EmitMachineConstantPoolValue");
1327}
1328
1329/// PrintSpecial - Print information related to the specified machine instr
1330/// that is independent of the operand, and may be independent of the instr
1331/// itself.  This can be useful for portably encoding the comment character
1332/// or other bits of target-specific knowledge into the asmstrings.  The
1333/// syntax used is ${:comment}.  Targets can override this to add support
1334/// for their own strange codes.
1335void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) const {
1336  if (!strcmp(Code, "private")) {
1337    O << TAI->getPrivateGlobalPrefix();
1338  } else if (!strcmp(Code, "comment")) {
1339    if (VerboseAsm)
1340      O << TAI->getCommentString();
1341  } else if (!strcmp(Code, "uid")) {
1342    // Comparing the address of MI isn't sufficient, because machineinstrs may
1343    // be allocated to the same address across functions.
1344    const Function *ThisF = MI->getParent()->getParent()->getFunction();
1345
1346    // If this is a new LastFn instruction, bump the counter.
1347    if (LastMI != MI || LastFn != ThisF) {
1348      ++Counter;
1349      LastMI = MI;
1350      LastFn = ThisF;
1351    }
1352    O << Counter;
1353  } else {
1354    std::string msg;
1355    raw_string_ostream Msg(msg);
1356    Msg << "Unknown special formatter '" << Code
1357         << "' for machine instr: " << *MI;
1358    llvm_report_error(Msg.str());
1359  }
1360}
1361
1362/// processDebugLoc - Processes the debug information of each machine
1363/// instruction's DebugLoc.
1364void AsmPrinter::processDebugLoc(DebugLoc DL) {
1365  if (TAI->doesSupportDebugInformation() && DW->ShouldEmitDwarfDebug()) {
1366    if (!DL.isUnknown()) {
1367      DebugLocTuple CurDLT = MF->getDebugLocTuple(DL);
1368
1369      if (CurDLT.CompileUnit != 0 && PrevDLT != CurDLT)
1370        printLabel(DW->RecordSourceLine(CurDLT.Line, CurDLT.Col,
1371                                        DICompileUnit(CurDLT.CompileUnit)));
1372
1373      PrevDLT = CurDLT;
1374    }
1375  }
1376}
1377
1378/// printInlineAsm - This method formats and prints the specified machine
1379/// instruction that is an inline asm.
1380void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
1381  unsigned NumOperands = MI->getNumOperands();
1382
1383  // Count the number of register definitions.
1384  unsigned NumDefs = 0;
1385  for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
1386       ++NumDefs)
1387    assert(NumDefs != NumOperands-1 && "No asm string?");
1388
1389  assert(MI->getOperand(NumDefs).isSymbol() && "No asm string?");
1390
1391  // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
1392  const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
1393
1394  // If this asmstr is empty, just print the #APP/#NOAPP markers.
1395  // These are useful to see where empty asm's wound up.
1396  if (AsmStr[0] == 0) {
1397    O << TAI->getInlineAsmStart() << "\n\t" << TAI->getInlineAsmEnd() << '\n';
1398    return;
1399  }
1400
1401  O << TAI->getInlineAsmStart() << "\n\t";
1402
1403  // The variant of the current asmprinter.
1404  int AsmPrinterVariant = TAI->getAssemblerDialect();
1405
1406  int CurVariant = -1;            // The number of the {.|.|.} region we are in.
1407  const char *LastEmitted = AsmStr; // One past the last character emitted.
1408
1409  while (*LastEmitted) {
1410    switch (*LastEmitted) {
1411    default: {
1412      // Not a special case, emit the string section literally.
1413      const char *LiteralEnd = LastEmitted+1;
1414      while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
1415             *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
1416        ++LiteralEnd;
1417      if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1418        O.write(LastEmitted, LiteralEnd-LastEmitted);
1419      LastEmitted = LiteralEnd;
1420      break;
1421    }
1422    case '\n':
1423      ++LastEmitted;   // Consume newline character.
1424      O << '\n';       // Indent code with newline.
1425      break;
1426    case '$': {
1427      ++LastEmitted;   // Consume '$' character.
1428      bool Done = true;
1429
1430      // Handle escapes.
1431      switch (*LastEmitted) {
1432      default: Done = false; break;
1433      case '$':     // $$ -> $
1434        if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
1435          O << '$';
1436        ++LastEmitted;  // Consume second '$' character.
1437        break;
1438      case '(':             // $( -> same as GCC's { character.
1439        ++LastEmitted;      // Consume '(' character.
1440        if (CurVariant != -1) {
1441          llvm_report_error("Nested variants found in inline asm string: '"
1442                            + std::string(AsmStr) + "'");
1443        }
1444        CurVariant = 0;     // We're in the first variant now.
1445        break;
1446      case '|':
1447        ++LastEmitted;  // consume '|' character.
1448        if (CurVariant == -1)
1449          O << '|';       // this is gcc's behavior for | outside a variant
1450        else
1451          ++CurVariant;   // We're in the next variant.
1452        break;
1453      case ')':         // $) -> same as GCC's } char.
1454        ++LastEmitted;  // consume ')' character.
1455        if (CurVariant == -1)
1456          O << '}';     // this is gcc's behavior for } outside a variant
1457        else
1458          CurVariant = -1;
1459        break;
1460      }
1461      if (Done) break;
1462
1463      bool HasCurlyBraces = false;
1464      if (*LastEmitted == '{') {     // ${variable}
1465        ++LastEmitted;               // Consume '{' character.
1466        HasCurlyBraces = true;
1467      }
1468
1469      // If we have ${:foo}, then this is not a real operand reference, it is a
1470      // "magic" string reference, just like in .td files.  Arrange to call
1471      // PrintSpecial.
1472      if (HasCurlyBraces && *LastEmitted == ':') {
1473        ++LastEmitted;
1474        const char *StrStart = LastEmitted;
1475        const char *StrEnd = strchr(StrStart, '}');
1476        if (StrEnd == 0) {
1477          llvm_report_error("Unterminated ${:foo} operand in inline asm string: '"
1478                            + std::string(AsmStr) + "'");
1479        }
1480
1481        std::string Val(StrStart, StrEnd);
1482        PrintSpecial(MI, Val.c_str());
1483        LastEmitted = StrEnd+1;
1484        break;
1485      }
1486
1487      const char *IDStart = LastEmitted;
1488      char *IDEnd;
1489      errno = 0;
1490      long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
1491      if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
1492        llvm_report_error("Bad $ operand number in inline asm string: '"
1493                          + std::string(AsmStr) + "'");
1494      }
1495      LastEmitted = IDEnd;
1496
1497      char Modifier[2] = { 0, 0 };
1498
1499      if (HasCurlyBraces) {
1500        // If we have curly braces, check for a modifier character.  This
1501        // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
1502        if (*LastEmitted == ':') {
1503          ++LastEmitted;    // Consume ':' character.
1504          if (*LastEmitted == 0) {
1505            llvm_report_error("Bad ${:} expression in inline asm string: '"
1506                              + std::string(AsmStr) + "'");
1507          }
1508
1509          Modifier[0] = *LastEmitted;
1510          ++LastEmitted;    // Consume modifier character.
1511        }
1512
1513        if (*LastEmitted != '}') {
1514          llvm_report_error("Bad ${} expression in inline asm string: '"
1515                            + std::string(AsmStr) + "'");
1516        }
1517        ++LastEmitted;    // Consume '}' character.
1518      }
1519
1520      if ((unsigned)Val >= NumOperands-1) {
1521        llvm_report_error("Invalid $ operand number in inline asm string: '"
1522                          + std::string(AsmStr) + "'");
1523      }
1524
1525      // Okay, we finally have a value number.  Ask the target to print this
1526      // operand!
1527      if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
1528        unsigned OpNo = 1;
1529
1530        bool Error = false;
1531
1532        // Scan to find the machine operand number for the operand.
1533        for (; Val; --Val) {
1534          if (OpNo >= MI->getNumOperands()) break;
1535          unsigned OpFlags = MI->getOperand(OpNo).getImm();
1536          OpNo += InlineAsm::getNumOperandRegisters(OpFlags) + 1;
1537        }
1538
1539        if (OpNo >= MI->getNumOperands()) {
1540          Error = true;
1541        } else {
1542          unsigned OpFlags = MI->getOperand(OpNo).getImm();
1543          ++OpNo;  // Skip over the ID number.
1544
1545          if (Modifier[0]=='l')  // labels are target independent
1546            printBasicBlockLabel(MI->getOperand(OpNo).getMBB(),
1547                                 false, false, false);
1548          else {
1549            AsmPrinter *AP = const_cast<AsmPrinter*>(this);
1550            if ((OpFlags & 7) == 4) {
1551              Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
1552                                                Modifier[0] ? Modifier : 0);
1553            } else {
1554              Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
1555                                          Modifier[0] ? Modifier : 0);
1556            }
1557          }
1558        }
1559        if (Error) {
1560          std::string msg;
1561          raw_string_ostream Msg(msg);
1562          Msg << "Invalid operand found in inline asm: '"
1563               << AsmStr << "'\n";
1564          MI->print(Msg);
1565          llvm_report_error(Msg.str());
1566        }
1567      }
1568      break;
1569    }
1570    }
1571  }
1572  O << "\n\t" << TAI->getInlineAsmEnd() << '\n';
1573}
1574
1575/// printImplicitDef - This method prints the specified machine instruction
1576/// that is an implicit def.
1577void AsmPrinter::printImplicitDef(const MachineInstr *MI) const {
1578  if (VerboseAsm)
1579    O << '\t' << TAI->getCommentString() << " implicit-def: "
1580      << TRI->getAsmName(MI->getOperand(0).getReg()) << '\n';
1581}
1582
1583/// printLabel - This method prints a local label used by debug and
1584/// exception handling tables.
1585void AsmPrinter::printLabel(const MachineInstr *MI) const {
1586  printLabel(MI->getOperand(0).getImm());
1587}
1588
1589void AsmPrinter::printLabel(unsigned Id) const {
1590  O << TAI->getPrivateGlobalPrefix() << "label" << Id << ":\n";
1591}
1592
1593/// printDeclare - This method prints a local variable declaration used by
1594/// debug tables.
1595/// FIXME: It doesn't really print anything rather it inserts a DebugVariable
1596/// entry into dwarf table.
1597void AsmPrinter::printDeclare(const MachineInstr *MI) const {
1598  unsigned FI = MI->getOperand(0).getIndex();
1599  GlobalValue *GV = MI->getOperand(1).getGlobal();
1600  DW->RecordVariable(cast<GlobalVariable>(GV), FI, MI);
1601}
1602
1603/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
1604/// instruction, using the specified assembler variant.  Targets should
1605/// overried this to format as appropriate.
1606bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
1607                                 unsigned AsmVariant, const char *ExtraCode) {
1608  // Target doesn't support this yet!
1609  return true;
1610}
1611
1612bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
1613                                       unsigned AsmVariant,
1614                                       const char *ExtraCode) {
1615  // Target doesn't support this yet!
1616  return true;
1617}
1618
1619/// printBasicBlockLabel - This method prints the label for the specified
1620/// MachineBasicBlock
1621void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
1622                                      bool printAlign,
1623                                      bool printColon,
1624                                      bool printComment) const {
1625  if (printAlign) {
1626    unsigned Align = MBB->getAlignment();
1627    if (Align)
1628      EmitAlignment(Log2_32(Align));
1629  }
1630
1631  O << TAI->getPrivateGlobalPrefix() << "BB" << getFunctionNumber() << '_'
1632    << MBB->getNumber();
1633  if (printColon)
1634    O << ':';
1635  if (printComment && MBB->getBasicBlock())
1636    O << '\t' << TAI->getCommentString() << ' '
1637      << MBB->getBasicBlock()->getNameStr();
1638}
1639
1640/// printPICJumpTableSetLabel - This method prints a set label for the
1641/// specified MachineBasicBlock for a jumptable entry.
1642void AsmPrinter::printPICJumpTableSetLabel(unsigned uid,
1643                                           const MachineBasicBlock *MBB) const {
1644  if (!TAI->getSetDirective())
1645    return;
1646
1647  O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1648    << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
1649  printBasicBlockLabel(MBB, false, false, false);
1650  O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1651    << '_' << uid << '\n';
1652}
1653
1654void AsmPrinter::printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
1655                                           const MachineBasicBlock *MBB) const {
1656  if (!TAI->getSetDirective())
1657    return;
1658
1659  O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1660    << getFunctionNumber() << '_' << uid << '_' << uid2
1661    << "_set_" << MBB->getNumber() << ',';
1662  printBasicBlockLabel(MBB, false, false, false);
1663  O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
1664    << '_' << uid << '_' << uid2 << '\n';
1665}
1666
1667/// printDataDirective - This method prints the asm directive for the
1668/// specified type.
1669void AsmPrinter::printDataDirective(const Type *type, unsigned AddrSpace) {
1670  const TargetData *TD = TM.getTargetData();
1671  switch (type->getTypeID()) {
1672  case Type::FloatTyID: case Type::DoubleTyID:
1673  case Type::X86_FP80TyID: case Type::FP128TyID: case Type::PPC_FP128TyID:
1674    assert(0 && "Should have already output floating point constant.");
1675  default:
1676    assert(0 && "Can't handle printing this type of thing");
1677  case Type::IntegerTyID: {
1678    unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
1679    if (BitWidth <= 8)
1680      O << TAI->getData8bitsDirective(AddrSpace);
1681    else if (BitWidth <= 16)
1682      O << TAI->getData16bitsDirective(AddrSpace);
1683    else if (BitWidth <= 32)
1684      O << TAI->getData32bitsDirective(AddrSpace);
1685    else if (BitWidth <= 64) {
1686      assert(TAI->getData64bitsDirective(AddrSpace) &&
1687             "Target cannot handle 64-bit constant exprs!");
1688      O << TAI->getData64bitsDirective(AddrSpace);
1689    } else {
1690      llvm_unreachable("Target cannot handle given data directive width!");
1691    }
1692    break;
1693  }
1694  case Type::PointerTyID:
1695    if (TD->getPointerSize() == 8) {
1696      assert(TAI->getData64bitsDirective(AddrSpace) &&
1697             "Target cannot handle 64-bit pointer exprs!");
1698      O << TAI->getData64bitsDirective(AddrSpace);
1699    } else if (TD->getPointerSize() == 2) {
1700      O << TAI->getData16bitsDirective(AddrSpace);
1701    } else if (TD->getPointerSize() == 1) {
1702      O << TAI->getData8bitsDirective(AddrSpace);
1703    } else {
1704      O << TAI->getData32bitsDirective(AddrSpace);
1705    }
1706    break;
1707  }
1708}
1709
1710void AsmPrinter::printVisibility(const std::string& Name,
1711                                 unsigned Visibility) const {
1712  if (Visibility == GlobalValue::HiddenVisibility) {
1713    if (const char *Directive = TAI->getHiddenDirective())
1714      O << Directive << Name << '\n';
1715  } else if (Visibility == GlobalValue::ProtectedVisibility) {
1716    if (const char *Directive = TAI->getProtectedDirective())
1717      O << Directive << Name << '\n';
1718  }
1719}
1720
1721void AsmPrinter::printOffset(int64_t Offset) const {
1722  if (Offset > 0)
1723    O << '+' << Offset;
1724  else if (Offset < 0)
1725    O << Offset;
1726}
1727
1728GCMetadataPrinter *AsmPrinter::GetOrCreateGCPrinter(GCStrategy *S) {
1729  if (!S->usesMetadata())
1730    return 0;
1731
1732  gcp_iterator GCPI = GCMetadataPrinters.find(S);
1733  if (GCPI != GCMetadataPrinters.end())
1734    return GCPI->second;
1735
1736  const char *Name = S->getName().c_str();
1737
1738  for (GCMetadataPrinterRegistry::iterator
1739         I = GCMetadataPrinterRegistry::begin(),
1740         E = GCMetadataPrinterRegistry::end(); I != E; ++I)
1741    if (strcmp(Name, I->getName()) == 0) {
1742      GCMetadataPrinter *GMP = I->instantiate();
1743      GMP->S = S;
1744      GCMetadataPrinters.insert(std::make_pair(S, GMP));
1745      return GMP;
1746    }
1747
1748  cerr << "no GCMetadataPrinter registered for GC: " << Name << "\n";
1749  llvm_unreachable(0);
1750}
1751
1752/// EmitComments - Pretty-print comments for instructions
1753void AsmPrinter::EmitComments(const MachineInstr &MI) const
1754{
1755  if (VerboseAsm) {
1756    if (!MI.getDebugLoc().isUnknown()) {
1757      DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
1758
1759      // Print source line info
1760      O.PadToColumn(TAI->getCommentColumn(), 1);
1761      O << TAI->getCommentString() << " SrcLine ";
1762      if (DLT.CompileUnit->hasInitializer()) {
1763        Constant *Name = DLT.CompileUnit->getInitializer();
1764        if (ConstantArray *NameString = dyn_cast<ConstantArray>(Name))
1765          if (NameString->isString()) {
1766            O << NameString->getAsString() << " ";
1767          }
1768      }
1769      O << DLT.Line;
1770      if (DLT.Col != 0)
1771        O << ":" << DLT.Col;
1772    }
1773  }
1774}
1775
1776/// EmitComments - Pretty-print comments for instructions
1777void AsmPrinter::EmitComments(const MCInst &MI) const
1778{
1779  if (VerboseAsm) {
1780    if (!MI.getDebugLoc().isUnknown()) {
1781      DebugLocTuple DLT = MF->getDebugLocTuple(MI.getDebugLoc());
1782
1783      // Print source line info
1784      O.PadToColumn(TAI->getCommentColumn(), 1);
1785      O << TAI->getCommentString() << " SrcLine ";
1786      if (DLT.CompileUnit->hasInitializer()) {
1787        Constant *Name = DLT.CompileUnit->getInitializer();
1788        if (ConstantArray *NameString = dyn_cast<ConstantArray>(Name))
1789          if (NameString->isString()) {
1790            O << NameString->getAsString() << " ";
1791          }
1792      }
1793      O << DLT.Line;
1794      if (DLT.Col != 0)
1795        O << ":" << DLT.Col;
1796    }
1797  }
1798}
1799