Provide TargetMachine implementations with reference to Target they were created
[oota-llvm.git] / lib / Target / X86 / X86TargetMachine.h
1 //===-- X86TargetMachine.h - Define TargetMachine for the X86 ---*- 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 X86 specific subclass of TargetMachine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef X86TARGETMACHINE_H
15 #define X86TARGETMACHINE_H
16
17 #include "llvm/Target/TargetMachine.h"
18 #include "llvm/Target/TargetData.h"
19 #include "llvm/Target/TargetFrameInfo.h"
20 #include "X86.h"
21 #include "X86ELFWriterInfo.h"
22 #include "X86InstrInfo.h"
23 #include "X86JITInfo.h"
24 #include "X86Subtarget.h"
25 #include "X86ISelLowering.h"
26
27 namespace llvm {
28   
29 class formatted_raw_ostream;
30
31 class X86TargetMachine : public LLVMTargetMachine {
32   X86Subtarget      Subtarget;
33   const TargetData  DataLayout; // Calculates type size & alignment
34   TargetFrameInfo   FrameInfo;
35   X86InstrInfo      InstrInfo;
36   X86JITInfo        JITInfo;
37   X86TargetLowering TLInfo;
38   X86ELFWriterInfo  ELFWriterInfo;
39   Reloc::Model      DefRelocModel; // Reloc model before it's overridden.
40
41 protected:
42   virtual const TargetAsmInfo *createTargetAsmInfo() const;
43
44   // To avoid having target depend on the asmprinter stuff libraries, asmprinter
45   // set this functions to ctor pointer at startup time if they are linked in.
46   typedef FunctionPass *(*AsmPrinterCtorFn)(formatted_raw_ostream &o,
47                                             TargetMachine &tm,
48                                             bool verbose);
49   static AsmPrinterCtorFn AsmPrinterCtor;
50
51 public:
52   X86TargetMachine(const Target &T, const Module &M, const std::string &FS, 
53                    bool is64Bit);
54
55   virtual const X86InstrInfo     *getInstrInfo() const { return &InstrInfo; }
56   virtual const TargetFrameInfo  *getFrameInfo() const { return &FrameInfo; }
57   virtual       X86JITInfo       *getJITInfo()         { return &JITInfo; }
58   virtual const X86Subtarget     *getSubtargetImpl() const{ return &Subtarget; }
59   virtual       X86TargetLowering *getTargetLowering() const { 
60     return const_cast<X86TargetLowering*>(&TLInfo); 
61   }
62   virtual const X86RegisterInfo  *getRegisterInfo() const {
63     return &InstrInfo.getRegisterInfo();
64   }
65   virtual const TargetData       *getTargetData() const { return &DataLayout; }
66   virtual const X86ELFWriterInfo *getELFWriterInfo() const {
67     return Subtarget.isTargetELF() ? &ELFWriterInfo : 0;
68   }
69
70   static unsigned getModuleMatchQuality(const Module &M);
71   static unsigned getJITMatchQuality();
72
73   static void registerAsmPrinter(AsmPrinterCtorFn F) {
74     AsmPrinterCtor = F;
75   }
76
77   // Set up the pass pipeline.
78   virtual bool addInstSelector(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
79   virtual bool addPreRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
80   virtual bool addPostRegAlloc(PassManagerBase &PM, CodeGenOpt::Level OptLevel);
81   virtual bool addAssemblyEmitter(PassManagerBase &PM,
82                                   CodeGenOpt::Level OptLevel, 
83                                   bool Verbose, formatted_raw_ostream &Out);
84   virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel,
85                               bool DumpAsm, MachineCodeEmitter &MCE);
86   virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel,
87                               bool DumpAsm, JITCodeEmitter &JCE);
88   virtual bool addCodeEmitter(PassManagerBase &PM, CodeGenOpt::Level OptLevel,
89                               bool DumpAsm, ObjectCodeEmitter &OCE);
90   virtual bool addSimpleCodeEmitter(PassManagerBase &PM,
91                                     CodeGenOpt::Level OptLevel,
92                                     bool DumpAsm, MachineCodeEmitter &MCE);
93   virtual bool addSimpleCodeEmitter(PassManagerBase &PM,
94                                     CodeGenOpt::Level OptLevel,
95                                     bool DumpAsm, JITCodeEmitter &JCE);
96   virtual bool addSimpleCodeEmitter(PassManagerBase &PM,
97                                     CodeGenOpt::Level OptLevel,
98                                     bool DumpAsm, ObjectCodeEmitter &OCE);
99 };
100
101 /// X86_32TargetMachine - X86 32-bit target machine.
102 ///
103 class X86_32TargetMachine : public X86TargetMachine {
104 public:
105   X86_32TargetMachine(const Target &T, const Module &M, const std::string &FS);
106   
107   static unsigned getJITMatchQuality();
108   static unsigned getModuleMatchQuality(const Module &M);
109 };
110
111 /// X86_64TargetMachine - X86 64-bit target machine.
112 ///
113 class X86_64TargetMachine : public X86TargetMachine {
114 public:
115   X86_64TargetMachine(const Target &T, const Module &M, const std::string &FS);
116   
117   static unsigned getJITMatchQuality();
118   static unsigned getModuleMatchQuality(const Module &M);
119 };
120
121 } // End llvm namespace
122
123 #endif