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::addCodeEmitter(PassManagerBase &PM,
102 CodeGenOpt::Level OptLevel,
103 MachineCodeEmitter &MCE) {
104 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
105 // FIXME: This should be moved to TargetJITInfo!!
106 if (Subtarget.isPPC64()) {
107 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
108 // instructions to materialize arbitrary global variable + function +
109 // constant pool addresses.
110 setRelocationModel(Reloc::PIC_);
111 // Temporary workaround for the inability of PPC64 JIT to handle jump
113 DisableJumpTables = true;
115 setRelocationModel(Reloc::Static);
118 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
120 Subtarget.SetJITMode();
122 // Machine code emitter pass for PowerPC.
123 PM.add(createPPCCodeEmitterPass(*this, MCE));
128 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
129 CodeGenOpt::Level OptLevel,
130 JITCodeEmitter &JCE) {
131 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
132 // FIXME: This should be moved to TargetJITInfo!!
133 if (Subtarget.isPPC64()) {
134 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
135 // instructions to materialize arbitrary global variable + function +
136 // constant pool addresses.
137 setRelocationModel(Reloc::PIC_);
138 // Temporary workaround for the inability of PPC64 JIT to handle jump
140 DisableJumpTables = true;
142 setRelocationModel(Reloc::Static);
145 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
147 Subtarget.SetJITMode();
149 // Machine code emitter pass for PowerPC.
150 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
155 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
156 CodeGenOpt::Level OptLevel,
157 ObjectCodeEmitter &OCE) {
158 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
159 // FIXME: This should be moved to TargetJITInfo!!
160 if (Subtarget.isPPC64()) {
161 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
162 // instructions to materialize arbitrary global variable + function +
163 // constant pool addresses.
164 setRelocationModel(Reloc::PIC_);
165 // Temporary workaround for the inability of PPC64 JIT to handle jump
167 DisableJumpTables = true;
169 setRelocationModel(Reloc::Static);
172 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
174 Subtarget.SetJITMode();
176 // Machine code emitter pass for PowerPC.
177 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));
182 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
183 CodeGenOpt::Level OptLevel,
184 MachineCodeEmitter &MCE) {
185 // Machine code emitter pass for PowerPC.
186 PM.add(createPPCCodeEmitterPass(*this, MCE));
190 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
191 CodeGenOpt::Level OptLevel,
192 JITCodeEmitter &JCE) {
193 // Machine code emitter pass for PowerPC.
194 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
198 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
199 CodeGenOpt::Level OptLevel,
200 ObjectCodeEmitter &OCE) {
201 // Machine code emitter pass for PowerPC.
202 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));