blob: 8079c6e9cc605a418d0fb2f1443feaa4f02f1109 [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"
Chris Lattner621c44d2009-08-22 20:48:53 +000015#include "PPCMCAsmInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000016#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 Dunbarde46a5b2009-11-06 10:58:06 +000023static const MCAsmInfo *createMCAsmInfo(const Target &T, StringRef TT) {
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000024 Triple TheTriple(TT);
Daniel Dunbaree3b6c62009-08-13 17:03:38 +000025 bool isPPC64 = TheTriple.getArch() == Triple::ppc64;
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000026 if (TheTriple.getOS() == Triple::Darwin)
Chris Lattnercd4cab92009-08-22 21:03:30 +000027 return new PPCMCAsmInfoDarwin(isPPC64);
Chris Lattner621c44d2009-08-22 20:48:53 +000028 return new PPCLinuxMCAsmInfo(isPPC64);
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000029
30}
31
Daniel Dunbarc680b012009-07-25 06:49:55 +000032extern "C" void LLVMInitializePowerPCTarget() {
33 // Register the targets
34 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
35 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
Chris Lattnerd88f9fd2009-08-12 07:22:17 +000036
Chris Lattner621c44d2009-08-22 20:48:53 +000037 RegisterAsmInfoFn C(ThePPC32Target, createMCAsmInfo);
38 RegisterAsmInfoFn D(ThePPC64Target, createMCAsmInfo);
Daniel Dunbarc680b012009-07-25 06:49:55 +000039}
Douglas Gregor1dc5ff42009-06-16 20:12:29 +000040
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041
Chris Lattnerd9236ec2009-08-11 20:42:37 +000042PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT,
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000043 const std::string &FS, bool is64Bit)
Chris Lattnerd9236ec2009-08-11 20:42:37 +000044 : LLVMTargetMachine(T, TT),
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000045 Subtarget(TT, FS, is64Bit),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
47 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
48 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
49
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000050 if (getRelocationModel() == Reloc::Default) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051 if (Subtarget.isDarwin())
52 setRelocationModel(Reloc::DynamicNoPIC);
53 else
54 setRelocationModel(Reloc::Static);
Anton Korobeynikov8c90d2a2008-02-20 11:22:39 +000055 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056}
57
58/// Override this for PowerPC. Tail merging happily breaks up instruction issue
59/// groups, which typically degrades performance.
Dan Gohman62ea18a2007-11-19 20:46:23 +000060bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000062PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000063 const std::string &FS)
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000064 : PPCTargetMachine(T, TT, FS, false) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065}
66
67
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000068PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbarfe5939f2009-07-15 20:24:03 +000069 const std::string &FS)
Daniel Dunbarf5c2b852009-08-02 23:37:13 +000070 : PPCTargetMachine(T, TT, FS, true) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000071}
72
73
74//===----------------------------------------------------------------------===//
75// Pass Pipeline Configuration
76//===----------------------------------------------------------------------===//
77
Bill Wendling5ed22ac2009-04-29 23:29:43 +000078bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
79 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000080 // Install an instruction selector.
81 PM.add(createPPCISelDag(*this));
82 return false;
83}
84
Bill Wendling5ed22ac2009-04-29 23:29:43 +000085bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
86 CodeGenOpt::Level OptLevel) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000087 // Must run branch selection immediately preceding the asm printer.
88 PM.add(createPPCBranchSelectionPass());
89 return false;
90}
91
Bill Wendling5ed22ac2009-04-29 23:29:43 +000092bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
93 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +000094 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000095 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
96 // FIXME: This should be moved to TargetJITInfo!!
97 if (Subtarget.isPPC64()) {
98 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
99 // instructions to materialize arbitrary global variable + function +
100 // constant pool addresses.
101 setRelocationModel(Reloc::PIC_);
Dale Johannesen493492f2008-07-31 18:13:12 +0000102 // Temporary workaround for the inability of PPC64 JIT to handle jump
103 // tables.
104 DisableJumpTables = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000105 } else {
106 setRelocationModel(Reloc::Static);
107 }
108
109 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
110 // writing?
111 Subtarget.SetJITMode();
112
113 // Machine code emitter pass for PowerPC.
114 PM.add(createPPCCodeEmitterPass(*this, MCE));
Anton Korobeynikov01c0e9f2008-08-17 13:54:28 +0000115
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000116 return false;
117}
118
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000119bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
120 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000121 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000122 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
123 // FIXME: This should be moved to TargetJITInfo!!
124 if (Subtarget.isPPC64()) {
125 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
126 // instructions to materialize arbitrary global variable + function +
127 // constant pool addresses.
128 setRelocationModel(Reloc::PIC_);
129 // Temporary workaround for the inability of PPC64 JIT to handle jump
130 // tables.
131 DisableJumpTables = true;
132 } else {
133 setRelocationModel(Reloc::Static);
134 }
135
136 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
137 // writing?
138 Subtarget.SetJITMode();
139
140 // Machine code emitter pass for PowerPC.
141 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000142
143 return false;
144}
145
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000146bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
147 CodeGenOpt::Level OptLevel,
Daniel Dunbar3e0ad8b2009-07-15 22:33:19 +0000148 ObjectCodeEmitter &OCE) {
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000149 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
150 // FIXME: This should be moved to TargetJITInfo!!
151 if (Subtarget.isPPC64()) {
152 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
153 // instructions to materialize arbitrary global variable + function +
154 // constant pool addresses.
155 setRelocationModel(Reloc::PIC_);
156 // Temporary workaround for the inability of PPC64 JIT to handle jump
157 // tables.
158 DisableJumpTables = true;
159 } else {
160 setRelocationModel(Reloc::Static);
161 }
162
163 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
164 // writing?
165 Subtarget.SetJITMode();
166
167 // Machine code emitter pass for PowerPC.
168 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000169
170 return false;
171}
172
Bill Wendling5ed22ac2009-04-29 23:29:43 +0000173bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
174 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000175 MachineCodeEmitter &MCE) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176 // Machine code emitter pass for PowerPC.
177 PM.add(createPPCCodeEmitterPass(*this, MCE));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000178 return false;
179}
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000180
181bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
182 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes8e2537b2009-06-01 19:57:37 +0000183 JITCodeEmitter &JCE) {
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000184 // Machine code emitter pass for PowerPC.
185 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopes1ea31ff2009-05-30 20:51:52 +0000186 return false;
187}
188
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000189bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
190 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000191 ObjectCodeEmitter &OCE) {
192 // Machine code emitter pass for PowerPC.
193 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopesaabb9a52009-07-06 05:09:34 +0000194 return false;
195}
196
197