1 //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Top-level implementation for the PowerPC target.
12 //===----------------------------------------------------------------------===//
15 #include "PPCTargetAsmInfo.h"
16 #include "PPCTargetMachine.h"
17 #include "llvm/Module.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/Target/TargetMachineRegistry.h"
20 #include "llvm/Target/TargetOptions.h"
21 #include "llvm/Support/FormattedStream.h"
24 /// PowerPCTargetMachineModule - Note that this is used on hosts that
25 /// cannot link in a library unless there are references into the
26 /// library. In particular, it seems that it is not possible to get
27 /// things to work on Win32 without this. Though it is unused, do not
29 extern "C" int PowerPCTargetMachineModule;
30 int PowerPCTargetMachineModule = 0;
32 // Register the targets
33 extern Target ThePPC32Target;
34 static RegisterTarget<PPC32TargetMachine>
35 X(ThePPC32Target, "ppc32", "PowerPC 32");
37 extern Target ThePPC64Target;
38 static RegisterTarget<PPC64TargetMachine>
39 Y(ThePPC64Target, "ppc64", "PowerPC 64");
41 // Force static initialization.
42 extern "C" void LLVMInitializePowerPCTarget() { }
44 // No assembler printer by default
45 PPCTargetMachine::AsmPrinterCtorFn PPCTargetMachine::AsmPrinterCtor = 0;
47 const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
48 if (Subtarget.isDarwin())
49 return new PPCDarwinTargetAsmInfo(*this);
51 return new PPCLinuxTargetAsmInfo(*this);
54 PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M,
55 const std::string &FS, bool is64Bit)
56 : LLVMTargetMachine(T),
57 Subtarget(*this, M, FS, is64Bit),
58 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
59 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
60 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
62 if (getRelocationModel() == Reloc::Default) {
63 if (Subtarget.isDarwin())
64 setRelocationModel(Reloc::DynamicNoPIC);
66 setRelocationModel(Reloc::Static);
70 /// Override this for PowerPC. Tail merging happily breaks up instruction issue
71 /// groups, which typically degrades performance.
72 bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
74 PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
75 const std::string &FS)
76 : PPCTargetMachine(T, M, FS, false) {
80 PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
81 const std::string &FS)
82 : PPCTargetMachine(T, M, FS, true) {
86 //===----------------------------------------------------------------------===//
87 // Pass Pipeline Configuration
88 //===----------------------------------------------------------------------===//
90 bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
91 CodeGenOpt::Level OptLevel) {
92 // Install an instruction selector.
93 PM.add(createPPCISelDag(*this));
97 bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
98 CodeGenOpt::Level OptLevel) {
99 // Must run branch selection immediately preceding the asm printer.
100 PM.add(createPPCBranchSelectionPass());
104 bool PPCTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
105 CodeGenOpt::Level OptLevel,
107 formatted_raw_ostream &Out) {
108 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
110 PM.add(AsmPrinterCtor(Out, *this, Verbose));
115 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
116 CodeGenOpt::Level OptLevel,
117 bool DumpAsm, MachineCodeEmitter &MCE) {
118 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
119 // FIXME: This should be moved to TargetJITInfo!!
120 if (Subtarget.isPPC64()) {
121 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
122 // instructions to materialize arbitrary global variable + function +
123 // constant pool addresses.
124 setRelocationModel(Reloc::PIC_);
125 // Temporary workaround for the inability of PPC64 JIT to handle jump
127 DisableJumpTables = true;
129 setRelocationModel(Reloc::Static);
132 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
134 Subtarget.SetJITMode();
136 // Machine code emitter pass for PowerPC.
137 PM.add(createPPCCodeEmitterPass(*this, MCE));
139 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
141 PM.add(AsmPrinterCtor(ferrs(), *this, true));
147 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
148 CodeGenOpt::Level OptLevel,
149 bool DumpAsm, JITCodeEmitter &JCE) {
150 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
151 // FIXME: This should be moved to TargetJITInfo!!
152 if (Subtarget.isPPC64()) {
153 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
154 // instructions to materialize arbitrary global variable + function +
155 // constant pool addresses.
156 setRelocationModel(Reloc::PIC_);
157 // Temporary workaround for the inability of PPC64 JIT to handle jump
159 DisableJumpTables = true;
161 setRelocationModel(Reloc::Static);
164 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
166 Subtarget.SetJITMode();
168 // Machine code emitter pass for PowerPC.
169 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
171 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
173 PM.add(AsmPrinterCtor(ferrs(), *this, true));
179 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
180 CodeGenOpt::Level OptLevel,
181 bool DumpAsm, ObjectCodeEmitter &OCE) {
182 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
183 // FIXME: This should be moved to TargetJITInfo!!
184 if (Subtarget.isPPC64()) {
185 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
186 // instructions to materialize arbitrary global variable + function +
187 // constant pool addresses.
188 setRelocationModel(Reloc::PIC_);
189 // Temporary workaround for the inability of PPC64 JIT to handle jump
191 DisableJumpTables = true;
193 setRelocationModel(Reloc::Static);
196 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
198 Subtarget.SetJITMode();
200 // Machine code emitter pass for PowerPC.
201 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
203 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
205 PM.add(AsmPrinterCtor(ferrs(), *this, true));
211 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
212 CodeGenOpt::Level OptLevel,
214 MachineCodeEmitter &MCE) {
215 // Machine code emitter pass for PowerPC.
216 PM.add(createPPCCodeEmitterPass(*this, MCE));
218 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
220 PM.add(AsmPrinterCtor(ferrs(), *this, true));
226 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
227 CodeGenOpt::Level OptLevel,
229 JITCodeEmitter &JCE) {
230 // Machine code emitter pass for PowerPC.
231 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
233 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
235 PM.add(AsmPrinterCtor(ferrs(), *this, true));
241 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
242 CodeGenOpt::Level OptLevel,
244 ObjectCodeEmitter &OCE) {
245 // Machine code emitter pass for PowerPC.
246 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
248 assert(AsmPrinterCtor && "AsmPrinter was not linked in");
250 PM.add(AsmPrinterCtor(ferrs(), *this, true));