Split thumb-related stuff into separate classes.
[oota-llvm.git] / lib / Target / ARM / ARMTargetMachine.h
1 //===-- ARMTargetMachine.h - Define TargetMachine for ARM -------*- 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 ARM specific subclass of TargetMachine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef ARMTARGETMACHINE_H
15 #define ARMTARGETMACHINE_H
16
17 #include "llvm/Target/TargetMachine.h"
18 #include "llvm/Target/TargetData.h"
19 #include "llvm/Target/TargetFrameInfo.h"
20 #include "ARMInstrInfo.h"
21 #include "ARMFrameInfo.h"
22 #include "ARMJITInfo.h"
23 #include "ARMSubtarget.h"
24 #include "ARMISelLowering.h"
25 #include "ThumbInstrInfo.h"
26
27 namespace llvm {
28
29 class Module;
30
31 class ARMBaseTargetMachine : public LLVMTargetMachine {
32 protected:
33   ARMSubtarget        Subtarget;
34
35 private:
36   ARMFrameInfo        FrameInfo;
37   ARMJITInfo          JITInfo;
38   InstrItineraryData  InstrItins;
39   Reloc::Model        DefRelocModel;    // Reloc model before it's overridden.
40
41 protected:
42   // To avoid having target depend on the asmprinter stuff libraries, asmprinter
43   // set this functions to ctor pointer at startup time if they are linked in.
44   typedef FunctionPass *(*AsmPrinterCtorFn)(raw_ostream &o,
45                                             ARMBaseTargetMachine &tm,
46                                             CodeGenOpt::Level OptLevel,
47                                             bool verbose);
48   static AsmPrinterCtorFn AsmPrinterCtor;
49
50 public:
51   ARMBaseTargetMachine(const Module &M, const std::string &FS, bool isThumb);
52
53   virtual const ARMFrameInfo     *getFrameInfo() const { return &FrameInfo; }
54   virtual       ARMJITInfo       *getJITInfo()         { return &JITInfo; }
55   virtual const ARMSubtarget  *getSubtargetImpl() const { return &Subtarget; }
56   virtual const InstrItineraryData getInstrItineraryData() const {
57     return InstrItins;
58   }
59
60   static void registerAsmPrinter(AsmPrinterCtorFn F) {
61     AsmPrinterCtor = F;
62   }
63
64   static unsigned getModuleMatchQuality(const Module &M);
65   static unsigned getJITMatchQuality();
66
67   virtual const TargetAsmInfo *createTargetAsmInfo() const;
68
69   // Pass Pipeline Configuration
70   virtual bool addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
71   virtual bool addPreRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
72   virtual bool addPreEmitPass(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
73   virtual bool addAssemblyEmitter(PassManagerBase &PM,
74                                   CodeGenOpt::Level OptLevel,
75                                   bool Verbose, raw_ostream &Out);
76   virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel,
77                               bool DumpAsm, MachineCodeEmitter &MCE);
78   virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel,
79                               bool DumpAsm, JITCodeEmitter &MCE);
80   virtual bool addSimpleCodeEmitter(PassManagerBase &PM,
81                                     CodeGenOpt::Level OptLevel,
82                                     bool DumpAsm,
83                                     MachineCodeEmitter &MCE);
84   virtual bool addSimpleCodeEmitter(PassManagerBase &PM,
85                                     CodeGenOpt::Level OptLevel,
86                                     bool DumpAsm,
87                                     JITCodeEmitter &MCE);
88 };
89
90 /// ARMTargetMachine - ARM target machine.
91 ///
92 class ARMTargetMachine : public ARMBaseTargetMachine {
93   ARMInstrInfo        InstrInfo;
94   const TargetData    DataLayout;       // Calculates type size & alignment
95   ARMTargetLowering   TLInfo;
96 public:
97   ARMTargetMachine(const Module &M, const std::string &FS);
98
99   virtual const ARMRegisterInfo  *getRegisterInfo() const {
100     return &InstrInfo.getRegisterInfo();
101   }
102
103   virtual       ARMTargetLowering *getTargetLowering() const {
104     return const_cast<ARMTargetLowering*>(&TLInfo);
105   }
106
107   virtual const ARMInstrInfo     *getInstrInfo() const { return &InstrInfo; }
108   virtual const TargetData       *getTargetData() const { return &DataLayout; }
109
110   static unsigned getJITMatchQuality();
111   static unsigned getModuleMatchQuality(const Module &M);
112 };
113
114 /// ThumbTargetMachine - Thumb target machine.
115 ///
116 class ThumbTargetMachine : public ARMBaseTargetMachine {
117   ThumbInstrInfo      InstrInfo;
118   const TargetData    DataLayout;       // Calculates type size & alignment
119   ARMTargetLowering   TLInfo;
120 public:
121   ThumbTargetMachine(const Module &M, const std::string &FS);
122
123   virtual const ARMRegisterInfo  *getRegisterInfo() const {
124     return &InstrInfo.getRegisterInfo();
125   }
126
127   virtual       ARMTargetLowering *getTargetLowering() const {
128     return const_cast<ARMTargetLowering*>(&TLInfo);
129   }
130
131   virtual const ThumbInstrInfo   *getInstrInfo() const { return &InstrInfo; }
132   virtual const TargetData       *getTargetData() const { return &DataLayout; }
133
134   static unsigned getJITMatchQuality();
135   static unsigned getModuleMatchQuality(const Module &M);
136 };
137
138 } // end namespace llvm
139
140 #endif