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 // Register the targets
25 extern Target ThePPC32Target;
26 static RegisterTarget<PPC32TargetMachine>
27 X(ThePPC32Target, "ppc32", "PowerPC 32");
29 extern Target ThePPC64Target;
30 static RegisterTarget<PPC64TargetMachine>
31 Y(ThePPC64Target, "ppc64", "PowerPC 64");
33 // Force static initialization.
34 extern "C" void LLVMInitializePowerPCTarget() { }
36 const TargetAsmInfo *PPCTargetMachine::createTargetAsmInfo() const {
37 if (Subtarget.isDarwin())
38 return new PPCDarwinTargetAsmInfo(*this);
40 return new PPCLinuxTargetAsmInfo(*this);
43 PPCTargetMachine::PPCTargetMachine(const Target&T, const Module &M,
44 const std::string &FS, bool is64Bit)
45 : LLVMTargetMachine(T),
46 Subtarget(*this, M, FS, is64Bit),
47 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
48 FrameInfo(*this, is64Bit), JITInfo(*this, is64Bit), TLInfo(*this),
49 InstrItins(Subtarget.getInstrItineraryData()), MachOWriterInfo(*this) {
51 if (getRelocationModel() == Reloc::Default) {
52 if (Subtarget.isDarwin())
53 setRelocationModel(Reloc::DynamicNoPIC);
55 setRelocationModel(Reloc::Static);
59 /// Override this for PowerPC. Tail merging happily breaks up instruction issue
60 /// groups, which typically degrades performance.
61 bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
63 PPC32TargetMachine::PPC32TargetMachine(const Target &T, const Module &M,
64 const std::string &FS)
65 : PPCTargetMachine(T, M, FS, false) {
69 PPC64TargetMachine::PPC64TargetMachine(const Target &T, const Module &M,
70 const std::string &FS)
71 : PPCTargetMachine(T, M, FS, true) {
75 //===----------------------------------------------------------------------===//
76 // Pass Pipeline Configuration
77 //===----------------------------------------------------------------------===//
79 bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
80 CodeGenOpt::Level OptLevel) {
81 // Install an instruction selector.
82 PM.add(createPPCISelDag(*this));
86 bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
87 CodeGenOpt::Level OptLevel) {
88 // Must run branch selection immediately preceding the asm printer.
89 PM.add(createPPCBranchSelectionPass());
93 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
94 CodeGenOpt::Level OptLevel,
95 MachineCodeEmitter &MCE) {
96 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
97 // FIXME: This should be moved to TargetJITInfo!!
98 if (Subtarget.isPPC64()) {
99 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
100 // instructions to materialize arbitrary global variable + function +
101 // constant pool addresses.
102 setRelocationModel(Reloc::PIC_);
103 // Temporary workaround for the inability of PPC64 JIT to handle jump
105 DisableJumpTables = true;
107 setRelocationModel(Reloc::Static);
110 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
112 Subtarget.SetJITMode();
114 // Machine code emitter pass for PowerPC.
115 PM.add(createPPCCodeEmitterPass(*this, MCE));
120 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
121 CodeGenOpt::Level OptLevel,
122 JITCodeEmitter &JCE) {
123 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
124 // FIXME: This should be moved to TargetJITInfo!!
125 if (Subtarget.isPPC64()) {
126 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
127 // instructions to materialize arbitrary global variable + function +
128 // constant pool addresses.
129 setRelocationModel(Reloc::PIC_);
130 // Temporary workaround for the inability of PPC64 JIT to handle jump
132 DisableJumpTables = true;
134 setRelocationModel(Reloc::Static);
137 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
139 Subtarget.SetJITMode();
141 // Machine code emitter pass for PowerPC.
142 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
147 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
148 CodeGenOpt::Level OptLevel,
149 ObjectCodeEmitter &OCE) {
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(createPPCObjectCodeEmitterPass(*this, OCE));
174 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
175 CodeGenOpt::Level OptLevel,
176 MachineCodeEmitter &MCE) {
177 // Machine code emitter pass for PowerPC.
178 PM.add(createPPCCodeEmitterPass(*this, MCE));
182 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
183 CodeGenOpt::Level OptLevel,
184 JITCodeEmitter &JCE) {
185 // Machine code emitter pass for PowerPC.
186 PM.add(createPPCJITCodeEmitterPass(*this, JCE));
190 bool PPCTargetMachine::addSimpleCodeEmitter(PassManagerBase &PM,
191 CodeGenOpt::Level OptLevel,
192 ObjectCodeEmitter &OCE) {
193 // Machine code emitter pass for PowerPC.
194 PM.add(createPPCObjectCodeEmitterPass(*this, OCE));