blob: 41f4699fc061d4f7cf778107fdec53e8db02a25f [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/PassManager.h"
Dale Johannesen72324642008-07-31 18:13:12 +000018#include "llvm/Target/TargetOptions.h"
Daniel Dunbar0c795d62009-07-25 06:49:55 +000019#include "llvm/Target/TargetRegistry.h"
David Greene71847812009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.h"
Misha Brukman5dfe3a92004-06-21 16:55:25 +000021using namespace llvm;
22
Chris Lattnera7ac47c2009-08-12 07:22:17 +000023static const TargetAsmInfo *createTargetAsmInfo(const Target &T,
24 const StringRef &TT) {
25 Triple TheTriple(TT);
26 bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
27 if (TheTriple.getOS() == Triple::Darwin)
28 return new PPCDarwinTargetAsmInfo(isPPC64);
29 return new PPCLinuxTargetAsmInfo(isPPC64);
30
31}
32
Daniel Dunbar0c795d62009-07-25 06:49:55 +000033extern "C" void LLVMInitializePowerPCTarget() {
34 // Register the targets
35 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
36 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
Chris Lattnera7ac47c2009-08-12 07:22:17 +000037
38 RegisterAsmInfoFn C(ThePPC32Target, createTargetAsmInfo);
39 RegisterAsmInfoFn D(ThePPC64Target, createTargetAsmInfo);
Daniel Dunbar0c795d62009-07-25 06:49:55 +000040}
Douglas Gregor1555a232009-06-16 20:12:29 +000041
Jim Laskeyfde1b3b2006-09-07 23:39:26 +000042
Chris Lattner0a31d2f2009-08-11 20:42:37 +000043PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT,
Daniel Dunbar51b198a2009-07-15 20:24:03 +000044 const std::string &FS, bool is64Bit)
Chris Lattner0a31d2f2009-08-11 20:42:37 +000045 : LLVMTargetMachine(T, TT),
Daniel Dunbare28039c2009-08-02 23:37:13 +000046 Subtarget(TT, FS, is64Bit),
Chris Lattnerb1d26f62006-06-17 00:01:04 +000047 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Chris Lattnerff790892006-11-18 01:34:43 +000048 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
Bill Wendling0ea18ff2007-01-24 03:41:36 +000049 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
Chris Lattner94de9a82006-06-16 01:37:27 +000050
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000051 if (getRelocationModel() == Reloc::Default) {
Evan Cheng4c1aa862006-02-22 20:19:42 +000052 if (Subtarget.isDarwin())
53 setRelocationModel(Reloc::DynamicNoPIC);
54 else
Jim Laskeybf111822006-12-21 20:26:09 +000055 setRelocationModel(Reloc::Static);
Anton Korobeynikov7c1c2612008-02-20 11:22:39 +000056 }
Nate Begeman21e463b2005-10-16 05:39:50 +000057}
58
Dale Johannesen81da02b2007-05-22 17:14:46 +000059/// Override this for PowerPC. Tail merging happily breaks up instruction issue
60/// groups, which typically degrades performance.
Dan Gohman50cdabc2007-11-19 20:46:23 +000061bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dale Johannesen81da02b2007-05-22 17:14:46 +000062
Daniel Dunbare28039c2009-08-02 23:37:13 +000063PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbar51b198a2009-07-15 20:24:03 +000064 const std::string &FS)
Daniel Dunbare28039c2009-08-02 23:37:13 +000065 : PPCTargetMachine(T, TT, FS, false) {
Chris Lattner94de9a82006-06-16 01:37:27 +000066}
67
68
Daniel Dunbare28039c2009-08-02 23:37:13 +000069PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbar51b198a2009-07-15 20:24:03 +000070 const std::string &FS)
Daniel Dunbare28039c2009-08-02 23:37:13 +000071 : PPCTargetMachine(T, TT, FS, true) {
Chris Lattner94de9a82006-06-16 01:37:27 +000072}
73
Misha Brukmanb5f662f2005-04-21 23:30:14 +000074
Chris Lattner1911fd42006-09-04 04:14:57 +000075//===----------------------------------------------------------------------===//
76// Pass Pipeline Configuration
77//===----------------------------------------------------------------------===//
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000078
Bill Wendling98a366d2009-04-29 23:29:43 +000079bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
80 CodeGenOpt::Level OptLevel) {
Chris Lattner8482dd82005-08-17 19:33:30 +000081 // Install an instruction selector.
Chris Lattner05f1fe82006-01-12 01:46:07 +000082 PM.add(createPPCISelDag(*this));
Nate Begeman7a4fe9b2004-08-11 07:40:04 +000083 return false;
84}
85
Bill Wendling98a366d2009-04-29 23:29:43 +000086bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
87 CodeGenOpt::Level OptLevel) {
Chris Lattner1911fd42006-09-04 04:14:57 +000088 // Must run branch selection immediately preceding the asm printer.
89 PM.add(createPPCBranchSelectionPass());
90 return false;
91}
92
Bill Wendling98a366d2009-04-29 23:29:43 +000093bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
94 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +000095 MachineCodeEmitter &MCE) {
Chris Lattnere150b8e2006-12-08 04:54:03 +000096 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
Chris Lattner1911fd42006-09-04 04:14:57 +000097 // FIXME: This should be moved to TargetJITInfo!!
Chris Lattnere150b8e2006-12-08 04:54:03 +000098 if (Subtarget.isPPC64()) {
99 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
100 // instructions to materialize arbitrary global variable + function +
101 // constant pool addresses.
102 setRelocationModel(Reloc::PIC_);
Dale Johannesen72324642008-07-31 18:13:12 +0000103 // Temporary workaround for the inability of PPC64 JIT to handle jump
104 // tables.
105 DisableJumpTables = true;
Chris Lattnere150b8e2006-12-08 04:54:03 +0000106 } else {
107 setRelocationModel(Reloc::Static);
108 }
109
Chris Lattner57fc62c2006-12-11 23:22:45 +0000110 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
111 // writing?
112 Subtarget.SetJITMode();
Chris Lattner1911fd42006-09-04 04:14:57 +0000113
114 // Machine code emitter pass for PowerPC.
Nate Begemaneb883af2006-08-23 21:08:52 +0000115 PM.add(createPPCCodeEmitterPass(*this, MCE));
Anton Korobeynikov06be9972008-08-17 13:54:28 +0000116
Nate Begemaneb883af2006-08-23 21:08:52 +0000117 return false;
118}
Chris Lattner1911fd42006-09-04 04:14:57 +0000119
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000120bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
121 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000122 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000123 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
124 // FIXME: This should be moved to TargetJITInfo!!
125 if (Subtarget.isPPC64()) {
126 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
127 // instructions to materialize arbitrary global variable + function +
128 // constant pool addresses.
129 setRelocationModel(Reloc::PIC_);
130 // Temporary workaround for the inability of PPC64 JIT to handle jump
131 // tables.
132 DisableJumpTables = true;
133 } else {
134 setRelocationModel(Reloc::Static);
135 }
136
137 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
138 // writing?
139 Subtarget.SetJITMode();
140
141 // Machine code emitter pass for PowerPC.
142 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000143
144 return false;
145}
146
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000147bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
148 CodeGenOpt::Level OptLevel,
Daniel Dunbarcfe9a602009-07-15 22:33:19 +0000149 ObjectCodeEmitter &OCE) {
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000150 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
151 // FIXME: This should be moved to TargetJITInfo!!
152 if (Subtarget.isPPC64()) {
153 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
154 // instructions to materialize arbitrary global variable + function +
155 // constant pool addresses.
156 setRelocationModel(Reloc::PIC_);
157 // Temporary workaround for the inability of PPC64 JIT to handle jump
158 // tables.
159 DisableJumpTables = true;
160 } else {
161 setRelocationModel(Reloc::Static);
162 }
163
164 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
165 // writing?
166 Subtarget.SetJITMode();
167
168 // Machine code emitter pass for PowerPC.
169 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000170
171 return false;
172}
173
Bill Wendling98a366d2009-04-29 23:29:43 +0000174bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
175 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes434dd4f2009-06-01 19:57:37 +0000176 MachineCodeEmitter &MCE) {
Bill Wendlingeb1ac332007-02-08 01:39:44 +0000177 // Machine code emitter pass for PowerPC.
178 PM.add(createPPCCodeEmitterPass(*this, MCE));
179 return false;
180}
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000181
182bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
183 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes434dd4f2009-06-01 19:57:37 +0000184 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000185 // Machine code emitter pass for PowerPC.
186 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa3f99f92009-05-30 20:51:52 +0000187 return false;
188}
189
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000190bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
191 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000192 ObjectCodeEmitter &OCE) {
193 // Machine code emitter pass for PowerPC.
194 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesac57e6e2009-07-06 05:09:34 +0000195 return false;
196}
197
198