blob: 1928d6ac26ef098adf1297e0ea109bbe67a9d4d8 [file] [log] [blame]
Nate Begeman6cca84e2005-10-16 05:39:50 +00001//===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
Misha Brukmanb4402432005-04-21 23:30:14 +00002//
Misha Brukmane05203f2004-06-21 16:55:25 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Brukmanb4402432005-04-21 23:30:14 +00007//
Misha Brukmane05203f2004-06-21 16:55:25 +00008//===----------------------------------------------------------------------===//
Misha Brukmanb4402432005-04-21 23:30:14 +00009//
Chris Lattner73785d22005-08-15 23:47:04 +000010// Top-level implementation for the PowerPC target.
Misha Brukmane05203f2004-06-21 16:55:25 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattnerbfca1ab2005-10-14 23:51:18 +000014#include "PPC.h"
Jim Laskeyae92ce82006-09-07 23:39:26 +000015#include "PPCTargetAsmInfo.h"
Chris Lattner6f3b9542005-10-14 23:59:06 +000016#include "PPCTargetMachine.h"
Misha Brukmane05203f2004-06-21 16:55:25 +000017#include "llvm/Module.h"
18#include "llvm/PassManager.h"
Chris Lattner4266f802004-07-11 02:48:49 +000019#include "llvm/Target/TargetMachineRegistry.h"
Dale Johannesenc31eb202008-07-31 18:13:12 +000020#include "llvm/Target/TargetOptions.h"
David Greenea31f96c2009-07-14 20:18:05 +000021#include "llvm/Support/FormattedStream.h"
Misha Brukmane05203f2004-06-21 16:55:25 +000022using namespace llvm;
23
Oscar Fuentesba4eb2a2008-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 Gohmand78c4002008-05-13 00:00:25 +000032// Register the targets
Daniel Dunbare8338102009-07-15 20:24:03 +000033extern Target ThePPC32Target;
Dan Gohmand78c4002008-05-13 00:00:25 +000034static RegisterTarget<PPC32TargetMachine>
Daniel Dunbare8338102009-07-15 20:24:03 +000035X(ThePPC32Target, "ppc32", "PowerPC 32");
36
37extern Target ThePPC64Target;
Dan Gohmand78c4002008-05-13 00:00:25 +000038static RegisterTarget<PPC64TargetMachine>
Daniel Dunbare8338102009-07-15 20:24:03 +000039Y(ThePPC64Target, "ppc64", "PowerPC 64");
Nate Begemanf17ea0f2004-08-11 07:40:04 +000040
Bob Wilson5a495fe2009-06-23 23:59:40 +000041// Force static initialization.
42extern "C" void LLVMInitializePowerPCTarget() { }
Douglas Gregor1b731d52009-06-16 20:12:29 +000043
Jim Laskeyae92ce82006-09-07 23:39:26 +000044const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
Jim Laskey28663c72006-12-21 20:26:09 +000045 if (Subtarget.isDarwin())
Anton Korobeynikovbc780e32008-07-19 21:44:57 +000046 return new PPCDarwinTargetAsmInfo(*this);
Jim Laskey28663c72006-12-21 20:26:09 +000047 else
Anton Korobeynikovbc780e32008-07-19 21:44:57 +000048 return new PPCLinuxTargetAsmInfo(*this);
Jim Laskeyae92ce82006-09-07 23:39:26 +000049}
50
Daniel Dunbare8338102009-07-15 20:24:03 +000051PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M,
52 const std::string &FS, bool is64Bit)
53 : LLVMTargetMachine(T),
54 Subtarget(*this, M, FS, is64Bit),
Chris Lattner49cadab2006-06-17 00:01:04 +000055 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Chris Lattner572e2382006-11-18 01:34:43 +000056 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
Bill Wendling40cb8112007-01-24 03:41:36 +000057 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
Chris Lattner0c4aa142006-06-16 01:37:27 +000058
Anton Korobeynikov40d67c52008-02-20 11:22:39 +000059 if (getRelocationModel() == Reloc::Default) {
Evan Cheng73136df2006-02-22 20:19:42 +000060 if (Subtarget.isDarwin())
61 setRelocationModel(Reloc::DynamicNoPIC);
62 else
Jim Laskey28663c72006-12-21 20:26:09 +000063 setRelocationModel(Reloc::Static);
Anton Korobeynikov40d67c52008-02-20 11:22:39 +000064 }
Nate Begeman6cca84e2005-10-16 05:39:50 +000065}
66
Dale Johannesen82810c82007-05-22 17:14:46 +000067/// Override this for PowerPC. Tail merging happily breaks up instruction issue
68/// groups, which typically degrades performance.
Dan Gohmanaad83c82007-11-19 20:46:23 +000069bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dale Johannesen82810c82007-05-22 17:14:46 +000070
Daniel Dunbare8338102009-07-15 20:24:03 +000071PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
72 const std::string &FS)
73 : PPCTargetMachine(T, M, FS, false) {
Chris Lattner0c4aa142006-06-16 01:37:27 +000074}
75
76
Daniel Dunbare8338102009-07-15 20:24:03 +000077PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
78 const std::string &FS)
79 : PPCTargetMachine(T, M, FS, true) {
Chris Lattner0c4aa142006-06-16 01:37:27 +000080}
81
Misha Brukmanb4402432005-04-21 23:30:14 +000082
Chris Lattner12e97302006-09-04 04:14:57 +000083//===----------------------------------------------------------------------===//
84// Pass Pipeline Configuration
85//===----------------------------------------------------------------------===//
Nate Begemanf17ea0f2004-08-11 07:40:04 +000086
Bill Wendling026e5d72009-04-29 23:29:43 +000087bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
88 CodeGenOpt::Level OptLevel) {
Chris Lattnerc6aa8062005-08-17 19:33:30 +000089 // Install an instruction selector.
Chris Lattner33792a42006-01-12 01:46:07 +000090 PM.add(createPPCISelDag(*this));
Nate Begemanf17ea0f2004-08-11 07:40:04 +000091 return false;
92}
93
Bill Wendling026e5d72009-04-29 23:29:43 +000094bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
95 CodeGenOpt::Level OptLevel) {
Chris Lattner12e97302006-09-04 04:14:57 +000096 // Must run branch selection immediately preceding the asm printer.
97 PM.add(createPPCBranchSelectionPass());
98 return false;
99}
100
Bill Wendling084669a2009-04-29 00:15:41 +0000101bool PPCTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
Bill Wendling026e5d72009-04-29 23:29:43 +0000102 CodeGenOpt::Level OptLevel,
Bill Wendling084669a2009-04-29 00:15:41 +0000103 bool Verbose,
David Greenea31f96c2009-07-14 20:18:05 +0000104 formatted_raw_ostream &Out) {
Daniel Dunbar53022882009-07-15 22:01:32 +0000105 FunctionPass *Printer = getTarget().createAsmPrinter(Out, *this, Verbose);
106 if (!Printer)
107 llvm_report_error("unable to create assembly printer");
108 PM.add(Printer);
Chris Lattner12e97302006-09-04 04:14:57 +0000109 return false;
110}
111
Bill Wendling026e5d72009-04-29 23:29:43 +0000112bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
113 CodeGenOpt::Level OptLevel,
Evan Cheng9d5df0a2007-07-20 21:56:13 +0000114 bool DumpAsm, MachineCodeEmitter &MCE) {
Chris Lattner09fecf92006-12-08 04:54:03 +0000115 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
Chris Lattner12e97302006-09-04 04:14:57 +0000116 // FIXME: This should be moved to TargetJITInfo!!
Chris Lattner09fecf92006-12-08 04:54:03 +0000117 if (Subtarget.isPPC64()) {
118 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
119 // instructions to materialize arbitrary global variable + function +
120 // constant pool addresses.
121 setRelocationModel(Reloc::PIC_);
Dale Johannesenc31eb202008-07-31 18:13:12 +0000122 // Temporary workaround for the inability of PPC64 JIT to handle jump
123 // tables.
124 DisableJumpTables = true;
Chris Lattner09fecf92006-12-08 04:54:03 +0000125 } else {
126 setRelocationModel(Reloc::Static);
127 }
128
Chris Lattnerf4646a72006-12-11 23:22:45 +0000129 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
130 // writing?
131 Subtarget.SetJITMode();
Chris Lattner12e97302006-09-04 04:14:57 +0000132
133 // Machine code emitter pass for PowerPC.
Nate Begeman3cb39212006-08-23 21:08:52 +0000134 PM.add(createPPCCodeEmitterPass(*this, MCE));
Daniel Dunbareb8c83b2009-07-15 12:49:15 +0000135 if (DumpAsm)
136 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Anton Korobeynikov28dc9d02008-08-17 13:54:28 +0000137
Nate Begeman3cb39212006-08-23 21:08:52 +0000138 return false;
139}
Chris Lattner12e97302006-09-04 04:14:57 +0000140
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000141bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
142 CodeGenOpt::Level OptLevel,
143 bool DumpAsm, JITCodeEmitter &JCE) {
144 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
145 // FIXME: This should be moved to TargetJITInfo!!
146 if (Subtarget.isPPC64()) {
147 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
148 // instructions to materialize arbitrary global variable + function +
149 // constant pool addresses.
150 setRelocationModel(Reloc::PIC_);
151 // Temporary workaround for the inability of PPC64 JIT to handle jump
152 // tables.
153 DisableJumpTables = true;
154 } else {
155 setRelocationModel(Reloc::Static);
156 }
157
158 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
159 // writing?
160 Subtarget.SetJITMode();
161
162 // Machine code emitter pass for PowerPC.
163 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Daniel Dunbareb8c83b2009-07-15 12:49:15 +0000164 if (DumpAsm)
165 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000166
167 return false;
168}
169
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000170bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
171 CodeGenOpt::Level OptLevel,
172 bool DumpAsm, ObjectCodeEmitter &OCE) {
173 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
174 // FIXME: This should be moved to TargetJITInfo!!
175 if (Subtarget.isPPC64()) {
176 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
177 // instructions to materialize arbitrary global variable + function +
178 // constant pool addresses.
179 setRelocationModel(Reloc::PIC_);
180 // Temporary workaround for the inability of PPC64 JIT to handle jump
181 // tables.
182 DisableJumpTables = true;
183 } else {
184 setRelocationModel(Reloc::Static);
185 }
186
187 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
188 // writing?
189 Subtarget.SetJITMode();
190
191 // Machine code emitter pass for PowerPC.
192 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Daniel Dunbareb8c83b2009-07-15 12:49:15 +0000193 if (DumpAsm)
194 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000195
196 return false;
197}
198
Bill Wendling026e5d72009-04-29 23:29:43 +0000199bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
200 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes9fd794b2009-06-01 19:57:37 +0000201 bool DumpAsm,
202 MachineCodeEmitter &MCE) {
Bill Wendling2aa9a422007-02-08 01:39:44 +0000203 // Machine code emitter pass for PowerPC.
204 PM.add(createPPCCodeEmitterPass(*this, MCE));
Daniel Dunbareb8c83b2009-07-15 12:49:15 +0000205 if (DumpAsm)
206 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Anton Korobeynikov28dc9d02008-08-17 13:54:28 +0000207
Bill Wendling2aa9a422007-02-08 01:39:44 +0000208 return false;
209}
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000210
211bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
212 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes9fd794b2009-06-01 19:57:37 +0000213 bool DumpAsm,
214 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000215 // Machine code emitter pass for PowerPC.
216 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Daniel Dunbareb8c83b2009-07-15 12:49:15 +0000217 if (DumpAsm)
218 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000219
220 return false;
221}
222
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000223bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
224 CodeGenOpt::Level OptLevel,
225 bool DumpAsm,
226 ObjectCodeEmitter &OCE) {
227 // Machine code emitter pass for PowerPC.
228 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Daniel Dunbareb8c83b2009-07-15 12:49:15 +0000229 if (DumpAsm)
230 addAssemblyEmitter(PM, OptLevel, true, ferrs());
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000231
232 return false;
233}
234
235