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