blob: a22dac82332be8b3391342e86485522ba25112ed [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();
191 if (((GV->isDeclaration() || GV->hasWeakLinkage() ||
Chris Lattnereebec972009-07-01 16:53:44 +0000192 GV->hasLinkOnceLinkage() || GV->hasCommonLinkage() ||
193 GV->hasAvailableExternallyLinkage()))) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194 // Dynamically-resolved functions need a stub for the function.
195 std::string Name = Mang->getValueName(GV);
196 FnStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000197 printSuffixedName(Name, "$stub");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000198 return;
199 }
200 }
201 if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
202 std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
203 FnStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000204 printSuffixedName(Name, "$stub");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000205 return;
206 }
207 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000208
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000209 printOp(MI->getOperand(OpNo));
210 }
211 void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000212 O << (int)MI->getOperand(OpNo).getImm()*4;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213 }
214 void printPICLabel(const MachineInstr *MI, unsigned OpNo) {
Evan Cheng477013c2007-10-14 05:57:21 +0000215 O << "\"L" << getFunctionNumber() << "$pb\"\n";
216 O << "\"L" << getFunctionNumber() << "$pb\":";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217 }
218 void printSymbolHi(const MachineInstr *MI, unsigned OpNo) {
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000219 if (MI->getOperand(OpNo).isImm()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000220 printS16ImmOperand(MI, OpNo);
221 } else {
222 if (Subtarget.isDarwin()) O << "ha16(";
223 printOp(MI->getOperand(OpNo));
224 if (TM.getRelocationModel() == Reloc::PIC_)
Evan Cheng477013c2007-10-14 05:57:21 +0000225 O << "-\"L" << getFunctionNumber() << "$pb\"";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000226 if (Subtarget.isDarwin())
227 O << ')';
228 else
229 O << "@ha";
230 }
231 }
232 void printSymbolLo(const MachineInstr *MI, unsigned OpNo) {
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000233 if (MI->getOperand(OpNo).isImm()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234 printS16ImmOperand(MI, OpNo);
235 } else {
236 if (Subtarget.isDarwin()) O << "lo16(";
237 printOp(MI->getOperand(OpNo));
238 if (TM.getRelocationModel() == Reloc::PIC_)
Evan Cheng477013c2007-10-14 05:57:21 +0000239 O << "-\"L" << getFunctionNumber() << "$pb\"";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000240 if (Subtarget.isDarwin())
241 O << ')';
242 else
243 O << "@l";
244 }
245 }
246 void printcrbitm(const MachineInstr *MI, unsigned OpNo) {
247 unsigned CCReg = MI->getOperand(OpNo).getReg();
248 unsigned RegNo = enumRegToMachineReg(CCReg);
249 O << (0x80 >> RegNo);
250 }
251 // The new addressing mode printers.
252 void printMemRegImm(const MachineInstr *MI, unsigned OpNo) {
253 printSymbolLo(MI, OpNo);
254 O << '(';
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000255 if (MI->getOperand(OpNo+1).isReg() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000256 MI->getOperand(OpNo+1).getReg() == PPC::R0)
257 O << "0";
258 else
259 printOperand(MI, OpNo+1);
260 O << ')';
261 }
262 void printMemRegImmShifted(const MachineInstr *MI, unsigned OpNo) {
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000263 if (MI->getOperand(OpNo).isImm())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000264 printS16X4ImmOperand(MI, OpNo);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000265 else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000266 printSymbolLo(MI, OpNo);
267 O << '(';
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000268 if (MI->getOperand(OpNo+1).isReg() &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 MI->getOperand(OpNo+1).getReg() == PPC::R0)
270 O << "0";
271 else
272 printOperand(MI, OpNo+1);
273 O << ')';
274 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000275
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276 void printMemRegReg(const MachineInstr *MI, unsigned OpNo) {
277 // When used as the base register, r0 reads constant zero rather than
278 // the value contained in the register. For this reason, the darwin
279 // assembler requires that we print r0 as 0 (no r) when used as the base.
280 const MachineOperand &MO = MI->getOperand(OpNo);
281 printRegister(MO, true);
282 O << ", ";
283 printOperand(MI, OpNo+1);
284 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000285
286 void printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000287 const char *Modifier);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000288
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000289 virtual bool runOnMachineFunction(MachineFunction &F) = 0;
290 virtual bool doFinalization(Module &M) = 0;
291
292 virtual void EmitExternalGlobal(const GlobalVariable *GV);
293 };
294
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000295 /// PPCLinuxAsmPrinter - PowerPC assembly printer, customized for Linux
Bill Wendling4f405312009-02-24 08:30:20 +0000296 class VISIBILITY_HIDDEN PPCLinuxAsmPrinter : public PPCAsmPrinter {
Bill Wendling4f405312009-02-24 08:30:20 +0000297 public:
Bill Wendling58ed5d22009-04-29 00:15:41 +0000298 explicit PPCLinuxAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
Daniel Dunbarb10d2222009-07-01 01:48:54 +0000299 const TargetAsmInfo *T, bool V)
300 : PPCAsmPrinter(O, TM, T, V){}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301
302 virtual const char *getPassName() const {
303 return "Linux PPC Assembly Printer";
304 }
305
306 bool runOnMachineFunction(MachineFunction &F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000307 bool doFinalization(Module &M);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000308
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000309 void getAnalysisUsage(AnalysisUsage &AU) const {
310 AU.setPreservesAll();
311 AU.addRequired<MachineModuleInfo>();
Devang Patelaa1e8432009-01-08 23:40:34 +0000312 AU.addRequired<DwarfWriter>();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000313 PPCAsmPrinter::getAnalysisUsage(AU);
314 }
315
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000316 void printModuleLevelGV(const GlobalVariable* GVar);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317 };
318
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000319 /// PPCDarwinAsmPrinter - PowerPC assembly printer, customized for Darwin/Mac
320 /// OS X
Bill Wendling4f405312009-02-24 08:30:20 +0000321 class VISIBILITY_HIDDEN PPCDarwinAsmPrinter : public PPCAsmPrinter {
Devang Patelaa1e8432009-01-08 23:40:34 +0000322 raw_ostream &OS;
Bill Wendling4f405312009-02-24 08:30:20 +0000323 public:
Bill Wendling58ed5d22009-04-29 00:15:41 +0000324 explicit PPCDarwinAsmPrinter(raw_ostream &O, PPCTargetMachine &TM,
Daniel Dunbarb10d2222009-07-01 01:48:54 +0000325 const TargetAsmInfo *T, bool V)
326 : PPCAsmPrinter(O, TM, T, V), OS(O) {}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000327
328 virtual const char *getPassName() const {
329 return "Darwin PPC Assembly Printer";
330 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000331
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000332 bool runOnMachineFunction(MachineFunction &F);
333 bool doInitialization(Module &M);
334 bool doFinalization(Module &M);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000335
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000336 void getAnalysisUsage(AnalysisUsage &AU) const {
337 AU.setPreservesAll();
338 AU.addRequired<MachineModuleInfo>();
Devang Patelaa1e8432009-01-08 23:40:34 +0000339 AU.addRequired<DwarfWriter>();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340 PPCAsmPrinter::getAnalysisUsage(AU);
341 }
342
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000343 void printModuleLevelGV(const GlobalVariable* GVar);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000344 };
345} // end of anonymous namespace
346
347// Include the auto-generated portion of the assembly writer
348#include "PPCGenAsmWriter.inc"
349
350void PPCAsmPrinter::printOp(const MachineOperand &MO) {
351 switch (MO.getType()) {
352 case MachineOperand::MO_Immediate:
353 cerr << "printOp() does not handle immediate values\n";
354 abort();
355 return;
356
357 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner6017d482007-12-30 23:10:15 +0000358 printBasicBlockLabel(MO.getMBB());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000359 return;
360 case MachineOperand::MO_JumpTableIndex:
Evan Cheng477013c2007-10-14 05:57:21 +0000361 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Chris Lattner6017d482007-12-30 23:10:15 +0000362 << '_' << MO.getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363 // FIXME: PIC relocation model
364 return;
365 case MachineOperand::MO_ConstantPoolIndex:
Evan Cheng477013c2007-10-14 05:57:21 +0000366 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber()
Chris Lattner6017d482007-12-30 23:10:15 +0000367 << '_' << MO.getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000368 return;
369 case MachineOperand::MO_ExternalSymbol:
370 // Computing the address of an external symbol, not calling it.
371 if (TM.getRelocationModel() != Reloc::Static) {
372 std::string Name(TAI->getGlobalPrefix()); Name += MO.getSymbolName();
373 GVStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000374 printSuffixedName(Name, "$non_lazy_ptr");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000375 return;
376 }
377 O << TAI->getGlobalPrefix() << MO.getSymbolName();
378 return;
379 case MachineOperand::MO_GlobalAddress: {
380 // Computing the address of a global symbol, not calling it.
381 GlobalValue *GV = MO.getGlobal();
382 std::string Name = Mang->getValueName(GV);
383
384 // External or weakly linked global variables need non-lazily-resolved stubs
385 if (TM.getRelocationModel() != Reloc::Static) {
Chris Lattnereebec972009-07-01 16:53:44 +0000386 if (GV->isDeclaration() || GV->isWeakForLinker() ||
387 GV->hasAvailableExternallyLinkage()) {
Evan Chenga65854f2008-12-05 01:06:39 +0000388 if (GV->hasHiddenVisibility()) {
Chris Lattnereebec972009-07-01 16:53:44 +0000389 if (GV->isDeclaration() || GV->hasCommonLinkage() ||
390 GV->hasAvailableExternallyLinkage()) {
Evan Chenga65854f2008-12-05 01:06:39 +0000391 HiddenGVStubs.insert(Name);
392 printSuffixedName(Name, "$non_lazy_ptr");
Chris Lattnereebec972009-07-01 16:53:44 +0000393 } else {
394 O << Name;
Evan Chenga65854f2008-12-05 01:06:39 +0000395 }
396 } else {
397 GVStubs.insert(Name);
398 printSuffixedName(Name, "$non_lazy_ptr");
399 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000400 return;
401 }
402 }
403 O << Name;
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000404
Anton Korobeynikov440f23d2008-11-22 16:15:34 +0000405 printOffset(MO.getOffset());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000406 return;
407 }
408
409 default:
410 O << "<unknown operand type: " << MO.getType() << ">";
411 return;
412 }
413}
414
415/// EmitExternalGlobal - In this case we need to use the indirect symbol.
416///
417void PPCAsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
Bill Wendling26a8ab92009-04-10 00:12:49 +0000418 std::string Name;
419 getGlobalLinkName(GV, Name);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000420 if (TM.getRelocationModel() != Reloc::Static) {
Evan Chenga65854f2008-12-05 01:06:39 +0000421 if (GV->hasHiddenVisibility())
422 HiddenGVStubs.insert(Name);
423 else
424 GVStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000425 printSuffixedName(Name, "$non_lazy_ptr");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426 return;
427 }
428 O << Name;
429}
430
431/// PrintAsmOperand - Print out an operand for an inline asm expression.
432///
433bool PPCAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000434 unsigned AsmVariant,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000435 const char *ExtraCode) {
436 // Does this asm operand have a single letter operand modifier?
437 if (ExtraCode && ExtraCode[0]) {
438 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000439
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000440 switch (ExtraCode[0]) {
441 default: return true; // Unknown modifier.
442 case 'c': // Don't print "$" before a global var name or constant.
443 // PPC never has a prefix.
444 printOperand(MI, OpNo);
445 return false;
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000446 case 'L': // Write second word of DImode reference.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447 // Verify that this operand has two consecutive registers.
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000448 if (!MI->getOperand(OpNo).isReg() ||
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000449 OpNo+1 == MI->getNumOperands() ||
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000450 !MI->getOperand(OpNo+1).isReg())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451 return true;
452 ++OpNo; // Return the high-part.
453 break;
454 case 'I':
455 // Write 'i' if an integer constant, otherwise nothing. Used to print
456 // addi vs add, etc.
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000457 if (MI->getOperand(OpNo).isImm())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000458 O << "i";
459 return false;
460 }
461 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000462
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000463 printOperand(MI, OpNo);
464 return false;
465}
466
467bool PPCAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000468 unsigned AsmVariant,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469 const char *ExtraCode) {
470 if (ExtraCode && ExtraCode[0])
471 return true; // Unknown modifier.
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000472 if (MI->getOperand(OpNo).isReg())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473 printMemRegReg(MI, OpNo);
474 else
475 printMemRegImm(MI, OpNo);
476 return false;
477}
478
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000479void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480 const char *Modifier) {
481 assert(Modifier && "Must specify 'cc' or 'reg' as predicate op modifier!");
482 unsigned Code = MI->getOperand(OpNo).getImm();
483 if (!strcmp(Modifier, "cc")) {
484 switch ((PPC::Predicate)Code) {
485 case PPC::PRED_ALWAYS: return; // Don't print anything for always.
486 case PPC::PRED_LT: O << "lt"; return;
487 case PPC::PRED_LE: O << "le"; return;
488 case PPC::PRED_EQ: O << "eq"; return;
489 case PPC::PRED_GE: O << "ge"; return;
490 case PPC::PRED_GT: O << "gt"; return;
491 case PPC::PRED_NE: O << "ne"; return;
492 case PPC::PRED_UN: O << "un"; return;
493 case PPC::PRED_NU: O << "nu"; return;
494 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000495
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000496 } else {
497 assert(!strcmp(Modifier, "reg") &&
498 "Need to specify 'cc' or 'reg' as predicate op modifier!");
499 // Don't print the register for 'always'.
500 if (Code == PPC::PRED_ALWAYS) return;
501 printOperand(MI, OpNo+1);
502 }
503}
504
505
506/// printMachineInstruction -- Print out a single PowerPC MI in Darwin syntax to
507/// the current output stream.
508///
509void PPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
510 ++EmittedInsts;
511
512 // Check for slwi/srwi mnemonics.
513 if (MI->getOpcode() == PPC::RLWINM) {
514 bool FoundMnemonic = false;
Chris Lattnera96056a2007-12-30 20:49:49 +0000515 unsigned char SH = MI->getOperand(2).getImm();
516 unsigned char MB = MI->getOperand(3).getImm();
517 unsigned char ME = MI->getOperand(4).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518 if (SH <= 31 && MB == 0 && ME == (31-SH)) {
Nate Begemanbd5cdf12008-02-05 08:49:09 +0000519 O << "\tslwi "; FoundMnemonic = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520 }
521 if (SH <= 31 && MB == (32-SH) && ME == 31) {
Nate Begemanbd5cdf12008-02-05 08:49:09 +0000522 O << "\tsrwi "; FoundMnemonic = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000523 SH = 32-SH;
524 }
525 if (FoundMnemonic) {
526 printOperand(MI, 0);
527 O << ", ";
528 printOperand(MI, 1);
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000529 O << ", " << (unsigned int)SH << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000530 return;
531 }
532 } else if (MI->getOpcode() == PPC::OR || MI->getOpcode() == PPC::OR8) {
533 if (MI->getOperand(1).getReg() == MI->getOperand(2).getReg()) {
Nate Begemanbd5cdf12008-02-05 08:49:09 +0000534 O << "\tmr ";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535 printOperand(MI, 0);
536 O << ", ";
537 printOperand(MI, 1);
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000538 O << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539 return;
540 }
541 } else if (MI->getOpcode() == PPC::RLDICR) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000542 unsigned char SH = MI->getOperand(2).getImm();
543 unsigned char ME = MI->getOperand(3).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000544 // rldicr RA, RS, SH, 63-SH == sldi RA, RS, SH
545 if (63-SH == ME) {
Nate Begemanbd5cdf12008-02-05 08:49:09 +0000546 O << "\tsldi ";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547 printOperand(MI, 0);
548 O << ", ";
549 printOperand(MI, 1);
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000550 O << ", " << (unsigned int)SH << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000551 return;
552 }
553 }
554
555 if (printInstruction(MI))
556 return; // Printer was automatically generated
557
558 assert(0 && "Unhandled instruction in asm writer!");
559 abort();
560 return;
561}
562
563/// runOnMachineFunction - This uses the printMachineInstruction()
564/// method to print assembly for each instruction.
565///
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000566bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling4f405312009-02-24 08:30:20 +0000567 this->MF = &MF;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568
569 SetupMachineFunction(MF);
570 O << "\n\n";
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000571
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000572 // Print out constants referenced by the function
573 EmitConstantPool(MF.getConstantPool());
574
575 // Print out labels for the function.
576 const Function *F = MF.getFunction();
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000577 SwitchToSection(TAI->SectionForGlobal(F));
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000578
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000579 switch (F->getLinkage()) {
580 default: assert(0 && "Unknown linkage type!");
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000581 case Function::PrivateLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000582 case Function::InternalLinkage: // Symbols default to internal.
583 break;
584 case Function::ExternalLinkage:
585 O << "\t.global\t" << CurrentFnName << '\n'
586 << "\t.type\t" << CurrentFnName << ", @function\n";
587 break;
Duncan Sands19d161f2009-03-07 15:45:40 +0000588 case Function::WeakAnyLinkage:
589 case Function::WeakODRLinkage:
590 case Function::LinkOnceAnyLinkage:
591 case Function::LinkOnceODRLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592 O << "\t.global\t" << CurrentFnName << '\n';
593 O << "\t.weak\t" << CurrentFnName << '\n';
594 break;
595 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000596
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000597 printVisibility(CurrentFnName, F->getVisibility());
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000598
Bill Wendling25a8ae32009-06-30 22:38:32 +0000599 EmitAlignment(MF.getAlignment(), F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000600 O << CurrentFnName << ":\n";
601
602 // Emit pre-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000603 DW->BeginFunction(&MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604
605 // Print out code for the function.
606 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
607 I != E; ++I) {
608 // Print a label for the basic block.
609 if (I != MF.begin()) {
Evan Cheng45c1edb2008-02-28 00:43:03 +0000610 printBasicBlockLabel(I, true, true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000611 O << '\n';
612 }
613 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
614 II != E; ++II) {
615 // Print the assembly for the instruction.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000616 printMachineInstruction(II);
617 }
618 }
619
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000620 O << "\t.size\t" << CurrentFnName << ",.-" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000621
622 // Print out jump tables referenced by the function.
623 EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000624
Dale Johannesendd9e1c92008-12-03 19:33:10 +0000625 SwitchToSection(TAI->SectionForGlobal(F));
626
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000627 // Emit post-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000628 DW->EndFunction(&MF);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000629
Dan Gohmaneb94abd2008-11-07 19:49:17 +0000630 O.flush();
631
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000632 // We didn't modify anything.
633 return false;
634}
635
Chris Lattner2b638a72008-02-15 19:04:54 +0000636/// PrintUnmangledNameSafely - Print out the printable characters in the name.
Dan Gohman8387bb32009-03-03 02:55:14 +0000637/// Don't print things like \\n or \\0.
Owen Anderson847b99b2008-08-21 00:14:44 +0000638static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) {
Chris Lattner2b638a72008-02-15 19:04:54 +0000639 for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
640 Name != E; ++Name)
641 if (isprint(*Name))
642 OS << *Name;
643}
644
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000645void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000646 const TargetData *TD = TM.getTargetData();
647
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000648 if (!GVar->hasInitializer())
649 return; // External global require no code
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000650
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000651 // Check to see if this is a special global used by LLVM, if so, emit it.
652 if (EmitSpecialLLVMGlobal(GVar))
653 return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000655 std::string name = Mang->getValueName(GVar);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000656
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000657 printVisibility(name, GVar->getVisibility());
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000658
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000659 Constant *C = GVar->getInitializer();
Devang Patel880595f2009-06-26 02:26:12 +0000660 if (isa<MDNode>(C) || isa<MDString>(C))
Devang Patelf667ab42009-06-25 00:47:42 +0000661 return;
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000662 const Type *Type = C->getType();
Duncan Sandsec4f97d2009-05-09 07:06:46 +0000663 unsigned Size = TD->getTypeAllocSize(Type);
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000664 unsigned Align = TD->getPreferredAlignmentLog(GVar);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000665
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000666 SwitchToSection(TAI->SectionForGlobal(GVar));
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000667
668 if (C->isNullValue() && /* FIXME: Verify correct */
669 !GVar->hasSection() &&
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000670 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
Duncan Sands19d161f2009-03-07 15:45:40 +0000671 GVar->isWeakForLinker())) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000672 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000673
674 if (GVar->hasExternalLinkage()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000675 O << "\t.global " << name << '\n';
676 O << "\t.type " << name << ", @object\n";
Nick Lewycky3246a9c2007-07-25 03:48:45 +0000677 O << name << ":\n";
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000678 O << "\t.zero " << Size << '\n';
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000679 } else if (GVar->hasLocalLinkage()) {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000680 O << TAI->getLCOMMDirective() << name << ',' << Size;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000681 } else {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000682 O << ".comm " << name << ',' << Size;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000683 }
Evan Cheng11db8142009-03-24 00:17:40 +0000684 if (VerboseAsm) {
685 O << "\t\t" << TAI->getCommentString() << " '";
686 PrintUnmangledNameSafely(GVar, O);
687 O << "'";
688 }
689 O << '\n';
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000690 return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000691 }
692
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000693 switch (GVar->getLinkage()) {
Duncan Sands19d161f2009-03-07 15:45:40 +0000694 case GlobalValue::LinkOnceAnyLinkage:
695 case GlobalValue::LinkOnceODRLinkage:
696 case GlobalValue::WeakAnyLinkage:
697 case GlobalValue::WeakODRLinkage:
Duncan Sandsb95df792009-03-11 20:14:15 +0000698 case GlobalValue::CommonLinkage:
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000699 O << "\t.global " << name << '\n'
700 << "\t.type " << name << ", @object\n"
701 << "\t.weak " << name << '\n';
702 break;
703 case GlobalValue::AppendingLinkage:
704 // FIXME: appending linkage variables should go into a section of
705 // their name or something. For now, just emit them as external.
706 case GlobalValue::ExternalLinkage:
707 // If external or appending, declare as a global symbol
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000708 O << "\t.global " << name << '\n'
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000709 << "\t.type " << name << ", @object\n";
710 // FALL THROUGH
711 case GlobalValue::InternalLinkage:
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000712 case GlobalValue::PrivateLinkage:
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000713 break;
714 default:
715 cerr << "Unknown linkage type!";
716 abort();
717 }
718
719 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +0000720 O << name << ":";
721 if (VerboseAsm) {
722 O << "\t\t\t\t" << TAI->getCommentString() << " '";
723 PrintUnmangledNameSafely(GVar, O);
724 O << "'";
725 }
726 O << '\n';
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000727
Anton Korobeynikov894be4b2008-08-08 18:23:49 +0000728 EmitGlobalConstant(C);
729 O << '\n';
730}
731
732bool PPCLinuxAsmPrinter::doFinalization(Module &M) {
733 // Print out module-level global variables here.
734 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
735 I != E; ++I)
736 printModuleLevelGV(I);
737
Dan Gohman4a558a32007-07-25 19:33:14 +0000738 return AsmPrinter::doFinalization(M);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739}
740
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000741/// runOnMachineFunction - This uses the printMachineInstruction()
742/// method to print assembly for each instruction.
743///
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000744bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling4f405312009-02-24 08:30:20 +0000745 this->MF = &MF;
746
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000747 SetupMachineFunction(MF);
748 O << "\n\n";
Dale Johannesenfb3ac732007-11-20 23:24:42 +0000749
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 // Print out constants referenced by the function
751 EmitConstantPool(MF.getConstantPool());
752
753 // Print out labels for the function.
754 const Function *F = MF.getFunction();
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000755 SwitchToSection(TAI->SectionForGlobal(F));
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000756
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000757 switch (F->getLinkage()) {
758 default: assert(0 && "Unknown linkage type!");
evancheng47ae8142009-01-25 06:32:01 +0000759 case Function::PrivateLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000760 case Function::InternalLinkage: // Symbols default to internal.
761 break;
762 case Function::ExternalLinkage:
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000763 O << "\t.globl\t" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000764 break;
Duncan Sands19d161f2009-03-07 15:45:40 +0000765 case Function::WeakAnyLinkage:
766 case Function::WeakODRLinkage:
767 case Function::LinkOnceAnyLinkage:
768 case Function::LinkOnceODRLinkage:
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000769 O << "\t.globl\t" << CurrentFnName << '\n';
770 O << "\t.weak_definition\t" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 break;
772 }
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000773
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000774 printVisibility(CurrentFnName, F->getVisibility());
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000775
Bill Wendling25a8ae32009-06-30 22:38:32 +0000776 EmitAlignment(MF.getAlignment(), F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000777 O << CurrentFnName << ":\n";
778
779 // Emit pre-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000780 DW->BeginFunction(&MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000781
Bill Wendling36ccaea2008-01-26 06:51:24 +0000782 // If the function is empty, then we need to emit *something*. Otherwise, the
783 // function's label might be associated with something that it wasn't meant to
784 // be associated with. We emit a noop in this situation.
785 MachineFunction::iterator I = MF.begin();
786
Bill Wendlingb5880a72008-01-26 09:03:52 +0000787 if (++I == MF.end() && MF.front().empty())
788 O << "\tnop\n";
Bill Wendling36ccaea2008-01-26 06:51:24 +0000789
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000790 // Print out code for the function.
791 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
792 I != E; ++I) {
793 // Print a label for the basic block.
794 if (I != MF.begin()) {
Evan Cheng11db8142009-03-24 00:17:40 +0000795 printBasicBlockLabel(I, true, true, VerboseAsm);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 O << '\n';
797 }
Bill Wendling36ccaea2008-01-26 06:51:24 +0000798 for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
799 II != IE; ++II) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000800 // Print the assembly for the instruction.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000801 printMachineInstruction(II);
802 }
803 }
804
805 // Print out jump tables referenced by the function.
806 EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000807
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808 // Emit post-function debug information.
Devang Patelaa1e8432009-01-08 23:40:34 +0000809 DW->EndFunction(&MF);
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000810
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000811 // We didn't modify anything.
812 return false;
813}
814
815
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000816bool PPCDarwinAsmPrinter::doInitialization(Module &M) {
Dan Gohman12300e12008-03-25 21:45:14 +0000817 static const char *const CPUDirectives[] = {
Dale Johannesen161badc2008-02-14 23:35:16 +0000818 "",
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000819 "ppc",
820 "ppc601",
821 "ppc602",
822 "ppc603",
823 "ppc7400",
824 "ppc750",
825 "ppc970",
826 "ppc64"
827 };
828
829 unsigned Directive = Subtarget.getDarwinDirective();
830 if (Subtarget.isGigaProcessor() && Directive < PPC::DIR_970)
831 Directive = PPC::DIR_970;
832 if (Subtarget.hasAltivec() && Directive < PPC::DIR_7400)
833 Directive = PPC::DIR_7400;
834 if (Subtarget.isPPC64() && Directive < PPC::DIR_970)
835 Directive = PPC::DIR_64;
836 assert(Directive <= PPC::DIR_64 && "Directive out of range.");
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000837 O << "\t.machine " << CPUDirectives[Directive] << '\n';
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000838
Dan Gohman4a558a32007-07-25 19:33:14 +0000839 bool Result = AsmPrinter::doInitialization(M);
Devang Patelc20079e2009-06-20 01:00:07 +0000840 assert(MMI);
Dale Johannesen58e0eeb2008-07-09 20:43:39 +0000841
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000842 // Prime text sections so they are adjacent. This reduces the likelihood a
843 // large data or debug section causes a branch to exceed 16M limit.
Dale Johannesen3c788322008-01-11 00:54:37 +0000844 SwitchToTextSection("\t.section __TEXT,__textcoal_nt,coalesced,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000845 "pure_instructions");
846 if (TM.getRelocationModel() == Reloc::PIC_) {
Dale Johannesen3c788322008-01-11 00:54:37 +0000847 SwitchToTextSection("\t.section __TEXT,__picsymbolstub1,symbol_stubs,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000848 "pure_instructions,32");
849 } else if (TM.getRelocationModel() == Reloc::DynamicNoPIC) {
Dale Johannesen3c788322008-01-11 00:54:37 +0000850 SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000851 "pure_instructions,16");
852 }
Anton Korobeynikov55b94962008-09-24 22:15:21 +0000853 SwitchToSection(TAI->getTextSection());
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000854
Dan Gohman4a558a32007-07-25 19:33:14 +0000855 return Result;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000856}
857
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000858void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
859 const TargetData *TD = TM.getTargetData();
860
861 if (!GVar->hasInitializer())
862 return; // External global require no code
863
864 // Check to see if this is a special global used by LLVM, if so, emit it.
865 if (EmitSpecialLLVMGlobal(GVar)) {
866 if (TM.getRelocationModel() == Reloc::Static) {
867 if (GVar->getName() == "llvm.global_ctors")
868 O << ".reference .constructors_used\n";
869 else if (GVar->getName() == "llvm.global_dtors")
870 O << ".reference .destructors_used\n";
871 }
872 return;
873 }
874
875 std::string name = Mang->getValueName(GVar);
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000876
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000877 printVisibility(name, GVar->getVisibility());
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000878
879 Constant *C = GVar->getInitializer();
880 const Type *Type = C->getType();
Duncan Sandsec4f97d2009-05-09 07:06:46 +0000881 unsigned Size = TD->getTypeAllocSize(Type);
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000882 unsigned Align = TD->getPreferredAlignmentLog(GVar);
883
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000884 SwitchToSection(TAI->SectionForGlobal(GVar));
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000885
886 if (C->isNullValue() && /* FIXME: Verify correct */
887 !GVar->hasSection() &&
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000888 (GVar->hasLocalLinkage() || GVar->hasExternalLinkage() ||
Duncan Sands19d161f2009-03-07 15:45:40 +0000889 GVar->isWeakForLinker()) &&
Evan Chengcf84b142009-02-18 02:19:52 +0000890 TAI->SectionKindForGlobal(GVar) != SectionKind::RODataMergeStr) {
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000891 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
892
893 if (GVar->hasExternalLinkage()) {
894 O << "\t.globl " << name << '\n';
895 O << "\t.zerofill __DATA, __common, " << name << ", "
896 << Size << ", " << Align;
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000897 } else if (GVar->hasLocalLinkage()) {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000898 O << TAI->getLCOMMDirective() << name << ',' << Size << ',' << Align;
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000899 } else if (!GVar->hasCommonLinkage()) {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000900 O << "\t.globl " << name << '\n'
901 << TAI->getWeakDefDirective() << name << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000902 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +0000903 O << name << ":";
904 if (VerboseAsm) {
905 O << "\t\t\t\t" << TAI->getCommentString() << " ";
906 PrintUnmangledNameSafely(GVar, O);
907 }
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000908 O << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000909 EmitGlobalConstant(C);
910 return;
911 } else {
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000912 O << ".comm " << name << ',' << Size;
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000913 // Darwin 9 and above support aligned common data.
914 if (Subtarget.isDarwin9())
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000915 O << ',' << Align;
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000916 }
Evan Cheng11db8142009-03-24 00:17:40 +0000917 if (VerboseAsm) {
918 O << "\t\t" << TAI->getCommentString() << " '";
919 PrintUnmangledNameSafely(GVar, O);
920 O << "'";
921 }
922 O << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000923 return;
924 }
925
926 switch (GVar->getLinkage()) {
Duncan Sands19d161f2009-03-07 15:45:40 +0000927 case GlobalValue::LinkOnceAnyLinkage:
928 case GlobalValue::LinkOnceODRLinkage:
929 case GlobalValue::WeakAnyLinkage:
930 case GlobalValue::WeakODRLinkage:
Duncan Sandsb95df792009-03-11 20:14:15 +0000931 case GlobalValue::CommonLinkage:
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000932 O << "\t.globl " << name << '\n'
933 << "\t.weak_definition " << name << '\n';
934 break;
935 case GlobalValue::AppendingLinkage:
936 // FIXME: appending linkage variables should go into a section of
937 // their name or something. For now, just emit them as external.
938 case GlobalValue::ExternalLinkage:
939 // If external or appending, declare as a global symbol
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +0000940 O << "\t.globl " << name << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000941 // FALL THROUGH
942 case GlobalValue::InternalLinkage:
evancheng47ae8142009-01-25 06:32:01 +0000943 case GlobalValue::PrivateLinkage:
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000944 break;
945 default:
946 cerr << "Unknown linkage type!";
947 abort();
948 }
949
950 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +0000951 O << name << ":";
952 if (VerboseAsm) {
953 O << "\t\t\t\t" << TAI->getCommentString() << " '";
954 PrintUnmangledNameSafely(GVar, O);
955 O << "'";
956 }
957 O << '\n';
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000958
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000959 EmitGlobalConstant(C);
960 O << '\n';
961}
962
Anton Korobeynikov28f86d12008-08-08 18:22:59 +0000963bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000964 const TargetData *TD = TM.getTargetData();
965
966 // Print out module-level global variables here.
967 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
Anton Korobeynikov248e9c52008-08-08 18:23:25 +0000968 I != E; ++I)
969 printModuleLevelGV(I);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000970
971 bool isPPC64 = TD->getPointerSizeInBits() == 64;
972
973 // Output stubs for dynamically-linked functions
974 if (TM.getRelocationModel() == Reloc::PIC_) {
Evan Chenga65854f2008-12-05 01:06:39 +0000975 for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000976 i != e; ++i) {
Dale Johannesen3c788322008-01-11 00:54:37 +0000977 SwitchToTextSection("\t.section __TEXT,__picsymbolstub1,symbol_stubs,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000978 "pure_instructions,32");
979 EmitAlignment(4);
Evan Chenga65854f2008-12-05 01:06:39 +0000980 const char *p = i->getKeyData();
981 bool hasQuote = p[0]=='\"';
Dale Johannesena21b5202008-05-19 21:38:18 +0000982 printSuffixedName(p, "$stub");
983 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +0000984 O << "\t.indirect_symbol " << p << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000985 O << "\tmflr r0\n";
Evan Chenga65854f2008-12-05 01:06:39 +0000986 O << "\tbcl 20,31,";
987 if (hasQuote)
988 O << "\"L0$" << &p[1];
989 else
990 O << "L0$" << p;
991 O << '\n';
992 if (hasQuote)
993 O << "\"L0$" << &p[1];
994 else
995 O << "L0$" << p;
996 O << ":\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000997 O << "\tmflr r11\n";
Dale Johannesena21b5202008-05-19 21:38:18 +0000998 O << "\taddis r11,r11,ha16(";
999 printSuffixedName(p, "$lazy_ptr");
Evan Chenga65854f2008-12-05 01:06:39 +00001000 O << "-";
1001 if (hasQuote)
1002 O << "\"L0$" << &p[1];
1003 else
1004 O << "L0$" << p;
1005 O << ")\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001006 O << "\tmtlr r0\n";
1007 if (isPPC64)
Dale Johannesena21b5202008-05-19 21:38:18 +00001008 O << "\tldu r12,lo16(";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001009 else
Dale Johannesena21b5202008-05-19 21:38:18 +00001010 O << "\tlwzu r12,lo16(";
1011 printSuffixedName(p, "$lazy_ptr");
Evan Chenga65854f2008-12-05 01:06:39 +00001012 O << "-";
1013 if (hasQuote)
1014 O << "\"L0$" << &p[1];
1015 else
1016 O << "L0$" << p;
1017 O << ")(r11)\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001018 O << "\tmtctr r12\n";
1019 O << "\tbctr\n";
1020 SwitchToDataSection(".lazy_symbol_pointer");
Dale Johannesena21b5202008-05-19 21:38:18 +00001021 printSuffixedName(p, "$lazy_ptr");
1022 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001023 O << "\t.indirect_symbol " << p << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001024 if (isPPC64)
1025 O << "\t.quad dyld_stub_binding_helper\n";
1026 else
1027 O << "\t.long dyld_stub_binding_helper\n";
1028 }
1029 } else {
Evan Chenga65854f2008-12-05 01:06:39 +00001030 for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001031 i != e; ++i) {
Dale Johannesen3c788322008-01-11 00:54:37 +00001032 SwitchToTextSection("\t.section __TEXT,__symbol_stub1,symbol_stubs,"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001033 "pure_instructions,16");
1034 EmitAlignment(4);
Evan Chenga65854f2008-12-05 01:06:39 +00001035 const char *p = i->getKeyData();
Dale Johannesena21b5202008-05-19 21:38:18 +00001036 printSuffixedName(p, "$stub");
1037 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001038 O << "\t.indirect_symbol " << p << '\n';
Dale Johannesena21b5202008-05-19 21:38:18 +00001039 O << "\tlis r11,ha16(";
1040 printSuffixedName(p, "$lazy_ptr");
1041 O << ")\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001042 if (isPPC64)
Dale Johannesena21b5202008-05-19 21:38:18 +00001043 O << "\tldu r12,lo16(";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001044 else
Dale Johannesena21b5202008-05-19 21:38:18 +00001045 O << "\tlwzu r12,lo16(";
1046 printSuffixedName(p, "$lazy_ptr");
1047 O << ")(r11)\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001048 O << "\tmtctr r12\n";
1049 O << "\tbctr\n";
1050 SwitchToDataSection(".lazy_symbol_pointer");
Dale Johannesena21b5202008-05-19 21:38:18 +00001051 printSuffixedName(p, "$lazy_ptr");
1052 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001053 O << "\t.indirect_symbol " << p << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001054 if (isPPC64)
1055 O << "\t.quad dyld_stub_binding_helper\n";
1056 else
1057 O << "\t.long dyld_stub_binding_helper\n";
1058 }
1059 }
1060
Anton Korobeynikovdaf7efe2008-08-08 18:24:10 +00001061 O << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001062
Dale Johannesen85535762008-04-02 00:25:04 +00001063 if (TAI->doesSupportExceptionHandling() && MMI) {
Dale Johannesenfb3ac732007-11-20 23:24:42 +00001064 // Add the (possibly multiple) personalities to the set of global values.
Dale Johannesen85535762008-04-02 00:25:04 +00001065 // Only referenced functions get into the Personalities list.
Chris Lattner2424eac2009-06-24 19:09:55 +00001066 const std::vector<Function *> &Personalities = MMI->getPersonalities();
Dale Johannesenfb3ac732007-11-20 23:24:42 +00001067 for (std::vector<Function *>::const_iterator I = Personalities.begin(),
1068 E = Personalities.end(); I != E; ++I)
1069 if (*I) GVStubs.insert("_" + (*I)->getName());
1070 }
1071
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001072 // Output stubs for external and common global variables.
Dan Gohman3f7d94b2007-10-03 19:26:29 +00001073 if (!GVStubs.empty()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001074 SwitchToDataSection(".non_lazy_symbol_pointer");
Evan Chenga65854f2008-12-05 01:06:39 +00001075 for (StringSet<>::iterator i = GVStubs.begin(), e = GVStubs.end();
1076 i != e; ++i) {
1077 std::string p = i->getKeyData();
Dale Johannesena21b5202008-05-19 21:38:18 +00001078 printSuffixedName(p, "$non_lazy_ptr");
1079 O << ":\n";
Evan Chenga65854f2008-12-05 01:06:39 +00001080 O << "\t.indirect_symbol " << p << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001081 if (isPPC64)
1082 O << "\t.quad\t0\n";
1083 else
1084 O << "\t.long\t0\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001085 }
1086 }
1087
Evan Chenga65854f2008-12-05 01:06:39 +00001088 if (!HiddenGVStubs.empty()) {
1089 SwitchToSection(TAI->getDataSection());
1090 for (StringSet<>::iterator i = HiddenGVStubs.begin(), e = HiddenGVStubs.end();
1091 i != e; ++i) {
1092 std::string p = i->getKeyData();
1093 EmitAlignment(isPPC64 ? 3 : 2);
1094 printSuffixedName(p, "$non_lazy_ptr");
1095 O << ":\n";
1096 if (isPPC64)
1097 O << "\t.quad\t";
1098 else
1099 O << "\t.long\t";
1100 O << p << '\n';
1101 }
1102 }
1103
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001104 // Funny Darwin hack: This flag tells the linker that no global symbols
1105 // contain code that falls through to other global symbols (e.g. the obvious
1106 // implementation of multiple entry points). If this doesn't occur, the
1107 // linker can safely perform dead code stripping. Since LLVM never generates
1108 // code that does this, it is always safe to set.
1109 O << "\t.subsections_via_symbols\n";
1110
Dan Gohman4a558a32007-07-25 19:33:14 +00001111 return AsmPrinter::doFinalization(M);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001112}
1113
1114
1115
1116/// createPPCAsmPrinterPass - Returns a pass that prints the PPC assembly code
1117/// for a MachineFunction to the given output stream, in a format that the
1118/// Darwin assembler can deal with.
1119///
Owen Anderson847b99b2008-08-21 00:14:44 +00001120FunctionPass *llvm::createPPCAsmPrinterPass(raw_ostream &o,
Bill Wendling4f405312009-02-24 08:30:20 +00001121 PPCTargetMachine &tm,
Bill Wendling5ed22ac2009-04-29 23:29:43 +00001122 bool verbose) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001123 const PPCSubtarget *Subtarget = &tm.getSubtarget<PPCSubtarget>();
1124
1125 if (Subtarget->isDarwin()) {
Daniel Dunbarb10d2222009-07-01 01:48:54 +00001126 return new PPCDarwinAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001127 } else {
Daniel Dunbarb10d2222009-07-01 01:48:54 +00001128 return new PPCLinuxAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001129 }
1130}
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +00001131
1132namespace {
1133 static struct Register {
1134 Register() {
1135 PPCTargetMachine::registerAsmPrinter(createPPCAsmPrinterPass);
1136 }
1137 } Registrator;
1138}
Oscar Fuentes4f012352008-11-15 21:36:30 +00001139
1140extern "C" int PowerPCAsmPrinterForceLink;
1141int PowerPCAsmPrinterForceLink = 0;
Douglas Gregor1dc5ff42009-06-16 20:12:29 +00001142
Bob Wilsonebbc1c42009-06-23 23:59:40 +00001143// Force static initialization.
1144extern "C" void LLVMInitializePowerPCAsmPrinter() { }