blob: 77b307242059c780923f635d0e1261e1cbf2737c [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 Dunbar51b198a2009-07-15 20:24:03 +000033extern Target ThePPC32Target;
Dan Gohman844731a2008-05-13 00:00:25 +000034static RegisterTarget<PPC32TargetMachine>
Daniel Dunbar51b198a2009-07-15 20:24:03 +000035X(ThePPC32Target, "ppc32", "PowerPC 32");
36
37extern Target ThePPC64Target;
Dan Gohman844731a2008-05-13 00:00:25 +000038static RegisterTarget<PPC64TargetMachine>
Daniel Dunbar51b198a2009-07-15 20:24:03 +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
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000044const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
Jim Laskeybf111822006-12-21 20:26:09 +000045 if (Subtarget.isDarwin())
Anton Korobeynikovbadd8df2008-07-19 21:44:57 +000046 return new PPCDarwinTargetAsmInfo(*this);
Jim Laskeybf111822006-12-21 20:26:09 +000047 else
Anton Korobeynikovbadd8df2008-07-19 21:44:57 +000048 return new PPCLinuxTargetAsmInfo(*this);
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000049}
50
Daniel Dunbar51b198a2009-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 Lattnerb1d26f62006-06-17 00:01:04 +000055 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Chris Lattnerff790892006-11-18 01:34:43 +000056 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
Bill Wendling0ea18ff2007-01-24 03:41:36 +000057 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
Chris Lattner94de9a82006-06-16 01:37:27 +000058
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000059 if (getRelocationModel() == Reloc::Default) {
Evan Cheng4c1aa862006-02-22 20:19:42 +000060 if (Subtarget.isDarwin())
61 setRelocationModel(Reloc::DynamicNoPIC);
62 else
Jim Laskeybf111822006-12-21 20:26:09 +000063 setRelocationModel(Reloc::Static);
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000064 }
Nate Begeman21e463b2005-10-16 05:39:50 +000065}
66
Dale Johannesen81da02b2007-05-22 17:14:46 +000067/// Override this for PowerPC. Tail merging happily breaks up instruction issue
68/// groups, which typically degrades performance.
Dan Gohman50cdabc2007-11-19 20:46:23 +000069bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dale Johannesen81da02b2007-05-22 17:14:46 +000070
Daniel Dunbar51b198a2009-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 Lattner94de9a82006-06-16 01:37:27 +000074}
75
76
Daniel Dunbar51b198a2009-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 Lattner94de9a82006-06-16 01:37:27 +000080}
81
Misha Brukmanb5f662f2005-04-21 23:30:14 +000082
Chris Lattner1911fd42006-09-04 04:14:57 +000083//===----------------------------------------------------------------------===//
84// Pass Pipeline Configuration
85//===----------------------------------------------------------------------===//
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000086
Bill Wendling98a366d2009-04-29 23:29:43 +000087bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
88 CodeGenOpt::Level OptLevel) {
Chris Lattner8482dd82005-08-17 19:33:30 +000089 // Install an instruction selector.
Chris Lattner05f1fe82006-01-12 01:46:07 +000090 PM.add(createPPCISelDag(*this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000091 return false;
92}
93
Bill Wendling98a366d2009-04-29 23:29:43 +000094bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
95 CodeGenOpt::Level OptLevel) {
Chris Lattner1911fd42006-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 Wendling98a366d2009-04-29 23:29:43 +0000101bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
102 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000103 MachineCodeEmitter &MCE) {
Chris Lattnere150b8e2006-12-08 04:54:03 +0000104 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
Chris Lattner1911fd42006-09-04 04:14:57 +0000105 // FIXME: This should be moved to TargetJITInfo!!
Chris Lattnere150b8e2006-12-08 04:54:03 +0000106 if (Subtarget.isPPC64()) {
107 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
108 // instructions to materialize arbitrary global variable + function +
109 // constant pool addresses.
110 setRelocationModel(Reloc::PIC_);
Dale Johannesen72324642008-07-31 18:13:12 +0000111 // Temporary workaround for the inability of PPC64 JIT to handle jump
112 // tables.
113 DisableJumpTables = true;
Chris Lattnere150b8e2006-12-08 04:54:03 +0000114 } else {
115 setRelocationModel(Reloc::Static);
116 }
117
Chris Lattner57fc62c2006-12-11 23:22:45 +0000118 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
119 // writing?
120 Subtarget.SetJITMode();
Chris Lattner1911fd42006-09-04 04:14:57 +0000121
122 // Machine code emitter pass for PowerPC.
Nate Begemaneb883af2006-08-23 21:08:52 +0000123 PM.add(createPPCCodeEmitterPass(*this, MCE));
Anton Korobeynikov06be9972008-08-17 13:54:28 +0000124
Nate Begemaneb883af2006-08-23 21:08:52 +0000125 return false;
126}
Chris Lattner1911fd42006-09-04 04:14:57 +0000127
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000128bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
129 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000130 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000131 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
132 // FIXME: This should be moved to TargetJITInfo!!
133 if (Subtarget.isPPC64()) {
134 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
135 // instructions to materialize arbitrary global variable + function +
136 // constant pool addresses.
137 setRelocationModel(Reloc::PIC_);
138 // Temporary workaround for the inability of PPC64 JIT to handle jump
139 // tables.
140 DisableJumpTables = true;
141 } else {
142 setRelocationModel(Reloc::Static);
143 }
144
145 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
146 // writing?
147 Subtarget.SetJITMode();
148
149 // Machine code emitter pass for PowerPC.
150 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000151
152 return false;
153}
154
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000155bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
156 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000157 ObjectCodeEmitter &OCE) {
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000158 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
159 // FIXME: This should be moved to TargetJITInfo!!
160 if (Subtarget.isPPC64()) {
161 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
162 // instructions to materialize arbitrary global variable + function +
163 // constant pool addresses.
164 setRelocationModel(Reloc::PIC_);
165 // Temporary workaround for the inability of PPC64 JIT to handle jump
166 // tables.
167 DisableJumpTables = true;
168 } else {
169 setRelocationModel(Reloc::Static);
170 }
171
172 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
173 // writing?
174 Subtarget.SetJITMode();
175
176 // Machine code emitter pass for PowerPC.
177 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000178
179 return false;
180}
181
Bill Wendling98a366d2009-04-29 23:29:43 +0000182bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
183 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes434dd4f2009-06-01 19:57:37 +0000184 MachineCodeEmitter &MCE) {
Bill Wendlingeb1ac332007-02-08 01:39:44 +0000185 // Machine code emitter pass for PowerPC.
186 PM.add(createPPCCodeEmitterPass(*this, MCE));
187 return false;
188}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000189
190bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
191 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes434dd4f2009-06-01 19:57:37 +0000192 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000193 // Machine code emitter pass for PowerPC.
194 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000195 return false;
196}
197
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000198bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
199 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000200 ObjectCodeEmitter &OCE) {
201 // Machine code emitter pass for PowerPC.
202 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000203 return false;
204}
205
206