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 "PPCTargetMachine.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/MC/MCStreamer.h"
18 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/Target/TargetRegistry.h"
20 #include "llvm/Support/FormattedStream.h"
23 // This is duplicated code. Refactor this.
24 static MCStreamer *createMCStreamer(const Target &T, const std::string &TT,
25 MCContext &Ctx, TargetAsmBackend &TAB,
27 MCCodeEmitter *Emitter,
30 if (Triple(TT).isOSDarwin())
31 return createMachOStreamer(Ctx, TAB, OS, Emitter, RelaxAll);
36 extern "C" void LLVMInitializePowerPCTarget() {
37 // Register the targets
38 RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
39 RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
41 // Register the MC Code Emitter
42 TargetRegistry::RegisterCodeEmitter(ThePPC32Target, createPPCMCCodeEmitter);
43 TargetRegistry::RegisterCodeEmitter(ThePPC64Target, createPPCMCCodeEmitter);
46 // Register the asm backend.
47 TargetRegistry::RegisterAsmBackend(ThePPC32Target, createPPCAsmBackend);
48 TargetRegistry::RegisterAsmBackend(ThePPC64Target, createPPCAsmBackend);
50 // Register the object streamer.
51 TargetRegistry::RegisterObjectStreamer(ThePPC32Target, createMCStreamer);
52 TargetRegistry::RegisterObjectStreamer(ThePPC64Target, createMCStreamer);
56 PPCTargetMachine::PPCTargetMachine(const Target &T, const std::string &TT,
57 const std::string &CPU,
58 const std::string &FS, bool is64Bit)
59 : LLVMTargetMachine(T, TT, CPU, FS),
60 Subtarget(TT, CPU, FS, is64Bit),
61 DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
62 FrameLowering(Subtarget), JITInfo(*this, is64Bit),
63 TLInfo(*this), TSInfo(*this),
64 InstrItins(Subtarget.getInstrItineraryData()) {
66 if (getRelocationModel() == Reloc::Default) {
67 if (Subtarget.isDarwin())
68 setRelocationModel(Reloc::DynamicNoPIC);
70 setRelocationModel(Reloc::Static);
74 /// Override this for PowerPC. Tail merging happily breaks up instruction issue
75 /// groups, which typically degrades performance.
76 bool PPCTargetMachine::getEnableTailMergeDefault() const { return false; }
78 PPC32TargetMachine::PPC32TargetMachine(const Target &T, const std::string &TT,
79 const std::string &CPU,
80 const std::string &FS)
81 : PPCTargetMachine(T, TT, CPU, FS, false) {
85 PPC64TargetMachine::PPC64TargetMachine(const Target &T, const std::string &TT,
86 const std::string &CPU,
87 const std::string &FS)
88 : PPCTargetMachine(T, TT, CPU, FS, true) {
92 //===----------------------------------------------------------------------===//
93 // Pass Pipeline Configuration
94 //===----------------------------------------------------------------------===//
96 bool PPCTargetMachine::addInstSelector(PassManagerBase &PM,
97 CodeGenOpt::Level OptLevel) {
98 // Install an instruction selector.
99 PM.add(createPPCISelDag(*this));
103 bool PPCTargetMachine::addPreEmitPass(PassManagerBase &PM,
104 CodeGenOpt::Level OptLevel) {
105 // Must run branch selection immediately preceding the asm printer.
106 PM.add(createPPCBranchSelectionPass());
110 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
111 CodeGenOpt::Level OptLevel,
112 JITCodeEmitter &JCE) {
113 // The JIT should use the static relocation model in ppc32 mode, PIC in ppc64.
114 // FIXME: This should be moved to TargetJITInfo!!
115 if (Subtarget.isPPC64()) {
116 // We use PIC codegen in ppc64 mode, because otherwise we'd have to use many
117 // instructions to materialize arbitrary global variable + function +
118 // constant pool addresses.
119 setRelocationModel(Reloc::PIC_);
120 // Temporary workaround for the inability of PPC64 JIT to handle jump
122 DisableJumpTables = true;
124 setRelocationModel(Reloc::Static);
127 // Inform the subtarget that we are in JIT mode. FIXME: does this break macho
129 Subtarget.SetJITMode();
131 // Machine code emitter pass for PowerPC.
132 PM.add(createPPCJITCodeEmitterPass(*this, JCE));