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