blob: 251be7679b28f0c68efde012e4291eff6bcae153 [file] [log] [blame]
Nate Begeman6cca84e2005-10-16 05:39:50 +00001//===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
Misha Brukmanb4402432005-04-21 23:30:14 +00002//
Misha Brukmane05203f2004-06-21 16:55:25 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb4402432005-04-21 23:30:14 +00007//
Misha Brukmane05203f2004-06-21 16:55:25 +00008//===----------------------------------------------------------------------===//
Misha Brukmanb4402432005-04-21 23:30:14 +00009//
Chris Lattner73785d22005-08-15 23:47:04 +000010// Top-level implementation for the PowerPC target.
Misha Brukmane05203f2004-06-21 16:55:25 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattnerbfca1ab2005-10-14 23:51:18 +000014#include "PPC.h"
Jim Laskeyae92ce82006-09-07 23:39:26 +000015#include "PPCTargetAsmInfo.h"
Chris Lattner6f3b9542005-10-14 23:59:06 +000016#include "PPCTargetMachine.h"
Misha Brukmane05203f2004-06-21 16:55:25 +000017#include "llvm/PassManager.h"
Dale Johannesenc31eb202008-07-31 18:13:12 +000018#include "llvm/Target/TargetOptions.h"
Daniel Dunbar5680b4f2009-07-25 06:49:55 +000019#include "llvm/Target/TargetRegistry.h"
David Greenea31f96c2009-07-14 20:18:05 +000020#include "llvm/Support/FormattedStream.h"
Misha Brukmane05203f2004-06-21 16:55:25 +000021using namespace llvm;
22
Daniel Dunbar5680b4f2009-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 Gregor1b731d52009-06-16 20:12:29 +000028
Jim Laskeyae92ce82006-09-07 23:39:26 +000029const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
Jim Laskey28663c72006-12-21 20:26:09 +000030 if (Subtarget.isDarwin())
Anton Korobeynikovbc780e32008-07-19 21:44:57 +000031 return new PPCDarwinTargetAsmInfo(*this);
Jim Laskey28663c72006-12-21 20:26:09 +000032 else
Anton Korobeynikovbc780e32008-07-19 21:44:57 +000033 return new PPCLinuxTargetAsmInfo(*this);
Jim Laskeyae92ce82006-09-07 23:39:26 +000034}
35
Daniel Dunbarc3719c32009-08-02 23:37:13 +000036PPCTargetMachine::PPCTargetMachine(const Target&T, const std::string &TT,
Daniel Dunbare8338102009-07-15 20:24:03 +000037 const std::string &FS, bool is64Bit)
38 : LLVMTargetMachine(T),
Daniel Dunbarc3719c32009-08-02 23:37:13 +000039 Subtarget(TT, FS, is64Bit),
Chris Lattner49cadab2006-06-17 00:01:04 +000040 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
Chris Lattner572e2382006-11-18 01:34:43 +000041 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
Bill Wendling40cb8112007-01-24 03:41:36 +000042 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
Chris Lattner0c4aa142006-06-16 01:37:27 +000043
Anton Korobeynikov40d67c52008-02-20 11:22:39 +000044 if (getRelocationModel() == Reloc::Default) {
Evan Cheng73136df2006-02-22 20:19:42 +000045 if (Subtarget.isDarwin())
46 setRelocationModel(Reloc::DynamicNoPIC);
47 else
Jim Laskey28663c72006-12-21 20:26:09 +000048 setRelocationModel(Reloc::Static);
Anton Korobeynikov40d67c52008-02-20 11:22:39 +000049 }
Nate Begeman6cca84e2005-10-16 05:39:50 +000050}
51
Dale Johannesen82810c82007-05-22 17:14:46 +000052/// Override this for PowerPC. Tail merging happily breaks up instruction issue
53/// groups, which typically degrades performance.
Dan Gohmanaad83c82007-11-19 20:46:23 +000054bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
Dale Johannesen82810c82007-05-22 17:14:46 +000055
Daniel Dunbarc3719c32009-08-02 23:37:13 +000056PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbare8338102009-07-15 20:24:03 +000057 const std::string &FS)
Daniel Dunbarc3719c32009-08-02 23:37:13 +000058 : PPCTargetMachine(T, TT, FS, false) {
Chris Lattner0c4aa142006-06-16 01:37:27 +000059}
60
61
Daniel Dunbarc3719c32009-08-02 23:37:13 +000062PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT,
Daniel Dunbare8338102009-07-15 20:24:03 +000063 const std::string &FS)
Daniel Dunbarc3719c32009-08-02 23:37:13 +000064 : PPCTargetMachine(T, TT, FS, true) {
Chris Lattner0c4aa142006-06-16 01:37:27 +000065}
66
Misha Brukmanb4402432005-04-21 23:30:14 +000067
Chris Lattner12e97302006-09-04 04:14:57 +000068//===----------------------------------------------------------------------===//
69// Pass Pipeline Configuration
70//===----------------------------------------------------------------------===//
Nate Begemanf17ea0f2004-08-11 07:40:04 +000071
Bill Wendling026e5d72009-04-29 23:29:43 +000072bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
73 CodeGenOpt::Level OptLevel) {
Chris Lattnerc6aa8062005-08-17 19:33:30 +000074 // Install an instruction selector.
Chris Lattner33792a42006-01-12 01:46:07 +000075 PM.add(createPPCISelDag(*this));
Nate Begemanf17ea0f2004-08-11 07:40:04 +000076 return false;
77}
78
Bill Wendling026e5d72009-04-29 23:29:43 +000079bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
80 CodeGenOpt::Level OptLevel) {
Chris Lattner12e97302006-09-04 04:14:57 +000081 // Must run branch selection immediately preceding the asm printer.
82 PM.add(createPPCBranchSelectionPass());
83 return false;
84}
85
Bill Wendling026e5d72009-04-29 23:29:43 +000086bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
87 CodeGenOpt::Level OptLevel,
Daniel Dunbarc9013922009-07-15 22:33:19 +000088 MachineCodeEmitter &MCE) {
Chris Lattner09fecf92006-12-08 04:54:03 +000089 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
Chris Lattner12e97302006-09-04 04:14:57 +000090 // FIXME: This should be moved to TargetJITInfo!!
Chris Lattner09fecf92006-12-08 04:54:03 +000091 if (Subtarget.isPPC64()) {
92 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
93 // instructions to materialize arbitrary global variable + function +
94 // constant pool addresses.
95 setRelocationModel(Reloc::PIC_);
Dale Johannesenc31eb202008-07-31 18:13:12 +000096 // Temporary workaround for the inability of PPC64 JIT to handle jump
97 // tables.
98 DisableJumpTables = true;
Chris Lattner09fecf92006-12-08 04:54:03 +000099 } else {
100 setRelocationModel(Reloc::Static);
101 }
102
Chris Lattnerf4646a72006-12-11 23:22:45 +0000103 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
104 // writing?
105 Subtarget.SetJITMode();
Chris Lattner12e97302006-09-04 04:14:57 +0000106
107 // Machine code emitter pass for PowerPC.
Nate Begeman3cb39212006-08-23 21:08:52 +0000108 PM.add(createPPCCodeEmitterPass(*this, MCE));
Anton Korobeynikov28dc9d02008-08-17 13:54:28 +0000109
Nate Begeman3cb39212006-08-23 21:08:52 +0000110 return false;
111}
Chris Lattner12e97302006-09-04 04:14:57 +0000112
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000113bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
114 CodeGenOpt::Level OptLevel,
Daniel Dunbarc9013922009-07-15 22:33:19 +0000115 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000116 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
117 // FIXME: This should be moved to TargetJITInfo!!
118 if (Subtarget.isPPC64()) {
119 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
120 // instructions to materialize arbitrary global variable + function +
121 // constant pool addresses.
122 setRelocationModel(Reloc::PIC_);
123 // Temporary workaround for the inability of PPC64 JIT to handle jump
124 // tables.
125 DisableJumpTables = true;
126 } else {
127 setRelocationModel(Reloc::Static);
128 }
129
130 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
131 // writing?
132 Subtarget.SetJITMode();
133
134 // Machine code emitter pass for PowerPC.
135 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000136
137 return false;
138}
139
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000140bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
141 CodeGenOpt::Level OptLevel,
Daniel Dunbarc9013922009-07-15 22:33:19 +0000142 ObjectCodeEmitter &OCE) {
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000143 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
144 // FIXME: This should be moved to TargetJITInfo!!
145 if (Subtarget.isPPC64()) {
146 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
147 // instructions to materialize arbitrary global variable + function +
148 // constant pool addresses.
149 setRelocationModel(Reloc::PIC_);
150 // Temporary workaround for the inability of PPC64 JIT to handle jump
151 // tables.
152 DisableJumpTables = true;
153 } else {
154 setRelocationModel(Reloc::Static);
155 }
156
157 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
158 // writing?
159 Subtarget.SetJITMode();
160
161 // Machine code emitter pass for PowerPC.
162 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000163
164 return false;
165}
166
Bill Wendling026e5d72009-04-29 23:29:43 +0000167bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
168 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes9fd794b2009-06-01 19:57:37 +0000169 MachineCodeEmitter &MCE) {
Bill Wendling2aa9a422007-02-08 01:39:44 +0000170 // Machine code emitter pass for PowerPC.
171 PM.add(createPPCCodeEmitterPass(*this, MCE));
172 return false;
173}
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000174
175bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
176 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes9fd794b2009-06-01 19:57:37 +0000177 JITCodeEmitter &JCE) {
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000178 // Machine code emitter pass for PowerPC.
179 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +0000180 return false;
181}
182
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000183bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
184 CodeGenOpt::Level OptLevel,
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000185 ObjectCodeEmitter &OCE) {
186 // Machine code emitter pass for PowerPC.
187 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
Bruno Cardoso Lopes5661ea62009-07-06 05:09:34 +0000188 return false;
189}
190
191