Improve support for type-generic vector intrinsics by teaching TableGen how
[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 is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the TargetMachine and LLVMTargetMachine classes.
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
20 namespace llvm {
21
22 class TargetAsmInfo;
23 class TargetData;
24 class TargetSubtarget;
25 class TargetInstrInfo;
26 class TargetJITInfo;
27 class TargetLowering;
28 class TargetFrameInfo;
29 class MachineCodeEmitter;
30 class TargetRegisterInfo;
31 class Module;
32 class PassManagerBase;
33 class PassManager;
34 class Pass;
35 class TargetMachOWriterInfo;
36 class TargetELFWriterInfo;
37 class raw_ostream;
38
39 // Relocation model types.
40 namespace Reloc {
41   enum Model {
42     Default,
43     Static,
44     PIC_,         // Cannot be named PIC due to collision with -DPIC
45     DynamicNoPIC
46   };
47 }
48
49 // Code model types.
50 namespace CodeModel {
51   enum Model {
52     Default,
53     Small,
54     Kernel,
55     Medium,
56     Large
57   };
58 }
59
60 namespace FileModel {
61   enum Model {
62     Error,
63     None,
64     AsmFile,
65     MachOFile,
66     ElfFile
67   };
68 }
69
70 //===----------------------------------------------------------------------===//
71 ///
72 /// TargetMachine - Primary interface to the complete machine description for
73 /// the target machine.  All target-specific information should be accessible
74 /// through this interface.
75 ///
76 class TargetMachine {
77   TargetMachine(const TargetMachine &);   // DO NOT IMPLEMENT
78   void operator=(const TargetMachine &);  // DO NOT IMPLEMENT
79 protected: // Can only create subclasses.
80   TargetMachine() : AsmInfo(0) { }
81
82   /// getSubtargetImpl - virtual method implemented by subclasses that returns
83   /// a reference to that target's TargetSubtarget-derived member variable.
84   virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
85   
86   /// AsmInfo - Contains target specific asm information.
87   ///
88   mutable const TargetAsmInfo *AsmInfo;
89   
90   /// createTargetAsmInfo - Create a new instance of target specific asm
91   /// information.
92   virtual const TargetAsmInfo *createTargetAsmInfo() const { return 0; }
93
94 public:
95   virtual ~TargetMachine();
96
97   /// getModuleMatchQuality - This static method should be implemented by
98   /// targets to indicate how closely they match the specified module.  This is
99   /// used by the LLC tool to determine which target to use when an explicit
100   /// -march option is not specified.  If a target returns zero, it will never
101   /// be chosen without an explicit -march option.
102   static unsigned getModuleMatchQuality(const Module &) { return 0; }
103
104   /// getJITMatchQuality - This static method should be implemented by targets
105   /// that provide JIT capabilities to indicate how suitable they are for
106   /// execution on the current host.  If a value of 0 is returned, the target
107   /// will not be used unless an explicit -march option is used.
108   static unsigned getJITMatchQuality() { return 0; }
109
110   // Interfaces to the major aspects of target machine information:
111   // -- Instruction opcode and operand information
112   // -- Pipelines and scheduling information
113   // -- Stack frame information
114   // -- Selection DAG lowering information
115   //
116   virtual const TargetInstrInfo        *getInstrInfo() const { return 0; }
117   virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
118   virtual       TargetLowering    *getTargetLowering() const { return 0; }
119   virtual const TargetData            *getTargetData() const { return 0; }
120   
121   
122   /// getTargetAsmInfo - Return target specific asm information.
123   ///
124   const TargetAsmInfo *getTargetAsmInfo() const {
125     if (!AsmInfo) AsmInfo = createTargetAsmInfo();
126     return AsmInfo;
127   }
128   
129   /// getSubtarget - This method returns a pointer to the specified type of
130   /// TargetSubtarget.  In debug builds, it verifies that the object being
131   /// returned is of the correct type.
132   template<typename STC> const STC &getSubtarget() const {
133     const TargetSubtarget *TST = getSubtargetImpl();
134     assert(TST && dynamic_cast<const STC*>(TST) &&
135            "Not the right kind of subtarget!");
136     return *static_cast<const STC*>(TST);
137   }
138
139   /// getRegisterInfo - If register information is available, return it.  If
140   /// not, return null.  This is kept separate from RegInfo until RegInfo has
141   /// details of graph coloring register allocation removed from it.
142   ///
143   virtual const TargetRegisterInfo *getRegisterInfo() const { return 0; }
144
145   /// getJITInfo - If this target supports a JIT, return information for it,
146   /// otherwise return null.
147   ///
148   virtual TargetJITInfo *getJITInfo() { return 0; }
149   
150   /// getInstrItineraryData - Returns instruction itinerary data for the target
151   /// or specific subtarget.
152   ///
153   virtual const InstrItineraryData getInstrItineraryData() const {  
154     return InstrItineraryData();
155   }
156
157   /// getMachOWriterInfo - If this target supports a Mach-O writer, return
158   /// information for it, otherwise return null.
159   /// 
160   virtual const TargetMachOWriterInfo *getMachOWriterInfo() const { return 0; }
161
162   /// getELFWriterInfo - If this target supports an ELF writer, return
163   /// information for it, otherwise return null.
164   /// 
165   virtual const TargetELFWriterInfo *getELFWriterInfo() const { return 0; }
166
167   /// getRelocationModel - Returns the code generation relocation model. The
168   /// choices are static, PIC, and dynamic-no-pic, and target default.
169   static Reloc::Model getRelocationModel();
170
171   /// setRelocationModel - Sets the code generation relocation model.
172   static void setRelocationModel(Reloc::Model Model);
173
174   /// getCodeModel - Returns the code model. The choices are small, kernel,
175   /// medium, large, and target default.
176   static CodeModel::Model getCodeModel();
177
178   /// setCodeModel - Sets the code model.
179   static void setCodeModel(CodeModel::Model Model);
180
181   /// CodeGenFileType - These enums are meant to be passed into
182   /// addPassesToEmitFile to indicate what type of file to emit.
183   enum CodeGenFileType {
184     AssemblyFile, ObjectFile, DynamicLibrary
185   };
186
187   /// getEnableTailMergeDefault - the default setting for -enable-tail-merge
188   /// on this target.  User flag overrides.
189   virtual bool getEnableTailMergeDefault() const { return true; }
190
191   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
192   /// specified file emitted.  Typically this will involve several steps of code
193   /// generation.  If Fast is set to true, the code generator should emit code
194   /// as fast as possible, though the generated code may be less efficient.
195   /// This method should return FileModel::Error if emission of this file type
196   /// is not supported.
197   ///
198   virtual FileModel::Model addPassesToEmitFile(PassManagerBase &,
199                                                raw_ostream &,
200                                                CodeGenFileType,
201                                                bool /*Fast*/) {
202     return FileModel::None;
203   }
204
205   /// addPassesToEmitFileFinish - If the passes to emit the specified file had
206   /// to be split up (e.g., to add an object writer pass), this method can be
207   /// used to finish up adding passes to emit the file, if necessary.
208   ///
209   virtual bool addPassesToEmitFileFinish(PassManagerBase &,
210                                          MachineCodeEmitter *, bool /*Fast*/) {
211     return true;
212   }
213  
214   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
215   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
216   /// actually outputting the machine code and resolving things like the address
217   /// of functions.  This method returns true if machine code emission is
218   /// not supported.
219   ///
220   virtual bool addPassesToEmitMachineCode(PassManagerBase &,
221                                           MachineCodeEmitter &,
222                                           bool /*Fast*/) {
223     return true;
224   }
225
226   /// addPassesToEmitWholeFile - This method can be implemented by targets that 
227   /// require having the entire module at once.  This is not recommended, do not
228   /// use this.
229   virtual bool WantsWholeFile() const { return false; }
230   virtual bool addPassesToEmitWholeFile(PassManager &, raw_ostream &,
231                                         CodeGenFileType, bool /*Fast*/) {
232     return true;
233   }
234 };
235
236 /// LLVMTargetMachine - This class describes a target machine that is
237 /// implemented with the LLVM target-independent code generator.
238 ///
239 class LLVMTargetMachine : public TargetMachine {
240 protected: // Can only create subclasses.
241   LLVMTargetMachine() { }
242
243   /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
244   /// both emitting to assembly files or machine code output.
245   ///
246   bool addCommonCodeGenPasses(PassManagerBase &, bool /*Fast*/);
247
248 public:
249   
250   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
251   /// specified file emitted.  Typically this will involve several steps of code
252   /// generation.  If Fast is set to true, the code generator should emit code
253   /// as fast as possible, though the generated code may be less efficient.
254   /// This method should return FileModel::Error if emission of this file type
255   /// is not supported.
256   ///
257   /// The default implementation of this method adds components from the
258   /// LLVM retargetable code generator, invoking the methods below to get
259   /// target-specific passes in standard locations.
260   ///
261   virtual FileModel::Model addPassesToEmitFile(PassManagerBase &PM,
262                                                raw_ostream &Out,
263                                                CodeGenFileType FileType,
264                                                bool Fast);
265   
266   /// addPassesToEmitFileFinish - If the passes to emit the specified file had
267   /// to be split up (e.g., to add an object writer pass), this method can be
268   /// used to finish up adding passes to emit the file, if necessary.
269   ///
270   virtual bool addPassesToEmitFileFinish(PassManagerBase &PM,
271                                          MachineCodeEmitter *MCE, bool Fast);
272  
273   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
274   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
275   /// actually outputting the machine code and resolving things like the address
276   /// of functions.  This method returns true if machine code emission is
277   /// not supported.
278   ///
279   virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
280                                           MachineCodeEmitter &MCE, bool Fast);
281   
282   /// Target-Independent Code Generator Pass Configuration Options.
283   
284   /// addInstSelector - This method should add any "last minute" LLVM->LLVM
285   /// passes, then install an instruction selector pass, which converts from
286   /// LLVM code to machine instructions.
287   virtual bool addInstSelector(PassManagerBase &, bool /*Fast*/) {
288     return true;
289   }
290
291   /// addPreRegAllocPasses - This method may be implemented by targets that want
292   /// to run passes immediately before register allocation. This should return
293   /// true if -print-machineinstrs should print after these passes.
294   virtual bool addPreRegAlloc(PassManagerBase &, bool /*Fast*/) {
295     return false;
296   }
297
298   /// addPostRegAllocPasses - This method may be implemented by targets that
299   /// want to run passes after register allocation but before prolog-epilog
300   /// insertion.  This should return true if -print-machineinstrs should print
301   /// after these passes.
302   virtual bool addPostRegAlloc(PassManagerBase &, bool /*Fast*/) {
303     return false;
304   }
305   
306   /// addPreEmitPass - This pass may be implemented by targets that want to run
307   /// passes immediately before machine code is emitted.  This should return
308   /// true if -print-machineinstrs should print out the code after the passes.
309   virtual bool addPreEmitPass(PassManagerBase &, bool /*Fast*/) {
310     return false;
311   }
312   
313   
314   /// addAssemblyEmitter - This pass should be overridden by the target to add
315   /// the asmprinter, if asm emission is supported.  If this is not supported,
316   /// 'true' should be returned.
317   virtual bool addAssemblyEmitter(PassManagerBase &, bool /*Fast*/, 
318                                   raw_ostream &) {
319     return true;
320   }
321   
322   /// addCodeEmitter - This pass should be overridden by the target to add a
323   /// code emitter, if supported.  If this is not supported, 'true' should be
324   /// returned. If DumpAsm is true, the generated assembly is printed to cerr.
325   virtual bool addCodeEmitter(PassManagerBase &, bool /*Fast*/,
326                               bool /*DumpAsm*/, MachineCodeEmitter &) {
327     return true;
328   }
329
330   /// addSimpleCodeEmitter - This pass should be overridden by the target to add
331   /// a code emitter (without setting flags), if supported.  If this is not
332   /// supported, 'true' should be returned.  If DumpAsm is true, the generated
333   /// assembly is printed to cerr.
334   virtual bool addSimpleCodeEmitter(PassManagerBase &, bool /*Fast*/,
335                                     bool /*DumpAsm*/, MachineCodeEmitter &) {
336     return true;
337   }
338
339   /// getEnableTailMergeDefault - the default setting for -enable-tail-merge
340   /// on this target.  User flag overrides.
341   virtual bool getEnableTailMergeDefault() const { return true; }
342 };
343
344 } // End llvm namespace
345
346 #endif