PTX: Customize codegen passes in backend
[oota-llvm.git] / lib / Target / PTX / PTXTargetMachine.h
1 //===-- PTXTargetMachine.h - Define TargetMachine for PTX -------*- C++ -*-===//
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 // This file declares the PTX specific subclass of TargetMachine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef PTX_TARGET_MACHINE_H
15 #define PTX_TARGET_MACHINE_H
16
17 #include "PTXISelLowering.h"
18 #include "PTXInstrInfo.h"
19 #include "PTXFrameLowering.h"
20 #include "PTXSubtarget.h"
21 #include "llvm/Target/TargetData.h"
22 #include "llvm/Target/TargetFrameLowering.h"
23 #include "llvm/Target/TargetMachine.h"
24
25 namespace llvm {
26 class PTXTargetMachine : public LLVMTargetMachine {
27   private:
28     const TargetData  DataLayout;
29     PTXSubtarget      Subtarget; // has to be initialized before FrameLowering
30     PTXFrameLowering  FrameLowering;
31     PTXInstrInfo      InstrInfo;
32     PTXTargetLowering TLInfo;
33
34   public:
35     PTXTargetMachine(const Target &T, StringRef TT,
36                      StringRef CPU, StringRef FS,
37                      Reloc::Model RM, CodeModel::Model CM,
38                      bool is64Bit);
39
40     virtual const TargetData *getTargetData() const { return &DataLayout; }
41
42     virtual const TargetFrameLowering *getFrameLowering() const {
43       return &FrameLowering;
44     }
45
46     virtual const PTXInstrInfo *getInstrInfo() const { return &InstrInfo; }
47     virtual const TargetRegisterInfo *getRegisterInfo() const {
48       return &InstrInfo.getRegisterInfo(); }
49
50     virtual const PTXTargetLowering *getTargetLowering() const {
51       return &TLInfo; }
52
53     virtual const PTXSubtarget *getSubtargetImpl() const { return &Subtarget; }
54
55     virtual bool addInstSelector(PassManagerBase &PM,
56                                  CodeGenOpt::Level OptLevel);
57     virtual bool addPostRegAlloc(PassManagerBase &PM,
58                                  CodeGenOpt::Level OptLevel);
59
60     // We override this method to supply our own set of codegen passes.
61     virtual bool addPassesToEmitFile(PassManagerBase &,
62                                      formatted_raw_ostream &,
63                                      CodeGenFileType,
64                                      CodeGenOpt::Level,
65                                      bool = true);
66
67     // Emission of machine code through JITCodeEmitter is not supported.
68     virtual bool addPassesToEmitMachineCode(PassManagerBase &,
69                                             JITCodeEmitter &,
70                                             CodeGenOpt::Level,
71                                             bool = true) {
72       return true;
73     }
74
75     // Emission of machine code through MCJIT is not supported.
76     virtual bool addPassesToEmitMC(PassManagerBase &,
77                                    MCContext *&,
78                                    raw_ostream &,
79                                    CodeGenOpt::Level,
80                                    bool = true) {
81       return true;
82     }
83
84   private:
85
86     bool addCommonCodeGenPasses(PassManagerBase &, CodeGenOpt::Level,
87                                 bool DisableVerify, MCContext *&OutCtx);
88 }; // class PTXTargetMachine
89
90
91 class PTX32TargetMachine : public PTXTargetMachine {
92 public:
93
94   PTX32TargetMachine(const Target &T, StringRef TT,
95                      StringRef CPU, StringRef FS,
96                      Reloc::Model RM, CodeModel::Model CM);
97 }; // class PTX32TargetMachine
98
99 class PTX64TargetMachine : public PTXTargetMachine {
100 public:
101
102   PTX64TargetMachine(const Target &T, StringRef TT,
103                      StringRef CPU, StringRef FS,
104                      Reloc::Model RM, CodeModel::Model CM);
105 }; // class PTX32TargetMachine
106
107 } // namespace llvm
108
109 #endif // PTX_TARGET_MACHINE_H