blob: 7f1673cf462e2844545014c4fe270e3e78257226 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- PPCAsmPrinter.cpp - Print machine instrs to PowerPC assembly --------=//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
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"
Devang Patelf667ab42009-06-25 00:47:42 +000027#include "llvm/MDNode.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000028#include "llvm/Assembly/Writer.h"
29#include "llvm/CodeGen/AsmPrinter.h"
30#include "llvm/CodeGen/DwarfWriter.h"
31#include "llvm/CodeGen/MachineModuleInfo.h"
32#include "llvm/CodeGen/MachineFunctionPass.h"
33#include "llvm/CodeGen/MachineInstr.h"
Bill Wendling36ccaea2008-01-26 06:51:24 +000034#include "llvm/CodeGen/MachineInstrBuilder.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035#include "llvm/Support/Mangler.h"
36#include "llvm/Support/MathExtras.h"
37#include "llvm/Support/CommandLine.h"
38#include "llvm/Support/Debug.h"
39#include "llvm/Support/Compiler.h"
Owen Anderson847b99b2008-08-21 00:14:44 +000040#include "llvm/Support/raw_ostream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041#include "llvm/Target/TargetAsmInfo.h"
Dan Gohman1e57df32008-02-10 18:45:23 +000042#include "llvm/Target/TargetRegisterInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000043#include "llvm/Target/TargetInstrInfo.h"
44#include "llvm/Target/TargetOptions.h"
45#include "llvm/ADT/Statistic.h"
46#include "llvm/ADT/StringExtras.h"
Evan Chenga65854f2008-12-05 01:06:39 +000047#include "llvm/ADT/StringSet.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000048using namespace llvm;
49
50STATISTIC(EmittedInsts, "Number of machine instrs printed");
51
52namespace {
Bill Wendling4f405312009-02-24 08:30:20 +000053 class VISIBILITY_HIDDEN PPCAsmPrinter : public AsmPrinter {
54 protected:
Evan Chenga65854f2008-12-05 01:06:39 +000055 StringSet<> FnStubs, GVStubs, HiddenGVStubs;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056 const PPCSubtarget &Subtarget;
Bill Wendling4f405312009-02-24 08:30:20 +000057 public:
Bill Wendling58ed5d22009-04-29 00:15:41 +000058 explicit PPCAsmPrinter(raw_ostream &O, TargetMachine &TM,
Daniel Dunbarb10d2222009-07-01 01:48:54 +000059 const TargetAsmInfo *T, bool V)
60 : AsmPrinter(O, TM, T, V),
Bill Wendling4f405312009-02-24 08:30:20 +000061 Subtarget(TM.getSubtarget<PPCSubtarget>()) {}
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062
63 virtual const char *getPassName() const {
64 return "PowerPC Assembly Printer";
65 }
66
67 PPCTargetMachine &getTM() {
68 return static_cast<PPCTargetMachine&>(TM);
69 }
70
71 unsigned enumRegToMachineReg(unsigned enumReg) {
72 switch (enumReg) {
73 default: assert(0 && "Unhandled register!"); break;
74 case PPC::CR0: return 0;
75 case PPC::CR1: return 1;
76 case PPC::CR2: return 2;
77 case PPC::CR3: return 3;
78 case PPC::CR4: return 4;
79 case PPC::CR5: return 5;
80 case PPC::CR6: return 6;
81 case PPC::CR7: return 7;
82 }
83 abort();
84 }
85
86 /// printInstruction - This method is automatically generated by tablegen
87 /// from the instruction set description. This method returns true if the
88 /// machine instruction was sufficiently described to print it, otherwise it
89 /// returns false.
90 bool printInstruction(const MachineInstr *MI);
91
92 void printMachineInstruction(const MachineInstr *MI);
93 void printOp(const MachineOperand &MO);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +000094
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095 /// stripRegisterPrefix - This method strips the character prefix from a
96 /// register name so that only the number is left. Used by for linux asm.
97 const char *stripRegisterPrefix(const char *RegName) {
98 switch (RegName[0]) {
99 case 'r':
100 case 'f':
101 case 'v': return RegName + 1;
102 case 'c': if (RegName[1] == 'r') return RegName + 2;
103 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000104
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000105 return RegName;
106 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000107
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000108 /// printRegister - Print register according to target requirements.
109 ///
110 void printRegister(const MachineOperand &MO, bool R0AsZero) {
111 unsigned RegNo = MO.getReg();
Dan Gohman1e57df32008-02-10 18:45:23 +0000112 assert(TargetRegisterInfo::isPhysicalRegister(RegNo) && "Not physreg??");
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000113
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000114 // If we should use 0 for R0.
115 if (R0AsZero && RegNo == PPC::R0) {
116 O << "0";
117 return;
118 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000119
Bill Wendling8eeb9792008-02-26 21:11:01 +0000120 const char *RegName = TM.getRegisterInfo()->get(RegNo).AsmName;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000121 // Linux assembler (Others?) does not take register mnemonics.
122 // FIXME - What about special registers used in mfspr/mtspr?
123 if (!Subtarget.isDarwin()) RegName = stripRegisterPrefix(RegName);
124 O << RegName;
125 }
126
127 void printOperand(const MachineInstr *MI, unsigned OpNo) {
128 const MachineOperand &MO = MI->getOperand(OpNo);
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000129 if (MO.isReg()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000130 printRegister(MO, false);
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000131 } else if (MO.isImm()) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000132 O << MO.getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000133 } else {
134 printOp(MO);
135 }
136 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000137
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000138 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
139 unsigned AsmVariant, const char *ExtraCode);
140 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
141 unsigned AsmVariant, const char *ExtraCode);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000142
143
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000144 void printS5ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000145 char value = MI->getOperand(OpNo).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000146 value = (value << (32-5)) >> (32-5);
147 O << (int)value;
148 }
149 void printU5ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000150 unsigned char value = MI->getOperand(OpNo).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000151 assert(value <= 31 && "Invalid u5imm argument!");
152 O << (unsigned int)value;
153 }
154 void printU6ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000155 unsigned char value = MI->getOperand(OpNo).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000156 assert(value <= 63 && "Invalid u6imm argument!");
157 O << (unsigned int)value;
158 }
159 void printS16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000160 O << (short)MI->getOperand(OpNo).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161 }
162 void printU16ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000163 O << (unsigned short)MI->getOperand(OpNo).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164 }
165 void printS16X4ImmOperand(const MachineInstr *MI, unsigned OpNo) {
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000166 if (MI->getOperand(OpNo).isImm()) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000167 O << (short)(MI->getOperand(OpNo).getImm()*4);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000168 } else {
169 O << "lo16(";
170 printOp(MI->getOperand(OpNo));
171 if (TM.getRelocationModel() == Reloc::PIC_)
Evan Cheng477013c2007-10-14 05:57:21 +0000172 O << "-\"L" << getFunctionNumber() << "$pb\")";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173 else
174 O << ')';
175 }
176 }
177 void printBranchOperand(const MachineInstr *MI, unsigned OpNo) {
178 // Branches can take an immediate operand. This is used by the branch
179 // selection pass to print $+8, an eight byte displacement from the PC.
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000180 if (MI->getOperand(OpNo).isImm()) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000181 O << "$+" << MI->getOperand(OpNo).getImm()*4;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000182 } else {
183 printOp(MI->getOperand(OpNo));
184 }
185 }
186 void printCallOperand(const MachineInstr *MI, unsigned OpNo) {
187 const MachineOperand &MO = MI->getOperand(OpNo);
188 if (TM.getRelocationModel() != Reloc::Static) {
189 if (MO.getType() == MachineOperand::MO_GlobalAddress) {
190 GlobalValue *GV = MO.getGlobal();
Chris Lattner0fd4feb2009-07-02 16:08:53 +0000191 if (GV->isDeclaration() || GV->isWeakForLinker()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000192 // Dynamically-resolved functions need a stub for the function.
193 std::string Name = Mang->getValueName(GV);
194 FnStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000195 printSuffixedName(Name, "$stub");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000196 return;
197 }
198 }
199 if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
200 std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
201 FnStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000202 printSuffixedName(Name, "$stub");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000203 return;
204 }
205 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000206
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000207 printOp(MI->getOperand(OpNo));
208 }
209 void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000210 O << (int)MI->getOperand(OpNo).getImm()*4;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000211 }
212 void printPICLabel(const MachineInstr *MI, unsigned OpNo) {
Evan Cheng477013c2007-10-14 05:57:21 +0000213 O << "\"L" << getFunctionNumber() << "$pb\"\n";
214 O << "\"L" << getFunctionNumber() << "$pb\":";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215 }
216 void printSymbolHi(const MachineInstr *MI, unsigned OpNo) {
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000217 if (MI->getOperand(OpNo).isImm()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218 printS16ImmOperand(MI, OpNo);
219 } else {
220 if (Subtarget.isDarwin()) O << "ha16(";
221 printOp(MI->getOperand(OpNo));
222 if (TM.getRelocationModel() == Reloc::PIC_)
Evan Cheng477013c2007-10-14 05:57:21 +0000223 O << "-\"L" << getFunctionNumber() << "$pb\"";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224 if (Subtarget.isDarwin())
225 O << ')';
226 else
227 O << "@ha";
228 }
229 }
230 void printSymbolLo(const MachineInstr *MI, unsigned OpNo) {
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000231 if (MI->getOperand(OpNo).isImm()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000232 printS16ImmOperand(MI, OpNo);
233 } else {
234 if (Subtarget.isDarwin()) O << "lo16(";
235 printOp(MI->getOperand(OpNo));
236 if (TM.getRelocationModel() == Reloc::PIC_)
Evan Cheng477013c2007-10-14 05:57:21 +0000237 O << "-\"L" << getFunctionNumber() << "$pb\"";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000238 if (Subtarget.isDarwin())
239 O << ')';
240 else
241 O << "@l";
242 }
243 }
244 void printcrbitm(const MachineInstr *MI, unsigned OpNo) {
245 unsigned CCReg = MI->getOperand(OpNo).getReg();
246 unsigned RegNo = enumRegToMachineReg(CCReg);
247 O << (0x80 >> RegNo);
248 }
249 // The new addressing mode printers.
250 void printMemRegImm(const MachineInstr *MI, unsigned OpNo) {
251 printSymbolLo(MI, OpNo);
252 O << '(';
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000253 if (MI->getOperand(OpNo+1).isReg() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000254 MI->getOperand(OpNo+1).getReg() == PPC::R0)
255 O << "0";
256 else
257 printOperand(MI, OpNo+1);
258 O << ')';
259 }
260 void printMemRegImmShifted(const MachineInstr *MI, unsigned OpNo) {
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000261 if (MI->getOperand(OpNo).isImm())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000262 printS16X4ImmOperand(MI, OpNo);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000263 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264 printSymbolLo(MI, OpNo);
265 O << '(';
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000266 if (MI->getOperand(OpNo+1).isReg() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000267 MI->getOperand(OpNo+1).getReg() == PPC::R0)
268 O << "0";
269 else
270 printOperand(MI, OpNo+1);
271 O << ')';
272 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000273
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000274 void printMemRegReg(const MachineInstr *MI, unsigned OpNo) {
275 // When used as the base register, r0 reads constant zero rather than
276 // the value contained in the register. For this reason, the darwin
277 // assembler requires that we print r0 as 0 (no r) when used as the base.
278 const MachineOperand &MO = MI->getOperand(OpNo);
279 printRegister(MO, true);
280 O << ", ";
281 printOperand(MI, OpNo+1);
282 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000283
284 void printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285 const char *Modifier);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000286
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287 virtual bool runOnMachineFunction(MachineFunction &F) = 0;
288 virtual bool doFinalization(Module &M) = 0;
289
290 virtual void EmitExternalGlobal(const GlobalVariable *GV);
291 };
292
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000293 /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
Bill Wendling4f405312009-02-24 08:30:20 +0000294 class VISIBILITY_HIDDEN PPCLinuxAsmPrinter : public PPCAsmPrinter {
Bill Wendling4f405312009-02-24 08:30:20 +0000295 public:
Bill Wendling58ed5d22009-04-29 00:15:41 +0000296 explicit PPCLinuxAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
Daniel Dunbarb10d2222009-07-01 01:48:54 +0000297 const TargetAsmInfo *T, bool V)
298 : PPCAsmPrinter(O, TM, T, V){}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000299
300 virtual const char *getPassName() const {
301 return "Linux PPC Assembly Printer";
302 }
303
304 bool runOnMachineFunction(MachineFunction &F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000305 bool doFinalization(Module &M);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000306
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307 void getAnalysisUsage(AnalysisUsage &AU) const {
308 AU.setPreservesAll();
309 AU.addRequired<MachineModuleInfo>();
Devang Patelaa1e8432009-01-08 23:40:34 +0000310 AU.addRequired<DwarfWriter>();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311 PPCAsmPrinter::getAnalysisUsage(AU);
312 }
313
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000314 void printModuleLevelGV(const GlobalVariable* GVar);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000315 };
316
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000317 /// PPCDarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac
318 /// OS X
Bill Wendling4f405312009-02-24 08:30:20 +0000319 class VISIBILITY_HIDDEN PPCDarwinAsmPrinter : public PPCAsmPrinter {
Devang Patelaa1e8432009-01-08 23:40:34 +0000320 raw_ostream &OS;
Bill Wendling4f405312009-02-24 08:30:20 +0000321 public:
Bill Wendling58ed5d22009-04-29 00:15:41 +0000322 explicit PPCDarwinAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
Daniel Dunbarb10d2222009-07-01 01:48:54 +0000323 const TargetAsmInfo *T, bool V)
324 : PPCAsmPrinter(O, TM, T, V), OS(O) {}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000325
326 virtual const char *getPassName() const {
327 return "Darwin PPC Assembly Printer";
328 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000329
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330 bool runOnMachineFunction(MachineFunction &F);
331 bool doInitialization(Module &M);
332 bool doFinalization(Module &M);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000333
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334 void getAnalysisUsage(AnalysisUsage &AU) const {
335 AU.setPreservesAll();
336 AU.addRequired<MachineModuleInfo>();
Devang Patelaa1e8432009-01-08 23:40:34 +0000337 AU.addRequired<DwarfWriter>();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338 PPCAsmPrinter::getAnalysisUsage(AU);
339 }
340
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000341 void printModuleLevelGV(const GlobalVariable* GVar);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000342 };
343} // end of anonymous namespace
344
345// Include the auto-generated portion of the assembly writer
346#include "PPCGenAsmWriter.inc"
347
348void PPCAsmPrinter::printOp(const MachineOperand &MO) {
349 switch (MO.getType()) {
350 case MachineOperand::MO_Immediate:
351 cerr << "printOp() does not handle immediate values\n";
352 abort();
353 return;
354
355 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner6017d482007-12-30 23:10:15 +0000356 printBasicBlockLabel(MO.getMBB());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357 return;
358 case MachineOperand::MO_JumpTableIndex:
Evan Cheng477013c2007-10-14 05:57:21 +0000359 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Chris Lattner6017d482007-12-30 23:10:15 +0000360 << '_' << MO.getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361 // FIXME: PIC relocation model
362 return;
363 case MachineOperand::MO_ConstantPoolIndex:
Evan Cheng477013c2007-10-14 05:57:21 +0000364 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
Chris Lattner6017d482007-12-30 23:10:15 +0000365 << '_' << MO.getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000366 return;
367 case MachineOperand::MO_ExternalSymbol:
368 // Computing the address of an external symbol, not calling it.
369 if (TM.getRelocationModel() != Reloc::Static) {
370 std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
371 GVStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000372 printSuffixedName(Name, "$non_lazy_ptr");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000373 return;
374 }
375 O << TAI->getGlobalPrefix() << MO.getSymbolName();
376 return;
377 case MachineOperand::MO_GlobalAddress: {
378 // Computing the address of a global symbol, not calling it.
379 GlobalValue *GV = MO.getGlobal();
380 std::string Name = Mang->getValueName(GV);
381
382 // External or weakly linked global variables need non-lazily-resolved stubs
383 if (TM.getRelocationModel() != Reloc::Static) {
Chris Lattner0fd4feb2009-07-02 16:08:53 +0000384 if (GV->isDeclaration() || GV->isWeakForLinker()) {
Evan Chenga65854f2008-12-05 01:06:39 +0000385 if (GV->hasHiddenVisibility()) {
Chris Lattnereebec972009-07-01 16:53:44 +0000386 if (GV->isDeclaration() || GV->hasCommonLinkage() ||
387 GV->hasAvailableExternallyLinkage()) {
Evan Chenga65854f2008-12-05 01:06:39 +0000388 HiddenGVStubs.insert(Name);
389 printSuffixedName(Name, "$non_lazy_ptr");
Chris Lattnereebec972009-07-01 16:53:44 +0000390 } else {
391 O << Name;
Evan Chenga65854f2008-12-05 01:06:39 +0000392 }
393 } else {
394 GVStubs.insert(Name);
395 printSuffixedName(Name, "$non_lazy_ptr");
396 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000397 return;
398 }
399 }
400 O << Name;
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000401
Anton Korobeynikov440f23d2008-11-22 16:15:34 +0000402 printOffset(MO.getOffset());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000403 return;
404 }
405
406 default:
407 O << "<unknown operand type: " << MO.getType() << ">";
408 return;
409 }
410}
411
412/// EmitExternalGlobal - In this case we need to use the indirect symbol.
413///
414void PPCAsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
Bill Wendling26a8ab92009-04-10 00:12:49 +0000415 std::string Name;
416 getGlobalLinkName(GV, Name);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000417 if (TM.getRelocationModel() != Reloc::Static) {
Evan Chenga65854f2008-12-05 01:06:39 +0000418 if (GV->hasHiddenVisibility())
419 HiddenGVStubs.insert(Name);
420 else
421 GVStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000422 printSuffixedName(Name, "$non_lazy_ptr");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000423 return;
424 }
425 O << Name;
426}
427
428/// PrintAsmOperand - Print out an operand for an inline asm expression.
429///
430bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000431 unsigned AsmVariant,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000432 const char *ExtraCode) {
433 // Does this asm operand have a single letter operand modifier?
434 if (ExtraCode && ExtraCode[0]) {
435 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000436
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000437 switch (ExtraCode[0]) {
438 default: return true; // Unknown modifier.
439 case 'c': // Don't print "$" before a global var name or constant.
440 // PPC never has a prefix.
441 printOperand(MI, OpNo);
442 return false;
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000443 case 'L': // Write second word of DImode reference.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000444 // Verify that this operand has two consecutive registers.
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000445 if (!MI->getOperand(OpNo).isReg() ||
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000446 OpNo+1 == MI->getNumOperands() ||
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000447 !MI->getOperand(OpNo+1).isReg())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448 return true;
449 ++OpNo; // Return the high-part.
450 break;
451 case 'I':
452 // Write 'i' if an integer constant, otherwise nothing. Used to print
453 // addi vs add, etc.
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000454 if (MI->getOperand(OpNo).isImm())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000455 O << "i";
456 return false;
457 }
458 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000459
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000460 printOperand(MI, OpNo);
461 return false;
462}
463
464bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000465 unsigned AsmVariant,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000466 const char *ExtraCode) {
467 if (ExtraCode && ExtraCode[0])
468 return true; // Unknown modifier.
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000469 if (MI->getOperand(OpNo).isReg())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000470 printMemRegReg(MI, OpNo);
471 else
472 printMemRegImm(MI, OpNo);
473 return false;
474}
475
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000476void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000477 const char *Modifier) {
478 assert(Modifier && "Must specify 'cc' or 'reg' as predicate op modifier!");
479 unsigned Code = MI->getOperand(OpNo).getImm();
480 if (!strcmp(Modifier, "cc")) {
481 switch ((PPC::Predicate)Code) {
482 case PPC::PRED_ALWAYS: return; // Don't print anything for always.
483 case PPC::PRED_LT: O << "lt"; return;
484 case PPC::PRED_LE: O << "le"; return;
485 case PPC::PRED_EQ: O << "eq"; return;
486 case PPC::PRED_GE: O << "ge"; return;
487 case PPC::PRED_GT: O << "gt"; return;
488 case PPC::PRED_NE: O << "ne"; return;
489 case PPC::PRED_UN: O << "un"; return;
490 case PPC::PRED_NU: O << "nu"; return;
491 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000492
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000493 } else {
494 assert(!strcmp(Modifier, "reg") &&
495 "Need to specify 'cc' or 'reg' as predicate op modifier!");
496 // Don't print the register for 'always'.
497 if (Code == PPC::PRED_ALWAYS) return;
498 printOperand(MI, OpNo+1);
499 }
500}
501
502
503/// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to
504/// the current output stream.
505///
506void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
507 ++EmittedInsts;
508
509 // Check for slwi/srwi mnemonics.
510 if (MI->getOpcode() == PPC::RLWINM) {
511 bool FoundMnemonic = false;
Chris Lattnera96056a2007-12-30 20:49:49 +0000512 unsigned char SH = MI->getOperand(2).getImm();
513 unsigned char MB = MI->getOperand(3).getImm();
514 unsigned char ME = MI->getOperand(4).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000515 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
Nate Begemanbd5cdf12008-02-05 08:49:09 +0000516 O << "\tslwi "; FoundMnemonic = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000517 }
518 if (SH <= 31 && MB == (32-SH) && ME == 31) {
Nate Begemanbd5cdf12008-02-05 08:49:09 +0000519 O << "\tsrwi "; FoundMnemonic = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520 SH = 32-SH;
521 }
522 if (FoundMnemonic) {
523 printOperand(MI, 0);
524 O << ", ";
525 printOperand(MI, 1);
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000526 O << ", " << (unsigned int)SH << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527 return;
528 }
529 } else if (MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) {
530 if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
Nate Begemanbd5cdf12008-02-05 08:49:09 +0000531 O << "\tmr ";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000532 printOperand(MI, 0);
533 O << ", ";
534 printOperand(MI, 1);
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000535 O << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000536 return;
537 }
538 } else if (MI->getOpcode() == PPC::RLDICR) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000539 unsigned char SH = MI->getOperand(2).getImm();
540 unsigned char ME = MI->getOperand(3).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541 // rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH
542 if (63-SH == ME) {
Nate Begemanbd5cdf12008-02-05 08:49:09 +0000543 O << "\tsldi ";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544 printOperand(MI, 0);
545 O << ", ";
546 printOperand(MI, 1);
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000547 O << ", " << (unsigned int)SH << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548 return;
549 }
550 }
551
552 if (printInstruction(MI))
553 return; // Printer was automatically generated
554
555 assert(0 && "Unhandled instruction in asm writer!");
556 abort();
557 return;
558}
559
560/// runOnMachineFunction - This uses the printMachineInstruction()
561/// method to print assembly for each instruction.
562///
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000563bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling4f405312009-02-24 08:30:20 +0000564 this->MF = &MF;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000565
566 SetupMachineFunction(MF);
567 O << "\n\n";
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000568
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569 // Print out constants referenced by the function
570 EmitConstantPool(MF.getConstantPool());
571
572 // Print out labels for the function.
573 const Function *F = MF.getFunction();
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000574 SwitchToSection(TAI->SectionForGlobal(F));
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000575
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000576 switch (F->getLinkage()) {
577 default: assert(0 && "Unknown linkage type!");
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000578 case Function::PrivateLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000579 case Function::InternalLinkage: // Symbols default to internal.
580 break;
581 case Function::ExternalLinkage:
582 O << "\t.global\t" << CurrentFnName << '\n'
583 << "\t.type\t" << CurrentFnName << ", @function\n";
584 break;
Duncan Sands19d161f2009-03-07 15:45:40 +0000585 case Function::WeakAnyLinkage:
586 case Function::WeakODRLinkage:
587 case Function::LinkOnceAnyLinkage:
588 case Function::LinkOnceODRLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589 O << "\t.global\t" << CurrentFnName << '\n';
590 O << "\t.weak\t" << CurrentFnName << '\n';
591 break;
592 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000593
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000594 printVisibility(CurrentFnName, F->getVisibility());
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000595
Bill Wendling25a8ae32009-06-30 22:38:32 +0000596 EmitAlignment(MF.getAlignment(), F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000597 O << CurrentFnName << ":\n";
598
599 // Emit pre-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000600 DW->BeginFunction(&MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000601
602 // Print out code for the function.
603 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
604 I != E; ++I) {
605 // Print a label for the basic block.
606 if (I != MF.begin()) {
Evan Cheng45c1edb2008-02-28 00:43:03 +0000607 printBasicBlockLabel(I, true, true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000608 O << '\n';
609 }
610 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
611 II != E; ++II) {
612 // Print the assembly for the instruction.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613 printMachineInstruction(II);
614 }
615 }
616
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000617 O << "\t.size\t" << CurrentFnName << ",.-" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618
619 // Print out jump tables referenced by the function.
620 EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000621
Dale Johannesendd9e1c92008-12-03 19:33:10 +0000622 SwitchToSection(TAI->SectionForGlobal(F));
623
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624 // Emit post-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000625 DW->EndFunction(&MF);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000626
Dan Gohmaneb94abd2008-11-07 19:49:17 +0000627 O.flush();
628
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000629 // We didn't modify anything.
630 return false;
631}
632
Chris Lattner2b638a72008-02-15 19:04:54 +0000633/// PrintUnmangledNameSafely - Print out the printable characters in the name.
Dan Gohman8387bb32009-03-03 02:55:14 +0000634/// Don't print things like \\n or \\0.
Owen Anderson847b99b2008-08-21 00:14:44 +0000635static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) {
Chris Lattner2b638a72008-02-15 19:04:54 +0000636 for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
637 Name != E; ++Name)
638 if (isprint(*Name))
639 OS << *Name;
640}
641
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000642void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000643 const TargetData *TD = TM.getTargetData();
644
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000645 if (!GVar->hasInitializer())
646 return; // External global require no code
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000647
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000648 // Check to see if this is a special global used by LLVM, if so, emit it.
649 if (EmitSpecialLLVMGlobal(GVar))
650 return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000652 std::string name = Mang->getValueName(GVar);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000653
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000654 printVisibility(name, GVar->getVisibility());
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000655
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000656 Constant *C = GVar->getInitializer();
Devang Patel880595f2009-06-26 02:26:12 +0000657 if (isa<MDNode>(C) || isa<MDString>(C))
Devang Patelf667ab42009-06-25 00:47:42 +0000658 return;
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000659 const Type *Type = C->getType();
Duncan Sandsec4f97d2009-05-09 07:06:46 +0000660 unsigned Size = TD->getTypeAllocSize(Type);
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000661 unsigned Align = TD->getPreferredAlignmentLog(GVar);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000662
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000663 SwitchToSection(TAI->SectionForGlobal(GVar));
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000664
665 if (C->isNullValue() && /* FIXME: Verify correct */
666 !GVar->hasSection() &&
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000667 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
Duncan Sands19d161f2009-03-07 15:45:40 +0000668 GVar->isWeakForLinker())) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000670
671 if (GVar->hasExternalLinkage()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000672 O << "\t.global " << name << '\n';
673 O << "\t.type " << name << ", @object\n";
Nick Lewycky3246a9c2007-07-25 03:48:45 +0000674 O << name << ":\n";
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000675 O << "\t.zero " << Size << '\n';
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000676 } else if (GVar->hasLocalLinkage()) {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000677 O << TAI->getLCOMMDirective() << name << ',' << Size;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000678 } else {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000679 O << ".comm " << name << ',' << Size;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000680 }
Evan Cheng11db8142009-03-24 00:17:40 +0000681 if (VerboseAsm) {
682 O << "\t\t" << TAI->getCommentString() << " '";
683 PrintUnmangledNameSafely(GVar, O);
684 O << "'";
685 }
686 O << '\n';
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000687 return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688 }
689
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000690 switch (GVar->getLinkage()) {
Duncan Sands19d161f2009-03-07 15:45:40 +0000691 case GlobalValue::LinkOnceAnyLinkage:
692 case GlobalValue::LinkOnceODRLinkage:
693 case GlobalValue::WeakAnyLinkage:
694 case GlobalValue::WeakODRLinkage:
Duncan Sandsb95df792009-03-11 20:14:15 +0000695 case GlobalValue::CommonLinkage:
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000696 O << "\t.global " << name << '\n'
697 << "\t.type " << name << ", @object\n"
698 << "\t.weak " << name << '\n';
699 break;
700 case GlobalValue::AppendingLinkage:
701 // FIXME: appending linkage variables should go into a section of
702 // their name or something. For now, just emit them as external.
703 case GlobalValue::ExternalLinkage:
704 // If external or appending, declare as a global symbol
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000705 O << "\t.global " << name << '\n'
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000706 << "\t.type " << name << ", @object\n";
707 // FALL THROUGH
708 case GlobalValue::InternalLinkage:
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000709 case GlobalValue::PrivateLinkage:
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000710 break;
711 default:
712 cerr << "Unknown linkage type!";
713 abort();
714 }
715
716 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +0000717 O << name << ":";
718 if (VerboseAsm) {
719 O << "\t\t\t\t" << TAI->getCommentString() << " '";
720 PrintUnmangledNameSafely(GVar, O);
721 O << "'";
722 }
723 O << '\n';
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000724
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000725 EmitGlobalConstant(C);
726 O << '\n';
727}
728
729bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
730 // Print out module-level global variables here.
731 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
732 I != E; ++I)
733 printModuleLevelGV(I);
734
Dan Gohman4a558a32007-07-25 19:33:14 +0000735 return AsmPrinter::doFinalization(M);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000736}
737
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000738/// runOnMachineFunction - This uses the printMachineInstruction()
739/// method to print assembly for each instruction.
740///
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000741bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling4f405312009-02-24 08:30:20 +0000742 this->MF = &MF;
743
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000744 SetupMachineFunction(MF);
745 O << "\n\n";
Dale Johannesenfb3ac732007-11-20 23:24:42 +0000746
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000747 // Print out constants referenced by the function
748 EmitConstantPool(MF.getConstantPool());
749
750 // Print out labels for the function.
751 const Function *F = MF.getFunction();
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000752 SwitchToSection(TAI->SectionForGlobal(F));
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000753
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000754 switch (F->getLinkage()) {
755 default: assert(0 && "Unknown linkage type!");
evancheng47ae8142009-01-25 06:32:01 +0000756 case Function::PrivateLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000757 case Function::InternalLinkage: // Symbols default to internal.
758 break;
759 case Function::ExternalLinkage:
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000760 O << "\t.globl\t" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000761 break;
Duncan Sands19d161f2009-03-07 15:45:40 +0000762 case Function::WeakAnyLinkage:
763 case Function::WeakODRLinkage:
764 case Function::LinkOnceAnyLinkage:
765 case Function::LinkOnceODRLinkage:
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000766 O << "\t.globl\t" << CurrentFnName << '\n';
767 O << "\t.weak_definition\t" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000768 break;
769 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000770
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000771 printVisibility(CurrentFnName, F->getVisibility());
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000772
Bill Wendling25a8ae32009-06-30 22:38:32 +0000773 EmitAlignment(MF.getAlignment(), F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774 O << CurrentFnName << ":\n";
775
776 // Emit pre-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000777 DW->BeginFunction(&MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000778
Bill Wendling36ccaea2008-01-26 06:51:24 +0000779 // If the function is empty, then we need to emit *something*. Otherwise, the
780 // function's label might be associated with something that it wasn't meant to
781 // be associated with. We emit a noop in this situation.
782 MachineFunction::iterator I = MF.begin();
783
Bill Wendlingb5880a72008-01-26 09:03:52 +0000784 if (++I == MF.end() && MF.front().empty())
785 O << "\tnop\n";
Bill Wendling36ccaea2008-01-26 06:51:24 +0000786
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000787 // Print out code for the function.
788 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
789 I != E; ++I) {
790 // Print a label for the basic block.
791 if (I != MF.begin()) {
Evan Cheng11db8142009-03-24 00:17:40 +0000792 printBasicBlockLabel(I, true, true, VerboseAsm);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000793 O << '\n';
794 }
Bill Wendling36ccaea2008-01-26 06:51:24 +0000795 for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
796 II != IE; ++II) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797 // Print the assembly for the instruction.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000798 printMachineInstruction(II);
799 }
800 }
801
802 // Print out jump tables referenced by the function.
803 EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000804
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000805 // Emit post-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000806 DW->EndFunction(&MF);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000807
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808 // We didn't modify anything.
809 return false;
810}
811
812
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000813bool PPCDarwinAsmPrinter::doInitialization(Module &M) {
Dan Gohman12300e12008-03-25 21:45:14 +0000814 static const char *const CPUDirectives[] = {
Dale Johannesen161badc2008-02-14 23:35:16 +0000815 "",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816 "ppc",
817 "ppc601",
818 "ppc602",
819 "ppc603",
820 "ppc7400",
821 "ppc750",
822 "ppc970",
823 "ppc64"
824 };
825
826 unsigned Directive = Subtarget.getDarwinDirective();
827 if (Subtarget.isGigaProcessor() && Directive < PPC::DIR_970)
828 Directive = PPC::DIR_970;
829 if (Subtarget.hasAltivec() && Directive < PPC::DIR_7400)
830 Directive = PPC::DIR_7400;
831 if (Subtarget.isPPC64() && Directive < PPC::DIR_970)
832 Directive = PPC::DIR_64;
833 assert(Directive <= PPC::DIR_64 && "Directive out of range.");
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000834 O << "\t.machine " << CPUDirectives[Directive] << '\n';
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000835
Dan Gohman4a558a32007-07-25 19:33:14 +0000836 bool Result = AsmPrinter::doInitialization(M);
Devang Patelc20079e2009-06-20 01:00:07 +0000837 assert(MMI);
Dale Johannesen58e0eeb2008-07-09 20:43:39 +0000838
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000839 // Prime text sections so they are adjacent. This reduces the likelihood a
840 // large data or debug section causes a branch to exceed 16M limit.
Dale Johannesen3c788322008-01-11 00:54:37 +0000841 SwitchToTextSection("\t.section __TEXT,__textcoal_nt,coalesced,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842 "pure_instructions");
843 if (TM.getRelocationModel() == Reloc::PIC_) {
Dale Johannesen3c788322008-01-11 00:54:37 +0000844 SwitchToTextSection("\t.section __TEXT,__picsymbolstub1,symbol_stubs,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000845 "pure_instructions,32");
846 } else if (TM.getRelocationModel() == Reloc::DynamicNoPIC) {
Dale Johannesen3c788322008-01-11 00:54:37 +0000847 SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848 "pure_instructions,16");
849 }
Anton Korobeynikov55b94962008-09-24 22:15:21 +0000850 SwitchToSection(TAI->getTextSection());
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000851
Dan Gohman4a558a32007-07-25 19:33:14 +0000852 return Result;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000853}
854
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000855void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
856 const TargetData *TD = TM.getTargetData();
857
858 if (!GVar->hasInitializer())
859 return; // External global require no code
860
861 // Check to see if this is a special global used by LLVM, if so, emit it.
862 if (EmitSpecialLLVMGlobal(GVar)) {
863 if (TM.getRelocationModel() == Reloc::Static) {
864 if (GVar->getName() == "llvm.global_ctors")
865 O << ".reference .constructors_used\n";
866 else if (GVar->getName() == "llvm.global_dtors")
867 O << ".reference .destructors_used\n";
868 }
869 return;
870 }
871
872 std::string name = Mang->getValueName(GVar);
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000873
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000874 printVisibility(name, GVar->getVisibility());
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000875
876 Constant *C = GVar->getInitializer();
877 const Type *Type = C->getType();
Duncan Sandsec4f97d2009-05-09 07:06:46 +0000878 unsigned Size = TD->getTypeAllocSize(Type);
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000879 unsigned Align = TD->getPreferredAlignmentLog(GVar);
880
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000881 SwitchToSection(TAI->SectionForGlobal(GVar));
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000882
883 if (C->isNullValue() && /* FIXME: Verify correct */
884 !GVar->hasSection() &&
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000885 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
Duncan Sands19d161f2009-03-07 15:45:40 +0000886 GVar->isWeakForLinker()) &&
Evan Chengcf84b142009-02-18 02:19:52 +0000887 TAI->SectionKindForGlobal(GVar) != SectionKind::RODataMergeStr) {
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000888 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
889
890 if (GVar->hasExternalLinkage()) {
891 O << "\t.globl " << name << '\n';
892 O << "\t.zerofill __DATA, __common, " << name << ", "
893 << Size << ", " << Align;
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000894 } else if (GVar->hasLocalLinkage()) {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000895 O << TAI->getLCOMMDirective() << name << ',' << Size << ',' << Align;
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000896 } else if (!GVar->hasCommonLinkage()) {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000897 O << "\t.globl " << name << '\n'
898 << TAI->getWeakDefDirective() << name << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000899 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +0000900 O << name << ":";
901 if (VerboseAsm) {
902 O << "\t\t\t\t" << TAI->getCommentString() << " ";
903 PrintUnmangledNameSafely(GVar, O);
904 }
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000905 O << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000906 EmitGlobalConstant(C);
907 return;
908 } else {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000909 O << ".comm " << name << ',' << Size;
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000910 // Darwin 9 and above support aligned common data.
911 if (Subtarget.isDarwin9())
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000912 O << ',' << Align;
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000913 }
Evan Cheng11db8142009-03-24 00:17:40 +0000914 if (VerboseAsm) {
915 O << "\t\t" << TAI->getCommentString() << " '";
916 PrintUnmangledNameSafely(GVar, O);
917 O << "'";
918 }
919 O << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000920 return;
921 }
922
923 switch (GVar->getLinkage()) {
Duncan Sands19d161f2009-03-07 15:45:40 +0000924 case GlobalValue::LinkOnceAnyLinkage:
925 case GlobalValue::LinkOnceODRLinkage:
926 case GlobalValue::WeakAnyLinkage:
927 case GlobalValue::WeakODRLinkage:
Duncan Sandsb95df792009-03-11 20:14:15 +0000928 case GlobalValue::CommonLinkage:
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000929 O << "\t.globl " << name << '\n'
930 << "\t.weak_definition " << name << '\n';
931 break;
932 case GlobalValue::AppendingLinkage:
933 // FIXME: appending linkage variables should go into a section of
934 // their name or something. For now, just emit them as external.
935 case GlobalValue::ExternalLinkage:
936 // If external or appending, declare as a global symbol
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000937 O << "\t.globl " << name << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000938 // FALL THROUGH
939 case GlobalValue::InternalLinkage:
evancheng47ae8142009-01-25 06:32:01 +0000940 case GlobalValue::PrivateLinkage:
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000941 break;
942 default:
943 cerr << "Unknown linkage type!";
944 abort();
945 }
946
947 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +0000948 O << name << ":";
949 if (VerboseAsm) {
950 O << "\t\t\t\t" << TAI->getCommentString() << " '";
951 PrintUnmangledNameSafely(GVar, O);
952 O << "'";
953 }
954 O << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000955
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000956 EmitGlobalConstant(C);
957 O << '\n';
958}
959
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000960bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000961 const TargetData *TD = TM.getTargetData();
962
963 // Print out module-level global variables here.
964 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000965 I != E; ++I)
966 printModuleLevelGV(I);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000967
968 bool isPPC64 = TD->getPointerSizeInBits() == 64;
969
970 // Output stubs for dynamically-linked functions
971 if (TM.getRelocationModel() == Reloc::PIC_) {
Evan Chenga65854f2008-12-05 01:06:39 +0000972 for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000973 i != e; ++i) {
Dale Johannesen3c788322008-01-11 00:54:37 +0000974 SwitchToTextSection("\t.section __TEXT,__picsymbolstub1,symbol_stubs,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000975 "pure_instructions,32");
976 EmitAlignment(4);
Evan Chenga65854f2008-12-05 01:06:39 +0000977 const char *p = i->getKeyData();
978 bool hasQuote = p[0]=='\"';
Dale Johannesena21b5202008-05-19 21:38:18 +0000979 printSuffixedName(p, "$stub");
980 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +0000981 O << "\t.indirect_symbol " << p << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000982 O << "\tmflr r0\n";
Evan Chenga65854f2008-12-05 01:06:39 +0000983 O << "\tbcl 20,31,";
984 if (hasQuote)
985 O << "\"L0$" << &p[1];
986 else
987 O << "L0$" << p;
988 O << '\n';
989 if (hasQuote)
990 O << "\"L0$" << &p[1];
991 else
992 O << "L0$" << p;
993 O << ":\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000994 O << "\tmflr r11\n";
Dale Johannesena21b5202008-05-19 21:38:18 +0000995 O << "\taddis r11,r11,ha16(";
996 printSuffixedName(p, "$lazy_ptr");
Evan Chenga65854f2008-12-05 01:06:39 +0000997 O << "-";
998 if (hasQuote)
999 O << "\"L0$" << &p[1];
1000 else
1001 O << "L0$" << p;
1002 O << ")\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001003 O << "\tmtlr r0\n";
1004 if (isPPC64)
Dale Johannesena21b5202008-05-19 21:38:18 +00001005 O << "\tldu r12,lo16(";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006 else
Dale Johannesena21b5202008-05-19 21:38:18 +00001007 O << "\tlwzu r12,lo16(";
1008 printSuffixedName(p, "$lazy_ptr");
Evan Chenga65854f2008-12-05 01:06:39 +00001009 O << "-";
1010 if (hasQuote)
1011 O << "\"L0$" << &p[1];
1012 else
1013 O << "L0$" << p;
1014 O << ")(r11)\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001015 O << "\tmtctr r12\n";
1016 O << "\tbctr\n";
1017 SwitchToDataSection(".lazy_symbol_pointer");
Dale Johannesena21b5202008-05-19 21:38:18 +00001018 printSuffixedName(p, "$lazy_ptr");
1019 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001020 O << "\t.indirect_symbol " << p << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001021 if (isPPC64)
1022 O << "\t.quad dyld_stub_binding_helper\n";
1023 else
1024 O << "\t.long dyld_stub_binding_helper\n";
1025 }
1026 } else {
Evan Chenga65854f2008-12-05 01:06:39 +00001027 for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001028 i != e; ++i) {
Dale Johannesen3c788322008-01-11 00:54:37 +00001029 SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001030 "pure_instructions,16");
1031 EmitAlignment(4);
Evan Chenga65854f2008-12-05 01:06:39 +00001032 const char *p = i->getKeyData();
Dale Johannesena21b5202008-05-19 21:38:18 +00001033 printSuffixedName(p, "$stub");
1034 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001035 O << "\t.indirect_symbol " << p << '\n';
Dale Johannesena21b5202008-05-19 21:38:18 +00001036 O << "\tlis r11,ha16(";
1037 printSuffixedName(p, "$lazy_ptr");
1038 O << ")\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001039 if (isPPC64)
Dale Johannesena21b5202008-05-19 21:38:18 +00001040 O << "\tldu r12,lo16(";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001041 else
Dale Johannesena21b5202008-05-19 21:38:18 +00001042 O << "\tlwzu r12,lo16(";
1043 printSuffixedName(p, "$lazy_ptr");
1044 O << ")(r11)\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001045 O << "\tmtctr r12\n";
1046 O << "\tbctr\n";
1047 SwitchToDataSection(".lazy_symbol_pointer");
Dale Johannesena21b5202008-05-19 21:38:18 +00001048 printSuffixedName(p, "$lazy_ptr");
1049 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001050 O << "\t.indirect_symbol " << p << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001051 if (isPPC64)
1052 O << "\t.quad dyld_stub_binding_helper\n";
1053 else
1054 O << "\t.long dyld_stub_binding_helper\n";
1055 }
1056 }
1057
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +00001058 O << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001059
Dale Johannesen85535762008-04-02 00:25:04 +00001060 if (TAI->doesSupportExceptionHandling() && MMI) {
Dale Johannesenfb3ac732007-11-20 23:24:42 +00001061 // Add the (possibly multiple) personalities to the set of global values.
Dale Johannesen85535762008-04-02 00:25:04 +00001062 // Only referenced functions get into the Personalities list.
Chris Lattner2424eac2009-06-24 19:09:55 +00001063 const std::vector<Function *> &Personalities = MMI->getPersonalities();
Dale Johannesenfb3ac732007-11-20 23:24:42 +00001064 for (std::vector<Function *>::const_iterator I = Personalities.begin(),
1065 E = Personalities.end(); I != E; ++I)
1066 if (*I) GVStubs.insert("_" + (*I)->getName());
1067 }
1068
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001069 // Output stubs for external and common global variables.
Dan Gohman3f7d94b2007-10-03 19:26:29 +00001070 if (!GVStubs.empty()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001071 SwitchToDataSection(".non_lazy_symbol_pointer");
Evan Chenga65854f2008-12-05 01:06:39 +00001072 for (StringSet<>::iterator i = GVStubs.begin(), e = GVStubs.end();
1073 i != e; ++i) {
1074 std::string p = i->getKeyData();
Dale Johannesena21b5202008-05-19 21:38:18 +00001075 printSuffixedName(p, "$non_lazy_ptr");
1076 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001077 O << "\t.indirect_symbol " << p << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001078 if (isPPC64)
1079 O << "\t.quad\t0\n";
1080 else
1081 O << "\t.long\t0\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001082 }
1083 }
1084
Evan Chenga65854f2008-12-05 01:06:39 +00001085 if (!HiddenGVStubs.empty()) {
1086 SwitchToSection(TAI->getDataSection());
1087 for (StringSet<>::iterator i = HiddenGVStubs.begin(), e = HiddenGVStubs.end();
1088 i != e; ++i) {
1089 std::string p = i->getKeyData();
1090 EmitAlignment(isPPC64 ? 3 : 2);
1091 printSuffixedName(p, "$non_lazy_ptr");
1092 O << ":\n";
1093 if (isPPC64)
1094 O << "\t.quad\t";
1095 else
1096 O << "\t.long\t";
1097 O << p << '\n';
1098 }
1099 }
1100
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001101 // Funny Darwin hack: This flag tells the linker that no global symbols
1102 // contain code that falls through to other global symbols (e.g. the obvious
1103 // implementation of multiple entry points). If this doesn't occur, the
1104 // linker can safely perform dead code stripping. Since LLVM never generates
1105 // code that does this, it is always safe to set.
1106 O << "\t.subsections_via_symbols\n";
1107
Dan Gohman4a558a32007-07-25 19:33:14 +00001108 return AsmPrinter::doFinalization(M);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001109}
1110
1111
1112
1113/// createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code
1114/// for a MachineFunction to the given output stream, in a format that the
1115/// Darwin assembler can deal with.
1116///
Owen Anderson847b99b2008-08-21 00:14:44 +00001117FunctionPass *llvm::createPPCAsmPrinterPass(raw_ostream &o,
Bill Wendling4f405312009-02-24 08:30:20 +00001118 PPCTargetMachine &tm,
Bill Wendling5ed22ac2009-04-29 23:29:43 +00001119 bool verbose) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001120 const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>();
1121
1122 if (Subtarget->isDarwin()) {
Daniel Dunbarb10d2222009-07-01 01:48:54 +00001123 return new PPCDarwinAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001124 } else {
Daniel Dunbarb10d2222009-07-01 01:48:54 +00001125 return new PPCLinuxAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001126 }
1127}
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +00001128
1129namespace {
1130 static struct Register {
1131 Register() {
1132 PPCTargetMachine::registerAsmPrinter(createPPCAsmPrinterPass);
1133 }
1134 } Registrator;
1135}
Oscar Fuentes4f012352008-11-15 21:36:30 +00001136
1137extern "C" int PowerPCAsmPrinterForceLink;
1138int PowerPCAsmPrinterForceLink = 0;
Douglas Gregor1dc5ff42009-06-16 20:12:29 +00001139
Bob Wilsonebbc1c42009-06-23 23:59:40 +00001140// Force static initialization.
1141extern "C" void LLVMInitializePowerPCAsmPrinter() { }