Refactor a bunch of includes so that TargetMachine.h doesn't have to include
[oota-llvm.git] / include / llvm / Target / TargetMachine.h
1 //===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the general parts of a Target machine.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGETMACHINE_H
15 #define LLVM_TARGET_TARGETMACHINE_H
16
17 #include "llvm/Target/TargetInstrItineraries.h"
18 #include <cassert>
19 #include <string>
20
21 namespace llvm {
22
23 class TargetData;
24 class TargetSubtarget;
25 class TargetInstrInfo;
26 class TargetInstrDescriptor;
27 class TargetJITInfo;
28 class TargetLowering;
29 class TargetFrameInfo;
30 class MachineCodeEmitter;
31 class MRegisterInfo;
32 class Module;
33 class FunctionPassManager;
34 class PassManager;
35 class Pass;
36
37 // Relocation model types.
38 namespace Reloc {
39   enum Model {
40     Default,
41     Static,
42     PIC,
43     DynamicNoPIC
44   };
45 }
46
47 //===----------------------------------------------------------------------===//
48 ///
49 /// TargetMachine - Primary interface to the complete machine description for
50 /// the target machine.  All target-specific information should be accessible
51 /// through this interface.
52 ///
53 class TargetMachine {
54   const std::string Name;
55
56   TargetMachine(const TargetMachine&);   // DO NOT IMPLEMENT
57   void operator=(const TargetMachine&);  // DO NOT IMPLEMENT
58 protected: // Can only create subclasses...
59   TargetMachine(const std::string &name) : Name(name) { };
60
61   /// This constructor is used for targets that support arbitrary TargetData
62   /// layouts, like the C backend.  It initializes the TargetData to match that
63   /// of the specified module.
64   ///
65   TargetMachine(const std::string &name, const Module &M);
66
67   /// getSubtargetImpl - virtual method implemented by subclasses that returns
68   /// a reference to that target's TargetSubtarget-derived member variable.
69   virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
70 public:
71   virtual ~TargetMachine();
72
73   /// getModuleMatchQuality - This static method should be implemented by
74   /// targets to indicate how closely they match the specified module.  This is
75   /// used by the LLC tool to determine which target to use when an explicit
76   /// -march option is not specified.  If a target returns zero, it will never
77   /// be chosen without an explicit -march option.
78   static unsigned getModuleMatchQuality(const Module &M) { return 0; }
79
80   /// getJITMatchQuality - This static method should be implemented by targets
81   /// that provide JIT capabilities to indicate how suitable they are for
82   /// execution on the current host.  If a value of 0 is returned, the target
83   /// will not be used unless an explicit -march option is used.
84   static unsigned getJITMatchQuality() { return 0; }
85
86
87   const std::string &getName() const { return Name; }
88
89   // Interfaces to the major aspects of target machine information:
90   // -- Instruction opcode and operand information
91   // -- Pipelines and scheduling information
92   // -- Stack frame information
93   // -- Selection DAG lowering information
94   //
95   virtual const TargetInstrInfo        *getInstrInfo() const { return 0; }
96   virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
97   virtual       TargetLowering    *getTargetLowering() const { return 0; }
98   virtual const TargetData            *getTargetData() const { return 0; }
99
100   /// getSubtarget - This method returns a pointer to the specified type of
101   /// TargetSubtarget.  In debug builds, it verifies that the object being
102   /// returned is of the correct type.
103   template<typename STC> const STC &getSubtarget() const {
104     const TargetSubtarget *TST = getSubtargetImpl();
105     assert(TST && dynamic_cast<const STC*>(TST) &&
106            "Not the right kind of subtarget!");
107     return *static_cast<const STC*>(TST);
108   }
109
110   /// getRegisterInfo - If register information is available, return it.  If
111   /// not, return null.  This is kept separate from RegInfo until RegInfo has
112   /// details of graph coloring register allocation removed from it.
113   ///
114   virtual const MRegisterInfo*          getRegisterInfo() const { return 0; }
115
116   /// getJITInfo - If this target supports a JIT, return information for it,
117   /// otherwise return null.
118   ///
119   virtual TargetJITInfo *getJITInfo() { return 0; }
120   
121   /// getInstrItineraryData - Returns instruction itinerary data for the target
122   /// or specific subtarget.
123   ///
124   virtual const InstrItineraryData getInstrItineraryData() const {  
125     return InstrItineraryData();
126   }
127
128   /// getRelocationModel - Returns the code generation relocation model. The
129   /// choices are static, PIC, and dynamic-no-pic, and target default.
130   static Reloc::Model getRelocationModel();
131
132   /// setRelocationModel - Sets the code generation relocation model.
133   static void setRelocationModel(Reloc::Model Model);
134
135   /// CodeGenFileType - These enums are meant to be passed into
136   /// addPassesToEmitFile to indicate what type of file to emit.
137   enum CodeGenFileType {
138     AssemblyFile, ObjectFile, DynamicLibrary
139   };
140
141   /// addPassesToEmitFile - Add passes to the specified pass manager to get
142   /// the specified file emitted.  Typically this will involve several steps of
143   /// code generation.  If Fast is set to true, the code generator should emit
144   /// code as fast as possible, without regard for compile time.  This method
145   /// should return true if emission of this file type is not supported.
146   ///
147   virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
148                                    CodeGenFileType FileType, bool Fast) {
149     return true;
150   }
151
152   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
153   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
154   /// actually outputting the machine code and resolving things like the address
155   /// of functions.  This method should returns true if machine code emission is
156   /// not supported.
157   ///
158   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
159                                           MachineCodeEmitter &MCE) {
160     return true;
161   }
162 };
163
164 } // End llvm namespace
165
166 #endif