Code refactoring: pull SchedPreference enum from TargetLowering.h to TargetMachine...
[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 <string>
20
21 namespace llvm {
22
23 class Target;
24 class MCAsmInfo;
25 class TargetData;
26 class TargetSubtarget;
27 class TargetInstrInfo;
28 class TargetIntrinsicInfo;
29 class TargetJITInfo;
30 class TargetLowering;
31 class TargetSelectionDAGInfo;
32 class TargetFrameInfo;
33 class JITCodeEmitter;
34 class MCContext;
35 class TargetRegisterInfo;
36 class PassManagerBase;
37 class PassManager;
38 class Pass;
39 class TargetELFWriterInfo;
40 class formatted_raw_ostream;
41
42 // Relocation model types.
43 namespace Reloc {
44   enum Model {
45     Default,
46     Static,
47     PIC_,         // Cannot be named PIC due to collision with -DPIC
48     DynamicNoPIC
49   };
50 }
51
52 // Code model types.
53 namespace CodeModel {
54   enum Model {
55     Default,
56     Small,
57     Kernel,
58     Medium,
59     Large
60   };
61 }
62
63 // Code generation optimization level.
64 namespace CodeGenOpt {
65   enum Level {
66     None,        // -O0
67     Less,        // -O1
68     Default,     // -O2, -Os
69     Aggressive   // -O3
70   };
71 }
72
73 namespace Sched {
74   enum Preference {
75     Latency,          // Scheduling for shortest total latency.
76     RegPressure       // Scheduling for lowest register pressure.
77   };
78 }
79
80 //===----------------------------------------------------------------------===//
81 ///
82 /// TargetMachine - Primary interface to the complete machine description for
83 /// the target machine.  All target-specific information should be accessible
84 /// through this interface.
85 ///
86 class TargetMachine {
87   TargetMachine(const TargetMachine &);   // DO NOT IMPLEMENT
88   void operator=(const TargetMachine &);  // DO NOT IMPLEMENT
89 protected: // Can only create subclasses.
90   TargetMachine(const Target &);
91
92   /// getSubtargetImpl - virtual method implemented by subclasses that returns
93   /// a reference to that target's TargetSubtarget-derived member variable.
94   virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
95
96   /// TheTarget - The Target that this machine was created for.
97   const Target &TheTarget;
98   
99   /// AsmInfo - Contains target specific asm information.
100   ///
101   const MCAsmInfo *AsmInfo;
102   
103 public:
104   virtual ~TargetMachine();
105
106   const Target &getTarget() const { return TheTarget; }
107
108   // Interfaces to the major aspects of target machine information:
109   // -- Instruction opcode and operand information
110   // -- Pipelines and scheduling information
111   // -- Stack frame information
112   // -- Selection DAG lowering information
113   //
114   virtual const TargetInstrInfo        *getInstrInfo() const { return 0; }
115   virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
116   virtual const TargetLowering    *getTargetLowering() const { return 0; }
117   virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
118   virtual const TargetData            *getTargetData() const { return 0; }
119   
120   /// getMCAsmInfo - Return target specific asm information.
121   ///
122   const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
123   
124   /// getSubtarget - This method returns a pointer to the specified type of
125   /// TargetSubtarget.  In debug builds, it verifies that the object being
126   /// returned is of the correct type.
127   template<typename STC> const STC &getSubtarget() const {
128     return *static_cast<const STC*>(getSubtargetImpl());
129   }
130
131   /// getRegisterInfo - If register information is available, return it.  If
132   /// not, return null.  This is kept separate from RegInfo until RegInfo has
133   /// details of graph coloring register allocation removed from it.
134   ///
135   virtual const TargetRegisterInfo *getRegisterInfo() const { return 0; }
136   
137   /// getIntrinsicInfo - If intrinsic information is available, return it.  If
138   /// not, return null.
139   ///
140   virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { return 0; }
141
142   /// getJITInfo - If this target supports a JIT, return information for it,
143   /// otherwise return null.
144   ///
145   virtual TargetJITInfo *getJITInfo() { return 0; }
146   
147   /// getInstrItineraryData - Returns instruction itinerary data for the target
148   /// or specific subtarget.
149   ///
150   virtual const InstrItineraryData getInstrItineraryData() const {  
151     return InstrItineraryData();
152   }
153
154   /// getELFWriterInfo - If this target supports an ELF writer, return
155   /// information for it, otherwise return null.
156   /// 
157   virtual const TargetELFWriterInfo *getELFWriterInfo() const { return 0; }
158
159   /// getRelocationModel - Returns the code generation relocation model. The
160   /// choices are static, PIC, and dynamic-no-pic, and target default.
161   static Reloc::Model getRelocationModel();
162
163   /// setRelocationModel - Sets the code generation relocation model.
164   ///
165   static void setRelocationModel(Reloc::Model Model);
166
167   /// getCodeModel - Returns the code model. The choices are small, kernel,
168   /// medium, large, and target default.
169   static CodeModel::Model getCodeModel();
170
171   /// setCodeModel - Sets the code model.
172   ///
173   static void setCodeModel(CodeModel::Model Model);
174
175   /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
176   ///
177   static bool getAsmVerbosityDefault();
178
179   /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
180   /// is false.
181   static void setAsmVerbosityDefault(bool);
182
183   /// getDataSections - Return true if data objects should be emitted into their
184   /// own section, corresponds to -fdata-sections.
185   static bool getDataSections();
186
187   /// getFunctionSections - Return true if functions should be emitted into
188   /// their own section, corresponding to -ffunction-sections.
189   static bool getFunctionSections();
190
191   /// setDataSections - Set if the data are emit into separate sections.
192   static void setDataSections(bool);
193
194   /// setFunctionSections - Set if the functions are emit into separate
195   /// sections.
196   static void setFunctionSections(bool);
197
198   /// CodeGenFileType - These enums are meant to be passed into
199   /// addPassesToEmitFile to indicate what type of file to emit, and returned by
200   /// it to indicate what type of file could actually be made.
201   enum CodeGenFileType {
202     CGFT_AssemblyFile,
203     CGFT_ObjectFile,
204     CGFT_Null         // Do not emit any output.
205   };
206
207   /// getEnableTailMergeDefault - the default setting for -enable-tail-merge
208   /// on this target.  User flag overrides.
209   virtual bool getEnableTailMergeDefault() const { return true; }
210
211   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
212   /// specified file emitted.  Typically this will involve several steps of code
213   /// generation.  This method should return true if emission of this file type
214   /// is not supported, or false on success.
215   virtual bool addPassesToEmitFile(PassManagerBase &,
216                                    formatted_raw_ostream &,
217                                    CodeGenFileType,
218                                    CodeGenOpt::Level,
219                                    bool = true) {
220     return true;
221   }
222
223   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
224   /// get machine code emitted.  This uses a JITCodeEmitter object to handle
225   /// actually outputting the machine code and resolving things like the address
226   /// of functions.  This method returns true if machine code emission is
227   /// not supported.
228   ///
229   virtual bool addPassesToEmitMachineCode(PassManagerBase &,
230                                           JITCodeEmitter &,
231                                           CodeGenOpt::Level,
232                                           bool = true) {
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   std::string TargetTriple;
242
243 protected: // Can only create subclasses.
244   LLVMTargetMachine(const Target &T, const std::string &TargetTriple);
245   
246 private:
247   /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
248   /// both emitting to assembly files or machine code output.
249   ///
250   bool addCommonCodeGenPasses(PassManagerBase &, CodeGenOpt::Level,
251                               bool DisableVerify, MCContext *&OutCtx);
252
253   virtual void setCodeModelForJIT();
254   virtual void setCodeModelForStatic();
255   
256 public:
257   
258   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
259   /// specified file emitted.  Typically this will involve several steps of code
260   /// generation.  If OptLevel is None, the code generator should emit code as
261   /// fast as possible, though the generated code may be less efficient.
262   virtual bool addPassesToEmitFile(PassManagerBase &PM,
263                                    formatted_raw_ostream &Out,
264                                    CodeGenFileType FileType,
265                                    CodeGenOpt::Level,
266                                    bool DisableVerify = true);
267   
268   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
269   /// get machine code emitted.  This uses a JITCodeEmitter 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                                           JITCodeEmitter &MCE,
276                                           CodeGenOpt::Level,
277                                           bool DisableVerify = true);
278   
279   /// Target-Independent Code Generator Pass Configuration Options.
280   
281   /// addInstSelector - This method should add any "last minute" LLVM->LLVM
282   /// passes, then install an instruction selector pass, which converts from
283   /// LLVM code to machine instructions.
284   virtual bool addInstSelector(PassManagerBase &, CodeGenOpt::Level) {
285     return true;
286   }
287
288   /// addPreRegAlloc - This method may be implemented by targets that want to
289   /// run passes immediately before register allocation. This should return
290   /// true if -print-machineinstrs should print after these passes.
291   virtual bool addPreRegAlloc(PassManagerBase &, CodeGenOpt::Level) {
292     return false;
293   }
294
295   /// addPostRegAlloc - This method may be implemented by targets that want
296   /// to run passes after register allocation but before prolog-epilog
297   /// insertion.  This should return true if -print-machineinstrs should print
298   /// after these passes.
299   virtual bool addPostRegAlloc(PassManagerBase &, CodeGenOpt::Level) {
300     return false;
301   }
302
303   /// addPreSched2 - This method may be implemented by targets that want to
304   /// run passes after prolog-epilog insertion and before the second instruction
305   /// scheduling pass.  This should return true if -print-machineinstrs should
306   /// print after these passes.
307   virtual bool addPreSched2(PassManagerBase &, CodeGenOpt::Level) {
308     return false;
309   }
310   
311   /// addPreEmitPass - This pass may be implemented by targets that want to run
312   /// passes immediately before machine code is emitted.  This should return
313   /// true if -print-machineinstrs should print out the code after the passes.
314   virtual bool addPreEmitPass(PassManagerBase &, CodeGenOpt::Level) {
315     return false;
316   }
317   
318   
319   /// addCodeEmitter - This pass should be overridden by the target to add a
320   /// code emitter, if supported.  If this is not supported, 'true' should be
321   /// returned.
322   virtual bool addCodeEmitter(PassManagerBase &, CodeGenOpt::Level,
323                               JITCodeEmitter &) {
324     return true;
325   }
326
327   /// getEnableTailMergeDefault - the default setting for -enable-tail-merge
328   /// on this target.  User flag overrides.
329   virtual bool getEnableTailMergeDefault() const { return true; }
330 };
331
332 } // End llvm namespace
333
334 #endif