blob: da6ebc49a93ffd48f8d1f6b7177c724675f625b1 [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"
Dale Johannesen493492f2008-07-31 18:13:12 +000019#include "llvm/Target/TargetOptions.h"
Daniel Dunbarc680b012009-07-25 06:49:55 +000020#include "llvm/Target/TargetRegistry.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
Daniel Dunbarc680b012009-07-25 06:49:55 +000024extern "C" void LLVMInitializePowerPCTarget() {
25 // Register the targets
26 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
27 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
28}
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000029
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
31 if (Subtarget.isDarwin())
Anton Korobeynikovd15bc312008-07-19 21:44:57 +000032 return new PPCDarwinTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033 else
Anton Korobeynikovd15bc312008-07-19 21:44:57 +000034 return new PPCLinuxTargetAsmInfo(*this);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000035}
36
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000037PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M,
38 const std::string &FS, bool is64Bit)
39 : LLVMTargetMachine(T),
Daniel Dunbarb711cf02009-08-02 22:11:08 +000040 Subtarget(M.getTargetTriple(), FS, is64Bit),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
42 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
43 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
44
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000045 if (getRelocationModel() == Reloc::Default) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046 if (Subtarget.isDarwin())
47 setRelocationModel(Reloc::DynamicNoPIC);
48 else
49 setRelocationModel(Reloc::Static);
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000050 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051}
52
53/// Override this for PowerPC. Tail merging happily breaks up instruction issue
54/// groups, which typically degrades performance.
Dan Gohman62ea18a2007-11-19 20:46:23 +000055bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000057PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
58 const std::string &FS)
59 : PPCTargetMachine(T, M, FS, false) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060}
61
62
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000063PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
64 const std::string &FS)
65 : PPCTargetMachine(T, M, FS, true) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000066}
67
68
69//===----------------------------------------------------------------------===//
70// Pass Pipeline Configuration
71//===----------------------------------------------------------------------===//
72
Bill Wendling5ed22ac2009-04-29 23:29:43 +000073bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
74 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000075 // Install an instruction selector.
76 PM.add(createPPCISelDag(*this));
77 return false;
78}
79
Bill Wendling5ed22ac2009-04-29 23:29:43 +000080bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
81 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000082 // Must run branch selection immediately preceding the asm printer.
83 PM.add(createPPCBranchSelectionPass());
84 return false;
85}
86
Bill Wendling5ed22ac2009-04-29 23:29:43 +000087bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
88 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +000089 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
91 // FIXME: This should be moved to TargetJITInfo!!
92 if (Subtarget.isPPC64()) {
93 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
94 // instructions to materialize arbitrary global variable + function +
95 // constant pool addresses.
96 setRelocationModel(Reloc::PIC_);
Dale Johannesen493492f2008-07-31 18:13:12 +000097 // Temporary workaround for the inability of PPC64 JIT to handle jump
98 // tables.
99 DisableJumpTables = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000100 } else {
101 setRelocationModel(Reloc::Static);
102 }
103
104 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
105 // writing?
106 Subtarget.SetJITMode();
107
108 // Machine code emitter pass for PowerPC.
109 PM.add(createPPCCodeEmitterPass(*this, MCE));
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +0000110
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000111 return false;
112}
113
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000114bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
115 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000116 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000117 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
118 // FIXME: This should be moved to TargetJITInfo!!
119 if (Subtarget.isPPC64()) {
120 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
121 // instructions to materialize arbitrary global variable + function +
122 // constant pool addresses.
123 setRelocationModel(Reloc::PIC_);
124 // Temporary workaround for the inability of PPC64 JIT to handle jump
125 // tables.
126 DisableJumpTables = true;
127 } else {
128 setRelocationModel(Reloc::Static);
129 }
130
131 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
132 // writing?
133 Subtarget.SetJITMode();
134
135 // Machine code emitter pass for PowerPC.
136 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000137
138 return false;
139}
140
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000141bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
142 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000143 ObjectCodeEmitter &OCE) {
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000144 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
145 // FIXME: This should be moved to TargetJITInfo!!
146 if (Subtarget.isPPC64()) {
147 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
148 // instructions to materialize arbitrary global variable + function +
149 // constant pool addresses.
150 setRelocationModel(Reloc::PIC_);
151 // Temporary workaround for the inability of PPC64 JIT to handle jump
152 // tables.
153 DisableJumpTables = true;
154 } else {
155 setRelocationModel(Reloc::Static);
156 }
157
158 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
159 // writing?
160 Subtarget.SetJITMode();
161
162 // Machine code emitter pass for PowerPC.
163 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000164
165 return false;
166}
167
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000168bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
169 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000170 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171 // Machine code emitter pass for PowerPC.
172 PM.add(createPPCCodeEmitterPass(*this, MCE));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173 return false;
174}
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000175
176bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
177 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000178 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000179 // Machine code emitter pass for PowerPC.
180 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000181 return false;
182}
183
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000184bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
185 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000186 ObjectCodeEmitter &OCE) {
187 // Machine code emitter pass for PowerPC.
188 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000189 return false;
190}
191
192