This patch changes the ownership of TLOF from TargetLoweringBase to TargetMachine...
[oota-llvm.git] / lib / Target / Sparc / SparcTargetMachine.cpp
1 //===-- SparcTargetMachine.cpp - Define TargetMachine for Sparc -----------===//
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 //
11 //===----------------------------------------------------------------------===//
12
13 #include "SparcTargetMachine.h"
14 #include "SparcTargetObjectFile.h"
15 #include "Sparc.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/PassManager.h"
18 #include "llvm/Support/TargetRegistry.h"
19 using namespace llvm;
20
21 extern "C" void LLVMInitializeSparcTarget() {
22   // Register the target.
23   RegisterTargetMachine<SparcV8TargetMachine> X(TheSparcTarget);
24   RegisterTargetMachine<SparcV9TargetMachine> Y(TheSparcV9Target);
25 }
26
27 /// SparcTargetMachine ctor - Create an ILP32 architecture model
28 ///
29 SparcTargetMachine::SparcTargetMachine(const Target &T, StringRef TT,
30                                        StringRef CPU, StringRef FS,
31                                        const TargetOptions &Options,
32                                        Reloc::Model RM, CodeModel::Model CM,
33                                        CodeGenOpt::Level OL,
34                                        bool is64bit)
35   : LLVMTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL),
36     TLOF(make_unique<SparcELFTargetObjectFile>()),
37     Subtarget(TT, CPU, FS, *this, is64bit) {
38   initAsmInfo();
39 }
40
41 namespace {
42 /// Sparc Code Generator Pass Configuration Options.
43 class SparcPassConfig : public TargetPassConfig {
44 public:
45   SparcPassConfig(SparcTargetMachine *TM, PassManagerBase &PM)
46     : TargetPassConfig(TM, PM) {}
47
48   SparcTargetMachine &getSparcTargetMachine() const {
49     return getTM<SparcTargetMachine>();
50   }
51
52   void addIRPasses() override;
53   bool addInstSelector() override;
54   bool addPreEmitPass() override;
55 };
56 } // namespace
57
58 TargetPassConfig *SparcTargetMachine::createPassConfig(PassManagerBase &PM) {
59   return new SparcPassConfig(this, PM);
60 }
61
62 void SparcPassConfig::addIRPasses() {
63   addPass(createAtomicExpandPass(&getSparcTargetMachine()));
64
65   TargetPassConfig::addIRPasses();
66 }
67
68 bool SparcPassConfig::addInstSelector() {
69   addPass(createSparcISelDag(getSparcTargetMachine()));
70   return false;
71 }
72
73 /// addPreEmitPass - This pass may be implemented by targets that want to run
74 /// passes immediately before machine code is emitted.  This should return
75 /// true if -print-machineinstrs should print out the code after the passes.
76 bool SparcPassConfig::addPreEmitPass(){
77   addPass(createSparcDelaySlotFillerPass(getSparcTargetMachine()));
78   return true;
79 }
80
81 void SparcV8TargetMachine::anchor() { }
82
83 SparcV8TargetMachine::SparcV8TargetMachine(const Target &T,
84                                            StringRef TT, StringRef CPU,
85                                            StringRef FS,
86                                            const TargetOptions &Options,
87                                            Reloc::Model RM,
88                                            CodeModel::Model CM,
89                                            CodeGenOpt::Level OL)
90   : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, false) {
91 }
92
93 void SparcV9TargetMachine::anchor() { }
94
95 SparcV9TargetMachine::SparcV9TargetMachine(const Target &T,
96                                            StringRef TT,  StringRef CPU,
97                                            StringRef FS,
98                                            const TargetOptions &Options,
99                                            Reloc::Model RM,
100                                            CodeModel::Model CM,
101                                            CodeGenOpt::Level OL)
102   : SparcTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, true) {
103 }