blob: f56167e39018909991dc3d47d250b5329255c9a9 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// Top-level implementation for the PowerPC target.
11//
12//===----------------------------------------------------------------------===//
13
14#include "PPC.h"
15#include "PPCTargetAsmInfo.h"
16#include "PPCTargetMachine.h"
17#include "llvm/Module.h"
18#include "llvm/PassManager.h"
19#include "llvm/Target/TargetMachineRegistry.h"
Dale Johannesen493492f2008-07-31 18:13:12 +000020#include "llvm/Target/TargetOptions.h"
David Greene302008d2009-07-14 20:18:05 +000021#include "llvm/Support/FormattedStream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000022using namespace llvm;
23
Dan Gohman089efff2008-05-13 00:00:25 +000024// Register the targets
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000025extern Target ThePPC32Target;
Dan Gohman089efff2008-05-13 00:00:25 +000026static RegisterTarget<PPC32TargetMachine>
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000027X(ThePPC32Target, "ppc32", "PowerPC 32");
28
29extern Target ThePPC64Target;
Dan Gohman089efff2008-05-13 00:00:25 +000030static RegisterTarget<PPC64TargetMachine>
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000031Y(ThePPC64Target, "ppc64", "PowerPC 64");
Dan Gohmanf17a25c2007-07-18 16:29:46 +000032
Bob Wilsonebbc1c42009-06-23 23:59:40 +000033// Force static initialization.
34extern "C" void LLVMInitializePowerPCTarget() { }
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000035
Dan Gohmanf17a25c2007-07-18 16:29:46 +000036const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
37 if (Subtarget.isDarwin())
Anton Korobeynikovd15bc312008-07-19 21:44:57 +000038 return new PPCDarwinTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039 else
Anton Korobeynikovd15bc312008-07-19 21:44:57 +000040 return new PPCLinuxTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041}
42
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000043PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M,
44 const std::string &FS, bool is64Bit)
45 : LLVMTargetMachine(T),
46 Subtarget(*this, M, FS, is64Bit),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
48 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
49 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
50
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000051 if (getRelocationModel() == Reloc::Default) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 if (Subtarget.isDarwin())
53 setRelocationModel(Reloc::DynamicNoPIC);
54 else
55 setRelocationModel(Reloc::Static);
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000056 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057}
58
59/// Override this for PowerPC. Tail merging happily breaks up instruction issue
60/// groups, which typically degrades performance.
Dan Gohman62ea18a2007-11-19 20:46:23 +000061bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000063PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
64 const std::string &FS)
65 : PPCTargetMachine(T, M, FS, false) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000066}
67
68
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000069PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
70 const std::string &FS)
71 : PPCTargetMachine(T, M, FS, true) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000072}
73
74
75//===----------------------------------------------------------------------===//
76// Pass Pipeline Configuration
77//===----------------------------------------------------------------------===//
78
Bill Wendling5ed22ac2009-04-29 23:29:43 +000079bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
80 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000081 // Install an instruction selector.
82 PM.add(createPPCISelDag(*this));
83 return false;
84}
85
Bill Wendling5ed22ac2009-04-29 23:29:43 +000086bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
87 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000088 // Must run branch selection immediately preceding the asm printer.
89 PM.add(createPPCBranchSelectionPass());
90 return false;
91}
92
Bill Wendling5ed22ac2009-04-29 23:29:43 +000093bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
94 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +000095 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000096 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
97 // FIXME: This should be moved to TargetJITInfo!!
98 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 Johannesen493492f2008-07-31 18:13:12 +0000103 // Temporary workaround for the inability of PPC64 JIT to handle jump
104 // tables.
105 DisableJumpTables = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000106 } else {
107 setRelocationModel(Reloc::Static);
108 }
109
110 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
111 // writing?
112 Subtarget.SetJITMode();
113
114 // Machine code emitter pass for PowerPC.
115 PM.add(createPPCCodeEmitterPass(*this, MCE));
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +0000116
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000117 return false;
118}
119
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000120bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
121 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000122 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-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 Lopes1ea31ff2009-05-30 20:51:52 +0000143
144 return false;
145}
146
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000147bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
148 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000149 ObjectCodeEmitter &OCE) {
Bruno Cardoso Lopesaabb9a52009-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 Lopesaabb9a52009-07-06 05:09:34 +0000170
171 return false;
172}
173
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000174bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
175 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000176 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000177 // Machine code emitter pass for PowerPC.
178 PM.add(createPPCCodeEmitterPass(*this, MCE));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179 return false;
180}
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000181
182bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
183 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000184 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000185 // Machine code emitter pass for PowerPC.
186 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000187 return false;
188}
189
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000190bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
191 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000192 ObjectCodeEmitter &OCE) {
193 // Machine code emitter pass for PowerPC.
194 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000195 return false;
196}
197
198