blob: 3d5ae5221af565f984afb66461ec1ff9d61c9770 [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
25static RegisterTarget<PPC32TargetMachine>
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000026X(ThePPC32Target, "ppc32", "PowerPC 32");
27
Dan Gohman089efff2008-05-13 00:00:25 +000028static RegisterTarget<PPC64TargetMachine>
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000029Y(ThePPC64Target, "ppc64", "PowerPC 64");
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030
Bob Wilsonebbc1c42009-06-23 23:59:40 +000031// Force static initialization.
32extern "C" void LLVMInitializePowerPCTarget() { }
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000033
Dan Gohmanf17a25c2007-07-18 16:29:46 +000034const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
35 if (Subtarget.isDarwin())
Anton Korobeynikovd15bc312008-07-19 21:44:57 +000036 return new PPCDarwinTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037 else
Anton Korobeynikovd15bc312008-07-19 21:44:57 +000038 return new PPCLinuxTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039}
40
Daniel Dunbarfe5939f2009-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),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000045 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
46 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
47 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
48
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000049 if (getRelocationModel() == Reloc::Default) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 if (Subtarget.isDarwin())
51 setRelocationModel(Reloc::DynamicNoPIC);
52 else
53 setRelocationModel(Reloc::Static);
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000054 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055}
56
57/// Override this for PowerPC. Tail merging happily breaks up instruction issue
58/// groups, which typically degrades performance.
Dan Gohman62ea18a2007-11-19 20:46:23 +000059bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000061PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
62 const std::string &FS)
63 : PPCTargetMachine(T, M, FS, false) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064}
65
66
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000067PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
68 const std::string &FS)
69 : PPCTargetMachine(T, M, FS, true) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000070}
71
72
73//===----------------------------------------------------------------------===//
74// Pass Pipeline Configuration
75//===----------------------------------------------------------------------===//
76
Bill Wendling5ed22ac2009-04-29 23:29:43 +000077bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
78 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000079 // Install an instruction selector.
80 PM.add(createPPCISelDag(*this));
81 return false;
82}
83
Bill Wendling5ed22ac2009-04-29 23:29:43 +000084bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
85 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000086 // Must run branch selection immediately preceding the asm printer.
87 PM.add(createPPCBranchSelectionPass());
88 return false;
89}
90
Bill Wendling5ed22ac2009-04-29 23:29:43 +000091bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
92 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +000093 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000094 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
95 // FIXME: This should be moved to TargetJITInfo!!
96 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 Johannesen493492f2008-07-31 18:13:12 +0000101 // Temporary workaround for the inability of PPC64 JIT to handle jump
102 // tables.
103 DisableJumpTables = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000104 } else {
105 setRelocationModel(Reloc::Static);
106 }
107
108 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
109 // writing?
110 Subtarget.SetJITMode();
111
112 // Machine code emitter pass for PowerPC.
113 PM.add(createPPCCodeEmitterPass(*this, MCE));
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +0000114
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000115 return false;
116}
117
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000118bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
119 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000120 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-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 Lopes1ea31ff2009-05-30 20:51:52 +0000141
142 return false;
143}
144
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000145bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
146 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000147 ObjectCodeEmitter &OCE) {
Bruno Cardoso Lopesaabb9a52009-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 Lopesaabb9a52009-07-06 05:09:34 +0000168
169 return false;
170}
171
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000172bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
173 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000174 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000175 // Machine code emitter pass for PowerPC.
176 PM.add(createPPCCodeEmitterPass(*this, MCE));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000177 return false;
178}
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000179
180bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
181 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000182 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000183 // Machine code emitter pass for PowerPC.
184 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000185 return false;
186}
187
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000188bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
189 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000190 ObjectCodeEmitter &OCE) {
191 // Machine code emitter pass for PowerPC.
192 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000193 return false;
194}
195
196