LLVM API Documentation

PPCAsmPrinter.cpp

Go to the documentation of this file.
00001 //===-- PPCAsmPrinter.cpp - Print machine instrs to PowerPC assembly --------=//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains a printer that converts from our internal representation
00011 // of machine-dependent LLVM code to PowerPC assembly language. This printer is
00012 // the output mechanism used by `llc'.
00013 //
00014 // Documentation at http://developer.apple.com/documentation/DeveloperTools/
00015 // Reference/Assembler/ASMIntroduction/chapter_1_section_1.html
00016 //
00017 //===----------------------------------------------------------------------===//
00018 
00019 #define DEBUG_TYPE "asmprinter"
00020 #include "PPC.h"
00021 #include "PPCPredicates.h"
00022 #include "PPCTargetMachine.h"
00023 #include "PPCSubtarget.h"
00024 #include "llvm/Constants.h"
00025 #include "llvm/DerivedTypes.h"
00026 #include "llvm/Module.h"
00027 #include "llvm/Assembly/Writer.h"
00028 #include "llvm/CodeGen/AsmPrinter.h"
00029 #include "llvm/CodeGen/DwarfWriter.h"
00030 #include "llvm/CodeGen/MachineModuleInfo.h"
00031 #include "llvm/CodeGen/MachineFunctionPass.h"
00032 #include "llvm/CodeGen/MachineInstr.h"
00033 #include "llvm/CodeGen/MachineInstrBuilder.h"
00034 #include "llvm/MC/MCSectionMachO.h"
00035 #include "llvm/MC/MCStreamer.h"
00036 #include "llvm/Target/TargetAsmInfo.h"
00037 #include "llvm/Target/TargetLoweringObjectFile.h"
00038 #include "llvm/Target/TargetRegisterInfo.h"
00039 #include "llvm/Target/TargetInstrInfo.h"
00040 #include "llvm/Target/TargetOptions.h"
00041 #include "llvm/Target/TargetRegistry.h"
00042 #include "llvm/Support/Mangler.h"
00043 #include "llvm/Support/MathExtras.h"
00044 #include "llvm/Support/CommandLine.h"
00045 #include "llvm/Support/Debug.h"
00046 #include "llvm/Support/ErrorHandling.h"
00047 #include "llvm/Support/Compiler.h"
00048 #include "llvm/Support/FormattedStream.h"
00049 #include "llvm/ADT/Statistic.h"
00050 #include "llvm/ADT/StringExtras.h"
00051 #include "llvm/ADT/StringSet.h"
00052 using namespace llvm;
00053 
00054 STATISTIC(EmittedInsts, "Number of machine instrs printed");
00055 
00056 namespace {
00057   class VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
00058   protected:
00059     struct FnStubInfo {
00060       std::string Stub, LazyPtr, AnonSymbol;
00061       
00062       FnStubInfo() {}
00063       
00064       void Init(const GlobalValue *GV, Mangler *Mang) {
00065         // Already initialized.
00066         if (!Stub.empty()) return;
00067         Stub = Mang->getMangledName(GV, "$stub", true);
00068         LazyPtr = Mang->getMangledName(GV, "$lazy_ptr", true);
00069         AnonSymbol = Mang->getMangledName(GV, "$stub$tmp", true);
00070       }
00071 
00072       void Init(const std::string &GV, Mangler *Mang) {
00073         // Already initialized.
00074         if (!Stub.empty()) return;
00075         Stub = Mang->makeNameProper(GV + "$stub",
00076                                     Mangler::Private);
00077         LazyPtr = Mang->makeNameProper(GV + "$lazy_ptr",
00078                                        Mangler::Private);
00079         AnonSymbol = Mang->makeNameProper(GV + "$stub$tmp",
00080                                           Mangler::Private);
00081       }
00082     };
00083     
00084     StringMap<FnStubInfo> FnStubs;
00085     StringMap<std::string> GVStubs, HiddenGVStubs, TOC;
00086     const PPCSubtarget &Subtarget;
00087     uint64_t LabelID;
00088   public:
00089     explicit PPCAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
00090                            const TargetAsmInfo *T, bool V)
00091       : AsmPrinter(O, TM, T, V),
00092         Subtarget(TM.getSubtarget<PPCSubtarget>()), LabelID(0) {}
00093 
00094     virtual const char *getPassName() const {
00095       return "PowerPC Assembly Printer";
00096     }
00097 
00098     PPCTargetMachine &getTM() {
00099       return static_cast<PPCTargetMachine&>(TM);
00100     }
00101 
00102     unsigned enumRegToMachineReg(unsigned enumReg) {
00103       switch (enumReg) {
00104       default: llvm_unreachable("Unhandled register!");
00105       case PPC::CR0:  return  0;
00106       case PPC::CR1:  return  1;
00107       case PPC::CR2:  return  2;
00108       case PPC::CR3:  return  3;
00109       case PPC::CR4:  return  4;
00110       case PPC::CR5:  return  5;
00111       case PPC::CR6:  return  6;
00112       case PPC::CR7:  return  7;
00113       }
00114       llvm_unreachable(0);
00115     }
00116 
00117     /// printInstruction - This method is automatically generated by tablegen
00118     /// from the instruction set description.  This method returns true if the
00119     /// machine instruction was sufficiently described to print it, otherwise it
00120     /// returns false.
00121     void printInstruction(const MachineInstr *MI);
00122 
00123     void printMachineInstruction(const MachineInstr *MI);
00124     void printOp(const MachineOperand &MO);
00125 
00126     /// stripRegisterPrefix - This method strips the character prefix from a
00127     /// register name so that only the number is left.  Used by for linux asm.
00128     const char *stripRegisterPrefix(const char *RegName) {
00129       switch (RegName[0]) {
00130       case 'r':
00131       case 'f':
00132       case 'v': return RegName + 1;
00133       case 'c': if (RegName[1] == 'r') return RegName + 2;
00134       }
00135 
00136       return RegName;
00137     }
00138 
00139     /// printRegister - Print register according to target requirements.
00140     ///
00141     void printRegister(const MachineOperand &MO, bool R0AsZero) {
00142       unsigned RegNo = MO.getReg();
00143       assert(TargetRegisterInfo::isPhysicalRegister(RegNo) && "Not physreg??");
00144 
00145       // If we should use 0 for R0.
00146       if (R0AsZero && RegNo == PPC::R0) {
00147         O << "0";
00148         return;
00149       }
00150 
00151       const char *RegName = TM.getRegisterInfo()->get(RegNo).AsmName;
00152       // Linux assembler (Others?) does not take register mnemonics.
00153       // FIXME - What about special registers used in mfspr/mtspr?
00154       if (!Subtarget.isDarwin()) RegName = stripRegisterPrefix(RegName);
00155       O << RegName;
00156     }
00157 
00158     void printOperand(const MachineInstr *MI, unsigned OpNo) {
00159       const MachineOperand &MO = MI->getOperand(OpNo);
00160       if (MO.isReg()) {
00161         printRegister(MO, false);
00162       } else if (MO.isImm()) {
00163         O << MO.getImm();
00164       } else {
00165         printOp(MO);
00166       }
00167     }
00168 
00169     bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
00170                          unsigned AsmVariant, const char *ExtraCode);
00171     bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
00172                                unsigned AsmVariant, const char *ExtraCode);
00173 
00174 
00175     void printS5ImmOperand(const MachineInstr *MI, unsigned OpNo) {
00176       char value = MI->getOperand(OpNo).getImm();
00177       value = (value << (32-5)) >> (32-5);
00178       O << (int)value;
00179     }
00180     void printU5ImmOperand(const MachineInstr *MI, unsigned OpNo) {
00181       unsigned char value = MI->getOperand(OpNo).getImm();
00182       assert(value <= 31 && "Invalid u5imm argument!");
00183       O << (unsigned int)value;
00184     }
00185     void printU6ImmOperand(const MachineInstr *MI, unsigned OpNo) {
00186       unsigned char value = MI->getOperand(OpNo).getImm();
00187       assert(value <= 63 && "Invalid u6imm argument!");
00188       O << (unsigned int)value;
00189     }
00190     void printS16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
00191       O << (short)MI->getOperand(OpNo).getImm();
00192     }
00193     void printU16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
00194       O << (unsigned short)MI->getOperand(OpNo).getImm();
00195     }
00196     void printS16X4ImmOperand(const MachineInstr *MI, unsigned OpNo) {
00197       if (MI->getOperand(OpNo).isImm()) {
00198         O << (short)(MI->getOperand(OpNo).getImm()*4);
00199       } else {
00200         O << "lo16(";
00201         printOp(MI->getOperand(OpNo));
00202         if (TM.getRelocationModel() == Reloc::PIC_)
00203           O << "-\"L" << getFunctionNumber() << "$pb\")";
00204         else
00205           O << ')';
00206       }
00207     }
00208     void printBranchOperand(const MachineInstr *MI, unsigned OpNo) {
00209       // Branches can take an immediate operand.  This is used by the branch
00210       // selection pass to print $+8, an eight byte displacement from the PC.
00211       if (MI->getOperand(OpNo).isImm()) {
00212         O << "$+" << MI->getOperand(OpNo).getImm()*4;
00213       } else {
00214         printOp(MI->getOperand(OpNo));
00215       }
00216     }
00217     void printCallOperand(const MachineInstr *MI, unsigned OpNo) {
00218       const MachineOperand &MO = MI->getOperand(OpNo);
00219       if (TM.getRelocationModel() != Reloc::Static) {
00220         if (MO.getType() == MachineOperand::MO_GlobalAddress) {
00221           GlobalValue *GV = MO.getGlobal();
00222           if (GV->isDeclaration() || GV->isWeakForLinker()) {
00223             // Dynamically-resolved functions need a stub for the function.
00224             FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
00225             FnInfo.Init(GV, Mang);
00226             O << FnInfo.Stub;
00227             return;
00228           }
00229         }
00230         if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
00231           FnStubInfo &FnInfo =FnStubs[Mang->makeNameProper(MO.getSymbolName())];
00232           FnInfo.Init(MO.getSymbolName(), Mang);
00233           O << FnInfo.Stub;
00234           return;
00235         }
00236       }
00237 
00238       printOp(MI->getOperand(OpNo));
00239     }
00240     void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo) {
00241      O << (int)MI->getOperand(OpNo).getImm()*4;
00242     }
00243     void printPICLabel(const MachineInstr *MI, unsigned OpNo) {
00244       O << "\"L" << getFunctionNumber() << "$pb\"\n";
00245       O << "\"L" << getFunctionNumber() << "$pb\":";
00246     }
00247     void printSymbolHi(const MachineInstr *MI, unsigned OpNo) {
00248       if (MI->getOperand(OpNo).isImm()) {
00249         printS16ImmOperand(MI, OpNo);
00250       } else {
00251         if (Subtarget.isDarwin()) O << "ha16(";
00252         printOp(MI->getOperand(OpNo));
00253         if (TM.getRelocationModel() == Reloc::PIC_)
00254           O << "-\"L" << getFunctionNumber() << "$pb\"";
00255         if (Subtarget.isDarwin())
00256           O << ')';
00257         else
00258           O << "@ha";
00259       }
00260     }
00261     void printSymbolLo(const MachineInstr *MI, unsigned OpNo) {
00262       if (MI->getOperand(OpNo).isImm()) {
00263         printS16ImmOperand(MI, OpNo);
00264       } else {
00265         if (Subtarget.isDarwin()) O << "lo16(";
00266         printOp(MI->getOperand(OpNo));
00267         if (TM.getRelocationModel() == Reloc::PIC_)
00268           O << "-\"L" << getFunctionNumber() << "$pb\"";
00269         if (Subtarget.isDarwin())
00270           O << ')';
00271         else
00272           O << "@l";
00273       }
00274     }
00275     void printcrbitm(const MachineInstr *MI, unsigned OpNo) {
00276       unsigned CCReg = MI->getOperand(OpNo).getReg();
00277       unsigned RegNo = enumRegToMachineReg(CCReg);
00278       O << (0x80 >> RegNo);
00279     }
00280     // The new addressing mode printers.
00281     void printMemRegImm(const MachineInstr *MI, unsigned OpNo) {
00282       printSymbolLo(MI, OpNo);
00283       O << '(';
00284       if (MI->getOperand(OpNo+1).isReg() &&
00285           MI->getOperand(OpNo+1).getReg() == PPC::R0)
00286         O << "0";
00287       else
00288         printOperand(MI, OpNo+1);
00289       O << ')';
00290     }
00291     void printMemRegImmShifted(const MachineInstr *MI, unsigned OpNo) {
00292       if (MI->getOperand(OpNo).isImm())
00293         printS16X4ImmOperand(MI, OpNo);
00294       else
00295         printSymbolLo(MI, OpNo);
00296       O << '(';
00297       if (MI->getOperand(OpNo+1).isReg() &&
00298           MI->getOperand(OpNo+1).getReg() == PPC::R0)
00299         O << "0";
00300       else
00301         printOperand(MI, OpNo+1);
00302       O << ')';
00303     }
00304 
00305     void printMemRegReg(const MachineInstr *MI, unsigned OpNo) {
00306       // When used as the base register, r0 reads constant zero rather than
00307       // the value contained in the register.  For this reason, the darwin
00308       // assembler requires that we print r0 as 0 (no r) when used as the base.
00309       const MachineOperand &MO = MI->getOperand(OpNo);
00310       printRegister(MO, true);
00311       O << ", ";
00312       printOperand(MI, OpNo+1);
00313     }
00314 
00315     void printTOCEntryLabel(const MachineInstr *MI, unsigned OpNo) {
00316       const MachineOperand &MO = MI->getOperand(OpNo);
00317 
00318       assert(MO.getType() == MachineOperand::MO_GlobalAddress);
00319 
00320       GlobalValue *GV = MO.getGlobal();
00321 
00322       std::string Name = Mang->getMangledName(GV);
00323 
00324       // Map symbol -> label of TOC entry.
00325       if (TOC.count(Name) == 0) {
00326         std::string Label;
00327         Label += TAI->getPrivateGlobalPrefix();
00328         Label += "C";
00329         Label += utostr(LabelID++);
00330 
00331         TOC[Name] = Label;
00332       }
00333 
00334       O << TOC[Name] << "@toc";
00335     }
00336 
00337     void printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
00338                                const char *Modifier);
00339 
00340     virtual bool runOnMachineFunction(MachineFunction &F) = 0;
00341 
00342     virtual void EmitExternalGlobal(const GlobalVariable *GV);
00343   };
00344 
00345   /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
00346   class VISIBILITY_HIDDEN PPCLinuxAsmPrinter : public PPCAsmPrinter {
00347   public:
00348     explicit PPCLinuxAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
00349                                 const TargetAsmInfo *T, bool V)
00350       : PPCAsmPrinter(O, TM, T, V){}
00351 
00352     virtual const char *getPassName() const {
00353       return "Linux PPC Assembly Printer";
00354     }
00355 
00356     bool runOnMachineFunction(MachineFunction &F);
00357     bool doFinalization(Module &M);
00358 
00359     void getAnalysisUsage(AnalysisUsage &AU) const {
00360       AU.setPreservesAll();
00361       AU.addRequired<MachineModuleInfo>();
00362       AU.addRequired<DwarfWriter>();
00363       PPCAsmPrinter::getAnalysisUsage(AU);
00364     }
00365 
00366     void PrintGlobalVariable(const GlobalVariable *GVar);
00367   };
00368 
00369   /// PPCDarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac
00370   /// OS X
00371   class VISIBILITY_HIDDEN PPCDarwinAsmPrinter : public PPCAsmPrinter {
00372     formatted_raw_ostream &OS;
00373   public:
00374     explicit PPCDarwinAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
00375                                  const TargetAsmInfo *T, bool V)
00376       : PPCAsmPrinter(O, TM, T, V), OS(O) {}
00377 
00378     virtual const char *getPassName() const {
00379       return "Darwin PPC Assembly Printer";
00380     }
00381 
00382     bool runOnMachineFunction(MachineFunction &F);
00383     bool doInitialization(Module &M);
00384     bool doFinalization(Module &M);
00385 
00386     void getAnalysisUsage(AnalysisUsage &AU) const {
00387       AU.setPreservesAll();
00388       AU.addRequired<MachineModuleInfo>();
00389       AU.addRequired<DwarfWriter>();
00390       PPCAsmPrinter::getAnalysisUsage(AU);
00391     }
00392 
00393     void PrintGlobalVariable(const GlobalVariable *GVar);
00394   };
00395 } // end of anonymous namespace
00396 
00397 // Include the auto-generated portion of the assembly writer
00398 #include "PPCGenAsmWriter.inc"
00399 
00400 void PPCAsmPrinter::printOp(const MachineOperand &MO) {
00401   switch (MO.getType()) {
00402   case MachineOperand::MO_Immediate:
00403     llvm_unreachable("printOp() does not handle immediate values");
00404 
00405   case MachineOperand::MO_MachineBasicBlock:
00406     printBasicBlockLabel(MO.getMBB());
00407     return;
00408   case MachineOperand::MO_JumpTableIndex:
00409     O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
00410       << '_' << MO.getIndex();
00411     // FIXME: PIC relocation model
00412     return;
00413   case MachineOperand::MO_ConstantPoolIndex:
00414     O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
00415       << '_' << MO.getIndex();
00416     return;
00417   case MachineOperand::MO_ExternalSymbol: {
00418     // Computing the address of an external symbol, not calling it.
00419     std::string Name(TAI->getGlobalPrefix());
00420     Name += MO.getSymbolName();
00421     
00422     if (TM.getRelocationModel() != Reloc::Static) {
00423       GVStubs[Name] = Name+"$non_lazy_ptr";
00424       Name += "$non_lazy_ptr";
00425     }
00426     O << Name;
00427     return;
00428   }
00429   case MachineOperand::MO_GlobalAddress: {
00430     // Computing the address of a global symbol, not calling it.
00431     GlobalValue *GV = MO.getGlobal();
00432     std::string Name;
00433 
00434     // External or weakly linked global variables need non-lazily-resolved stubs
00435     if (TM.getRelocationModel() != Reloc::Static &&
00436         (GV->isDeclaration() || GV->isWeakForLinker())) {
00437       if (!GV->hasHiddenVisibility()) {
00438         Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
00439         GVStubs[Mang->getMangledName(GV)] = Name;
00440       } else if (GV->isDeclaration() || GV->hasCommonLinkage() ||
00441                  GV->hasAvailableExternallyLinkage()) {
00442         Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
00443         HiddenGVStubs[Mang->getMangledName(GV)] = Name;
00444       } else {
00445         Name = Mang->getMangledName(GV);
00446       }
00447     } else {
00448       Name = Mang->getMangledName(GV);
00449     }
00450     O << Name;
00451 
00452     printOffset(MO.getOffset());
00453     return;
00454   }
00455 
00456   default:
00457     O << "<unknown operand type: " << MO.getType() << ">";
00458     return;
00459   }
00460 }
00461 
00462 /// EmitExternalGlobal - In this case we need to use the indirect symbol.
00463 ///
00464 void PPCAsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
00465   std::string Name;
00466   
00467   if (TM.getRelocationModel() != Reloc::Static) {
00468     Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
00469   } else {
00470     Name = Mang->getMangledName(GV);
00471   }
00472   O << Name;
00473 }
00474 
00475 /// PrintAsmOperand - Print out an operand for an inline asm expression.
00476 ///
00477 bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
00478                                     unsigned AsmVariant,
00479                                     const char *ExtraCode) {
00480   // Does this asm operand have a single letter operand modifier?
00481   if (ExtraCode && ExtraCode[0]) {
00482     if (ExtraCode[1] != 0) return true; // Unknown modifier.
00483 
00484     switch (ExtraCode[0]) {
00485     default: return true;  // Unknown modifier.
00486     case 'c': // Don't print "$" before a global var name or constant.
00487       // PPC never has a prefix.
00488       printOperand(MI, OpNo);
00489       return false;
00490     case 'L': // Write second word of DImode reference.
00491       // Verify that this operand has two consecutive registers.
00492       if (!MI->getOperand(OpNo).isReg() ||
00493           OpNo+1 == MI->getNumOperands() ||
00494           !MI->getOperand(OpNo+1).isReg())
00495         return true;
00496       ++OpNo;   // Return the high-part.
00497       break;
00498     case 'I':
00499       // Write 'i' if an integer constant, otherwise nothing.  Used to print
00500       // addi vs add, etc.
00501       if (MI->getOperand(OpNo).isImm())
00502         O << "i";
00503       return false;
00504     }
00505   }
00506 
00507   printOperand(MI, OpNo);
00508   return false;
00509 }
00510 
00511 // At the moment, all inline asm memory operands are a single register.
00512 // In any case, the output of this routine should always be just one
00513 // assembler operand.
00514 
00515 bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
00516                                           unsigned AsmVariant,
00517                                           const char *ExtraCode) {
00518   if (ExtraCode && ExtraCode[0])
00519     return true; // Unknown modifier.
00520   assert (MI->getOperand(OpNo).isReg());
00521   printOperand(MI, OpNo);
00522   return false;
00523 }
00524 
00525 void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
00526                                           const char *Modifier) {
00527   assert(Modifier && "Must specify 'cc' or 'reg' as predicate op modifier!");
00528   unsigned Code = MI->getOperand(OpNo).getImm();
00529   if (!strcmp(Modifier, "cc")) {
00530     switch ((PPC::Predicate)Code) {
00531     case PPC::PRED_ALWAYS: return; // Don't print anything for always.
00532     case PPC::PRED_LT: O << "lt"; return;
00533     case PPC::PRED_LE: O << "le"; return;
00534     case PPC::PRED_EQ: O << "eq"; return;
00535     case PPC::PRED_GE: O << "ge"; return;
00536     case PPC::PRED_GT: O << "gt"; return;
00537     case PPC::PRED_NE: O << "ne"; return;
00538     case PPC::PRED_UN: O << "un"; return;
00539     case PPC::PRED_NU: O << "nu"; return;
00540     }
00541 
00542   } else {
00543     assert(!strcmp(Modifier, "reg") &&
00544            "Need to specify 'cc' or 'reg' as predicate op modifier!");
00545     // Don't print the register for 'always'.
00546     if (Code == PPC::PRED_ALWAYS) return;
00547     printOperand(MI, OpNo+1);
00548   }
00549 }
00550 
00551 
00552 /// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to
00553 /// the current output stream.
00554 ///
00555 void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
00556   ++EmittedInsts;
00557 
00558   // Check for slwi/srwi mnemonics.
00559   if (MI->getOpcode() == PPC::RLWINM) {
00560     bool FoundMnemonic = false;
00561     unsigned char SH = MI->getOperand(2).getImm();
00562     unsigned char MB = MI->getOperand(3).getImm();
00563     unsigned char ME = MI->getOperand(4).getImm();
00564     if (SH <= 31 && MB == 0 && ME == (31-SH)) {
00565       O << "\tslwi "; FoundMnemonic = true;
00566     }
00567     if (SH <= 31 && MB == (32-SH) && ME == 31) {
00568       O << "\tsrwi "; FoundMnemonic = true;
00569       SH = 32-SH;
00570     }
00571     if (FoundMnemonic) {
00572       printOperand(MI, 0);
00573       O << ", ";
00574       printOperand(MI, 1);
00575       O << ", " << (unsigned int)SH << '\n';
00576       return;
00577     }
00578   } else if (MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) {
00579     if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
00580       O << "\tmr ";
00581       printOperand(MI, 0);
00582       O << ", ";
00583       printOperand(MI, 1);
00584       O << '\n';
00585       return;
00586     }
00587   } else if (MI->getOpcode() == PPC::RLDICR) {
00588     unsigned char SH = MI->getOperand(2).getImm();
00589     unsigned char ME = MI->getOperand(3).getImm();
00590     // rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH
00591     if (63-SH == ME) {
00592       O << "\tsldi ";
00593       printOperand(MI, 0);
00594       O << ", ";
00595       printOperand(MI, 1);
00596       O << ", " << (unsigned int)SH << '\n';
00597       return;
00598     }
00599   }
00600 
00601   printInstruction(MI);
00602 }
00603 
00604 /// runOnMachineFunction - This uses the printMachineInstruction()
00605 /// method to print assembly for each instruction.
00606 ///
00607 bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
00608   this->MF = &MF;
00609 
00610   SetupMachineFunction(MF);
00611   O << "\n\n";
00612 
00613   // Print out constants referenced by the function
00614   EmitConstantPool(MF.getConstantPool());
00615 
00616   // Print out labels for the function.
00617   const Function *F = MF.getFunction();
00618   OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
00619 
00620   switch (F->getLinkage()) {
00621   default: llvm_unreachable("Unknown linkage type!");
00622   case Function::PrivateLinkage:
00623   case Function::LinkerPrivateLinkage:
00624   case Function::InternalLinkage:  // Symbols default to internal.
00625     break;
00626   case Function::ExternalLinkage:
00627     O << "\t.global\t" << CurrentFnName << '\n'
00628       << "\t.type\t" << CurrentFnName << ", @function\n";
00629     break;
00630   case Function::WeakAnyLinkage:
00631   case Function::WeakODRLinkage:
00632   case Function::LinkOnceAnyLinkage:
00633   case Function::LinkOnceODRLinkage:
00634     O << "\t.global\t" << CurrentFnName << '\n';
00635     O << "\t.weak\t" << CurrentFnName << '\n';
00636     break;
00637   }
00638 
00639   printVisibility(CurrentFnName, F->getVisibility());
00640 
00641   EmitAlignment(MF.getAlignment(), F);
00642 
00643   if (Subtarget.isPPC64()) {
00644     // Emit an official procedure descriptor.
00645     // FIXME 64-bit SVR4: Use MCSection here?
00646     O << "\t.section\t\".opd\",\"aw\"\n";
00647     O << "\t.align 3\n";
00648     O << CurrentFnName << ":\n";
00649     O << "\t.quad .L." << CurrentFnName << ",.TOC.@tocbase\n";
00650     O << "\t.previous\n";
00651     O << ".L." << CurrentFnName << ":\n";
00652   } else {
00653     O << CurrentFnName << ":\n";
00654   }
00655 
00656   // Emit pre-function debug information.
00657   DW->BeginFunction(&MF);
00658 
00659   // Print out code for the function.
00660   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
00661        I != E; ++I) {
00662     // Print a label for the basic block.
00663     if (I != MF.begin()) {
00664       printBasicBlockLabel(I, true, true);
00665       O << '\n';
00666     }
00667     for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
00668          II != E; ++II) {
00669       // Print the assembly for the instruction.
00670       printMachineInstruction(II);
00671     }
00672   }
00673 
00674   O << "\t.size\t" << CurrentFnName << ",.-" << CurrentFnName << '\n';
00675 
00676   // Print out jump tables referenced by the function.
00677   EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
00678 
00679   OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
00680 
00681   // Emit post-function debug information.
00682   DW->EndFunction(&MF);
00683 
00684   // We didn't modify anything.
00685   return false;
00686 }
00687 
00688 void PPCLinuxAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
00689   const TargetData *TD = TM.getTargetData();
00690 
00691   if (!GVar->hasInitializer())
00692     return;   // External global require no code
00693 
00694   // Check to see if this is a special global used by LLVM, if so, emit it.
00695   if (EmitSpecialLLVMGlobal(GVar))
00696     return;
00697 
00698   std::string name = Mang->getMangledName(GVar);
00699 
00700   printVisibility(name, GVar->getVisibility());
00701 
00702   Constant *C = GVar->getInitializer();
00703   const Type *Type = C->getType();
00704   unsigned Size = TD->getTypeAllocSize(Type);
00705   unsigned Align = TD->getPreferredAlignmentLog(GVar);
00706 
00707   OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(GVar, Mang,
00708                                                                   TM));
00709 
00710   if (C->isNullValue() && /* FIXME: Verify correct */
00711       !GVar->hasSection() &&
00712       (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
00713        GVar->isWeakForLinker())) {
00714       if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
00715 
00716       if (GVar->hasExternalLinkage()) {
00717         O << "\t.global " << name << '\n';
00718         O << "\t.type " << name << ", @object\n";
00719         O << name << ":\n";
00720         O << "\t.zero " << Size << '\n';
00721       } else if (GVar->hasLocalLinkage()) {
00722         O << TAI->getLCOMMDirective() << name << ',' << Size;
00723       } else {
00724         O << ".comm " << name << ',' << Size;
00725       }
00726       if (VerboseAsm) {
00727         O << "\t\t" << TAI->getCommentString() << " '";
00728         WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
00729         O << "'";
00730       }
00731       O << '\n';
00732       return;
00733   }
00734 
00735   switch (GVar->getLinkage()) {
00736    case GlobalValue::LinkOnceAnyLinkage:
00737    case GlobalValue::LinkOnceODRLinkage:
00738    case GlobalValue::WeakAnyLinkage:
00739    case GlobalValue::WeakODRLinkage:
00740    case GlobalValue::CommonLinkage:
00741     O << "\t.global " << name << '\n'
00742       << "\t.type " << name << ", @object\n"
00743       << "\t.weak " << name << '\n';
00744     break;
00745    case GlobalValue::AppendingLinkage:
00746     // FIXME: appending linkage variables should go into a section of
00747     // their name or something.  For now, just emit them as external.
00748    case GlobalValue::ExternalLinkage:
00749     // If external or appending, declare as a global symbol
00750     O << "\t.global " << name << '\n'
00751       << "\t.type " << name << ", @object\n";
00752     // FALL THROUGH
00753    case GlobalValue::InternalLinkage:
00754    case GlobalValue::PrivateLinkage:
00755    case GlobalValue::LinkerPrivateLinkage:
00756     break;
00757    default:
00758     llvm_unreachable("Unknown linkage type!");
00759   }
00760 
00761   EmitAlignment(Align, GVar);
00762   O << name << ":";
00763   if (VerboseAsm) {
00764     O << "\t\t\t\t" << TAI->getCommentString() << " '";
00765     WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
00766     O << "'";
00767   }
00768   O << '\n';
00769 
00770   EmitGlobalConstant(C);
00771   O << '\n';
00772 }
00773 
00774 bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
00775   const TargetData *TD = TM.getTargetData();
00776 
00777   bool isPPC64 = TD->getPointerSizeInBits() == 64;
00778 
00779   if (isPPC64 && !TOC.empty()) {
00780     // FIXME 64-bit SVR4: Use MCSection here?
00781     O << "\t.section\t\".toc\",\"aw\"\n";
00782 
00783     for (StringMap<std::string>::iterator I = TOC.begin(), E = TOC.end();
00784          I != E; ++I) {
00785       O << I->second << ":\n";
00786       O << "\t.tc " << I->getKeyData() << "[TC]," << I->getKeyData() << '\n';
00787     }
00788   }
00789 
00790   return AsmPrinter::doFinalization(M);
00791 }
00792 
00793 /// runOnMachineFunction - This uses the printMachineInstruction()
00794 /// method to print assembly for each instruction.
00795 ///
00796 bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
00797   this->MF = &MF;
00798 
00799   SetupMachineFunction(MF);
00800   O << "\n\n";
00801 
00802   // Print out constants referenced by the function
00803   EmitConstantPool(MF.getConstantPool());
00804 
00805   // Print out labels for the function.
00806   const Function *F = MF.getFunction();
00807   OutStreamer.SwitchSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
00808 
00809   switch (F->getLinkage()) {
00810   default: llvm_unreachable("Unknown linkage type!");
00811   case Function::PrivateLinkage:
00812   case Function::LinkerPrivateLinkage:
00813   case Function::InternalLinkage:  // Symbols default to internal.
00814     break;
00815   case Function::ExternalLinkage:
00816     O << "\t.globl\t" << CurrentFnName << '\n';
00817     break;
00818   case Function::WeakAnyLinkage:
00819   case Function::WeakODRLinkage:
00820   case Function::LinkOnceAnyLinkage:
00821   case Function::LinkOnceODRLinkage:
00822     O << "\t.globl\t" << CurrentFnName << '\n';
00823     O << "\t.weak_definition\t" << CurrentFnName << '\n';
00824     break;
00825   }
00826 
00827   printVisibility(CurrentFnName, F->getVisibility());
00828 
00829   EmitAlignment(MF.getAlignment(), F);
00830   O << CurrentFnName << ":\n";
00831 
00832   // Emit pre-function debug information.
00833   DW->BeginFunction(&MF);
00834 
00835   // If the function is empty, then we need to emit *something*. Otherwise, the
00836   // function's label might be associated with something that it wasn't meant to
00837   // be associated with. We emit a noop in this situation.
00838   MachineFunction::iterator I = MF.begin();
00839 
00840   if (++I == MF.end() && MF.front().empty())
00841     O << "\tnop\n";
00842 
00843   // Print out code for the function.
00844   for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
00845        I != E; ++I) {
00846     // Print a label for the basic block.
00847     if (I != MF.begin()) {
00848       printBasicBlockLabel(I, true, true, VerboseAsm);
00849       O << '\n';
00850     }
00851     for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
00852          II != IE; ++II) {
00853       // Print the assembly for the instruction.
00854       printMachineInstruction(II);
00855     }
00856   }
00857 
00858   // Print out jump tables referenced by the function.
00859   EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
00860 
00861   // Emit post-function debug information.
00862   DW->EndFunction(&MF);
00863 
00864   // We didn't modify anything.
00865   return false;
00866 }
00867 
00868 
00869 bool PPCDarwinAsmPrinter::doInitialization(Module &M) {
00870   static const char *const CPUDirectives[] = {
00871     "",
00872     "ppc",
00873     "ppc601",
00874     "ppc602",
00875     "ppc603",
00876     "ppc7400",
00877     "ppc750",
00878     "ppc970",
00879     "ppc64"
00880   };
00881 
00882   unsigned Directive = Subtarget.getDarwinDirective();
00883   if (Subtarget.isGigaProcessor() && Directive < PPC::DIR_970)
00884     Directive = PPC::DIR_970;
00885   if (Subtarget.hasAltivec() && Directive < PPC::DIR_7400)
00886     Directive = PPC::DIR_7400;
00887   if (Subtarget.isPPC64() && Directive < PPC::DIR_970)
00888     Directive = PPC::DIR_64;
00889   assert(Directive <= PPC::DIR_64 && "Directive out of range.");
00890   O << "\t.machine " << CPUDirectives[Directive] << '\n';
00891 
00892   bool Result = AsmPrinter::doInitialization(M);
00893   assert(MMI);
00894 
00895   // Prime text sections so they are adjacent.  This reduces the likelihood a
00896   // large data or debug section causes a branch to exceed 16M limit.
00897   TargetLoweringObjectFileMachO &TLOFMacho = 
00898     static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
00899   OutStreamer.SwitchSection(TLOFMacho.getTextCoalSection());
00900   if (TM.getRelocationModel() == Reloc::PIC_) {
00901     OutStreamer.SwitchSection(
00902             TLOFMacho.getMachOSection("__TEXT", "__picsymbolstub1",
00903                                       MCSectionMachO::S_SYMBOL_STUBS |
00904                                       MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
00905                                       32, SectionKind::getText()));
00906   } else if (TM.getRelocationModel() == Reloc::DynamicNoPIC) {
00907     OutStreamer.SwitchSection(
00908             TLOFMacho.getMachOSection("__TEXT","__symbol_stub1",
00909                                       MCSectionMachO::S_SYMBOL_STUBS |
00910                                       MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
00911                                       16, SectionKind::getText()));
00912   }
00913   OutStreamer.SwitchSection(getObjFileLowering().getTextSection());
00914 
00915   return Result;
00916 }
00917 
00918 void PPCDarwinAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
00919   const TargetData *TD = TM.getTargetData();
00920 
00921   if (!GVar->hasInitializer())
00922     return;   // External global require no code
00923 
00924   // Check to see if this is a special global used by LLVM, if so, emit it.
00925   if (EmitSpecialLLVMGlobal(GVar)) {
00926     if (TM.getRelocationModel() == Reloc::Static) {
00927       if (GVar->getName() == "llvm.global_ctors")
00928         O << ".reference .constructors_used\n";
00929       else if (GVar->getName() == "llvm.global_dtors")
00930         O << ".reference .destructors_used\n";
00931     }
00932     return;
00933   }
00934 
00935   std::string name = Mang->getMangledName(GVar);
00936   printVisibility(name, GVar->getVisibility());
00937 
00938   Constant *C = GVar->getInitializer();
00939   const Type *Type = C->getType();
00940   unsigned Size = TD->getTypeAllocSize(Type);
00941   unsigned Align = TD->getPreferredAlignmentLog(GVar);
00942 
00943   const MCSection *TheSection =
00944     getObjFileLowering().SectionForGlobal(GVar, Mang, TM);
00945   OutStreamer.SwitchSection(TheSection);
00946 
00947   /// FIXME: Drive this off the section!
00948   if (C->isNullValue() && /* FIXME: Verify correct */
00949       !GVar->hasSection() &&
00950       (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
00951        GVar->isWeakForLinker()) &&
00952       // Don't put things that should go in the cstring section into "comm".
00953       !TheSection->getKind().isMergeableCString()) {
00954     if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
00955 
00956     if (GVar->hasExternalLinkage()) {
00957       O << "\t.globl " << name << '\n';
00958       O << "\t.zerofill __DATA, __common, " << name << ", "
00959         << Size << ", " << Align;
00960     } else if (GVar->hasLocalLinkage()) {
00961       O << TAI->getLCOMMDirective() << name << ',' << Size << ',' << Align;
00962     } else if (!GVar->hasCommonLinkage()) {
00963       O << "\t.globl " << name << '\n'
00964         << TAI->getWeakDefDirective() << name << '\n';
00965       EmitAlignment(Align, GVar);
00966       O << name << ":";
00967       if (VerboseAsm) {
00968         O << "\t\t\t\t" << TAI->getCommentString() << " ";
00969         WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
00970       }
00971       O << '\n';
00972       EmitGlobalConstant(C);
00973       return;
00974     } else {
00975       O << ".comm " << name << ',' << Size;
00976       // Darwin 9 and above support aligned common data.
00977       if (Subtarget.isDarwin9())
00978         O << ',' << Align;
00979     }
00980     if (VerboseAsm) {
00981       O << "\t\t" << TAI->getCommentString() << " '";
00982       WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
00983       O << "'";
00984     }
00985     O << '\n';
00986     return;
00987   }
00988 
00989   switch (GVar->getLinkage()) {
00990    case GlobalValue::LinkOnceAnyLinkage:
00991    case GlobalValue::LinkOnceODRLinkage:
00992    case GlobalValue::WeakAnyLinkage:
00993    case GlobalValue::WeakODRLinkage:
00994    case GlobalValue::CommonLinkage:
00995     O << "\t.globl " << name << '\n'
00996       << "\t.weak_definition " << name << '\n';
00997     break;
00998    case GlobalValue::AppendingLinkage:
00999     // FIXME: appending linkage variables should go into a section of
01000     // their name or something.  For now, just emit them as external.
01001    case GlobalValue::ExternalLinkage:
01002     // If external or appending, declare as a global symbol
01003     O << "\t.globl " << name << '\n';
01004     // FALL THROUGH
01005    case GlobalValue::InternalLinkage:
01006    case GlobalValue::PrivateLinkage:
01007    case GlobalValue::LinkerPrivateLinkage:
01008     break;
01009    default:
01010     llvm_unreachable("Unknown linkage type!");
01011   }
01012 
01013   EmitAlignment(Align, GVar);
01014   O << name << ":";
01015   if (VerboseAsm) {
01016     O << "\t\t\t\t" << TAI->getCommentString() << " '";
01017     WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
01018     O << "'";
01019   }
01020   O << '\n';
01021 
01022   EmitGlobalConstant(C);
01023   O << '\n';
01024 }
01025 
01026 bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
01027   const TargetData *TD = TM.getTargetData();
01028 
01029   bool isPPC64 = TD->getPointerSizeInBits() == 64;
01030 
01031   // Darwin/PPC always uses mach-o.
01032   TargetLoweringObjectFileMachO &TLOFMacho = 
01033     static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
01034 
01035   
01036   const MCSection *LSPSection = 0;
01037   if (!FnStubs.empty()) // .lazy_symbol_pointer
01038     LSPSection = TLOFMacho.getLazySymbolPointerSection();
01039     
01040   
01041   // Output stubs for dynamically-linked functions
01042   if (TM.getRelocationModel() == Reloc::PIC_ && !FnStubs.empty()) {
01043     const MCSection *StubSection = 
01044       TLOFMacho.getMachOSection("__TEXT", "__picsymbolstub1",
01045                                 MCSectionMachO::S_SYMBOL_STUBS |
01046                                 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
01047                                 32, SectionKind::getText());
01048      for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(), E = FnStubs.end();
01049          I != E; ++I) {
01050       OutStreamer.SwitchSection(StubSection);
01051       EmitAlignment(4);
01052       const FnStubInfo &Info = I->second;
01053       O << Info.Stub << ":\n";
01054       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
01055       O << "\tmflr r0\n";
01056       O << "\tbcl 20,31," << Info.AnonSymbol << '\n';
01057       O << Info.AnonSymbol << ":\n";
01058       O << "\tmflr r11\n";
01059       O << "\taddis r11,r11,ha16(" << Info.LazyPtr << "-" << Info.AnonSymbol;
01060       O << ")\n";
01061       O << "\tmtlr r0\n";
01062       O << (isPPC64 ? "\tldu" : "\tlwzu") << " r12,lo16(";
01063       O << Info.LazyPtr << "-" << Info.AnonSymbol << ")(r11)\n";
01064       O << "\tmtctr r12\n";
01065       O << "\tbctr\n";
01066       
01067       OutStreamer.SwitchSection(LSPSection);
01068       O << Info.LazyPtr << ":\n";
01069       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
01070       O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";
01071     }
01072   } else if (!FnStubs.empty()) {
01073     const MCSection *StubSection =
01074       TLOFMacho.getMachOSection("__TEXT","__symbol_stub1",
01075                                 MCSectionMachO::S_SYMBOL_STUBS |
01076                                 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
01077                                 16, SectionKind::getText());
01078     
01079     for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(), E = FnStubs.end();
01080          I != E; ++I) {
01081       OutStreamer.SwitchSection(StubSection);
01082       EmitAlignment(4);
01083       const FnStubInfo &Info = I->second;
01084       O << Info.Stub << ":\n";
01085       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
01086       O << "\tlis r11,ha16(" << Info.LazyPtr << ")\n";
01087       O << (isPPC64 ? "\tldu" :  "\tlwzu") << " r12,lo16(";
01088       O << Info.LazyPtr << ")(r11)\n";
01089       O << "\tmtctr r12\n";
01090       O << "\tbctr\n";
01091       OutStreamer.SwitchSection(LSPSection);
01092       O << Info.LazyPtr << ":\n";
01093       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
01094       O << (isPPC64 ? "\t.quad" : "\t.long") << " dyld_stub_binding_helper\n";
01095     }
01096   }
01097 
01098   O << '\n';
01099 
01100   if (TAI->doesSupportExceptionHandling() && MMI) {
01101     // Add the (possibly multiple) personalities to the set of global values.
01102     // Only referenced functions get into the Personalities list.
01103     const std::vector<Function *> &Personalities = MMI->getPersonalities();
01104     for (std::vector<Function *>::const_iterator I = Personalities.begin(),
01105          E = Personalities.end(); I != E; ++I) {
01106       if (*I)
01107         GVStubs[Mang->getMangledName(*I)] =
01108           Mang->getMangledName(*I, "$non_lazy_ptr", true);
01109     }
01110   }
01111 
01112   // Output macho stubs for external and common global variables.
01113   if (!GVStubs.empty()) {
01114     // Switch with ".non_lazy_symbol_pointer" directive.
01115     OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
01116     EmitAlignment(isPPC64 ? 3 : 2);
01117     
01118     for (StringMap<std::string>::iterator I = GVStubs.begin(),
01119          E = GVStubs.end(); I != E; ++I) {
01120       O << I->second << ":\n";
01121       O << "\t.indirect_symbol " << I->getKeyData() << '\n';
01122       O << (isPPC64 ? "\t.quad\t0\n" : "\t.long\t0\n");
01123     }
01124   }
01125 
01126   if (!HiddenGVStubs.empty()) {
01127     OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
01128     EmitAlignment(isPPC64 ? 3 : 2);
01129     for (StringMap<std::string>::iterator I = HiddenGVStubs.begin(),
01130          E = HiddenGVStubs.end(); I != E; ++I) {
01131       O << I->second << ":\n";
01132       O << (isPPC64 ? "\t.quad\t" : "\t.long\t") << I->getKeyData() << '\n';
01133     }
01134   }
01135 
01136   // Funny Darwin hack: This flag tells the linker that no global symbols
01137   // contain code that falls through to other global symbols (e.g. the obvious
01138   // implementation of multiple entry points).  If this doesn't occur, the
01139   // linker can safely perform dead code stripping.  Since LLVM never generates
01140   // code that does this, it is always safe to set.
01141   O << "\t.subsections_via_symbols\n";
01142 
01143   return AsmPrinter::doFinalization(M);
01144 }
01145 
01146 
01147 
01148 /// createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code
01149 /// for a MachineFunction to the given output stream, in a format that the
01150 /// Darwin assembler can deal with.
01151 ///
01152 static AsmPrinter *createPPCAsmPrinterPass(formatted_raw_ostream &o,
01153                                            TargetMachine &tm,
01154                                            const TargetAsmInfo *tai,
01155                                            bool verbose) {
01156   const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>();
01157 
01158   if (Subtarget->isDarwin())
01159     return new PPCDarwinAsmPrinter(o, tm, tai, verbose);
01160   return new PPCLinuxAsmPrinter(o, tm, tai, verbose);
01161 }
01162 
01163 // Force static initialization.
01164 extern "C" void LLVMInitializePowerPCAsmPrinter() { 
01165   TargetRegistry::RegisterAsmPrinter(ThePPC32Target, createPPCAsmPrinterPass);
01166   TargetRegistry::RegisterAsmPrinter(ThePPC64Target, createPPCAsmPrinterPass);
01167 }