Eliminate target name.
[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_,         // Cannot be named PIC due to collision with -DPIC
43     DynamicNoPIC
44   };
45 }
46
47 // Code model types.
48 namespace CodeModel {
49   enum Model {
50     Default,
51     Small,
52     Kernel,
53     Medium,
54     Large
55   };
56 }
57
58 //===----------------------------------------------------------------------===//
59 ///
60 /// TargetMachine - Primary interface to the complete machine description for
61 /// the target machine.  All target-specific information should be accessible
62 /// through this interface.
63 ///
64 class TargetMachine {
65   TargetMachine(const TargetMachine&);   // DO NOT IMPLEMENT
66   void operator=(const TargetMachine&);  // DO NOT IMPLEMENT
67 protected: // Can only create subclasses.
68   TargetMachine() { }
69
70   /// getSubtargetImpl - virtual method implemented by subclasses that returns
71   /// a reference to that target's TargetSubtarget-derived member variable.
72   virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
73 public:
74   virtual ~TargetMachine();
75
76   /// getModuleMatchQuality - This static method should be implemented by
77   /// targets to indicate how closely they match the specified module.  This is
78   /// used by the LLC tool to determine which target to use when an explicit
79   /// -march option is not specified.  If a target returns zero, it will never
80   /// be chosen without an explicit -march option.
81   static unsigned getModuleMatchQuality(const Module &M) { return 0; }
82
83   /// getJITMatchQuality - This static method should be implemented by targets
84   /// that provide JIT capabilities to indicate how suitable they are for
85   /// execution on the current host.  If a value of 0 is returned, the target
86   /// will not be used unless an explicit -march option is used.
87   static unsigned getJITMatchQuality() { return 0; }
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   /// getCodeModel - Returns the code model. The choices are small, kernel,
136   /// medium, large, and target default.
137   static CodeModel::Model getCodeModel();
138
139   /// setCodeModel - Sets the code model.
140   static void setCodeModel(CodeModel::Model Model);
141
142   /// CodeGenFileType - These enums are meant to be passed into
143   /// addPassesToEmitFile to indicate what type of file to emit.
144   enum CodeGenFileType {
145     AssemblyFile, ObjectFile, DynamicLibrary
146   };
147
148   /// addPassesToEmitFile - Add passes to the specified pass manager to get
149   /// the specified file emitted.  Typically this will involve several steps of
150   /// code generation.  If Fast is set to true, the code generator should emit
151   /// code as fast as possible, without regard for compile time.  This method
152   /// should return true if emission of this file type is not supported.
153   ///
154   virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
155                                    CodeGenFileType FileType, bool Fast) {
156     return true;
157   }
158
159   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
160   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
161   /// actually outputting the machine code and resolving things like the address
162   /// of functions.  This method should returns true if machine code emission is
163   /// not supported.
164   ///
165   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
166                                           MachineCodeEmitter &MCE) {
167     return true;
168   }
169 };
170
171 } // End llvm namespace
172
173 #endif