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 const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
45 if (Subtarget.isDarwin())
46 return new PPCDarwinTargetAsmInfo(*this);
48 return new PPCLinuxTargetAsmInfo(*this);
51 PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M,
52 const std::string &FS, bool is64Bit)
53 : LLVMTargetMachine(T),
54 Subtarget(*this, M, FS, is64Bit),
55 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
56 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
57 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
59 if (getRelocationModel() == Reloc::Default) {
60 if (Subtarget.isDarwin())
61 setRelocationModel(Reloc::DynamicNoPIC);
63 setRelocationModel(Reloc::Static);
67 /// Override this for PowerPC. Tail merging happily breaks up instruction issue
68 /// groups, which typically degrades performance.
69 bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
71 PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
72 const std::string &FS)
73 : PPCTargetMachine(T, M, FS, false) {
77 PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
78 const std::string &FS)
79 : PPCTargetMachine(T, M, FS, true) {
83 //===----------------------------------------------------------------------===//
84 // Pass Pipeline Configuration
85 //===----------------------------------------------------------------------===//
87 bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
88 CodeGenOpt::Level OptLevel) {
89 // Install an instruction selector.
90 PM.add(createPPCISelDag(*this));
94 bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
95 CodeGenOpt::Level OptLevel) {
96 // Must run branch selection immediately preceding the asm printer.
97 PM.add(createPPCBranchSelectionPass());
101 bool PPCTargetMachine::addAssemblyEmitter(PassManagerBase &PM,
102 CodeGenOpt::Level OptLevel,
104 formatted_raw_ostream &Out) {
105 FunctionPass *Printer = getTarget().createAsmPrinter(Out, *this, Verbose);
107 llvm_report_error("unable to create assembly printer");
112 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
113 CodeGenOpt::Level OptLevel,
114 MachineCodeEmitter &MCE) {
115 // 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
124 DisableJumpTables = true;
126 setRelocationModel(Reloc::Static);
129 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
131 Subtarget.SetJITMode();
133 // Machine code emitter pass for PowerPC.
134 PM.add(createPPCCodeEmitterPass(*this, MCE));
139 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
140 CodeGenOpt::Level OptLevel,
141 JITCodeEmitter &JCE) {
142 // 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
151 DisableJumpTables = true;
153 setRelocationModel(Reloc::Static);
156 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
158 Subtarget.SetJITMode();
160 // Machine code emitter pass for PowerPC.
161 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
166 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
167 CodeGenOpt::Level OptLevel,
168 ObjectCodeEmitter &OCE) {
169 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
170 // FIXME: This should be moved to TargetJITInfo!!
171 if (Subtarget.isPPC64()) {
172 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
173 // instructions to materialize arbitrary global variable + function +
174 // constant pool addresses.
175 setRelocationModel(Reloc::PIC_);
176 // Temporary workaround for the inability of PPC64 JIT to handle jump
178 DisableJumpTables = true;
180 setRelocationModel(Reloc::Static);
183 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
185 Subtarget.SetJITMode();
187 // Machine code emitter pass for PowerPC.
188 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
193 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
194 CodeGenOpt::Level OptLevel,
195 MachineCodeEmitter &MCE) {
196 // Machine code emitter pass for PowerPC.
197 PM.add(createPPCCodeEmitterPass(*this, MCE));
201 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
202 CodeGenOpt::Level OptLevel,
203 JITCodeEmitter &JCE) {
204 // Machine code emitter pass for PowerPC.
205 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
209 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
210 CodeGenOpt::Level OptLevel,
211 ObjectCodeEmitter &OCE) {
212 // Machine code emitter pass for PowerPC.
213 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));