blob: 7e401c453f0fc6781573ed70fbb7943f6c6fe7e9 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
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// Top-level implementation for the PowerPC target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PPC.h"
15#include "PPCTargetAsmInfo.h"
16#include "PPCTargetMachine.h"
17#include "llvm/Module.h"
18#include "llvm/PassManager.h"
19#include "llvm/Target/TargetMachineRegistry.h"
Dale Johannesen493492f2008-07-31 18:13:12 +000020#include "llvm/Target/TargetOptions.h"
David Greene302008d2009-07-14 20:18:05 +000021#include "llvm/Support/FormattedStream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000022using namespace llvm;
23
Oscar Fuentes4f012352008-11-15 21:36:30 +000024/// PowerPCTargetMachineModule - Note that this is used on hosts that
25/// cannot link in a library unless there are references into the
26/// library. In particular, it seems that it is not possible to get
27/// things to work on Win32 without this. Though it is unused, do not
28/// remove it.
29extern "C" int PowerPCTargetMachineModule;
30int PowerPCTargetMachineModule = 0;
31
Dan Gohman089efff2008-05-13 00:00:25 +000032// Register the targets
Daniel Dunbar6fa4f572009-07-15 09:22:31 +000033extern Target ThePPC32Target;
Dan Gohman089efff2008-05-13 00:00:25 +000034static RegisterTarget<PPC32TargetMachine>
Daniel Dunbar6fa4f572009-07-15 09:22:31 +000035X(ThePPC32Target, "ppc32", "PowerPC 32");
36
37extern Target ThePPC64Target;
Dan Gohman089efff2008-05-13 00:00:25 +000038static RegisterTarget<PPC64TargetMachine>
Daniel Dunbar6fa4f572009-07-15 09:22:31 +000039Y(ThePPC64Target, "ppc64", "PowerPC 64");
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040
Bob Wilsonebbc1c42009-06-23 23:59:40 +000041// Force static initialization.
42extern "C" void LLVMInitializePowerPCTarget() { }
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000043
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +000044// No assembler printer by default
45PPCTargetMachine::AsmPrinterCtorFn PPCTargetMachine::AsmPrinterCtor = 0;
46
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
48 if (Subtarget.isDarwin())
Anton Korobeynikovd15bc312008-07-19 21:44:57 +000049 return new PPCDarwinTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 else
Anton Korobeynikovd15bc312008-07-19 21:44:57 +000051 return new PPCLinuxTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052}
53
Daniel Dunbar8ea70212009-07-15 12:11:05 +000054PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M,
55 const std::string &FS, bool is64Bit)
56 : LLVMTargetMachine(T),
57 Subtarget(*this, M, FS, is64Bit),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
59 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
60 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
61
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000062 if (getRelocationModel() == Reloc::Default) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063 if (Subtarget.isDarwin())
64 setRelocationModel(Reloc::DynamicNoPIC);
65 else
66 setRelocationModel(Reloc::Static);
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000067 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000068}
69
70/// Override this for PowerPC. Tail merging happily breaks up instruction issue
71/// groups, which typically degrades performance.
Dan Gohman62ea18a2007-11-19 20:46:23 +000072bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073
Daniel Dunbar8ea70212009-07-15 12:11:05 +000074PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
75 const std::string &FS)
76 : PPCTargetMachine(T, M, FS, false) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077}
78
79
Daniel Dunbar8ea70212009-07-15 12:11:05 +000080PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
81 const std::string &FS)
82 : PPCTargetMachine(T, M, FS, true) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000083}
84
85
86//===----------------------------------------------------------------------===//
87// Pass Pipeline Configuration
88//===----------------------------------------------------------------------===//
89
Bill Wendling5ed22ac2009-04-29 23:29:43 +000090bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
91 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000092 // Install an instruction selector.
93 PM.add(createPPCISelDag(*this));
94 return false;
95}
96
Bill Wendling5ed22ac2009-04-29 23:29:43 +000097bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
98 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000099 // Must run branch selection immediately preceding the asm printer.
100 PM.add(createPPCBranchSelectionPass());
101 return false;
102}
103
Bill Wendling58ed5d22009-04-29 00:15:41 +0000104bool PPCTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000105 CodeGenOpt::Level OptLevel,
Bill Wendling58ed5d22009-04-29 00:15:41 +0000106 bool Verbose,
David Greene302008d2009-07-14 20:18:05 +0000107 formatted_raw_ostream &Out) {
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +0000108 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
109 if (AsmPrinterCtor)
Daniel Dunbarb10d2222009-07-01 01:48:54 +0000110 PM.add(AsmPrinterCtor(Out, *this, Verbose));
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +0000111
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000112 return false;
113}
114
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000115bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
116 CodeGenOpt::Level OptLevel,
Evan Cheng77547212007-07-20 21:56:13 +0000117 bool DumpAsm, MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000118 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
119 // FIXME: This should be moved to TargetJITInfo!!
120 if (Subtarget.isPPC64()) {
121 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
122 // instructions to materialize arbitrary global variable + function +
123 // constant pool addresses.
124 setRelocationModel(Reloc::PIC_);
Dale Johannesen493492f2008-07-31 18:13:12 +0000125 // Temporary workaround for the inability of PPC64 JIT to handle jump
126 // tables.
127 DisableJumpTables = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000128 } else {
129 setRelocationModel(Reloc::Static);
130 }
131
132 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
133 // writing?
134 Subtarget.SetJITMode();
135
136 // Machine code emitter pass for PowerPC.
137 PM.add(createPPCCodeEmitterPass(*this, MCE));
Daniel Dunbar8ba03b72009-07-15 12:49:15 +0000138 if (DumpAsm)
139 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +0000140
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000141 return false;
142}
143
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000144bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
145 CodeGenOpt::Level OptLevel,
146 bool DumpAsm, JITCodeEmitter &JCE) {
147 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
148 // FIXME: This should be moved to TargetJITInfo!!
149 if (Subtarget.isPPC64()) {
150 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
151 // instructions to materialize arbitrary global variable + function +
152 // constant pool addresses.
153 setRelocationModel(Reloc::PIC_);
154 // Temporary workaround for the inability of PPC64 JIT to handle jump
155 // tables.
156 DisableJumpTables = true;
157 } else {
158 setRelocationModel(Reloc::Static);
159 }
160
161 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
162 // writing?
163 Subtarget.SetJITMode();
164
165 // Machine code emitter pass for PowerPC.
166 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Daniel Dunbar8ba03b72009-07-15 12:49:15 +0000167 if (DumpAsm)
168 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000169
170 return false;
171}
172
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000173bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
174 CodeGenOpt::Level OptLevel,
175 bool DumpAsm, ObjectCodeEmitter &OCE) {
176 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
177 // FIXME: This should be moved to TargetJITInfo!!
178 if (Subtarget.isPPC64()) {
179 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
180 // instructions to materialize arbitrary global variable + function +
181 // constant pool addresses.
182 setRelocationModel(Reloc::PIC_);
183 // Temporary workaround for the inability of PPC64 JIT to handle jump
184 // tables.
185 DisableJumpTables = true;
186 } else {
187 setRelocationModel(Reloc::Static);
188 }
189
190 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
191 // writing?
192 Subtarget.SetJITMode();
193
194 // Machine code emitter pass for PowerPC.
195 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Daniel Dunbar8ba03b72009-07-15 12:49:15 +0000196 if (DumpAsm)
197 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000198
199 return false;
200}
201
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000202bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
203 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000204 bool DumpAsm,
205 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000206 // Machine code emitter pass for PowerPC.
207 PM.add(createPPCCodeEmitterPass(*this, MCE));
Daniel Dunbar8ba03b72009-07-15 12:49:15 +0000208 if (DumpAsm)
209 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +0000210
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000211 return false;
212}
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000213
214bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
215 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000216 bool DumpAsm,
217 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000218 // Machine code emitter pass for PowerPC.
219 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Daniel Dunbar8ba03b72009-07-15 12:49:15 +0000220 if (DumpAsm)
221 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000222
223 return false;
224}
225
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000226bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
227 CodeGenOpt::Level OptLevel,
228 bool DumpAsm,
229 ObjectCodeEmitter &OCE) {
230 // Machine code emitter pass for PowerPC.
231 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Daniel Dunbar8ba03b72009-07-15 12:49:15 +0000232 if (DumpAsm)
233 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000234
235 return false;
236}
237
238