Added TargetPassConfig. The first little step toward configuring codegen passes.
[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 "PPC.h"
15 #include "PPCTargetMachine.h"
16 #include "llvm/PassManager.h"
17 #include "llvm/MC/MCStreamer.h"
18 #include "llvm/CodeGen/Passes.h"
19 #include "llvm/Target/TargetOptions.h"
20 #include "llvm/Support/FormattedStream.h"
21 #include "llvm/Support/TargetRegistry.h"
22 using namespace llvm;
23
24 extern "C" void LLVMInitializePowerPCTarget() {
25   // Register the targets
26   RegisterTargetMachine<PPC32TargetMachine> A(ThePPC32Target);
27   RegisterTargetMachine<PPC64TargetMachine> B(ThePPC64Target);
28 }
29
30 PPCTargetMachine::PPCTargetMachine(const Target &T, StringRef TT,
31                                    StringRef CPU, StringRef FS,
32                                    const TargetOptions &Options,
33                                    Reloc::Model RM, CodeModel::Model CM,
34                                    CodeGenOpt::Level OL,
35                                    bool is64Bit)
36   : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
37     Subtarget(TT, CPU, FS, is64Bit),
38     DataLayout(Subtarget.getTargetDataString()), InstrInfo(*this),
39     FrameLowering(Subtarget), JITInfo(*this, is64Bit),
40     TLInfo(*this), TSInfo(*this),
41     InstrItins(Subtarget.getInstrItineraryData()) {
42 }
43
44 void PPC32TargetMachine::anchor() { }
45
46 PPC32TargetMachine::PPC32TargetMachine(const Target &T, StringRef TT,
47                                        StringRef CPU, StringRef FS,
48                                        const TargetOptions &Options,
49                                        Reloc::Model RM, CodeModel::Model CM,
50                                        CodeGenOpt::Level OL)
51   : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
52 }
53
54 void PPC64TargetMachine::anchor() { }
55
56 PPC64TargetMachine::PPC64TargetMachine(const Target &T, StringRef TT,
57                                        StringRef CPU,  StringRef FS,
58                                        const TargetOptions &Options,
59                                        Reloc::Model RM, CodeModel::Model CM,
60                                        CodeGenOpt::Level OL)
61   : PPCTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {
62 }
63
64
65 //===----------------------------------------------------------------------===//
66 // Pass Pipeline Configuration
67 //===----------------------------------------------------------------------===//
68
69 namespace {
70 /// PPC Code Generator Pass Configuration Options.
71 class PPCPassConfig : public TargetPassConfig {
72 public:
73   PPCPassConfig(PPCTargetMachine *TM, PassManagerBase &PM,
74                 bool DisableVerifyFlag)
75     : TargetPassConfig(TM, PM, DisableVerifyFlag) {}
76
77   PPCTargetMachine &getPPCTargetMachine() const {
78     return getTM<PPCTargetMachine>();
79   }
80
81   virtual bool addInstSelector();
82   virtual bool getEnableTailMergeDefault() const;
83   virtual bool addPreEmitPass();
84 };
85 } // namespace
86
87 TargetPassConfig *PPCTargetMachine::createPassConfig(PassManagerBase &PM,
88                                                      bool DisableVerify) {
89   return new PPCPassConfig(this, PM, DisableVerify);
90 }
91
92 bool PPCPassConfig::addInstSelector() {
93   // Install an instruction selector.
94   PM.add(createPPCISelDag(getPPCTargetMachine()));
95   return false;
96 }
97
98 /// Override this for PowerPC.  Tail merging happily breaks up instruction issue
99 /// groups, which typically degrades performance.
100 bool PPCPassConfig::getEnableTailMergeDefault() const { return false; }
101
102 bool PPCPassConfig::addPreEmitPass() {
103   // Must run branch selection immediately preceding the asm printer.
104   PM.add(createPPCBranchSelectionPass());
105   return false;
106 }
107
108 bool PPCTargetMachine::addCodeEmitter(PassManagerBase &PM,
109                                       JITCodeEmitter &JCE) {
110   // FIXME: This should be moved to TargetJITInfo!!
111   if (Subtarget.isPPC64())
112     // Temporary workaround for the inability of PPC64 JIT to handle jump
113     // tables.
114     Options.DisableJumpTables = true;
115
116   // Inform the subtarget that we are in JIT mode.  FIXME: does this break macho
117   // writing?
118   Subtarget.SetJITMode();
119
120   // Machine code emitter pass for PowerPC.
121   PM.add(createPPCJITCodeEmitterPass(*this, JCE));
122
123   return false;
124 }