Move PPCInstrInfo off of the target machine and onto the subtarget.
[oota-llvm.git] / lib / Target / PowerPC / PPCTargetMachine.cpp
1 //===-- PPCTargetMachine.cpp - Define TargetMachine for PowerPC -----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Top-level implementation for the PowerPC target.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "PPCTargetMachine.h"
15 #include "PPC.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/MC/MCStreamer.h"
18 #include "llvm/PassManager.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/FormattedStream.h"
21 #include "llvm/Support/TargetRegistry.h"
22 #include "llvm/Target/TargetOptions.h"
23 using namespace llvm;
24
25 static cl::
26 opt<bool> DisableCTRLoops("disable-ppc-ctrloops", cl::Hidden,
27                         cl::desc("Disable CTR loops for PPC"));
28
29 static cl::opt<bool>
30 VSXFMAMutateEarly("schedule-ppc-vsx-fma-mutation-early",
31   cl::Hidden, cl::desc("Schedule VSX FMA instruction mutation early"));
32
33 extern "C" void LLVMInitializePowerPCTarget() {
34   // Register the targets
35   RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
36   RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
37   RegisterTargetMachine<PPC64TargetMachine> C(ThePPC64LETarget);
38 }
39
40 PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT, StringRef CPU,
41                                    StringRef FS, const TargetOptions &Options,
42                                    Reloc::Model RM, CodeModel::Model CM,
43                                    CodeGenOpt::Level OL, bool is64Bit)
44     : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
45       Subtarget(TT, CPU, FS, is64Bit, OL), JITInfo(*this, is64Bit),
46       TLInfo(*this), TSInfo(*this) {
47   initAsmInfo();
48 }
49
50 void PPC32TargetMachine::anchor() { }
51
52 PPC32TargetMachine::PPC32TargetMachine(const Target &T, StringRef TT,
53                                        StringRef CPU, StringRef FS,
54                                        const TargetOptions &Options,
55                                        Reloc::Model RM, CodeModel::Model CM,
56                                        CodeGenOpt::Level OL)
57   : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
58 }
59
60 void PPC64TargetMachine::anchor() { }
61
62 PPC64TargetMachine::PPC64TargetMachine(const Target &T, StringRef TT,
63                                        StringRef CPU,  StringRef FS,
64                                        const TargetOptions &Options,
65                                        Reloc::Model RM, CodeModel::Model CM,
66                                        CodeGenOpt::Level OL)
67   : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {
68 }
69
70
71 //===----------------------------------------------------------------------===//
72 // Pass Pipeline Configuration
73 //===----------------------------------------------------------------------===//
74
75 namespace {
76 /// PPC Code Generator Pass Configuration Options.
77 class PPCPassConfig : public TargetPassConfig {
78 public:
79   PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM)
80     : TargetPassConfig(TM, PM) {}
81
82   PPCTargetMachine &getPPCTargetMachine() const {
83     return getTM<PPCTargetMachine>();
84   }
85
86   const PPCSubtarget &getPPCSubtarget() const {
87     return *getPPCTargetMachine().getSubtargetImpl();
88   }
89
90   bool addPreISel() override;
91   bool addILPOpts() override;
92   bool addInstSelector() override;
93   bool addPreRegAlloc() override;
94   bool addPreSched2() override;
95   bool addPreEmitPass() override;
96 };
97 } // namespace
98
99 TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM) {
100   return new PPCPassConfig(this, PM);
101 }
102
103 bool PPCPassConfig::addPreISel() {
104   if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
105     addPass(createPPCCTRLoops(getPPCTargetMachine()));
106
107   return false;
108 }
109
110 bool PPCPassConfig::addILPOpts() {
111   addPass(&EarlyIfConverterID);
112   return true;
113 }
114
115 bool PPCPassConfig::addInstSelector() {
116   // Install an instruction selector.
117   addPass(createPPCISelDag(getPPCTargetMachine()));
118
119 #ifndef NDEBUG
120   if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
121     addPass(createPPCCTRLoopsVerify());
122 #endif
123
124   addPass(createPPCVSXCopyPass());
125   return false;
126 }
127
128 bool PPCPassConfig::addPreRegAlloc() {
129   initializePPCVSXFMAMutatePass(*PassRegistry::getPassRegistry());
130   insertPass(VSXFMAMutateEarly ? &RegisterCoalescerID : &MachineSchedulerID,
131              &PPCVSXFMAMutateID);
132   return false;
133 }
134
135 bool PPCPassConfig::addPreSched2() {
136   addPass(createPPCVSXCopyCleanupPass());
137
138   if (getOptLevel() != CodeGenOpt::None)
139     addPass(&IfConverterID);
140
141   return true;
142 }
143
144 bool PPCPassConfig::addPreEmitPass() {
145   if (getOptLevel() != CodeGenOpt::None)
146     addPass(createPPCEarlyReturnPass());
147   // Must run branch selection immediately preceding the asm printer.
148   addPass(createPPCBranchSelectionPass());
149   return false;
150 }
151
152 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
153                                       JITCodeEmitter &JCE) {
154   // Inform the subtarget that we are in JIT mode.  FIXME: does this break macho
155   // writing?
156   Subtarget.SetJITMode();
157
158   // Machine code emitter pass for PowerPC.
159   PM.add(createPPCJITCodeEmitterPass(*this, JCE));
160
161   return false;
162 }
163
164 void PPCTargetMachine::addAnalysisPasses(PassManagerBase &PM) {
165   // Add first the target-independent BasicTTI pass, then our PPC pass. This
166   // allows the PPC pass to delegate to the target independent layer when
167   // appropriate.
168   PM.add(createBasicTargetTransformInfoPass(this));
169   PM.add(createPPCTargetTransformInfoPass(this));
170 }
171