1 //===-- PPCAsmPrinter.cpp - Print machine instrs to PowerPC assembly --------=//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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'.
14 // Documentation at http://developer.apple.com/documentation/DeveloperTools/
15 // Reference/Assembler/ASMIntroduction/chapter_1_section_1.html
17 //===----------------------------------------------------------------------===//
19 #define DEBUG_TYPE "asmprinter"
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/MachineDebugInfo.h"
31 #include "llvm/CodeGen/MachineFunctionPass.h"
32 #include "llvm/CodeGen/MachineInstr.h"
33 #include "llvm/Support/Mangler.h"
34 #include "llvm/Support/MathExtras.h"
35 #include "llvm/Support/CommandLine.h"
36 #include "llvm/Support/Debug.h"
37 #include "llvm/Support/Compiler.h"
38 #include "llvm/Target/TargetAsmInfo.h"
39 #include "llvm/Target/MRegisterInfo.h"
40 #include "llvm/Target/TargetInstrInfo.h"
41 #include "llvm/Target/TargetOptions.h"
42 #include "llvm/ADT/Statistic.h"
43 #include "llvm/ADT/StringExtras.h"
48 Statistic EmittedInsts("asm-printer", "Number of machine instrs printed");
50 struct VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
51 std::set<std::string> FnStubs, GVStubs;
52 const PPCSubtarget &Subtarget;
54 // Necessary for external weak linkage support
55 std::set<std::string> ExtWeakSymbols;
57 PPCAsmPrinter(std::ostream &O, TargetMachine &TM, const TargetAsmInfo *T)
58 : AsmPrinter(O, TM, T), Subtarget(TM.getSubtarget<PPCSubtarget>()) {
61 virtual const char *getPassName() const {
62 return "PowerPC Assembly Printer";
65 PPCTargetMachine &getTM() {
66 return static_cast<PPCTargetMachine&>(TM);
69 unsigned enumRegToMachineReg(unsigned enumReg) {
71 default: assert(0 && "Unhandled register!"); break;
72 case PPC::CR0: return 0;
73 case PPC::CR1: return 1;
74 case PPC::CR2: return 2;
75 case PPC::CR3: return 3;
76 case PPC::CR4: return 4;
77 case PPC::CR5: return 5;
78 case PPC::CR6: return 6;
79 case PPC::CR7: return 7;
84 /// printInstruction - This method is automatically generated by tablegen
85 /// from the instruction set description. This method returns true if the
86 /// machine instruction was sufficiently described to print it, otherwise it
88 bool printInstruction(const MachineInstr *MI);
90 void printMachineInstruction(const MachineInstr *MI);
91 void printOp(const MachineOperand &MO);
93 void printOperand(const MachineInstr *MI, unsigned OpNo) {
94 const MachineOperand &MO = MI->getOperand(OpNo);
95 if (MO.isRegister()) {
96 assert(MRegisterInfo::isPhysicalRegister(MO.getReg())&&"Not physreg??");
97 O << TM.getRegisterInfo()->get(MO.getReg()).Name;
98 } else if (MO.isImmediate()) {
99 O << MO.getImmedValue();
105 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
106 unsigned AsmVariant, const char *ExtraCode);
107 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
108 unsigned AsmVariant, const char *ExtraCode);
111 void printS5ImmOperand(const MachineInstr *MI, unsigned OpNo) {
112 char value = MI->getOperand(OpNo).getImmedValue();
113 value = (value << (32-5)) >> (32-5);
116 void printU5ImmOperand(const MachineInstr *MI, unsigned OpNo) {
117 unsigned char value = MI->getOperand(OpNo).getImmedValue();
118 assert(value <= 31 && "Invalid u5imm argument!");
119 O << (unsigned int)value;
121 void printU6ImmOperand(const MachineInstr *MI, unsigned OpNo) {
122 unsigned char value = MI->getOperand(OpNo).getImmedValue();
123 assert(value <= 63 && "Invalid u6imm argument!");
124 O << (unsigned int)value;
126 void printS16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
127 O << (short)MI->getOperand(OpNo).getImmedValue();
129 void printU16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
130 O << (unsigned short)MI->getOperand(OpNo).getImmedValue();
132 void printS16X4ImmOperand(const MachineInstr *MI, unsigned OpNo) {
133 if (MI->getOperand(OpNo).isImmediate()) {
134 O << (short)(MI->getOperand(OpNo).getImmedValue()*4);
137 printOp(MI->getOperand(OpNo));
138 if (TM.getRelocationModel() == Reloc::PIC_)
139 O << "-\"L" << getFunctionNumber() << "$pb\")";
144 void printBranchOperand(const MachineInstr *MI, unsigned OpNo) {
145 // Branches can take an immediate operand. This is used by the branch
146 // selection pass to print $+8, an eight byte displacement from the PC.
147 if (MI->getOperand(OpNo).isImmediate()) {
148 O << "$+" << MI->getOperand(OpNo).getImmedValue()*4;
150 printOp(MI->getOperand(OpNo));
153 void printCallOperand(const MachineInstr *MI, unsigned OpNo) {
154 const MachineOperand &MO = MI->getOperand(OpNo);
155 if (TM.getRelocationModel() != Reloc::Static) {
156 if (MO.getType() == MachineOperand::MO_GlobalAddress) {
157 GlobalValue *GV = MO.getGlobal();
158 if (((GV->isExternal() || GV->hasWeakLinkage() ||
159 GV->hasLinkOnceLinkage()))) {
160 // Dynamically-resolved functions need a stub for the function.
161 std::string Name = Mang->getValueName(GV);
162 FnStubs.insert(Name);
163 O << "L" << Name << "$stub";
164 if (GV->hasExternalWeakLinkage())
165 ExtWeakSymbols.insert(Name);
169 if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
170 std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
171 FnStubs.insert(Name);
172 O << "L" << Name << "$stub";
177 printOp(MI->getOperand(OpNo));
179 void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo) {
180 O << (int)MI->getOperand(OpNo).getImmedValue()*4;
182 void printPICLabel(const MachineInstr *MI, unsigned OpNo) {
183 O << "\"L" << getFunctionNumber() << "$pb\"\n";
184 O << "\"L" << getFunctionNumber() << "$pb\":";
186 void printSymbolHi(const MachineInstr *MI, unsigned OpNo) {
187 if (MI->getOperand(OpNo).isImmediate()) {
188 printS16ImmOperand(MI, OpNo);
191 printOp(MI->getOperand(OpNo));
192 if (TM.getRelocationModel() == Reloc::PIC_)
193 O << "-\"L" << getFunctionNumber() << "$pb\")";
198 void printSymbolLo(const MachineInstr *MI, unsigned OpNo) {
199 if (MI->getOperand(OpNo).isImmediate()) {
200 printS16ImmOperand(MI, OpNo);
203 printOp(MI->getOperand(OpNo));
204 if (TM.getRelocationModel() == Reloc::PIC_)
205 O << "-\"L" << getFunctionNumber() << "$pb\")";
210 void printcrbitm(const MachineInstr *MI, unsigned OpNo) {
211 unsigned CCReg = MI->getOperand(OpNo).getReg();
212 unsigned RegNo = enumRegToMachineReg(CCReg);
213 O << (0x80 >> RegNo);
215 // The new addressing mode printers.
216 void printMemRegImm(const MachineInstr *MI, unsigned OpNo) {
217 printSymbolLo(MI, OpNo);
219 if (MI->getOperand(OpNo+1).isRegister() &&
220 MI->getOperand(OpNo+1).getReg() == PPC::R0)
223 printOperand(MI, OpNo+1);
226 void printMemRegImmShifted(const MachineInstr *MI, unsigned OpNo) {
227 if (MI->getOperand(OpNo).isImmediate())
228 printS16X4ImmOperand(MI, OpNo);
230 printSymbolLo(MI, OpNo);
232 if (MI->getOperand(OpNo+1).isRegister() &&
233 MI->getOperand(OpNo+1).getReg() == PPC::R0)
236 printOperand(MI, OpNo+1);
240 void printMemRegReg(const MachineInstr *MI, unsigned OpNo) {
241 // When used as the base register, r0 reads constant zero rather than
242 // the value contained in the register. For this reason, the darwin
243 // assembler requires that we print r0 as 0 (no r) when used as the base.
244 const MachineOperand &MO = MI->getOperand(OpNo);
245 if (MO.getReg() == PPC::R0)
248 O << TM.getRegisterInfo()->get(MO.getReg()).Name;
250 printOperand(MI, OpNo+1);
253 void printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
254 const char *Modifier);
256 virtual bool runOnMachineFunction(MachineFunction &F) = 0;
257 virtual bool doFinalization(Module &M) = 0;
260 /// DarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac OS
262 struct VISIBILITY_HIDDEN DarwinAsmPrinter : public PPCAsmPrinter {
266 DarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM,
267 const TargetAsmInfo *T)
268 : PPCAsmPrinter(O, TM, T), DW(O, this, T) {
271 virtual const char *getPassName() const {
272 return "Darwin PPC Assembly Printer";
275 bool runOnMachineFunction(MachineFunction &F);
276 bool doInitialization(Module &M);
277 bool doFinalization(Module &M);
279 void getAnalysisUsage(AnalysisUsage &AU) const {
280 AU.setPreservesAll();
281 AU.addRequired<MachineDebugInfo>();
282 PPCAsmPrinter::getAnalysisUsage(AU);
285 /// getSectionForFunction - Return the section that we should emit the
286 /// specified function body into.
287 virtual std::string getSectionForFunction(const Function &F) const;
289 } // end of anonymous namespace
291 // Include the auto-generated portion of the assembly writer
292 #include "PPCGenAsmWriter.inc"
294 void PPCAsmPrinter::printOp(const MachineOperand &MO) {
295 switch (MO.getType()) {
296 case MachineOperand::MO_Immediate:
297 cerr << "printOp() does not handle immediate values\n";
301 case MachineOperand::MO_MachineBasicBlock:
302 printBasicBlockLabel(MO.getMachineBasicBlock());
304 case MachineOperand::MO_JumpTableIndex:
305 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
306 << '_' << MO.getJumpTableIndex();
307 // FIXME: PIC relocation model
309 case MachineOperand::MO_ConstantPoolIndex:
310 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
311 << '_' << MO.getConstantPoolIndex();
313 case MachineOperand::MO_ExternalSymbol:
314 // Computing the address of an external symbol, not calling it.
315 if (TM.getRelocationModel() != Reloc::Static) {
316 std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
317 GVStubs.insert(Name);
318 O << "L" << Name << "$non_lazy_ptr";
321 O << TAI->getGlobalPrefix() << MO.getSymbolName();
323 case MachineOperand::MO_GlobalAddress: {
324 // Computing the address of a global symbol, not calling it.
325 GlobalValue *GV = MO.getGlobal();
326 std::string Name = Mang->getValueName(GV);
328 // External or weakly linked global variables need non-lazily-resolved stubs
329 if (TM.getRelocationModel() != Reloc::Static) {
330 if (((GV->isExternal() || GV->hasWeakLinkage() ||
331 GV->hasLinkOnceLinkage()))) {
332 GVStubs.insert(Name);
333 O << "L" << Name << "$non_lazy_ptr";
339 if (GV->hasExternalWeakLinkage())
340 ExtWeakSymbols.insert(Name);
345 O << "<unknown operand type: " << MO.getType() << ">";
350 /// PrintAsmOperand - Print out an operand for an inline asm expression.
352 bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
354 const char *ExtraCode) {
355 // Does this asm operand have a single letter operand modifier?
356 if (ExtraCode && ExtraCode[0]) {
357 if (ExtraCode[1] != 0) return true; // Unknown modifier.
359 switch (ExtraCode[0]) {
360 default: return true; // Unknown modifier.
361 case 'L': // Write second word of DImode reference.
362 // Verify that this operand has two consecutive registers.
363 if (!MI->getOperand(OpNo).isRegister() ||
364 OpNo+1 == MI->getNumOperands() ||
365 !MI->getOperand(OpNo+1).isRegister())
367 ++OpNo; // Return the high-part.
372 printOperand(MI, OpNo);
376 bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
378 const char *ExtraCode) {
379 if (ExtraCode && ExtraCode[0])
380 return true; // Unknown modifier.
381 printMemRegReg(MI, OpNo);
385 void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
386 const char *Modifier) {
387 assert(Modifier && "Must specify 'cc' or 'reg' as predicate op modifier!");
388 unsigned Code = MI->getOperand(OpNo).getImm();
389 if (!strcmp(Modifier, "cc")) {
390 switch ((PPC::Predicate)Code) {
391 case PPC::PRED_ALWAYS: return; // Don't print anything for always.
392 case PPC::PRED_LT: O << "lt"; return;
393 case PPC::PRED_LE: O << "le"; return;
394 case PPC::PRED_EQ: O << "eq"; return;
395 case PPC::PRED_GE: O << "ge"; return;
396 case PPC::PRED_GT: O << "gt"; return;
397 case PPC::PRED_NE: O << "ne"; return;
398 case PPC::PRED_UN: O << "un"; return;
399 case PPC::PRED_NU: O << "nu"; return;
403 assert(!strcmp(Modifier, "reg") &&
404 "Need to specify 'cc' or 'reg' as predicate op modifier!");
405 // Don't print the register for 'always'.
406 if (Code == PPC::PRED_ALWAYS) return;
407 printOperand(MI, OpNo+1);
412 /// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to
413 /// the current output stream.
415 void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
418 // Check for slwi/srwi mnemonics.
419 if (MI->getOpcode() == PPC::RLWINM) {
420 bool FoundMnemonic = false;
421 unsigned char SH = MI->getOperand(2).getImmedValue();
422 unsigned char MB = MI->getOperand(3).getImmedValue();
423 unsigned char ME = MI->getOperand(4).getImmedValue();
424 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
425 O << "slwi "; FoundMnemonic = true;
427 if (SH <= 31 && MB == (32-SH) && ME == 31) {
428 O << "srwi "; FoundMnemonic = true;
435 O << ", " << (unsigned int)SH << "\n";
438 } else if (MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) {
439 if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
447 } else if (MI->getOpcode() == PPC::RLDICR) {
448 unsigned char SH = MI->getOperand(2).getImmedValue();
449 unsigned char ME = MI->getOperand(3).getImmedValue();
450 // rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH
456 O << ", " << (unsigned int)SH << "\n";
461 if (printInstruction(MI))
462 return; // Printer was automatically generated
464 assert(0 && "Unhandled instruction in asm writer!");
471 std::string DarwinAsmPrinter::getSectionForFunction(const Function &F) const {
472 switch (F.getLinkage()) {
473 default: assert(0 && "Unknown linkage type!");
474 case Function::ExternalLinkage:
475 case Function::InternalLinkage: return TAI->getTextSection();
476 case Function::WeakLinkage:
477 case Function::LinkOnceLinkage:
478 return ".section __TEXT,__textcoal_nt,coalesced,pure_instructions";
482 /// runOnMachineFunction - This uses the printMachineInstruction()
483 /// method to print assembly for each instruction.
485 bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
486 DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
488 SetupMachineFunction(MF);
491 // Print out constants referenced by the function
492 EmitConstantPool(MF.getConstantPool());
494 // Print out labels for the function.
495 const Function *F = MF.getFunction();
496 SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
498 switch (F->getLinkage()) {
499 default: assert(0 && "Unknown linkage type!");
500 case Function::InternalLinkage: // Symbols default to internal.
502 case Function::ExternalLinkage:
503 O << "\t.globl\t" << CurrentFnName << "\n";
505 case Function::WeakLinkage:
506 case Function::LinkOnceLinkage:
507 O << "\t.globl\t" << CurrentFnName << "\n";
508 O << "\t.weak_definition\t" << CurrentFnName << "\n";
512 O << CurrentFnName << ":\n";
514 // Emit pre-function debug information.
515 DW.BeginFunction(&MF);
517 // Print out code for the function.
518 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
520 // Print a label for the basic block.
521 if (I != MF.begin()) {
522 printBasicBlockLabel(I, true);
525 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
527 // Print the assembly for the instruction.
529 printMachineInstruction(II);
533 // Print out jump tables referenced by the function.
534 EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
536 // Emit post-function debug information.
539 // We didn't modify anything.
544 bool DarwinAsmPrinter::doInitialization(Module &M) {
545 const std::string &CPU = Subtarget.getCPU();
547 if (CPU != "generic")
548 O << "\t.machine ppc" << CPU << "\n";
549 else if (Subtarget.isGigaProcessor())
550 O << "\t.machine ppc970\n";
551 else if (Subtarget.isPPC64())
552 O << "\t.machine ppc64\n";
553 else if (Subtarget.hasAltivec())
554 O << "\t.machine ppc7400\n";
556 O << "\t.machine ppc\n";
558 AsmPrinter::doInitialization(M);
560 // Darwin wants symbols to be quoted if they have complex names.
561 Mang->setUseQuotes(true);
563 // Prime text sections so they are adjacent. This reduces the likelihood a
564 // large data or debug section causes a branch to exceed 16M limit.
565 SwitchToTextSection(".section __TEXT,__textcoal_nt,coalesced,"
566 "pure_instructions");
567 if (TM.getRelocationModel() == Reloc::PIC_) {
568 SwitchToTextSection(".section __TEXT,__picsymbolstub1,symbol_stubs,"
569 "pure_instructions,32");
570 } else if (TM.getRelocationModel() == Reloc::DynamicNoPIC) {
571 SwitchToTextSection(".section __TEXT,__symbol_stub1,symbol_stubs,"
572 "pure_instructions,16");
574 SwitchToTextSection(TAI->getTextSection());
576 // Emit initial debug information.
581 bool DarwinAsmPrinter::doFinalization(Module &M) {
582 const TargetData *TD = TM.getTargetData();
584 // Print out module-level global variables here.
585 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
587 if (!I->hasInitializer()) continue; // External global require no code
589 // Check to see if this is a special global used by LLVM, if so, emit it.
590 if (EmitSpecialLLVMGlobal(I))
593 std::string name = Mang->getValueName(I);
594 Constant *C = I->getInitializer();
595 unsigned Size = TD->getTypeSize(C->getType());
596 unsigned Align = TD->getPreferredAlignmentLog(I);
598 if (C->isNullValue() && /* FIXME: Verify correct */
599 (I->hasInternalLinkage() || I->hasWeakLinkage() ||
600 I->hasLinkOnceLinkage() ||
601 (I->hasExternalLinkage() && !I->hasSection()))) {
602 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
603 if (I->hasExternalLinkage()) {
604 O << "\t.globl " << name << '\n';
605 O << "\t.zerofill __DATA, __common, " << name << ", "
606 << Size << ", " << Align;
607 } else if (I->hasInternalLinkage()) {
608 SwitchToDataSection("\t.data", I);
609 O << TAI->getLCOMMDirective() << name << "," << Size << "," << Align;
611 SwitchToDataSection("\t.data", I);
612 O << ".comm " << name << "," << Size;
614 O << "\t\t; '" << I->getName() << "'\n";
616 switch (I->getLinkage()) {
617 case GlobalValue::LinkOnceLinkage:
618 case GlobalValue::WeakLinkage:
619 O << "\t.globl " << name << '\n'
620 << "\t.weak_definition " << name << '\n';
621 SwitchToDataSection(".section __DATA,__datacoal_nt,coalesced", I);
623 case GlobalValue::AppendingLinkage:
624 // FIXME: appending linkage variables should go into a section of
625 // their name or something. For now, just emit them as external.
626 case GlobalValue::ExternalLinkage:
627 // If external or appending, declare as a global symbol
628 O << "\t.globl " << name << "\n";
630 case GlobalValue::InternalLinkage:
631 if (I->isConstant()) {
632 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
633 if (TAI->getCStringSection() && CVA && CVA->isCString()) {
634 SwitchToDataSection(TAI->getCStringSection(), I);
639 SwitchToDataSection("\t.data", I);
642 cerr << "Unknown linkage type!";
646 EmitAlignment(Align, I);
647 O << name << ":\t\t\t\t; '" << I->getName() << "'\n";
649 // If the initializer is a extern weak symbol, remember to emit the weak
651 if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
652 if (GV->hasExternalWeakLinkage())
653 ExtWeakSymbols.insert(Mang->getValueName(GV));
655 EmitGlobalConstant(C);
660 if (TAI->getWeakRefDirective()) {
661 if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
662 SwitchToDataSection("");
663 for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
664 e = ExtWeakSymbols.end(); i != e; ++i) {
665 O << TAI->getWeakRefDirective() << *i << "\n";
669 bool isPPC64 = TD->getPointerSizeInBits() == 64;
671 // Output stubs for dynamically-linked functions
672 if (TM.getRelocationModel() == Reloc::PIC_) {
673 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
675 SwitchToTextSection(".section __TEXT,__picsymbolstub1,symbol_stubs,"
676 "pure_instructions,32");
678 O << "L" << *i << "$stub:\n";
679 O << "\t.indirect_symbol " << *i << "\n";
681 O << "\tbcl 20,31,L0$" << *i << "\n";
682 O << "L0$" << *i << ":\n";
684 O << "\taddis r11,r11,ha16(L" << *i << "$lazy_ptr-L0$" << *i << ")\n";
687 O << "\tldu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n";
689 O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr-L0$" << *i << ")(r11)\n";
690 O << "\tmtctr r12\n";
692 SwitchToDataSection(".lazy_symbol_pointer");
693 O << "L" << *i << "$lazy_ptr:\n";
694 O << "\t.indirect_symbol " << *i << "\n";
696 O << "\t.quad dyld_stub_binding_helper\n";
698 O << "\t.long dyld_stub_binding_helper\n";
701 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
703 SwitchToTextSection(".section __TEXT,__symbol_stub1,symbol_stubs,"
704 "pure_instructions,16");
706 O << "L" << *i << "$stub:\n";
707 O << "\t.indirect_symbol " << *i << "\n";
708 O << "\tlis r11,ha16(L" << *i << "$lazy_ptr)\n";
710 O << "\tldu r12,lo16(L" << *i << "$lazy_ptr)(r11)\n";
712 O << "\tlwzu r12,lo16(L" << *i << "$lazy_ptr)(r11)\n";
713 O << "\tmtctr r12\n";
715 SwitchToDataSection(".lazy_symbol_pointer");
716 O << "L" << *i << "$lazy_ptr:\n";
717 O << "\t.indirect_symbol " << *i << "\n";
719 O << "\t.quad dyld_stub_binding_helper\n";
721 O << "\t.long dyld_stub_binding_helper\n";
727 // Output stubs for external and common global variables.
728 if (GVStubs.begin() != GVStubs.end()) {
729 SwitchToDataSection(".non_lazy_symbol_pointer");
730 for (std::set<std::string>::iterator I = GVStubs.begin(),
731 E = GVStubs.end(); I != E; ++I) {
732 O << "L" << *I << "$non_lazy_ptr:\n";
733 O << "\t.indirect_symbol " << *I << "\n";
742 // Emit initial debug information.
745 // Funny Darwin hack: This flag tells the linker that no global symbols
746 // contain code that falls through to other global symbols (e.g. the obvious
747 // implementation of multiple entry points). If this doesn't occur, the
748 // linker can safely perform dead code stripping. Since LLVM never generates
749 // code that does this, it is always safe to set.
750 O << "\t.subsections_via_symbols\n";
752 AsmPrinter::doFinalization(M);
753 return false; // success
758 /// createDarwinCodePrinterPass - Returns a pass that prints the PPC assembly
759 /// code for a MachineFunction to the given output stream, in a format that the
760 /// Darwin assembler can deal with.
762 FunctionPass *llvm::createPPCAsmPrinterPass(std::ostream &o,
763 PPCTargetMachine &tm) {
764 return new DarwinAsmPrinter(o, tm, tm.getTargetAsmInfo());