blob: 3d5ae5221af565f984afb66461ec1ff9d61c9770 [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
Dan Gohman844731a2008-05-13 00:00:25 +000024// Register the targets
25static RegisterTarget<PPC32TargetMachine>
Daniel Dunbar51b198a2009-07-15 20:24:03 +000026X(ThePPC32Target, "ppc32", "PowerPC 32");
27
Dan Gohman844731a2008-05-13 00:00:25 +000028static RegisterTarget<PPC64TargetMachine>
Daniel Dunbar51b198a2009-07-15 20:24:03 +000029Y(ThePPC64Target, "ppc64", "PowerPC 64");
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000030
Bob Wilsona96751f2009-06-23 23:59:40 +000031// Force static initialization.
32extern "C" void LLVMInitializePowerPCTarget() { }
Douglas Gregor1555a232009-06-16 20:12:29 +000033
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000034const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
Jim Laskeybf111822006-12-21 20:26:09 +000035 if (Subtarget.isDarwin())
Anton Korobeynikovbadd8df2008-07-19 21:44:57 +000036 return new PPCDarwinTargetAsmInfo(*this);
Jim Laskeybf111822006-12-21 20:26:09 +000037 else
Anton Korobeynikovbadd8df2008-07-19 21:44:57 +000038 return new PPCLinuxTargetAsmInfo(*this);
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000039}
40
Daniel Dunbar51b198a2009-07-15 20:24:03 +000041PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M,
42 const std::string &FS, bool is64Bit)
43 : LLVMTargetMachine(T),
44 Subtarget(*this, M, FS, is64Bit),
Chris Lattnerb1d26f62006-06-17 00:01:04 +000045 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Chris Lattnerff790892006-11-18 01:34:43 +000046 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
Bill Wendling0ea18ff2007-01-24 03:41:36 +000047 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
Chris Lattner94de9a82006-06-16 01:37:27 +000048
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000049 if (getRelocationModel() == Reloc::Default) {
Evan Cheng4c1aa862006-02-22 20:19:42 +000050 if (Subtarget.isDarwin())
51 setRelocationModel(Reloc::DynamicNoPIC);
52 else
Jim Laskeybf111822006-12-21 20:26:09 +000053 setRelocationModel(Reloc::Static);
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000054 }
Nate Begeman21e463b2005-10-16 05:39:50 +000055}
56
Dale Johannesen81da02b2007-05-22 17:14:46 +000057/// Override this for PowerPC. Tail merging happily breaks up instruction issue
58/// groups, which typically degrades performance.
Dan Gohman50cdabc2007-11-19 20:46:23 +000059bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dale Johannesen81da02b2007-05-22 17:14:46 +000060
Daniel Dunbar51b198a2009-07-15 20:24:03 +000061PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
62 const std::string &FS)
63 : PPCTargetMachine(T, M, FS, false) {
Chris Lattner94de9a82006-06-16 01:37:27 +000064}
65
66
Daniel Dunbar51b198a2009-07-15 20:24:03 +000067PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
68 const std::string &FS)
69 : PPCTargetMachine(T, M, FS, true) {
Chris Lattner94de9a82006-06-16 01:37:27 +000070}
71
Misha Brukmanb5f662f2005-04-21 23:30:14 +000072
Chris Lattner1911fd42006-09-04 04:14:57 +000073//===----------------------------------------------------------------------===//
74// Pass Pipeline Configuration
75//===----------------------------------------------------------------------===//
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000076
Bill Wendling98a366d2009-04-29 23:29:43 +000077bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
78 CodeGenOpt::Level OptLevel) {
Chris Lattner8482dd82005-08-17 19:33:30 +000079 // Install an instruction selector.
Chris Lattner05f1fe82006-01-12 01:46:07 +000080 PM.add(createPPCISelDag(*this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000081 return false;
82}
83
Bill Wendling98a366d2009-04-29 23:29:43 +000084bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
85 CodeGenOpt::Level OptLevel) {
Chris Lattner1911fd42006-09-04 04:14:57 +000086 // Must run branch selection immediately preceding the asm printer.
87 PM.add(createPPCBranchSelectionPass());
88 return false;
89}
90
Bill Wendling98a366d2009-04-29 23:29:43 +000091bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
92 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +000093 MachineCodeEmitter &MCE) {
Chris Lattnere150b8e2006-12-08 04:54:03 +000094 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
Chris Lattner1911fd42006-09-04 04:14:57 +000095 // FIXME: This should be moved to TargetJITInfo!!
Chris Lattnere150b8e2006-12-08 04:54:03 +000096 if (Subtarget.isPPC64()) {
97 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
98 // instructions to materialize arbitrary global variable + function +
99 // constant pool addresses.
100 setRelocationModel(Reloc::PIC_);
Dale Johannesen72324642008-07-31 18:13:12 +0000101 // Temporary workaround for the inability of PPC64 JIT to handle jump
102 // tables.
103 DisableJumpTables = true;
Chris Lattnere150b8e2006-12-08 04:54:03 +0000104 } else {
105 setRelocationModel(Reloc::Static);
106 }
107
Chris Lattner57fc62c2006-12-11 23:22:45 +0000108 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
109 // writing?
110 Subtarget.SetJITMode();
Chris Lattner1911fd42006-09-04 04:14:57 +0000111
112 // Machine code emitter pass for PowerPC.
Nate Begemaneb883af2006-08-23 21:08:52 +0000113 PM.add(createPPCCodeEmitterPass(*this, MCE));
Anton Korobeynikov06be9972008-08-17 13:54:28 +0000114
Nate Begemaneb883af2006-08-23 21:08:52 +0000115 return false;
116}
Chris Lattner1911fd42006-09-04 04:14:57 +0000117
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000118bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
119 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000120 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000121 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
122 // FIXME: This should be moved to TargetJITInfo!!
123 if (Subtarget.isPPC64()) {
124 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
125 // instructions to materialize arbitrary global variable + function +
126 // constant pool addresses.
127 setRelocationModel(Reloc::PIC_);
128 // Temporary workaround for the inability of PPC64 JIT to handle jump
129 // tables.
130 DisableJumpTables = true;
131 } else {
132 setRelocationModel(Reloc::Static);
133 }
134
135 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
136 // writing?
137 Subtarget.SetJITMode();
138
139 // Machine code emitter pass for PowerPC.
140 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000141
142 return false;
143}
144
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000145bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
146 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000147 ObjectCodeEmitter &OCE) {
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000148 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
149 // FIXME: This should be moved to TargetJITInfo!!
150 if (Subtarget.isPPC64()) {
151 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
152 // instructions to materialize arbitrary global variable + function +
153 // constant pool addresses.
154 setRelocationModel(Reloc::PIC_);
155 // Temporary workaround for the inability of PPC64 JIT to handle jump
156 // tables.
157 DisableJumpTables = true;
158 } else {
159 setRelocationModel(Reloc::Static);
160 }
161
162 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
163 // writing?
164 Subtarget.SetJITMode();
165
166 // Machine code emitter pass for PowerPC.
167 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000168
169 return false;
170}
171
Bill Wendling98a366d2009-04-29 23:29:43 +0000172bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
173 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes434dd4f2009-06-01 19:57:37 +0000174 MachineCodeEmitter &MCE) {
Bill Wendlingeb1ac332007-02-08 01:39:44 +0000175 // Machine code emitter pass for PowerPC.
176 PM.add(createPPCCodeEmitterPass(*this, MCE));
177 return false;
178}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000179
180bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
181 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes434dd4f2009-06-01 19:57:37 +0000182 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000183 // Machine code emitter pass for PowerPC.
184 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000185 return false;
186}
187
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000188bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
189 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000190 ObjectCodeEmitter &OCE) {
191 // Machine code emitter pass for PowerPC.
192 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000193 return false;
194}
195
196