just finish MCizing FnStubInfo which cleans it up and simplifies it.
[oota-llvm.git] / lib / Target / PowerPC / AsmPrinter / PPCAsmPrinter.cpp
1 //===-- PPCAsmPrinter.cpp - Print machine instrs to PowerPC 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 PowerPC assembly language. This printer is
12 // the output mechanism used by `llc'.
13 //
14 // Documentation at http://developer.apple.com/documentation/DeveloperTools/
15 // Reference/Assembler/ASMIntroduction/chapter_1_section_1.html
16 //
17 //===----------------------------------------------------------------------===//
18
19 #define DEBUG_TYPE "asmprinter"
20 #include "PPC.h"
21 #include "PPCPredicates.h"
22 #include "PPCTargetMachine.h"
23 #include "PPCSubtarget.h"
24 #include "llvm/Constants.h"
25 #include "llvm/DerivedTypes.h"
26 #include "llvm/Module.h"
27 #include "llvm/Assembly/Writer.h"
28 #include "llvm/CodeGen/AsmPrinter.h"
29 #include "llvm/CodeGen/DwarfWriter.h"
30 #include "llvm/CodeGen/MachineModuleInfo.h"
31 #include "llvm/CodeGen/MachineFunctionPass.h"
32 #include "llvm/CodeGen/MachineInstr.h"
33 #include "llvm/CodeGen/MachineInstrBuilder.h"
34 #include "llvm/MC/MCAsmInfo.h"
35 #include "llvm/MC/MCContext.h"
36 #include "llvm/MC/MCSectionMachO.h"
37 #include "llvm/MC/MCStreamer.h"
38 #include "llvm/MC/MCSymbol.h"
39 #include "llvm/Target/TargetLoweringObjectFile.h"
40 #include "llvm/Target/TargetRegisterInfo.h"
41 #include "llvm/Target/TargetInstrInfo.h"
42 #include "llvm/Target/TargetOptions.h"
43 #include "llvm/Target/TargetRegistry.h"
44 #include "llvm/Support/Mangler.h"
45 #include "llvm/Support/MathExtras.h"
46 #include "llvm/Support/CommandLine.h"
47 #include "llvm/Support/Debug.h"
48 #include "llvm/Support/ErrorHandling.h"
49 #include "llvm/Support/FormattedStream.h"
50 #include "llvm/ADT/Statistic.h"
51 #include "llvm/ADT/StringExtras.h"
52 #include "llvm/ADT/StringSet.h"
53 #include "llvm/ADT/SmallString.h"
54 using namespace llvm;
55
56 STATISTIC(EmittedInsts, "Number of machine instrs printed");
57
58 namespace {
59   class PPCAsmPrinter : public AsmPrinter {
60   protected:
61     struct FnStubInfo {
62       MCSymbol *Stub, *LazyPtr, *AnonSymbol;
63       
64       FnStubInfo() {
65         Stub = LazyPtr = AnonSymbol = 0;
66       }
67       
68       void Init(const GlobalValue *GV, Mangler *Mang, MCContext &Ctx) {
69         // Already initialized.
70         if (Stub != 0) return;
71
72         // Get the names.
73         SmallString<128> TmpStr;
74         Mang->getNameWithPrefix(TmpStr, GV, true);
75         MakeSymbols(TmpStr, Ctx);
76       }
77
78       void Init(StringRef GVName, Mangler *Mang, MCContext &Ctx) {
79         assert(!GVName.empty() && "external symbol name shouldn't be empty");
80         if (Stub != 0) return; // Already initialized.
81         // Get the names for the external symbol name.
82         SmallString<128> TmpStr;
83         Mang->getNameWithPrefix(TmpStr, GVName, Mangler::Private);
84         MakeSymbols(TmpStr, Ctx);
85       }
86       
87       void MakeSymbols(SmallString<128> &TmpStr, MCContext &Ctx) {
88         TmpStr += "$stub";
89         Stub = Ctx.GetOrCreateSymbol(TmpStr.str());
90         TmpStr.erase(TmpStr.end()-5, TmpStr.end()); // Remove $stub
91
92         TmpStr += "$lazy_ptr";
93         LazyPtr = Ctx.GetOrCreateSymbol(TmpStr.str());
94         TmpStr.erase(TmpStr.end()-9, TmpStr.end()); // Remove $lazy_ptr
95         
96         TmpStr += "$stub$tmp";
97         AnonSymbol = Ctx.GetOrCreateSymbol(TmpStr.str());
98       }
99     };
100     
101     StringMap<FnStubInfo> FnStubs;
102     StringMap<std::string> GVStubs, HiddenGVStubs, TOC;
103     const PPCSubtarget &Subtarget;
104     uint64_t LabelID;
105   public:
106     explicit PPCAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
107                            const MCAsmInfo *T, bool V)
108       : AsmPrinter(O, TM, T, V),
109         Subtarget(TM.getSubtarget<PPCSubtarget>()), LabelID(0) {}
110
111     virtual const char *getPassName() const {
112       return "PowerPC Assembly Printer";
113     }
114
115     PPCTargetMachine &getTM() {
116       return static_cast<PPCTargetMachine&>(TM);
117     }
118
119     unsigned enumRegToMachineReg(unsigned enumReg) {
120       switch (enumReg) {
121       default: llvm_unreachable("Unhandled register!");
122       case PPC::CR0:  return  0;
123       case PPC::CR1:  return  1;
124       case PPC::CR2:  return  2;
125       case PPC::CR3:  return  3;
126       case PPC::CR4:  return  4;
127       case PPC::CR5:  return  5;
128       case PPC::CR6:  return  6;
129       case PPC::CR7:  return  7;
130       }
131       llvm_unreachable(0);
132     }
133
134     /// printInstruction - This method is automatically generated by tablegen
135     /// from the instruction set description.  This method returns true if the
136     /// machine instruction was sufficiently described to print it, otherwise it
137     /// returns false.
138     void printInstruction(const MachineInstr *MI);
139     static const char *getRegisterName(unsigned RegNo);
140
141
142     void printMachineInstruction(const MachineInstr *MI);
143     void printOp(const MachineOperand &MO);
144
145     /// stripRegisterPrefix - This method strips the character prefix from a
146     /// register name so that only the number is left.  Used by for linux asm.
147     const char *stripRegisterPrefix(const char *RegName) {
148       switch (RegName[0]) {
149       case 'r':
150       case 'f':
151       case 'v': return RegName + 1;
152       case 'c': if (RegName[1] == 'r') return RegName + 2;
153       }
154
155       return RegName;
156     }
157
158     /// printRegister - Print register according to target requirements.
159     ///
160     void printRegister(const MachineOperand &MO, bool R0AsZero) {
161       unsigned RegNo = MO.getReg();
162       assert(TargetRegisterInfo::isPhysicalRegister(RegNo) && "Not physreg??");
163
164       // If we should use 0 for R0.
165       if (R0AsZero && RegNo == PPC::R0) {
166         O << "0";
167         return;
168       }
169
170       const char *RegName = getRegisterName(RegNo);
171       // Linux assembler (Others?) does not take register mnemonics.
172       // FIXME - What about special registers used in mfspr/mtspr?
173       if (!Subtarget.isDarwin()) RegName = stripRegisterPrefix(RegName);
174       O << RegName;
175     }
176
177     void printOperand(const MachineInstr *MI, unsigned OpNo) {
178       const MachineOperand &MO = MI->getOperand(OpNo);
179       if (MO.isReg()) {
180         printRegister(MO, false);
181       } else if (MO.isImm()) {
182         O << MO.getImm();
183       } else {
184         printOp(MO);
185       }
186     }
187
188     bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
189                          unsigned AsmVariant, const char *ExtraCode);
190     bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
191                                unsigned AsmVariant, const char *ExtraCode);
192
193
194     void printS5ImmOperand(const MachineInstr *MI, unsigned OpNo) {
195       char value = MI->getOperand(OpNo).getImm();
196       value = (value << (32-5)) >> (32-5);
197       O << (int)value;
198     }
199     void printU5ImmOperand(const MachineInstr *MI, unsigned OpNo) {
200       unsigned char value = MI->getOperand(OpNo).getImm();
201       assert(value <= 31 && "Invalid u5imm argument!");
202       O << (unsigned int)value;
203     }
204     void printU6ImmOperand(const MachineInstr *MI, unsigned OpNo) {
205       unsigned char value = MI->getOperand(OpNo).getImm();
206       assert(value <= 63 && "Invalid u6imm argument!");
207       O << (unsigned int)value;
208     }
209     void printS16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
210       O << (short)MI->getOperand(OpNo).getImm();
211     }
212     void printU16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
213       O << (unsigned short)MI->getOperand(OpNo).getImm();
214     }
215     void printS16X4ImmOperand(const MachineInstr *MI, unsigned OpNo) {
216       if (MI->getOperand(OpNo).isImm()) {
217         O << (short)(MI->getOperand(OpNo).getImm()*4);
218       } else {
219         O << "lo16(";
220         printOp(MI->getOperand(OpNo));
221         if (TM.getRelocationModel() == Reloc::PIC_)
222           O << "-\"L" << getFunctionNumber() << "$pb\")";
223         else
224           O << ')';
225       }
226     }
227     void printBranchOperand(const MachineInstr *MI, unsigned OpNo) {
228       // Branches can take an immediate operand.  This is used by the branch
229       // selection pass to print $+8, an eight byte displacement from the PC.
230       if (MI->getOperand(OpNo).isImm()) {
231         O << "$+" << MI->getOperand(OpNo).getImm()*4;
232       } else {
233         printOp(MI->getOperand(OpNo));
234       }
235     }
236     void printCallOperand(const MachineInstr *MI, unsigned OpNo) {
237       const MachineOperand &MO = MI->getOperand(OpNo);
238       if (TM.getRelocationModel() != Reloc::Static) {
239         if (MO.getType() == MachineOperand::MO_GlobalAddress) {
240           GlobalValue *GV = MO.getGlobal();
241           if (GV->isDeclaration() || GV->isWeakForLinker()) {
242             // Dynamically-resolved functions need a stub for the function.
243             FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
244             FnInfo.Init(GV, Mang, OutContext);
245             FnInfo.Stub->print(O, MAI);
246             return;
247           }
248         }
249         if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
250           SmallString<128> MangledName;
251           Mang->getNameWithPrefix(MangledName, MO.getSymbolName());
252           FnStubInfo &FnInfo = FnStubs[MangledName.str()];
253           FnInfo.Init(MO.getSymbolName(), Mang, OutContext);
254           FnInfo.Stub->print(O, MAI);
255           return;
256         }
257       }
258
259       printOp(MI->getOperand(OpNo));
260     }
261     void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo) {
262      O << (int)MI->getOperand(OpNo).getImm()*4;
263     }
264     void printPICLabel(const MachineInstr *MI, unsigned OpNo) {
265       O << "\"L" << getFunctionNumber() << "$pb\"\n";
266       O << "\"L" << getFunctionNumber() << "$pb\":";
267     }
268     void printSymbolHi(const MachineInstr *MI, unsigned OpNo) {
269       if (MI->getOperand(OpNo).isImm()) {
270         printS16ImmOperand(MI, OpNo);
271       } else {
272         if (Subtarget.isDarwin()) O << "ha16(";
273         printOp(MI->getOperand(OpNo));
274         if (TM.getRelocationModel() == Reloc::PIC_)
275           O << "-\"L" << getFunctionNumber() << "$pb\"";
276         if (Subtarget.isDarwin())
277           O << ')';
278         else
279           O << "@ha";
280       }
281     }
282     void printSymbolLo(const MachineInstr *MI, unsigned OpNo) {
283       if (MI->getOperand(OpNo).isImm()) {
284         printS16ImmOperand(MI, OpNo);
285       } else {
286         if (Subtarget.isDarwin()) O << "lo16(";
287         printOp(MI->getOperand(OpNo));
288         if (TM.getRelocationModel() == Reloc::PIC_)
289           O << "-\"L" << getFunctionNumber() << "$pb\"";
290         if (Subtarget.isDarwin())
291           O << ')';
292         else
293           O << "@l";
294       }
295     }
296     void printcrbitm(const MachineInstr *MI, unsigned OpNo) {
297       unsigned CCReg = MI->getOperand(OpNo).getReg();
298       unsigned RegNo = enumRegToMachineReg(CCReg);
299       O << (0x80 >> RegNo);
300     }
301     // The new addressing mode printers.
302     void printMemRegImm(const MachineInstr *MI, unsigned OpNo) {
303       printSymbolLo(MI, OpNo);
304       O << '(';
305       if (MI->getOperand(OpNo+1).isReg() &&
306           MI->getOperand(OpNo+1).getReg() == PPC::R0)
307         O << "0";
308       else
309         printOperand(MI, OpNo+1);
310       O << ')';
311     }
312     void printMemRegImmShifted(const MachineInstr *MI, unsigned OpNo) {
313       if (MI->getOperand(OpNo).isImm())
314         printS16X4ImmOperand(MI, OpNo);
315       else
316         printSymbolLo(MI, OpNo);
317       O << '(';
318       if (MI->getOperand(OpNo+1).isReg() &&
319           MI->getOperand(OpNo+1).getReg() == PPC::R0)
320         O << "0";
321       else
322         printOperand(MI, OpNo+1);
323       O << ')';
324     }
325
326     void printMemRegReg(const MachineInstr *MI, unsigned OpNo) {
327       // When used as the base register, r0 reads constant zero rather than
328       // the value contained in the register.  For this reason, the darwin
329       // assembler requires that we print r0 as 0 (no r) when used as the base.
330       const MachineOperand &MO = MI->getOperand(OpNo);
331       printRegister(MO, true);
332       O << ", ";
333       printOperand(MI, OpNo+1);
334     }
335
336     void printTOCEntryLabel(const MachineInstr *MI, unsigned OpNo) {
337       const MachineOperand &MO = MI->getOperand(OpNo);
338
339       assert(MO.getType() == MachineOperand::MO_GlobalAddress);
340
341       GlobalValue *GV = MO.getGlobal();
342
343       std::string Name = Mang->getMangledName(GV);
344
345       // Map symbol -> label of TOC entry.
346       if (TOC.count(Name) == 0) {
347         std::string Label;
348         Label += MAI->getPrivateGlobalPrefix();
349         Label += "C";
350         Label += utostr(LabelID++);
351
352         TOC[Name] = Label;
353       }
354
355       O << TOC[Name] << "@toc";
356     }
357
358     void printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
359                                const char *Modifier);
360
361     virtual bool runOnMachineFunction(MachineFunction &F) = 0;
362   };
363
364   /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
365   class PPCLinuxAsmPrinter : public PPCAsmPrinter {
366   public:
367     explicit PPCLinuxAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
368                                 const MCAsmInfo *T, bool V)
369       : PPCAsmPrinter(O, TM, T, V){}
370
371     virtual const char *getPassName() const {
372       return "Linux PPC Assembly Printer";
373     }
374
375     bool runOnMachineFunction(MachineFunction &F);
376     bool doFinalization(Module &M);
377
378     void getAnalysisUsage(AnalysisUsage &AU) const {
379       AU.setPreservesAll();
380       AU.addRequired<MachineModuleInfo>();
381       AU.addRequired<DwarfWriter>();
382       PPCAsmPrinter::getAnalysisUsage(AU);
383     }
384
385     void PrintGlobalVariable(const GlobalVariable *GVar);
386   };
387
388   /// PPCDarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac
389   /// OS X
390   class PPCDarwinAsmPrinter : public PPCAsmPrinter {
391     formatted_raw_ostream &OS;
392   public:
393     explicit PPCDarwinAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
394                                  const MCAsmInfo *T, bool V)
395       : PPCAsmPrinter(O, TM, T, V), OS(O) {}
396
397     virtual const char *getPassName() const {
398       return "Darwin PPC Assembly Printer";
399     }
400
401     bool runOnMachineFunction(MachineFunction &F);
402     bool doFinalization(Module &M);
403     void EmitStartOfAsmFile(Module &M);
404
405     void getAnalysisUsage(AnalysisUsage &AU) const {
406       AU.setPreservesAll();
407       AU.addRequired<MachineModuleInfo>();
408       AU.addRequired<DwarfWriter>();
409       PPCAsmPrinter::getAnalysisUsage(AU);
410     }
411
412     void PrintGlobalVariable(const GlobalVariable *GVar);
413   };
414 } // end of anonymous namespace
415
416 // Include the auto-generated portion of the assembly writer
417 #include "PPCGenAsmWriter.inc"
418
419 void PPCAsmPrinter::printOp(const MachineOperand &MO) {
420   switch (MO.getType()) {
421   case MachineOperand::MO_Immediate:
422     llvm_unreachable("printOp() does not handle immediate values");
423
424   case MachineOperand::MO_MachineBasicBlock:
425     GetMBBSymbol(MO.getMBB()->getNumber())->print(O, MAI);
426     return;
427   case MachineOperand::MO_JumpTableIndex:
428     O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
429       << '_' << MO.getIndex();
430     // FIXME: PIC relocation model
431     return;
432   case MachineOperand::MO_ConstantPoolIndex:
433     O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
434       << '_' << MO.getIndex();
435     return;
436   case MachineOperand::MO_BlockAddress:
437     GetBlockAddressSymbol(MO.getBlockAddress())->print(O, MAI);
438     return;
439   case MachineOperand::MO_ExternalSymbol: {
440     // Computing the address of an external symbol, not calling it.
441     std::string Name(MAI->getGlobalPrefix());
442     Name += MO.getSymbolName();
443     
444     if (TM.getRelocationModel() != Reloc::Static) {
445       GVStubs[Name] = Name+"$non_lazy_ptr";
446       Name += "$non_lazy_ptr";
447     }
448     O << Name;
449     return;
450   }
451   case MachineOperand::MO_GlobalAddress: {
452     // Computing the address of a global symbol, not calling it.
453     GlobalValue *GV = MO.getGlobal();
454     std::string Name;
455
456     // External or weakly linked global variables need non-lazily-resolved stubs
457     if (TM.getRelocationModel() != Reloc::Static &&
458         (GV->isDeclaration() || GV->isWeakForLinker())) {
459       if (!GV->hasHiddenVisibility()) {
460         Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
461         GVStubs[Mang->getMangledName(GV)] = Name;
462       } else if (GV->isDeclaration() || GV->hasCommonLinkage() ||
463                  GV->hasAvailableExternallyLinkage()) {
464         Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
465         HiddenGVStubs[Mang->getMangledName(GV)] = Name;
466       } else {
467         Name = Mang->getMangledName(GV);
468       }
469     } else {
470       Name = Mang->getMangledName(GV);
471     }
472     O << Name;
473
474     printOffset(MO.getOffset());
475     return;
476   }
477
478   default:
479     O << "<unknown operand type: " << MO.getType() << ">";
480     return;
481   }
482 }
483
484 /// PrintAsmOperand - Print out an operand for an inline asm expression.
485 ///
486 bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
487                                     unsigned AsmVariant,
488                                     const char *ExtraCode) {
489   // Does this asm operand have a single letter operand modifier?
490   if (ExtraCode && ExtraCode[0]) {
491     if (ExtraCode[1] != 0) return true; // Unknown modifier.
492
493     switch (ExtraCode[0]) {
494     default: return true;  // Unknown modifier.
495     case 'c': // Don't print "$" before a global var name or constant.
496       // PPC never has a prefix.
497       printOperand(MI, OpNo);
498       return false;
499     case 'L': // Write second word of DImode reference.
500       // Verify that this operand has two consecutive registers.
501       if (!MI->getOperand(OpNo).isReg() ||
502           OpNo+1 == MI->getNumOperands() ||
503           !MI->getOperand(OpNo+1).isReg())
504         return true;
505       ++OpNo;   // Return the high-part.
506       break;
507     case 'I':
508       // Write 'i' if an integer constant, otherwise nothing.  Used to print
509       // addi vs add, etc.
510       if (MI->getOperand(OpNo).isImm())
511         O << "i";
512       return false;
513     }
514   }
515
516   printOperand(MI, OpNo);
517   return false;
518 }
519
520 // At the moment, all inline asm memory operands are a single register.
521 // In any case, the output of this routine should always be just one
522 // assembler operand.
523
524 bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
525                                           unsigned AsmVariant,
526                                           const char *ExtraCode) {
527   if (ExtraCode && ExtraCode[0])
528     return true; // Unknown modifier.
529   assert (MI->getOperand(OpNo).isReg());
530   O << "0(";
531   printOperand(MI, OpNo);
532   O << ")";
533   return false;
534 }
535
536 void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
537                                           const char *Modifier) {
538   assert(Modifier && "Must specify 'cc' or 'reg' as predicate op modifier!");
539   unsigned Code = MI->getOperand(OpNo).getImm();
540   if (!strcmp(Modifier, "cc")) {
541     switch ((PPC::Predicate)Code) {
542     case PPC::PRED_ALWAYS: return; // Don't print anything for always.
543     case PPC::PRED_LT: O << "lt"; return;
544     case PPC::PRED_LE: O << "le"; return;
545     case PPC::PRED_EQ: O << "eq"; return;
546     case PPC::PRED_GE: O << "ge"; return;
547     case PPC::PRED_GT: O << "gt"; return;
548     case PPC::PRED_NE: O << "ne"; return;
549     case PPC::PRED_UN: O << "un"; return;
550     case PPC::PRED_NU: O << "nu"; return;
551     }
552
553   } else {
554     assert(!strcmp(Modifier, "reg") &&
555            "Need to specify 'cc' or 'reg' as predicate op modifier!");
556     // Don't print the register for 'always'.
557     if (Code == PPC::PRED_ALWAYS) return;
558     printOperand(MI, OpNo+1);
559   }
560 }
561
562
563 /// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to
564 /// the current output stream.
565 ///
566 void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
567   ++EmittedInsts;
568   
569   processDebugLoc(MI, true);
570
571   // Check for slwi/srwi mnemonics.
572   bool useSubstituteMnemonic = false;
573   if (MI->getOpcode() == PPC::RLWINM) {
574     unsigned char SH = MI->getOperand(2).getImm();
575     unsigned char MB = MI->getOperand(3).getImm();
576     unsigned char ME = MI->getOperand(4).getImm();
577     if (SH <= 31 && MB == 0 && ME == (31-SH)) {
578       O << "\tslwi "; useSubstituteMnemonic = true;
579     }
580     if (SH <= 31 && MB == (32-SH) && ME == 31) {
581       O << "\tsrwi "; useSubstituteMnemonic = true;
582       SH = 32-SH;
583     }
584     if (useSubstituteMnemonic) {
585       printOperand(MI, 0);
586       O << ", ";
587       printOperand(MI, 1);
588       O << ", " << (unsigned int)SH;
589     }
590   } else if (MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) {
591     if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
592       useSubstituteMnemonic = true;
593       O << "\tmr ";
594       printOperand(MI, 0);
595       O << ", ";
596       printOperand(MI, 1);
597     }
598   } else if (MI->getOpcode() == PPC::RLDICR) {
599     unsigned char SH = MI->getOperand(2).getImm();
600     unsigned char ME = MI->getOperand(3).getImm();
601     // rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH
602     if (63-SH == ME) {
603       useSubstituteMnemonic = true;
604       O << "\tsldi ";
605       printOperand(MI, 0);
606       O << ", ";
607       printOperand(MI, 1);
608       O << ", " << (unsigned int)SH;
609     }
610   }
611
612   if (!useSubstituteMnemonic)
613     printInstruction(MI);
614
615   if (VerboseAsm)
616     EmitComments(*MI);
617   O << '\n';
618
619   processDebugLoc(MI, false);
620 }
621
622 /// runOnMachineFunction - This uses the printMachineInstruction()
623 /// method to print assembly for each instruction.
624 ///
625 bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
626   this->MF = &MF;
627
628   SetupMachineFunction(MF);
629   O << "\n\n";
630
631   // Print out constants referenced by the function
632   EmitConstantPool(MF.getConstantPool());
633
634   // Print out labels for the function.
635   const Function *F = MF.getFunction();
636   OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
637
638   switch (F->getLinkage()) {
639   default: llvm_unreachable("Unknown linkage type!");
640   case Function::PrivateLinkage:
641   case Function::InternalLinkage:  // Symbols default to internal.
642     break;
643   case Function::ExternalLinkage:
644     O << "\t.global\t" << CurrentFnName << '\n'
645       << "\t.type\t" << CurrentFnName << ", @function\n";
646     break;
647   case Function::LinkerPrivateLinkage:
648   case Function::WeakAnyLinkage:
649   case Function::WeakODRLinkage:
650   case Function::LinkOnceAnyLinkage:
651   case Function::LinkOnceODRLinkage:
652     O << "\t.global\t" << CurrentFnName << '\n';
653     O << "\t.weak\t" << CurrentFnName << '\n';
654     break;
655   }
656
657   printVisibility(CurrentFnName, F->getVisibility());
658
659   EmitAlignment(MF.getAlignment(), F);
660
661   if (Subtarget.isPPC64()) {
662     // Emit an official procedure descriptor.
663     // FIXME 64-bit SVR4: Use MCSection here?
664     O << "\t.section\t\".opd\",\"aw\"\n";
665     O << "\t.align 3\n";
666     O << CurrentFnName << ":\n";
667     O << "\t.quad .L." << CurrentFnName << ",.TOC.@tocbase\n";
668     O << "\t.previous\n";
669     O << ".L." << CurrentFnName << ":\n";
670   } else {
671     O << CurrentFnName << ":\n";
672   }
673
674   // Emit pre-function debug information.
675   DW->BeginFunction(&MF);
676
677   // Print out code for the function.
678   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
679        I != E; ++I) {
680     // Print a label for the basic block.
681     if (I != MF.begin()) {
682       EmitBasicBlockStart(I);
683     }
684     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
685          II != E; ++II) {
686       // Print the assembly for the instruction.
687       printMachineInstruction(II);
688     }
689   }
690
691   O << "\t.size\t" << CurrentFnName << ",.-" << CurrentFnName << '\n';
692
693   OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
694
695   // Emit post-function debug information.
696   DW->EndFunction(&MF);
697
698   // Print out jump tables referenced by the function.
699   EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
700
701   // We didn't modify anything.
702   return false;
703 }
704
705 void PPCLinuxAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
706   const TargetData *TD = TM.getTargetData();
707
708   if (!GVar->hasInitializer())
709     return;   // External global require no code
710
711   // Check to see if this is a special global used by LLVM, if so, emit it.
712   if (EmitSpecialLLVMGlobal(GVar))
713     return;
714
715   std::string name = Mang->getMangledName(GVar);
716
717   printVisibility(name, GVar->getVisibility());
718
719   Constant *C = GVar->getInitializer();
720   const Type *Type = C->getType();
721   unsigned Size = TD->getTypeAllocSize(Type);
722   unsigned Align = TD->getPreferredAlignmentLog(GVar);
723
724   OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(GVar, Mang,
725                                                                   TM));
726
727   if (C->isNullValue() && /* FIXME: Verify correct */
728       !GVar->hasSection() &&
729       (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
730        GVar->isWeakForLinker())) {
731       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
732
733       if (GVar->hasExternalLinkage()) {
734         O << "\t.global " << name << '\n';
735         O << "\t.type " << name << ", @object\n";
736         O << name << ":\n";
737         O << "\t.zero " << Size << '\n';
738       } else if (GVar->hasLocalLinkage()) {
739         O << MAI->getLCOMMDirective() << name << ',' << Size;
740       } else {
741         O << ".comm " << name << ',' << Size;
742       }
743       if (VerboseAsm) {
744         O << "\t\t" << MAI->getCommentString() << " '";
745         WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
746         O << "'";
747       }
748       O << '\n';
749       return;
750   }
751
752   switch (GVar->getLinkage()) {
753    case GlobalValue::LinkOnceAnyLinkage:
754    case GlobalValue::LinkOnceODRLinkage:
755    case GlobalValue::WeakAnyLinkage:
756    case GlobalValue::WeakODRLinkage:
757    case GlobalValue::CommonLinkage:
758    case GlobalValue::LinkerPrivateLinkage:
759     O << "\t.global " << name << '\n'
760       << "\t.type " << name << ", @object\n"
761       << "\t.weak " << name << '\n';
762     break;
763    case GlobalValue::AppendingLinkage:
764     // FIXME: appending linkage variables should go into a section of
765     // their name or something.  For now, just emit them as external.
766    case GlobalValue::ExternalLinkage:
767     // If external or appending, declare as a global symbol
768     O << "\t.global " << name << '\n'
769       << "\t.type " << name << ", @object\n";
770     // FALL THROUGH
771    case GlobalValue::InternalLinkage:
772    case GlobalValue::PrivateLinkage:
773     break;
774    default:
775     llvm_unreachable("Unknown linkage type!");
776   }
777
778   EmitAlignment(Align, GVar);
779   O << name << ":";
780   if (VerboseAsm) {
781     O << "\t\t\t\t" << MAI->getCommentString() << " '";
782     WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
783     O << "'";
784   }
785   O << '\n';
786
787   EmitGlobalConstant(C);
788   O << '\n';
789 }
790
791 bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
792   const TargetData *TD = TM.getTargetData();
793
794   bool isPPC64 = TD->getPointerSizeInBits() == 64;
795
796   if (isPPC64 && !TOC.empty()) {
797     // FIXME 64-bit SVR4: Use MCSection here?
798     O << "\t.section\t\".toc\",\"aw\"\n";
799
800     for (StringMap<std::string>::iterator I = TOC.begin(), E = TOC.end();
801          I != E; ++I) {
802       O << I->second << ":\n";
803       O << "\t.tc " << I->getKeyData() << "[TC]," << I->getKeyData() << '\n';
804     }
805   }
806
807   return AsmPrinter::doFinalization(M);
808 }
809
810 /// runOnMachineFunction - This uses the printMachineInstruction()
811 /// method to print assembly for each instruction.
812 ///
813 bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
814   this->MF = &MF;
815
816   SetupMachineFunction(MF);
817   O << "\n\n";
818
819   // Print out constants referenced by the function
820   EmitConstantPool(MF.getConstantPool());
821
822   // Print out labels for the function.
823   const Function *F = MF.getFunction();
824   OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
825
826   switch (F->getLinkage()) {
827   default: llvm_unreachable("Unknown linkage type!");
828   case Function::PrivateLinkage:
829   case Function::InternalLinkage:  // Symbols default to internal.
830     break;
831   case Function::ExternalLinkage:
832     O << "\t.globl\t" << CurrentFnName << '\n';
833     break;
834   case Function::WeakAnyLinkage:
835   case Function::WeakODRLinkage:
836   case Function::LinkOnceAnyLinkage:
837   case Function::LinkOnceODRLinkage:
838   case Function::LinkerPrivateLinkage:
839     O << "\t.globl\t" << CurrentFnName << '\n';
840     O << "\t.weak_definition\t" << CurrentFnName << '\n';
841     break;
842   }
843
844   printVisibility(CurrentFnName, F->getVisibility());
845
846   EmitAlignment(MF.getAlignment(), F);
847   O << CurrentFnName << ":\n";
848
849   // Emit pre-function debug information.
850   DW->BeginFunction(&MF);
851
852   // If the function is empty, then we need to emit *something*. Otherwise, the
853   // function's label might be associated with something that it wasn't meant to
854   // be associated with. We emit a noop in this situation.
855   MachineFunction::iterator I = MF.begin();
856
857   if (++I == MF.end() && MF.front().empty())
858     O << "\tnop\n";
859
860   // Print out code for the function.
861   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
862        I != E; ++I) {
863     // Print a label for the basic block.
864     if (I != MF.begin()) {
865       EmitBasicBlockStart(I);
866     }
867     for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
868          II != IE; ++II) {
869       // Print the assembly for the instruction.
870       printMachineInstruction(II);
871     }
872   }
873
874   // Emit post-function debug information.
875   DW->EndFunction(&MF);
876
877   // Print out jump tables referenced by the function.
878   EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
879
880   // We didn't modify anything.
881   return false;
882 }
883
884
885 void PPCDarwinAsmPrinter::EmitStartOfAsmFile(Module &M) {
886   static const char *const CPUDirectives[] = {
887     "",
888     "ppc",
889     "ppc601",
890     "ppc602",
891     "ppc603",
892     "ppc7400",
893     "ppc750",
894     "ppc970",
895     "ppc64"
896   };
897
898   unsigned Directive = Subtarget.getDarwinDirective();
899   if (Subtarget.isGigaProcessor() && Directive < PPC::DIR_970)
900     Directive = PPC::DIR_970;
901   if (Subtarget.hasAltivec() && Directive < PPC::DIR_7400)
902     Directive = PPC::DIR_7400;
903   if (Subtarget.isPPC64() && Directive < PPC::DIR_970)
904     Directive = PPC::DIR_64;
905   assert(Directive <= PPC::DIR_64 && "Directive out of range.");
906   O << "\t.machine " << CPUDirectives[Directive] << '\n';
907
908   // Prime text sections so they are adjacent.  This reduces the likelihood a
909   // large data or debug section causes a branch to exceed 16M limit.
910   TargetLoweringObjectFileMachO &TLOFMacho = 
911     static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
912   OutStreamer.SwitchSection(TLOFMacho.getTextCoalSection());
913   if (TM.getRelocationModel() == Reloc::PIC_) {
914     OutStreamer.SwitchSection(
915             TLOFMacho.getMachOSection("__TEXT", "__picsymbolstub1",
916                                       MCSectionMachO::S_SYMBOL_STUBS |
917                                       MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
918                                       32, SectionKind::getText()));
919   } else if (TM.getRelocationModel() == Reloc::DynamicNoPIC) {
920     OutStreamer.SwitchSection(
921             TLOFMacho.getMachOSection("__TEXT","__symbol_stub1",
922                                       MCSectionMachO::S_SYMBOL_STUBS |
923                                       MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
924                                       16, SectionKind::getText()));
925   }
926   OutStreamer.SwitchSection(getObjFileLowering().getTextSection());
927 }
928
929 void PPCDarwinAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
930   const TargetData *TD = TM.getTargetData();
931
932   if (!GVar->hasInitializer())
933     return;   // External global require no code
934
935   // Check to see if this is a special global used by LLVM, if so, emit it.
936   if (EmitSpecialLLVMGlobal(GVar)) {
937     if (TM.getRelocationModel() == Reloc::Static) {
938       if (GVar->getName() == "llvm.global_ctors")
939         O << ".reference .constructors_used\n";
940       else if (GVar->getName() == "llvm.global_dtors")
941         O << ".reference .destructors_used\n";
942     }
943     return;
944   }
945
946   std::string name = Mang->getMangledName(GVar);
947   printVisibility(name, GVar->getVisibility());
948
949   Constant *C = GVar->getInitializer();
950   const Type *Type = C->getType();
951   unsigned Size = TD->getTypeAllocSize(Type);
952   unsigned Align = TD->getPreferredAlignmentLog(GVar);
953
954   const MCSection *TheSection =
955     getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
956   OutStreamer.SwitchSection(TheSection);
957
958   /// FIXME: Drive this off the section!
959   if (C->isNullValue() && /* FIXME: Verify correct */
960       !GVar->hasSection() &&
961       (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
962        GVar->isWeakForLinker()) &&
963       // Don't put things that should go in the cstring section into "comm".
964       !TheSection->getKind().isMergeableCString()) {
965     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
966
967     if (GVar->hasExternalLinkage()) {
968       O << "\t.globl " << name << '\n';
969       O << "\t.zerofill __DATA, __common, " << name << ", "
970         << Size << ", " << Align;
971     } else if (GVar->hasLocalLinkage()) {
972       O << MAI->getLCOMMDirective() << name << ',' << Size << ',' << Align;
973     } else if (!GVar->hasCommonLinkage()) {
974       O << "\t.globl " << name << '\n'
975         << MAI->getWeakDefDirective() << name << '\n';
976       EmitAlignment(Align, GVar);
977       O << name << ":";
978       if (VerboseAsm) {
979         O << "\t\t\t\t" << MAI->getCommentString() << " ";
980         WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
981       }
982       O << '\n';
983       EmitGlobalConstant(C);
984       return;
985     } else {
986       O << ".comm " << name << ',' << Size;
987       // Darwin 9 and above support aligned common data.
988       if (Subtarget.isDarwin9())
989         O << ',' << Align;
990     }
991     if (VerboseAsm) {
992       O << "\t\t" << MAI->getCommentString() << " '";
993       WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
994       O << "'";
995     }
996     O << '\n';
997     return;
998   }
999
1000   switch (GVar->getLinkage()) {
1001    case GlobalValue::LinkOnceAnyLinkage:
1002    case GlobalValue::LinkOnceODRLinkage:
1003    case GlobalValue::WeakAnyLinkage:
1004    case GlobalValue::WeakODRLinkage:
1005    case GlobalValue::CommonLinkage:
1006    case GlobalValue::LinkerPrivateLinkage:
1007     O << "\t.globl " << name << '\n'
1008       << "\t.weak_definition " << name << '\n';
1009     break;
1010    case GlobalValue::AppendingLinkage:
1011     // FIXME: appending linkage variables should go into a section of
1012     // their name or something.  For now, just emit them as external.
1013    case GlobalValue::ExternalLinkage:
1014     // If external or appending, declare as a global symbol
1015     O << "\t.globl " << name << '\n';
1016     // FALL THROUGH
1017    case GlobalValue::InternalLinkage:
1018    case GlobalValue::PrivateLinkage:
1019     break;
1020    default:
1021     llvm_unreachable("Unknown linkage type!");
1022   }
1023
1024   EmitAlignment(Align, GVar);
1025   O << name << ":";
1026   if (VerboseAsm) {
1027     O << "\t\t\t\t" << MAI->getCommentString() << " '";
1028     WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
1029     O << "'";
1030   }
1031   O << '\n';
1032
1033   EmitGlobalConstant(C);
1034   O << '\n';
1035 }
1036
1037 bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
1038   const TargetData *TD = TM.getTargetData();
1039
1040   bool isPPC64 = TD->getPointerSizeInBits() == 64;
1041
1042   // Darwin/PPC always uses mach-o.
1043   TargetLoweringObjectFileMachO &TLOFMacho = 
1044     static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
1045
1046   
1047   const MCSection *LSPSection = 0;
1048   if (!FnStubs.empty()) // .lazy_symbol_pointer
1049     LSPSection = TLOFMacho.getLazySymbolPointerSection();
1050     
1051   
1052   // Output stubs for dynamically-linked functions
1053   if (TM.getRelocationModel() == Reloc::PIC_ && !FnStubs.empty()) {
1054     const MCSection *StubSection = 
1055       TLOFMacho.getMachOSection("__TEXT", "__picsymbolstub1",
1056                                 MCSectionMachO::S_SYMBOL_STUBS |
1057                                 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
1058                                 32, SectionKind::getText());
1059     for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(), E = FnStubs.end();
1060          I != E; ++I) {
1061       OutStreamer.SwitchSection(StubSection);
1062       EmitAlignment(4);
1063       const FnStubInfo &Info = I->second;
1064       Info.Stub->print(O, MAI);
1065       O << ":\n";
1066       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
1067       O << "\tmflr r0\n";
1068       O << "\tbcl 20,31,";
1069       Info.AnonSymbol->print(O, MAI);
1070       O << '\n';
1071       Info.AnonSymbol->print(O, MAI);
1072       O << ":\n";
1073       O << "\tmflr r11\n";
1074       O << "\taddis r11,r11,ha16(";
1075       Info.LazyPtr->print(O, MAI);
1076       O << '-';
1077       Info.AnonSymbol->print(O, MAI);
1078       O << ")\n";
1079       O << "\tmtlr r0\n";
1080       O << (isPPC64 ? "\tldu" : "\tlwzu") << " r12,lo16(";
1081       Info.LazyPtr->print(O, MAI);
1082       O << '-';
1083       Info.AnonSymbol->print(O, MAI);
1084       O << ")(r11)\n";
1085       O << "\tmtctr r12\n";
1086       O << "\tbctr\n";
1087       
1088       OutStreamer.SwitchSection(LSPSection);
1089       Info.LazyPtr->print(O, MAI);
1090       O << ":\n";
1091       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
1092       O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";
1093     }
1094   } else if (!FnStubs.empty()) {
1095     const MCSection *StubSection =
1096       TLOFMacho.getMachOSection("__TEXT","__symbol_stub1",
1097                                 MCSectionMachO::S_SYMBOL_STUBS |
1098                                 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
1099                                 16, SectionKind::getText());
1100     
1101     for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(), E = FnStubs.end();
1102          I != E; ++I) {
1103       OutStreamer.SwitchSection(StubSection);
1104       EmitAlignment(4);
1105       const FnStubInfo &Info = I->second;
1106       Info.Stub->print(O, MAI);
1107       O << ":\n";
1108       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
1109       O << "\tlis r11,ha16(";
1110       Info.LazyPtr->print(O, MAI);
1111       O << ")\n";
1112       O << (isPPC64 ? "\tldu" :  "\tlwzu") << " r12,lo16(";
1113       Info.LazyPtr->print(O, MAI);
1114       O << ")(r11)\n";
1115       O << "\tmtctr r12\n";
1116       O << "\tbctr\n";
1117       OutStreamer.SwitchSection(LSPSection);
1118       Info.LazyPtr->print(O, MAI);
1119       O << ":\n";
1120       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
1121       O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";
1122     }
1123   }
1124
1125   O << '\n';
1126
1127   if (MAI->doesSupportExceptionHandling() && MMI) {
1128     // Add the (possibly multiple) personalities to the set of global values.
1129     // Only referenced functions get into the Personalities list.
1130     const std::vector<Function *> &Personalities = MMI->getPersonalities();
1131     for (std::vector<Function *>::const_iterator I = Personalities.begin(),
1132          E = Personalities.end(); I != E; ++I) {
1133       if (*I)
1134         GVStubs[Mang->getMangledName(*I)] =
1135           Mang->getMangledName(*I, "$non_lazy_ptr", true);
1136     }
1137   }
1138
1139   // Output macho stubs for external and common global variables.
1140   if (!GVStubs.empty()) {
1141     // Switch with ".non_lazy_symbol_pointer" directive.
1142     OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
1143     EmitAlignment(isPPC64 ? 3 : 2);
1144     
1145     for (StringMap<std::string>::iterator I = GVStubs.begin(),
1146          E = GVStubs.end(); I != E; ++I) {
1147       O << I->second << ":\n";
1148       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
1149       O << (isPPC64 ? "\t.quad\t0\n" : "\t.long\t0\n");
1150     }
1151   }
1152
1153   if (!HiddenGVStubs.empty()) {
1154     OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
1155     EmitAlignment(isPPC64 ? 3 : 2);
1156     for (StringMap<std::string>::iterator I = HiddenGVStubs.begin(),
1157          E = HiddenGVStubs.end(); I != E; ++I) {
1158       O << I->second << ":\n";
1159       O << (isPPC64 ? "\t.quad\t" : "\t.long\t") << I->getKeyData() << '\n';
1160     }
1161   }
1162
1163   // Funny Darwin hack: This flag tells the linker that no global symbols
1164   // contain code that falls through to other global symbols (e.g. the obvious
1165   // implementation of multiple entry points).  If this doesn't occur, the
1166   // linker can safely perform dead code stripping.  Since LLVM never generates
1167   // code that does this, it is always safe to set.
1168   OutStreamer.EmitAssemblerFlag(MCStreamer::SubsectionsViaSymbols);
1169
1170   return AsmPrinter::doFinalization(M);
1171 }
1172
1173
1174
1175 /// createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code
1176 /// for a MachineFunction to the given output stream, in a format that the
1177 /// Darwin assembler can deal with.
1178 ///
1179 static AsmPrinter *createPPCAsmPrinterPass(formatted_raw_ostream &o,
1180                                            TargetMachine &tm,
1181                                            const MCAsmInfo *tai,
1182                                            bool verbose) {
1183   const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>();
1184
1185   if (Subtarget->isDarwin())
1186     return new PPCDarwinAsmPrinter(o, tm, tai, verbose);
1187   return new PPCLinuxAsmPrinter(o, tm, tai, verbose);
1188 }
1189
1190 // Force static initialization.
1191 extern "C" void LLVMInitializePowerPCAsmPrinter() { 
1192   TargetRegistry::RegisterAsmPrinter(ThePPC32Target, createPPCAsmPrinterPass);
1193   TargetRegistry::RegisterAsmPrinter(ThePPC64Target, createPPCAsmPrinterPass);
1194 }