SPU section handling is really huge mess. Replace remaining TAI calls for sections...
[oota-llvm.git] / lib / Target / CellSPU / SPUAsmPrinter.cpp
1 //===-- SPUAsmPrinter.cpp - Print machine instrs to Cell SPU assembly -------=//
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 contains a printer that converts from our internal representation
11 // of machine-dependent LLVM code to Cell SPU assembly language. This printer
12 // is the output mechanism used by `llc'.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #define DEBUG_TYPE "asmprinter"
17 #include "SPU.h"
18 #include "SPUTargetMachine.h"
19 #include "llvm/Constants.h"
20 #include "llvm/DerivedTypes.h"
21 #include "llvm/Module.h"
22 #include "llvm/Assembly/Writer.h"
23 #include "llvm/CodeGen/AsmPrinter.h"
24 #include "llvm/CodeGen/DwarfWriter.h"
25 #include "llvm/CodeGen/MachineModuleInfo.h"
26 #include "llvm/CodeGen/MachineFunctionPass.h"
27 #include "llvm/CodeGen/MachineInstr.h"
28 #include "llvm/Support/Mangler.h"
29 #include "llvm/Support/MathExtras.h"
30 #include "llvm/Support/CommandLine.h"
31 #include "llvm/Support/Debug.h"
32 #include "llvm/Support/Compiler.h"
33 #include "llvm/Support/raw_ostream.h"
34 #include "llvm/Target/TargetAsmInfo.h"
35 #include "llvm/Target/TargetRegisterInfo.h"
36 #include "llvm/Target/TargetInstrInfo.h"
37 #include "llvm/Target/TargetOptions.h"
38 #include "llvm/ADT/Statistic.h"
39 #include "llvm/ADT/StringExtras.h"
40 #include <set>
41 using namespace llvm;
42
43 namespace {
44   STATISTIC(EmittedInsts, "Number of machine instrs printed");
45
46   const std::string bss_section(".bss");
47
48   struct VISIBILITY_HIDDEN SPUAsmPrinter : public AsmPrinter {
49     std::set<std::string> FnStubs, GVStubs;
50
51     SPUAsmPrinter(raw_ostream &O, TargetMachine &TM, const TargetAsmInfo *T) :
52       AsmPrinter(O, TM, T)
53     {
54     }
55
56     virtual const char *getPassName() const {
57       return "STI CBEA SPU Assembly Printer";
58     }
59
60     SPUTargetMachine &getTM() {
61       return static_cast<SPUTargetMachine&>(TM);
62     }
63
64     /// printInstruction - This method is automatically generated by tablegen
65     /// from the instruction set description.  This method returns true if the
66     /// machine instruction was sufficiently described to print it, otherwise it
67     /// returns false.
68     bool printInstruction(const MachineInstr *MI);
69
70     void printMachineInstruction(const MachineInstr *MI);
71     void printOp(const MachineOperand &MO);
72
73     /// printRegister - Print register according to target requirements.
74     ///
75     void printRegister(const MachineOperand &MO, bool R0AsZero) {
76       unsigned RegNo = MO.getReg();
77       assert(TargetRegisterInfo::isPhysicalRegister(RegNo) &&
78              "Not physreg??");
79       O << TM.getRegisterInfo()->get(RegNo).AsmName;
80     }
81
82     void printOperand(const MachineInstr *MI, unsigned OpNo) {
83       const MachineOperand &MO = MI->getOperand(OpNo);
84       if (MO.isRegister()) {
85         assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg())&&"Not physreg??");
86         O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
87       } else if (MO.isImmediate()) {
88         O << MO.getImm();
89       } else {
90         printOp(MO);
91       }
92     }
93     
94     bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
95                          unsigned AsmVariant, const char *ExtraCode);
96     bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
97                                unsigned AsmVariant, const char *ExtraCode);
98    
99    
100     void
101     printS7ImmOperand(const MachineInstr *MI, unsigned OpNo)
102     {
103       int value = MI->getOperand(OpNo).getImm();
104       value = (value << (32 - 7)) >> (32 - 7);
105
106       assert((value >= -(1 << 8) && value <= (1 << 7) - 1)
107              && "Invalid s7 argument");
108       O << value;
109     }
110
111     void
112     printU7ImmOperand(const MachineInstr *MI, unsigned OpNo)
113     {
114       unsigned int value = MI->getOperand(OpNo).getImm();
115       assert(value < (1 << 8) && "Invalid u7 argument");
116       O << value;
117     }
118  
119     void
120     printMemRegImmS7(const MachineInstr *MI, unsigned OpNo)
121     {
122       char value = MI->getOperand(OpNo).getImm();
123       O << (int) value;
124       O << "(";
125       printOperand(MI, OpNo+1);
126       O << ")";
127     }
128
129     void
130     printS16ImmOperand(const MachineInstr *MI, unsigned OpNo)
131     {
132       O << (short) MI->getOperand(OpNo).getImm();
133     }
134
135     void
136     printU16ImmOperand(const MachineInstr *MI, unsigned OpNo)
137     {
138       O << (unsigned short)MI->getOperand(OpNo).getImm();
139     }
140
141     void
142     printU32ImmOperand(const MachineInstr *MI, unsigned OpNo)
143     {
144       O << (unsigned)MI->getOperand(OpNo).getImm();
145     }
146     
147     void
148     printMemRegReg(const MachineInstr *MI, unsigned OpNo) {
149       // When used as the base register, r0 reads constant zero rather than
150       // the value contained in the register.  For this reason, the darwin
151       // assembler requires that we print r0 as 0 (no r) when used as the base.
152       const MachineOperand &MO = MI->getOperand(OpNo);
153       O << TM.getRegisterInfo()->get(MO.getReg()).AsmName;
154       O << ", ";
155       printOperand(MI, OpNo+1);
156     }
157
158     void
159     printU18ImmOperand(const MachineInstr *MI, unsigned OpNo)
160     {
161       unsigned int value = MI->getOperand(OpNo).getImm();
162       assert(value <= (1 << 19) - 1 && "Invalid u18 argument");
163       O << value;
164     }
165
166     void
167     printS10ImmOperand(const MachineInstr *MI, unsigned OpNo)
168     {
169       short value = (short) (((int) MI->getOperand(OpNo).getImm() << 16)
170                              >> 16);
171       assert((value >= -(1 << 9) && value <= (1 << 9) - 1)
172              && "Invalid s10 argument");
173       O << value;
174     }
175
176     void
177     printU10ImmOperand(const MachineInstr *MI, unsigned OpNo)
178     {
179       short value = (short) (((int) MI->getOperand(OpNo).getImm() << 16)
180                              >> 16);
181       assert((value <= (1 << 10) - 1) && "Invalid u10 argument");
182       O << value;
183     }
184
185     void
186     printMemRegImmS10(const MachineInstr *MI, unsigned OpNo)
187     {
188       const MachineOperand &MO = MI->getOperand(OpNo);
189       assert(MO.isImmediate()
190              && "printMemRegImmS10 first operand is not immedate");
191       printS10ImmOperand(MI, OpNo);
192       O << "(";
193       printOperand(MI, OpNo+1);
194       O << ")";
195     }
196
197     void
198     printAddr256K(const MachineInstr *MI, unsigned OpNo)
199     {
200       /* Note: operand 1 is an offset or symbol name. */
201       if (MI->getOperand(OpNo).isImmediate()) {
202         printS16ImmOperand(MI, OpNo);
203       } else {
204         printOp(MI->getOperand(OpNo));
205         if (MI->getOperand(OpNo+1).isImmediate()) {
206           int displ = int(MI->getOperand(OpNo+1).getImm());
207           if (displ > 0)
208             O << "+" << displ;
209           else if (displ < 0)
210             O << displ;
211         }
212       }
213     }
214
215     void printCallOperand(const MachineInstr *MI, unsigned OpNo) {
216       printOp(MI->getOperand(OpNo));
217     }
218
219     void printPCRelativeOperand(const MachineInstr *MI, unsigned OpNo) {
220       printOp(MI->getOperand(OpNo));
221       O << "-.";
222     }
223
224     void printSymbolHi(const MachineInstr *MI, unsigned OpNo) {
225       if (MI->getOperand(OpNo).isImmediate()) {
226         printS16ImmOperand(MI, OpNo);
227       } else {
228         printOp(MI->getOperand(OpNo));
229         O << "@h";
230       }
231     }
232
233     void printSymbolLo(const MachineInstr *MI, unsigned OpNo) {
234       if (MI->getOperand(OpNo).isImmediate()) {
235         printS16ImmOperand(MI, OpNo);
236       } else {
237         printOp(MI->getOperand(OpNo));
238         O << "@l";
239       }
240     }
241
242     /// Print local store address
243     void printSymbolLSA(const MachineInstr *MI, unsigned OpNo) {
244       printOp(MI->getOperand(OpNo));
245     }
246
247     void printROTHNeg7Imm(const MachineInstr *MI, unsigned OpNo) {
248       if (MI->getOperand(OpNo).isImmediate()) {
249         int value = (int) MI->getOperand(OpNo).getImm();
250         assert((value >= 0 && value < 16)
251                && "Invalid negated immediate rotate 7-bit argument");
252         O << -value;
253       } else {
254         assert(0 &&"Invalid/non-immediate rotate amount in printRotateNeg7Imm");
255       }
256     }
257
258     void printROTNeg7Imm(const MachineInstr *MI, unsigned OpNo) {
259       if (MI->getOperand(OpNo).isImmediate()) {
260         int value = (int) MI->getOperand(OpNo).getImm();
261         assert((value >= 0 && value < 32)
262                && "Invalid negated immediate rotate 7-bit argument");
263         O << -value;
264       } else {
265         assert(0 &&"Invalid/non-immediate rotate amount in printRotateNeg7Imm");
266       }
267     }
268
269     virtual bool runOnMachineFunction(MachineFunction &F) = 0;
270     virtual bool doFinalization(Module &M) = 0;
271   };
272
273   /// LinuxAsmPrinter - SPU assembly printer, customized for Linux
274   struct VISIBILITY_HIDDEN LinuxAsmPrinter : public SPUAsmPrinter {
275   
276     DwarfWriter DW;
277     MachineModuleInfo *MMI;
278
279     LinuxAsmPrinter(raw_ostream &O, SPUTargetMachine &TM,
280                     const TargetAsmInfo *T) :
281       SPUAsmPrinter(O, TM, T),
282       DW(O, this, T),
283       MMI(0)
284     { }
285
286     virtual const char *getPassName() const {
287       return "STI CBEA SPU Assembly Printer";
288     }
289     
290     bool runOnMachineFunction(MachineFunction &F);
291     bool doInitialization(Module &M);
292     bool doFinalization(Module &M);
293     
294     void getAnalysisUsage(AnalysisUsage &AU) const {
295       AU.setPreservesAll();
296       AU.addRequired<MachineModuleInfo>();
297       SPUAsmPrinter::getAnalysisUsage(AU);
298     }
299
300     /// getSectionForFunction - Return the section that we should emit the
301     /// specified function body into.
302     virtual std::string getSectionForFunction(const Function &F) const;
303   };
304 } // end of anonymous namespace
305
306 // Include the auto-generated portion of the assembly writer
307 #include "SPUGenAsmWriter.inc"
308
309 void SPUAsmPrinter::printOp(const MachineOperand &MO) {
310   switch (MO.getType()) {
311   case MachineOperand::MO_Immediate:
312     cerr << "printOp() does not handle immediate values\n";
313     abort();
314     return;
315
316   case MachineOperand::MO_MachineBasicBlock:
317     printBasicBlockLabel(MO.getMBB());
318     return;
319   case MachineOperand::MO_JumpTableIndex:
320     O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
321       << '_' << MO.getIndex();
322     return;
323   case MachineOperand::MO_ConstantPoolIndex:
324     O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
325       << '_' << MO.getIndex();
326     return;
327   case MachineOperand::MO_ExternalSymbol:
328     // Computing the address of an external symbol, not calling it.
329     if (TM.getRelocationModel() != Reloc::Static) {
330       std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
331       GVStubs.insert(Name);
332       O << "L" << Name << "$non_lazy_ptr";
333       return;
334     }
335     O << TAI->getGlobalPrefix() << MO.getSymbolName();
336     return;
337   case MachineOperand::MO_GlobalAddress: {
338     // Computing the address of a global symbol, not calling it.
339     GlobalValue *GV = MO.getGlobal();
340     std::string Name = Mang->getValueName(GV);
341
342     // External or weakly linked global variables need non-lazily-resolved
343     // stubs
344     if (TM.getRelocationModel() != Reloc::Static) {
345       if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
346             GV->hasLinkOnceLinkage() || GV->hasCommonLinkage()))) {
347         GVStubs.insert(Name);
348         O << "L" << Name << "$non_lazy_ptr";
349         return;
350       }
351     }
352     O << Name;
353     
354     if (GV->hasExternalWeakLinkage())
355       ExtWeakSymbols.insert(GV);
356     return;
357   }
358
359   default:
360     O << "<unknown operand type: " << MO.getType() << ">";
361     return;
362   }
363 }
364
365 /// PrintAsmOperand - Print out an operand for an inline asm expression.
366 ///
367 bool SPUAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
368                                     unsigned AsmVariant, 
369                                     const char *ExtraCode) {
370   // Does this asm operand have a single letter operand modifier?
371   if (ExtraCode && ExtraCode[0]) {
372     if (ExtraCode[1] != 0) return true; // Unknown modifier.
373     
374     switch (ExtraCode[0]) {
375     default: return true;  // Unknown modifier.
376     case 'L': // Write second word of DImode reference.  
377       // Verify that this operand has two consecutive registers.
378       if (!MI->getOperand(OpNo).isRegister() ||
379           OpNo+1 == MI->getNumOperands() ||
380           !MI->getOperand(OpNo+1).isRegister())
381         return true;
382       ++OpNo;   // Return the high-part.
383       break;
384     }
385   }
386   
387   printOperand(MI, OpNo);
388   return false;
389 }
390
391 bool SPUAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
392                                           unsigned OpNo,
393                                           unsigned AsmVariant, 
394                                           const char *ExtraCode) {
395   if (ExtraCode && ExtraCode[0])
396     return true; // Unknown modifier.
397   printMemRegReg(MI, OpNo);
398   return false;
399 }
400
401 /// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax
402 /// to the current output stream.
403 ///
404 void SPUAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
405   ++EmittedInsts;
406   printInstruction(MI);
407 }
408
409
410
411 std::string LinuxAsmPrinter::getSectionForFunction(const Function &F) const {
412   switch (F.getLinkage()) {
413   default: assert(0 && "Unknown linkage type!");
414   case Function::ExternalLinkage:
415   case Function::InternalLinkage: return TAI->getTextSection();
416   case Function::WeakLinkage:
417   case Function::LinkOnceLinkage:
418     return ""; // Print nothing for the time being...
419   }
420 }
421
422 /// runOnMachineFunction - This uses the printMachineInstruction()
423 /// method to print assembly for each instruction.
424 ///
425 bool
426 LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF)
427 {
428   SetupMachineFunction(MF);
429   O << "\n\n";
430   
431   // Print out constants referenced by the function
432   EmitConstantPool(MF.getConstantPool());
433
434   // Print out labels for the function.
435   const Function *F = MF.getFunction();
436
437   SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
438   EmitAlignment(3, F);
439
440   switch (F->getLinkage()) {
441   default: assert(0 && "Unknown linkage type!");
442   case Function::InternalLinkage:  // Symbols default to internal.
443     break;
444   case Function::ExternalLinkage:
445     O << "\t.global\t" << CurrentFnName << "\n"
446       << "\t.type\t" << CurrentFnName << ", @function\n";
447     break;
448   case Function::WeakLinkage:
449   case Function::LinkOnceLinkage:
450     O << "\t.global\t" << CurrentFnName << "\n";
451     O << "\t.weak_definition\t" << CurrentFnName << "\n";
452     break;
453   }
454   O << CurrentFnName << ":\n";
455
456   // Emit pre-function debug information.
457   DW.BeginFunction(&MF);
458
459   // Print out code for the function.
460   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
461        I != E; ++I) {
462     // Print a label for the basic block.
463     if (I != MF.begin()) {
464       printBasicBlockLabel(I, true, true);
465       O << '\n';
466     }
467     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
468          II != E; ++II) {
469       // Print the assembly for the instruction.
470       printMachineInstruction(II);
471     }
472   }
473
474   O << "\t.size\t" << CurrentFnName << ",.-" << CurrentFnName << "\n";
475
476   // Print out jump tables referenced by the function.
477   EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
478   
479   // Emit post-function debug information.
480   DW.EndFunction();
481   
482   // We didn't modify anything.
483   return false;
484 }
485
486
487 bool LinuxAsmPrinter::doInitialization(Module &M) {
488   bool Result = AsmPrinter::doInitialization(M);
489   SwitchToTextSection("\t.text");
490   // Emit initial debug information.
491   DW.BeginModule(&M);
492   MMI = getAnalysisToUpdate<MachineModuleInfo>();
493   DW.SetModuleInfo(MMI);
494   return Result;
495 }
496
497 bool LinuxAsmPrinter::doFinalization(Module &M) {
498   const TargetData *TD = TM.getTargetData();
499
500   // Print out module-level global variables here.
501   for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
502        I != E; ++I) {
503     if (!I->hasInitializer()) continue;   // External global require no code
504     
505     // Check to see if this is a special global used by LLVM, if so, emit it.
506     if (EmitSpecialLLVMGlobal(I))
507       continue;
508     
509     std::string name = Mang->getValueName(I);
510     Constant *C = I->getInitializer();
511     unsigned Size = TD->getTypeStoreSize(C->getType());
512     unsigned Align = TD->getPreferredAlignmentLog(I);
513
514     if (C->isNullValue() && /* FIXME: Verify correct */
515         (I->hasInternalLinkage() || I->hasWeakLinkage() ||
516          I->hasLinkOnceLinkage() || I->hasCommonLinkage() ||
517          (I->hasExternalLinkage() && !I->hasSection()))) {
518       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
519       if (I->hasExternalLinkage()) {
520         // External linkage globals -> .bss section
521         // FIXME: Want to set the global variable's section so that
522         // SwitchToDataSection emits the ".section" directive
523         SwitchToDataSection("\t.section\t.bss", I);
524         O << "\t.global\t" << name << '\n';
525         O << "\t.align\t" << Align << '\n';
526         O << "\t.type\t" << name << ", @object\n";
527         O << "\t.size\t" << name << ", " << Size << '\n';
528         O << name << ":\n";
529         O << "\t.zero\t" << Size;
530       } else if (I->hasInternalLinkage()) {
531         SwitchToDataSection("\t.data", I);
532         O << ".local " << name << "\n";
533         O << TAI->getCOMMDirective() << name << "," << Size << "," << Align << "\n";
534       } else {
535         SwitchToDataSection("\t.data", I);
536         O << ".comm " << name << "," << Size;
537       }
538       O << "\t\t# '" << I->getName() << "'\n";
539     } else {
540       switch (I->getLinkage()) {
541       case GlobalValue::LinkOnceLinkage:
542       case GlobalValue::WeakLinkage:
543       case GlobalValue::CommonLinkage:
544         O << "\t.global " << name << '\n'
545           << "\t.weak_definition " << name << '\n';
546         SwitchToDataSection(".section __DATA,__datacoal_nt,coalesced", I);
547         break;
548       case GlobalValue::AppendingLinkage:
549         // FIXME: appending linkage variables should go into a section of
550         // their name or something.  For now, just emit them as external.
551       case GlobalValue::ExternalLinkage:
552         // If external or appending, declare as a global symbol
553         O << "\t.global " << name << "\n";
554         // FALL THROUGH
555       case GlobalValue::InternalLinkage:
556         if (I->isConstant()) {
557           const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
558           if (TAI->getCStringSection() && CVA && CVA->isCString()) {
559             SwitchToDataSection("\t.cstring", I);
560             break;
561           }
562         }
563
564         SwitchToDataSection("\t.data", I);
565         break;
566       default:
567         cerr << "Unknown linkage type!";
568         abort();
569       }
570
571       EmitAlignment(Align, I);
572       O << name << ":\t\t\t\t# '" << I->getName() << "'\n";
573
574       // If the initializer is a extern weak symbol, remember to emit the weak
575       // reference!
576       if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
577         if (GV->hasExternalWeakLinkage())
578           ExtWeakSymbols.insert(GV);
579
580       EmitGlobalConstant(C);
581       O << '\n';
582     }
583   }
584
585   // Output stubs for dynamically-linked functions
586   if (TM.getRelocationModel() == Reloc::PIC_) {
587     for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
588          i != e; ++i) {
589       SwitchToTextSection(".section __TEXT,__picsymbolstub1,symbol_stubs,"
590                           "pure_instructions,32");
591       EmitAlignment(4);
592       O << "L" << *i << "$stub:\n";
593       O << "\t.indirect_symbol " << *i << "\n";
594       O << "\tmflr r0\n";
595       O << "\tbcl 20,31,L0$" << *i << "\n";
596       O << "L0$" << *i << ":\n";
597       O << "\tmflr r11\n";
598       O << "\taddis r11,r11,ha16(L" << *i << "$lazy_ptr-L0$" << *i << ")\n";
599       O << "\tmtlr r0\n";
600       O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n";
601       O << "\tmtctr r12\n";
602       O << "\tbctr\n";
603       SwitchToDataSection(".lazy_symbol_pointer");
604       O << "L" << *i << "$lazy_ptr:\n";
605       O << "\t.indirect_symbol " << *i << "\n";
606       O << "\t.long dyld_stub_binding_helper\n";
607     }
608   } else {
609     for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
610          i != e; ++i) {
611       SwitchToTextSection(".section __TEXT,__symbol_stub1,symbol_stubs,"
612                           "pure_instructions,16");
613       EmitAlignment(4);
614       O << "L" << *i << "$stub:\n";
615       O << "\t.indirect_symbol " << *i << "\n";
616       O << "\tlis r11,ha16(L" << *i << "$lazy_ptr)\n";
617       O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr)(r11)\n";
618       O << "\tmtctr r12\n";
619       O << "\tbctr\n";
620       SwitchToDataSection(".lazy_symbol_pointer");
621       O << "L" << *i << "$lazy_ptr:\n";
622       O << "\t.indirect_symbol " << *i << "\n";
623       O << "\t.long dyld_stub_binding_helper\n";
624     }
625   }
626
627   O << "\n";
628
629   // Output stubs for external and common global variables.
630   if (GVStubs.begin() != GVStubs.end()) {
631     SwitchToDataSection(".non_lazy_symbol_pointer");
632     for (std::set<std::string>::iterator I = GVStubs.begin(),
633          E = GVStubs.end(); I != E; ++I) {
634       O << "L" << *I << "$non_lazy_ptr:\n";
635       O << "\t.indirect_symbol " << *I << "\n";
636       O << "\t.long\t0\n";
637     }
638   }
639
640   // Emit initial debug information.
641   DW.EndModule();
642
643   // Emit ident information
644   O << "\t.ident\t\"(llvm 2.2+) STI CBEA Cell SPU backend\"\n";
645
646   return AsmPrinter::doFinalization(M);
647 }
648
649
650
651 /// createSPUCodePrinterPass - Returns a pass that prints the Cell SPU
652 /// assembly code for a MachineFunction to the given output stream, in a format
653 /// that the Linux SPU assembler can deal with.
654 ///
655 FunctionPass *llvm::createSPUAsmPrinterPass(raw_ostream &o,
656                                             SPUTargetMachine &tm) {
657   return new LinuxAsmPrinter(o, tm, tm.getTargetAsmInfo());
658 }
659