Add the Object Code Emitter class. Original patch by Aaron Gray, I did some
[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 "Thumb1InstrInfo.h"
26 #include "Thumb2InstrInfo.h"
27
28 namespace llvm {
29
30 class Module;
31
32 class ARMBaseTargetMachine : public LLVMTargetMachine {
33 protected:
34   ARMSubtarget        Subtarget;
35
36 private:
37   ARMFrameInfo        FrameInfo;
38   ARMJITInfo          JITInfo;
39   InstrItineraryData  InstrItins;
40   Reloc::Model        DefRelocModel;    // Reloc model before it's overridden.
41
42 protected:
43   // To avoid having target depend on the asmprinter stuff libraries, asmprinter
44   // set this functions to ctor pointer at startup time if they are linked in.
45   typedef FunctionPass *(*AsmPrinterCtorFn)(raw_ostream &o,
46                                             ARMBaseTargetMachine &tm,
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 addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel,
81                               bool DumpAsm, ObjectCodeEmitter &OCE);
82   virtual bool addSimpleCodeEmitter(PassManagerBase &PM,
83                                     CodeGenOpt::Level OptLevel,
84                                     bool DumpAsm,
85                                     MachineCodeEmitter &MCE);
86   virtual bool addSimpleCodeEmitter(PassManagerBase &PM,
87                                     CodeGenOpt::Level OptLevel,
88                                     bool DumpAsm,
89                                     JITCodeEmitter &MCE);
90   virtual bool addSimpleCodeEmitter(PassManagerBase &PM,
91                                     CodeGenOpt::Level OptLevel,
92                                     bool DumpAsm,
93                                     ObjectCodeEmitter &OCE);
94 };
95
96 /// ARMTargetMachine - ARM target machine.
97 ///
98 class ARMTargetMachine : public ARMBaseTargetMachine {
99   ARMInstrInfo        InstrInfo;
100   const TargetData    DataLayout;       // Calculates type size & alignment
101   ARMTargetLowering   TLInfo;
102 public:
103   ARMTargetMachine(const Module &M, const std::string &FS);
104
105   virtual const ARMRegisterInfo  *getRegisterInfo() const {
106     return &InstrInfo.getRegisterInfo();
107   }
108
109   virtual       ARMTargetLowering *getTargetLowering() const {
110     return const_cast<ARMTargetLowering*>(&TLInfo);
111   }
112
113   virtual const ARMInstrInfo     *getInstrInfo() const { return &InstrInfo; }
114   virtual const TargetData       *getTargetData() const { return &DataLayout; }
115
116   static unsigned getJITMatchQuality();
117   static unsigned getModuleMatchQuality(const Module &M);
118 };
119
120 /// ThumbTargetMachine - Thumb target machine.
121 /// Due to the way architectures are handled, this represents both
122 ///   Thumb-1 and Thumb-2.
123 ///
124 class ThumbTargetMachine : public ARMBaseTargetMachine {
125   ARMBaseInstrInfo    *InstrInfo;   // either Thumb1InstrInfo or Thumb2InstrInfo
126   const TargetData    DataLayout;   // Calculates type size & alignment
127   ARMTargetLowering   TLInfo;
128 public:
129   ThumbTargetMachine(const Module &M, const std::string &FS);
130
131   /// returns either Thumb1RegisterInfo of Thumb2RegisterInfo
132   virtual const ARMBaseRegisterInfo *getRegisterInfo() const {
133     return &InstrInfo->getRegisterInfo();
134   }
135
136   virtual ARMTargetLowering *getTargetLowering() const {
137     return const_cast<ARMTargetLowering*>(&TLInfo);
138   }
139
140   /// returns either Thumb1InstrInfo or Thumb2InstrInfo
141   virtual const ARMBaseInstrInfo *getInstrInfo() const { return InstrInfo; }
142   virtual const TargetData       *getTargetData() const { return &DataLayout; }
143
144   static unsigned getJITMatchQuality();
145   static unsigned getModuleMatchQuality(const Module &M);
146 };
147
148 } // end namespace llvm
149
150 #endif