blob: 07667117a045a02779719c6e2b2274d11fdd51c2 [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"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000017#include "llvm/PassManager.h"
Dale Johannesen493492f2008-07-31 18:13:12 +000018#include "llvm/Target/TargetOptions.h"
Daniel Dunbarc680b012009-07-25 06:49:55 +000019#include "llvm/Target/TargetRegistry.h"
David Greene302008d2009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000021using namespace llvm;
22
Daniel Dunbarc680b012009-07-25 06:49:55 +000023extern "C" void LLVMInitializePowerPCTarget() {
24 // Register the targets
25 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
26 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
27}
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000028
Dan Gohmanf17a25c2007-07-18 16:29:46 +000029const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
30 if (Subtarget.isDarwin())
Chris Lattnerc8d14632009-08-11 22:52:15 +000031 return new PPCDarwinTargetAsmInfo(Subtarget.isPPC64());
32 return new PPCLinuxTargetAsmInfo(Subtarget.isPPC64());
Dan Gohmanf17a25c2007-07-18 16:29:46 +000033}
34
Chris Lattnerd9236ec2009-08-11 20:42:37 +000035PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT,
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000036 const std::string &FS, bool is64Bit)
Chris Lattnerd9236ec2009-08-11 20:42:37 +000037 : LLVMTargetMachine(T, TT),
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000038 Subtarget(TT, FS, is64Bit),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
40 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
41 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
42
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000043 if (getRelocationModel() == Reloc::Default) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044 if (Subtarget.isDarwin())
45 setRelocationModel(Reloc::DynamicNoPIC);
46 else
47 setRelocationModel(Reloc::Static);
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000048 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049}
50
51/// Override this for PowerPC. Tail merging happily breaks up instruction issue
52/// groups, which typically degrades performance.
Dan Gohman62ea18a2007-11-19 20:46:23 +000053bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000055PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000056 const std::string &FS)
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000057 : PPCTargetMachine(T, TT, FS, false) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058}
59
60
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000061PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000062 const std::string &FS)
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000063 : PPCTargetMachine(T, TT, FS, true) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064}
65
66
67//===----------------------------------------------------------------------===//
68// Pass Pipeline Configuration
69//===----------------------------------------------------------------------===//
70
Bill Wendling5ed22ac2009-04-29 23:29:43 +000071bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
72 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073 // Install an instruction selector.
74 PM.add(createPPCISelDag(*this));
75 return false;
76}
77
Bill Wendling5ed22ac2009-04-29 23:29:43 +000078bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
79 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080 // Must run branch selection immediately preceding the asm printer.
81 PM.add(createPPCBranchSelectionPass());
82 return false;
83}
84
Bill Wendling5ed22ac2009-04-29 23:29:43 +000085bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
86 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +000087 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000088 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
89 // FIXME: This should be moved to TargetJITInfo!!
90 if (Subtarget.isPPC64()) {
91 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
92 // instructions to materialize arbitrary global variable + function +
93 // constant pool addresses.
94 setRelocationModel(Reloc::PIC_);
Dale Johannesen493492f2008-07-31 18:13:12 +000095 // Temporary workaround for the inability of PPC64 JIT to handle jump
96 // tables.
97 DisableJumpTables = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000098 } else {
99 setRelocationModel(Reloc::Static);
100 }
101
102 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
103 // writing?
104 Subtarget.SetJITMode();
105
106 // Machine code emitter pass for PowerPC.
107 PM.add(createPPCCodeEmitterPass(*this, MCE));
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +0000108
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000109 return false;
110}
111
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000112bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
113 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000114 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000115 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
116 // FIXME: This should be moved to TargetJITInfo!!
117 if (Subtarget.isPPC64()) {
118 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
119 // instructions to materialize arbitrary global variable + function +
120 // constant pool addresses.
121 setRelocationModel(Reloc::PIC_);
122 // Temporary workaround for the inability of PPC64 JIT to handle jump
123 // tables.
124 DisableJumpTables = true;
125 } else {
126 setRelocationModel(Reloc::Static);
127 }
128
129 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
130 // writing?
131 Subtarget.SetJITMode();
132
133 // Machine code emitter pass for PowerPC.
134 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000135
136 return false;
137}
138
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000139bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
140 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000141 ObjectCodeEmitter &OCE) {
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000142 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
143 // FIXME: This should be moved to TargetJITInfo!!
144 if (Subtarget.isPPC64()) {
145 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
146 // instructions to materialize arbitrary global variable + function +
147 // constant pool addresses.
148 setRelocationModel(Reloc::PIC_);
149 // Temporary workaround for the inability of PPC64 JIT to handle jump
150 // tables.
151 DisableJumpTables = true;
152 } else {
153 setRelocationModel(Reloc::Static);
154 }
155
156 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
157 // writing?
158 Subtarget.SetJITMode();
159
160 // Machine code emitter pass for PowerPC.
161 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000162
163 return false;
164}
165
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000166bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
167 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000168 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169 // Machine code emitter pass for PowerPC.
170 PM.add(createPPCCodeEmitterPass(*this, MCE));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000171 return false;
172}
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000173
174bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
175 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000176 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000177 // Machine code emitter pass for PowerPC.
178 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000179 return false;
180}
181
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000182bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
183 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000184 ObjectCodeEmitter &OCE) {
185 // Machine code emitter pass for PowerPC.
186 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000187 return false;
188}
189
190