blob: 7e401c453f0fc6781573ed70fbb7943f6c6fe7e9 [file] [log] [blame]
Nate Begeman21e463b2005-10-16 05:39:50 +00001//===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Misha Brukman5dfe3a92004-06-21 16:55:25 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Misha Brukman5dfe3a92004-06-21 16:55:25 +00008//===----------------------------------------------------------------------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00009//
Chris Lattnerb0096bd2005-08-15 23:47:04 +000010// Top-level implementation for the PowerPC target.
Misha Brukman5dfe3a92004-06-21 16:55:25 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner26689592005-10-14 23:51:18 +000014#include "PPC.h"
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000015#include "PPCTargetAsmInfo.h"
Chris Lattner16e71f22005-10-14 23:59:06 +000016#include "PPCTargetMachine.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000017#include "llvm/Module.h"
18#include "llvm/PassManager.h"
Chris Lattnerd36c9702004-07-11 02:48:49 +000019#include "llvm/Target/TargetMachineRegistry.h"
Dale Johannesen72324642008-07-31 18:13:12 +000020#include "llvm/Target/TargetOptions.h"
David Greene71847812009-07-14 20:18:05 +000021#include "llvm/Support/FormattedStream.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000022using namespace llvm;
23
Oscar Fuentes92adc192008-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 Gohman844731a2008-05-13 00:00:25 +000032// Register the targets
Daniel Dunbar42467902009-07-15 09:22:31 +000033extern Target ThePPC32Target;
Dan Gohman844731a2008-05-13 00:00:25 +000034static RegisterTarget<PPC32TargetMachine>
Daniel Dunbar42467902009-07-15 09:22:31 +000035X(ThePPC32Target, "ppc32", "PowerPC 32");
36
37extern Target ThePPC64Target;
Dan Gohman844731a2008-05-13 00:00:25 +000038static RegisterTarget<PPC64TargetMachine>
Daniel Dunbar42467902009-07-15 09:22:31 +000039Y(ThePPC64Target, "ppc64", "PowerPC 64");
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000040
Bob Wilsona96751f2009-06-23 23:59:40 +000041// Force static initialization.
42extern "C" void LLVMInitializePowerPCTarget() { }
Douglas Gregor1555a232009-06-16 20:12:29 +000043
Anton Korobeynikov06be9972008-08-17 13:54:28 +000044// No assembler printer by default
45PPCTargetMachine::AsmPrinterCtorFn PPCTargetMachine::AsmPrinterCtor = 0;
46
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000047const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
Jim Laskeybf111822006-12-21 20:26:09 +000048 if (Subtarget.isDarwin())
Anton Korobeynikovbadd8df2008-07-19 21:44:57 +000049 return new PPCDarwinTargetAsmInfo(*this);
Jim Laskeybf111822006-12-21 20:26:09 +000050 else
Anton Korobeynikovbadd8df2008-07-19 21:44:57 +000051 return new PPCLinuxTargetAsmInfo(*this);
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000052}
53
Daniel Dunbar03f4bc52009-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),
Chris Lattnerb1d26f62006-06-17 00:01:04 +000058 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Chris Lattnerff790892006-11-18 01:34:43 +000059 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
Bill Wendling0ea18ff2007-01-24 03:41:36 +000060 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
Chris Lattner94de9a82006-06-16 01:37:27 +000061
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000062 if (getRelocationModel() == Reloc::Default) {
Evan Cheng4c1aa862006-02-22 20:19:42 +000063 if (Subtarget.isDarwin())
64 setRelocationModel(Reloc::DynamicNoPIC);
65 else
Jim Laskeybf111822006-12-21 20:26:09 +000066 setRelocationModel(Reloc::Static);
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000067 }
Nate Begeman21e463b2005-10-16 05:39:50 +000068}
69
Dale Johannesen81da02b2007-05-22 17:14:46 +000070/// Override this for PowerPC. Tail merging happily breaks up instruction issue
71/// groups, which typically degrades performance.
Dan Gohman50cdabc2007-11-19 20:46:23 +000072bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dale Johannesen81da02b2007-05-22 17:14:46 +000073
Daniel Dunbar03f4bc52009-07-15 12:11:05 +000074PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
75 const std::string &FS)
76 : PPCTargetMachine(T, M, FS, false) {
Chris Lattner94de9a82006-06-16 01:37:27 +000077}
78
79
Daniel Dunbar03f4bc52009-07-15 12:11:05 +000080PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
81 const std::string &FS)
82 : PPCTargetMachine(T, M, FS, true) {
Chris Lattner94de9a82006-06-16 01:37:27 +000083}
84
Misha Brukmanb5f662f2005-04-21 23:30:14 +000085
Chris Lattner1911fd42006-09-04 04:14:57 +000086//===----------------------------------------------------------------------===//
87// Pass Pipeline Configuration
88//===----------------------------------------------------------------------===//
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000089
Bill Wendling98a366d2009-04-29 23:29:43 +000090bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
91 CodeGenOpt::Level OptLevel) {
Chris Lattner8482dd82005-08-17 19:33:30 +000092 // Install an instruction selector.
Chris Lattner05f1fe82006-01-12 01:46:07 +000093 PM.add(createPPCISelDag(*this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000094 return false;
95}
96
Bill Wendling98a366d2009-04-29 23:29:43 +000097bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
98 CodeGenOpt::Level OptLevel) {
Chris Lattner1911fd42006-09-04 04:14:57 +000099 // Must run branch selection immediately preceding the asm printer.
100 PM.add(createPPCBranchSelectionPass());
101 return false;
102}
103
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000104bool PPCTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling98a366d2009-04-29 23:29:43 +0000105 CodeGenOpt::Level OptLevel,
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +0000106 bool Verbose,
David Greene71847812009-07-14 20:18:05 +0000107 formatted_raw_ostream &Out) {
Anton Korobeynikov06be9972008-08-17 13:54:28 +0000108 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
109 if (AsmPrinterCtor)
Daniel Dunbar5bcc8bd2009-07-01 01:48:54 +0000110 PM.add(AsmPrinterCtor(Out, *this, Verbose));
Anton Korobeynikov06be9972008-08-17 13:54:28 +0000111
Chris Lattner1911fd42006-09-04 04:14:57 +0000112 return false;
113}
114
Bill Wendling98a366d2009-04-29 23:29:43 +0000115bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
116 CodeGenOpt::Level OptLevel,
Evan Cheng8bd60352007-07-20 21:56:13 +0000117 bool DumpAsm, MachineCodeEmitter &MCE) {
Chris Lattnere150b8e2006-12-08 04:54:03 +0000118 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
Chris Lattner1911fd42006-09-04 04:14:57 +0000119 // FIXME: This should be moved to TargetJITInfo!!
Chris Lattnere150b8e2006-12-08 04:54:03 +0000120 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 Johannesen72324642008-07-31 18:13:12 +0000125 // Temporary workaround for the inability of PPC64 JIT to handle jump
126 // tables.
127 DisableJumpTables = true;
Chris Lattnere150b8e2006-12-08 04:54:03 +0000128 } else {
129 setRelocationModel(Reloc::Static);
130 }
131
Chris Lattner57fc62c2006-12-11 23:22:45 +0000132 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
133 // writing?
134 Subtarget.SetJITMode();
Chris Lattner1911fd42006-09-04 04:14:57 +0000135
136 // Machine code emitter pass for PowerPC.
Nate Begemaneb883af2006-08-23 21:08:52 +0000137 PM.add(createPPCCodeEmitterPass(*this, MCE));
Daniel Dunbarf3f47152009-07-15 12:49:15 +0000138 if (DumpAsm)
139 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Anton Korobeynikov06be9972008-08-17 13:54:28 +0000140
Nate Begemaneb883af2006-08-23 21:08:52 +0000141 return false;
142}
Chris Lattner1911fd42006-09-04 04:14:57 +0000143
Bruno Cardoso Lopesa3f99f92009-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 Dunbarf3f47152009-07-15 12:49:15 +0000167 if (DumpAsm)
168 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000169
170 return false;
171}
172
Bruno Cardoso Lopesac57e6e2009-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 Dunbarf3f47152009-07-15 12:49:15 +0000196 if (DumpAsm)
197 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000198
199 return false;
200}
201
Bill Wendling98a366d2009-04-29 23:29:43 +0000202bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
203 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes434dd4f2009-06-01 19:57:37 +0000204 bool DumpAsm,
205 MachineCodeEmitter &MCE) {
Bill Wendlingeb1ac332007-02-08 01:39:44 +0000206 // Machine code emitter pass for PowerPC.
207 PM.add(createPPCCodeEmitterPass(*this, MCE));
Daniel Dunbarf3f47152009-07-15 12:49:15 +0000208 if (DumpAsm)
209 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Anton Korobeynikov06be9972008-08-17 13:54:28 +0000210
Bill Wendlingeb1ac332007-02-08 01:39:44 +0000211 return false;
212}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000213
214bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
215 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes434dd4f2009-06-01 19:57:37 +0000216 bool DumpAsm,
217 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000218 // Machine code emitter pass for PowerPC.
219 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Daniel Dunbarf3f47152009-07-15 12:49:15 +0000220 if (DumpAsm)
221 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000222
223 return false;
224}
225
Bruno Cardoso Lopesac57e6e2009-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 Dunbarf3f47152009-07-15 12:49:15 +0000232 if (DumpAsm)
233 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000234
235 return false;
236}
237
238