1 //===-- PPCAsmPrinter.cpp - Print machine instrs to PowerPC assembly --------=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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/Analysis/DebugInfo.h"
25 #include "llvm/Constants.h"
26 #include "llvm/DerivedTypes.h"
27 #include "llvm/Module.h"
28 #include "llvm/Assembly/Writer.h"
29 #include "llvm/CodeGen/AsmPrinter.h"
30 #include "llvm/CodeGen/MachineFunctionPass.h"
31 #include "llvm/CodeGen/MachineInstr.h"
32 #include "llvm/CodeGen/MachineInstrBuilder.h"
33 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
34 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
35 #include "llvm/MC/MCAsmInfo.h"
36 #include "llvm/MC/MCContext.h"
37 #include "llvm/MC/MCExpr.h"
38 #include "llvm/MC/MCInst.h"
39 #include "llvm/MC/MCSectionMachO.h"
40 #include "llvm/MC/MCStreamer.h"
41 #include "llvm/MC/MCSymbol.h"
42 #include "llvm/Target/Mangler.h"
43 #include "llvm/Target/TargetRegisterInfo.h"
44 #include "llvm/Target/TargetInstrInfo.h"
45 #include "llvm/Target/TargetOptions.h"
46 #include "llvm/Target/TargetRegistry.h"
47 #include "llvm/Support/CommandLine.h"
48 #include "llvm/Support/Debug.h"
49 #include "llvm/Support/MathExtras.h"
50 #include "llvm/Support/ErrorHandling.h"
51 #include "llvm/Support/raw_ostream.h"
52 #include "llvm/ADT/StringExtras.h"
53 #include "llvm/ADT/StringSet.h"
54 #include "llvm/ADT/SmallString.h"
55 #include "InstPrinter/PPCInstPrinter.h"
59 class PPCAsmPrinter : public AsmPrinter {
61 DenseMap<MCSymbol*, MCSymbol*> TOC;
62 const PPCSubtarget &Subtarget;
65 explicit PPCAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
66 : AsmPrinter(TM, Streamer),
67 Subtarget(TM.getSubtarget<PPCSubtarget>()), TOCLabelID(0) {}
69 virtual const char *getPassName() const {
70 return "PowerPC Assembly Printer";
74 virtual void EmitInstruction(const MachineInstr *MI);
76 void printOperand(const MachineInstr *MI, unsigned OpNo, raw_ostream &O);
78 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
79 unsigned AsmVariant, const char *ExtraCode,
81 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
82 unsigned AsmVariant, const char *ExtraCode,
85 MachineLocation getDebugValueLocation(const MachineInstr *MI) const {
86 MachineLocation Location;
87 assert(MI->getNumOperands() == 4 && "Invalid no. of machine operands!");
88 // Frame address. Currently handles register +- offset only.
89 if (MI->getOperand(0).isReg() && MI->getOperand(2).isImm())
90 Location.set(MI->getOperand(0).getReg(), MI->getOperand(2).getImm());
92 DEBUG(dbgs() << "DBG_VALUE instruction ignored! " << *MI << "\n");
98 /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
99 class PPCLinuxAsmPrinter : public PPCAsmPrinter {
101 explicit PPCLinuxAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
102 : PPCAsmPrinter(TM, Streamer) {}
104 virtual const char *getPassName() const {
105 return "Linux PPC Assembly Printer";
108 bool doFinalization(Module &M);
110 virtual void EmitFunctionEntryLabel();
113 /// PPCDarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac
115 class PPCDarwinAsmPrinter : public PPCAsmPrinter {
117 explicit PPCDarwinAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
118 : PPCAsmPrinter(TM, Streamer) {}
120 virtual const char *getPassName() const {
121 return "Darwin PPC Assembly Printer";
124 bool doFinalization(Module &M);
125 void EmitStartOfAsmFile(Module &M);
127 void EmitFunctionStubs(const MachineModuleInfoMachO::SymbolListTy &Stubs);
129 } // end of anonymous namespace
131 /// stripRegisterPrefix - This method strips the character prefix from a
132 /// register name so that only the number is left. Used by for linux asm.
133 static const char *stripRegisterPrefix(const char *RegName) {
134 switch (RegName[0]) {
137 case 'v': return RegName + 1;
138 case 'c': if (RegName[1] == 'r') return RegName + 2;
144 void PPCAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
146 const MachineOperand &MO = MI->getOperand(OpNo);
148 switch (MO.getType()) {
149 case MachineOperand::MO_Register: {
150 const char *RegName = PPCInstPrinter::getRegisterName(MO.getReg());
151 // Linux assembler (Others?) does not take register mnemonics.
152 // FIXME - What about special registers used in mfspr/mtspr?
153 if (!Subtarget.isDarwin()) RegName = stripRegisterPrefix(RegName);
157 case MachineOperand::MO_Immediate:
161 case MachineOperand::MO_MachineBasicBlock:
162 O << *MO.getMBB()->getSymbol();
164 case MachineOperand::MO_JumpTableIndex:
165 O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
166 << '_' << MO.getIndex();
167 // FIXME: PIC relocation model
169 case MachineOperand::MO_ConstantPoolIndex:
170 O << MAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
171 << '_' << MO.getIndex();
173 case MachineOperand::MO_BlockAddress:
174 O << *GetBlockAddressSymbol(MO.getBlockAddress());
176 case MachineOperand::MO_ExternalSymbol: {
177 // Computing the address of an external symbol, not calling it.
178 if (TM.getRelocationModel() == Reloc::Static) {
179 O << *GetExternalSymbolSymbol(MO.getSymbolName());
184 OutContext.GetOrCreateSymbol(StringRef(MAI->getGlobalPrefix())+
185 MO.getSymbolName()+"$non_lazy_ptr");
186 MachineModuleInfoImpl::StubValueTy &StubSym =
187 MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(NLPSym);
188 if (StubSym.getPointer() == 0)
189 StubSym = MachineModuleInfoImpl::
190 StubValueTy(GetExternalSymbolSymbol(MO.getSymbolName()), true);
195 case MachineOperand::MO_GlobalAddress: {
196 // Computing the address of a global symbol, not calling it.
197 const GlobalValue *GV = MO.getGlobal();
198 MCSymbol *SymToPrint;
200 // External or weakly linked global variables need non-lazily-resolved stubs
201 if (TM.getRelocationModel() != Reloc::Static &&
202 (GV->isDeclaration() || GV->isWeakForLinker())) {
203 if (!GV->hasHiddenVisibility()) {
204 SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
205 MachineModuleInfoImpl::StubValueTy &StubSym =
206 MMI->getObjFileInfo<MachineModuleInfoMachO>()
207 .getGVStubEntry(SymToPrint);
208 if (StubSym.getPointer() == 0)
209 StubSym = MachineModuleInfoImpl::
210 StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage());
211 } else if (GV->isDeclaration() || GV->hasCommonLinkage() ||
212 GV->hasAvailableExternallyLinkage()) {
213 SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
215 MachineModuleInfoImpl::StubValueTy &StubSym =
216 MMI->getObjFileInfo<MachineModuleInfoMachO>().
217 getHiddenGVStubEntry(SymToPrint);
218 if (StubSym.getPointer() == 0)
219 StubSym = MachineModuleInfoImpl::
220 StubValueTy(Mang->getSymbol(GV), !GV->hasInternalLinkage());
222 SymToPrint = Mang->getSymbol(GV);
225 SymToPrint = Mang->getSymbol(GV);
230 printOffset(MO.getOffset(), O);
235 O << "<unknown operand type: " << MO.getType() << ">";
240 /// PrintAsmOperand - Print out an operand for an inline asm expression.
242 bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
244 const char *ExtraCode, raw_ostream &O) {
245 // Does this asm operand have a single letter operand modifier?
246 if (ExtraCode && ExtraCode[0]) {
247 if (ExtraCode[1] != 0) return true; // Unknown modifier.
249 switch (ExtraCode[0]) {
250 default: return true; // Unknown modifier.
251 case 'c': // Don't print "$" before a global var name or constant.
252 break; // PPC never has a prefix.
253 case 'L': // Write second word of DImode reference.
254 // Verify that this operand has two consecutive registers.
255 if (!MI->getOperand(OpNo).isReg() ||
256 OpNo+1 == MI->getNumOperands() ||
257 !MI->getOperand(OpNo+1).isReg())
259 ++OpNo; // Return the high-part.
262 // Write 'i' if an integer constant, otherwise nothing. Used to print
264 if (MI->getOperand(OpNo).isImm())
270 printOperand(MI, OpNo, O);
274 // At the moment, all inline asm memory operands are a single register.
275 // In any case, the output of this routine should always be just one
276 // assembler operand.
278 bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
280 const char *ExtraCode,
282 if (ExtraCode && ExtraCode[0])
283 return true; // Unknown modifier.
284 assert(MI->getOperand(OpNo).isReg());
286 printOperand(MI, OpNo, O);
292 /// EmitInstruction -- Print out a single PowerPC MI in Darwin syntax to
293 /// the current output stream.
295 void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
298 // Lower multi-instruction pseudo operations.
299 switch (MI->getOpcode()) {
301 case PPC::MovePCtoLR:
302 case PPC::MovePCtoLR8: {
303 // Transform %LR = MovePCtoLR
304 // Into this, where the label is the PIC base:
307 MCSymbol *PICBase = MF->getPICBaseSymbol();
310 TmpInst.setOpcode(PPC::BL_Darwin); // Darwin vs SVR4 doesn't matter here.
313 // FIXME: We would like an efficient form for this, so we don't have to do
314 // a lot of extra uniquing.
315 TmpInst.addOperand(MCOperand::CreateExpr(MCSymbolRefExpr::
316 Create(PICBase, OutContext)));
317 OutStreamer.EmitInstruction(TmpInst);
320 OutStreamer.EmitLabel(PICBase);
324 // Transform %X3 = LDtoc <ga:@min1>, %X2
325 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
327 // Change the opcode to LD, and the global address operand to be a
328 // reference to the TOC entry we will synthesize later.
329 TmpInst.setOpcode(PPC::LD);
330 const MachineOperand &MO = MI->getOperand(1);
331 assert(MO.isGlobal());
333 // Map symbol -> label of TOC entry.
334 MCSymbol *&TOCEntry = TOC[Mang->getSymbol(MO.getGlobal())];
336 TOCEntry = GetTempSymbol("C", TOCLabelID++);
339 MCSymbolRefExpr::Create(TOCEntry, MCSymbolRefExpr::VK_PPC_TOC,
341 TmpInst.getOperand(1) = MCOperand::CreateExpr(Exp);
342 OutStreamer.EmitInstruction(TmpInst);
347 // Transform: %R3 = MFCRpseud %CR7
348 // Into: %R3 = MFCR ;; cr7
349 OutStreamer.AddComment(PPCInstPrinter::
350 getRegisterName(MI->getOperand(1).getReg()));
351 TmpInst.setOpcode(PPC::MFCR);
352 TmpInst.addOperand(MCOperand::CreateReg(MI->getOperand(0).getReg()));
353 OutStreamer.EmitInstruction(TmpInst);
357 LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
358 OutStreamer.EmitInstruction(TmpInst);
361 void PPCLinuxAsmPrinter::EmitFunctionEntryLabel() {
362 if (!Subtarget.isPPC64()) // linux/ppc32 - Normal entry label.
363 return AsmPrinter::EmitFunctionEntryLabel();
365 // Emit an official procedure descriptor.
366 // FIXME 64-bit SVR4: Use MCSection here!
367 OutStreamer.EmitRawText(StringRef("\t.section\t\".opd\",\"aw\""));
368 OutStreamer.EmitRawText(StringRef("\t.align 3"));
369 OutStreamer.EmitLabel(CurrentFnSym);
370 OutStreamer.EmitRawText("\t.quad .L." + Twine(CurrentFnSym->getName()) +
372 OutStreamer.EmitRawText(StringRef("\t.previous"));
373 OutStreamer.EmitRawText(".L." + Twine(CurrentFnSym->getName()) + ":");
377 bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
378 const TargetData *TD = TM.getTargetData();
380 bool isPPC64 = TD->getPointerSizeInBits() == 64;
382 if (isPPC64 && !TOC.empty()) {
383 // FIXME 64-bit SVR4: Use MCSection here?
384 OutStreamer.EmitRawText(StringRef("\t.section\t\".toc\",\"aw\""));
386 // FIXME: This is nondeterminstic!
387 for (DenseMap<MCSymbol*, MCSymbol*>::iterator I = TOC.begin(),
388 E = TOC.end(); I != E; ++I) {
389 OutStreamer.EmitLabel(I->second);
390 OutStreamer.EmitRawText("\t.tc " + Twine(I->first->getName()) +
391 "[TC]," + I->first->getName());
395 return AsmPrinter::doFinalization(M);
398 void PPCDarwinAsmPrinter::EmitStartOfAsmFile(Module &M) {
399 static const char *const CPUDirectives[] = {
411 unsigned Directive = Subtarget.getDarwinDirective();
412 if (Subtarget.isGigaProcessor() && Directive < PPC::DIR_970)
413 Directive = PPC::DIR_970;
414 if (Subtarget.hasAltivec() && Directive < PPC::DIR_7400)
415 Directive = PPC::DIR_7400;
416 if (Subtarget.isPPC64() && Directive < PPC::DIR_970)
417 Directive = PPC::DIR_64;
418 assert(Directive <= PPC::DIR_64 && "Directive out of range.");
419 OutStreamer.EmitRawText("\t.machine " + Twine(CPUDirectives[Directive]));
421 // Prime text sections so they are adjacent. This reduces the likelihood a
422 // large data or debug section causes a branch to exceed 16M limit.
423 const TargetLoweringObjectFileMachO &TLOFMacho =
424 static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
425 OutStreamer.SwitchSection(TLOFMacho.getTextCoalSection());
426 if (TM.getRelocationModel() == Reloc::PIC_) {
427 OutStreamer.SwitchSection(
428 OutContext.getMachOSection("__TEXT", "__picsymbolstub1",
429 MCSectionMachO::S_SYMBOL_STUBS |
430 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
431 32, SectionKind::getText()));
432 } else if (TM.getRelocationModel() == Reloc::DynamicNoPIC) {
433 OutStreamer.SwitchSection(
434 OutContext.getMachOSection("__TEXT","__symbol_stub1",
435 MCSectionMachO::S_SYMBOL_STUBS |
436 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
437 16, SectionKind::getText()));
439 OutStreamer.SwitchSection(getObjFileLowering().getTextSection());
442 static MCSymbol *GetLazyPtr(MCSymbol *Sym, MCContext &Ctx) {
443 // Remove $stub suffix, add $lazy_ptr.
444 SmallString<128> TmpStr(Sym->getName().begin(), Sym->getName().end()-5);
445 TmpStr += "$lazy_ptr";
446 return Ctx.GetOrCreateSymbol(TmpStr.str());
449 static MCSymbol *GetAnonSym(MCSymbol *Sym, MCContext &Ctx) {
450 // Add $tmp suffix to $stub, yielding $stub$tmp.
451 SmallString<128> TmpStr(Sym->getName().begin(), Sym->getName().end());
453 return Ctx.GetOrCreateSymbol(TmpStr.str());
456 void PPCDarwinAsmPrinter::
457 EmitFunctionStubs(const MachineModuleInfoMachO::SymbolListTy &Stubs) {
458 bool isPPC64 = TM.getTargetData()->getPointerSizeInBits() == 64;
460 const TargetLoweringObjectFileMachO &TLOFMacho =
461 static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
463 // .lazy_symbol_pointer
464 const MCSection *LSPSection = TLOFMacho.getLazySymbolPointerSection();
466 // Output stubs for dynamically-linked functions
467 if (TM.getRelocationModel() == Reloc::PIC_) {
468 const MCSection *StubSection =
469 OutContext.getMachOSection("__TEXT", "__picsymbolstub1",
470 MCSectionMachO::S_SYMBOL_STUBS |
471 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
472 32, SectionKind::getText());
473 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
474 OutStreamer.SwitchSection(StubSection);
477 MCSymbol *Stub = Stubs[i].first;
478 MCSymbol *RawSym = Stubs[i].second.getPointer();
479 MCSymbol *LazyPtr = GetLazyPtr(Stub, OutContext);
480 MCSymbol *AnonSymbol = GetAnonSym(Stub, OutContext);
482 OutStreamer.EmitLabel(Stub);
483 OutStreamer.EmitSymbolAttribute(RawSym, MCSA_IndirectSymbol);
484 // FIXME: MCize this.
485 OutStreamer.EmitRawText(StringRef("\tmflr r0"));
486 OutStreamer.EmitRawText("\tbcl 20,31," + Twine(AnonSymbol->getName()));
487 OutStreamer.EmitLabel(AnonSymbol);
488 OutStreamer.EmitRawText(StringRef("\tmflr r11"));
489 OutStreamer.EmitRawText("\taddis r11,r11,ha16("+Twine(LazyPtr->getName())+
490 "-" + AnonSymbol->getName() + ")");
491 OutStreamer.EmitRawText(StringRef("\tmtlr r0"));
494 OutStreamer.EmitRawText("\tldu r12,lo16(" + Twine(LazyPtr->getName()) +
495 "-" + AnonSymbol->getName() + ")(r11)");
497 OutStreamer.EmitRawText("\tlwzu r12,lo16(" + Twine(LazyPtr->getName()) +
498 "-" + AnonSymbol->getName() + ")(r11)");
499 OutStreamer.EmitRawText(StringRef("\tmtctr r12"));
500 OutStreamer.EmitRawText(StringRef("\tbctr"));
502 OutStreamer.SwitchSection(LSPSection);
503 OutStreamer.EmitLabel(LazyPtr);
504 OutStreamer.EmitSymbolAttribute(RawSym, MCSA_IndirectSymbol);
507 OutStreamer.EmitRawText(StringRef("\t.quad dyld_stub_binding_helper"));
509 OutStreamer.EmitRawText(StringRef("\t.long dyld_stub_binding_helper"));
511 OutStreamer.AddBlankLine();
515 const MCSection *StubSection =
516 OutContext.getMachOSection("__TEXT","__symbol_stub1",
517 MCSectionMachO::S_SYMBOL_STUBS |
518 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
519 16, SectionKind::getText());
520 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
521 MCSymbol *Stub = Stubs[i].first;
522 MCSymbol *RawSym = Stubs[i].second.getPointer();
523 MCSymbol *LazyPtr = GetLazyPtr(Stub, OutContext);
525 OutStreamer.SwitchSection(StubSection);
527 OutStreamer.EmitLabel(Stub);
528 OutStreamer.EmitSymbolAttribute(RawSym, MCSA_IndirectSymbol);
529 OutStreamer.EmitRawText("\tlis r11,ha16(" + Twine(LazyPtr->getName()) +")");
531 OutStreamer.EmitRawText("\tldu r12,lo16(" + Twine(LazyPtr->getName()) +
534 OutStreamer.EmitRawText("\tlwzu r12,lo16(" + Twine(LazyPtr->getName()) +
536 OutStreamer.EmitRawText(StringRef("\tmtctr r12"));
537 OutStreamer.EmitRawText(StringRef("\tbctr"));
538 OutStreamer.SwitchSection(LSPSection);
539 OutStreamer.EmitLabel(LazyPtr);
540 OutStreamer.EmitSymbolAttribute(RawSym, MCSA_IndirectSymbol);
543 OutStreamer.EmitRawText(StringRef("\t.quad dyld_stub_binding_helper"));
545 OutStreamer.EmitRawText(StringRef("\t.long dyld_stub_binding_helper"));
548 OutStreamer.AddBlankLine();
552 bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
553 bool isPPC64 = TM.getTargetData()->getPointerSizeInBits() == 64;
555 // Darwin/PPC always uses mach-o.
556 const TargetLoweringObjectFileMachO &TLOFMacho =
557 static_cast<const TargetLoweringObjectFileMachO &>(getObjFileLowering());
558 MachineModuleInfoMachO &MMIMacho =
559 MMI->getObjFileInfo<MachineModuleInfoMachO>();
561 MachineModuleInfoMachO::SymbolListTy Stubs = MMIMacho.GetFnStubList();
563 EmitFunctionStubs(Stubs);
565 if (MAI->doesSupportExceptionHandling() && MMI) {
566 // Add the (possibly multiple) personalities to the set of global values.
567 // Only referenced functions get into the Personalities list.
568 const std::vector<const Function*> &Personalities = MMI->getPersonalities();
569 for (std::vector<const Function*>::const_iterator I = Personalities.begin(),
570 E = Personalities.end(); I != E; ++I) {
572 MCSymbol *NLPSym = GetSymbolWithGlobalValueBase(*I, "$non_lazy_ptr");
573 MachineModuleInfoImpl::StubValueTy &StubSym =
574 MMIMacho.getGVStubEntry(NLPSym);
575 StubSym = MachineModuleInfoImpl::StubValueTy(Mang->getSymbol(*I), true);
580 // Output stubs for dynamically-linked functions.
581 Stubs = MMIMacho.GetGVStubList();
583 // Output macho stubs for external and common global variables.
584 if (!Stubs.empty()) {
585 // Switch with ".non_lazy_symbol_pointer" directive.
586 OutStreamer.SwitchSection(TLOFMacho.getNonLazySymbolPointerSection());
587 EmitAlignment(isPPC64 ? 3 : 2);
589 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
591 OutStreamer.EmitLabel(Stubs[i].first);
592 // .indirect_symbol _foo
593 MachineModuleInfoImpl::StubValueTy &MCSym = Stubs[i].second;
594 OutStreamer.EmitSymbolAttribute(MCSym.getPointer(), MCSA_IndirectSymbol);
597 // External to current translation unit.
598 OutStreamer.EmitIntValue(0, isPPC64 ? 8 : 4/*size*/, 0/*addrspace*/);
600 // Internal to current translation unit.
602 // When we place the LSDA into the TEXT section, the type info pointers
603 // need to be indirect and pc-rel. We accomplish this by using NLPs.
604 // However, sometimes the types are local to the file. So we need to
605 // fill in the value for the NLP in those cases.
606 OutStreamer.EmitValue(MCSymbolRefExpr::Create(MCSym.getPointer(),
608 isPPC64 ? 8 : 4/*size*/, 0/*addrspace*/);
612 OutStreamer.AddBlankLine();
615 Stubs = MMIMacho.GetHiddenGVStubList();
616 if (!Stubs.empty()) {
617 OutStreamer.SwitchSection(getObjFileLowering().getDataSection());
618 EmitAlignment(isPPC64 ? 3 : 2);
620 for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
622 OutStreamer.EmitLabel(Stubs[i].first);
624 OutStreamer.EmitValue(MCSymbolRefExpr::
625 Create(Stubs[i].second.getPointer(),
627 isPPC64 ? 8 : 4/*size*/, 0/*addrspace*/);
631 OutStreamer.AddBlankLine();
634 // Funny Darwin hack: This flag tells the linker that no global symbols
635 // contain code that falls through to other global symbols (e.g. the obvious
636 // implementation of multiple entry points). If this doesn't occur, the
637 // linker can safely perform dead code stripping. Since LLVM never generates
638 // code that does this, it is always safe to set.
639 OutStreamer.EmitAssemblerFlag(MCAF_SubsectionsViaSymbols);
641 return AsmPrinter::doFinalization(M);
644 /// createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code
645 /// for a MachineFunction to the given output stream, in a format that the
646 /// Darwin assembler can deal with.
648 static AsmPrinter *createPPCAsmPrinterPass(TargetMachine &tm,
649 MCStreamer &Streamer) {
650 const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>();
652 if (Subtarget->isDarwin())
653 return new PPCDarwinAsmPrinter(tm, Streamer);
654 return new PPCLinuxAsmPrinter(tm, Streamer);
657 static MCInstPrinter *createPPCMCInstPrinter(const Target &T,
658 unsigned SyntaxVariant,
659 const MCAsmInfo &MAI) {
660 return new PPCInstPrinter(MAI, SyntaxVariant);
664 // Force static initialization.
665 extern "C" void LLVMInitializePowerPCAsmPrinter() {
666 TargetRegistry::RegisterAsmPrinter(ThePPC32Target, createPPCAsmPrinterPass);
667 TargetRegistry::RegisterAsmPrinter(ThePPC64Target, createPPCAsmPrinterPass);
669 TargetRegistry::RegisterMCInstPrinter(ThePPC32Target, createPPCMCInstPrinter);
670 TargetRegistry::RegisterMCInstPrinter(ThePPC64Target, createPPCMCInstPrinter);