Remove support for not using .loc directives.
[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/ADT/StringRef.h"
18 #include "llvm/Pass.h"
19 #include "llvm/Support/CodeGen.h"
20 #include "llvm/Target/TargetOptions.h"
21 #include <cassert>
22 #include <string>
23
24 namespace llvm {
25
26 class InstrItineraryData;
27 class JITCodeEmitter;
28 class GlobalValue;
29 class MCAsmInfo;
30 class MCCodeGenInfo;
31 class MCContext;
32 class Target;
33 class DataLayout;
34 class TargetLibraryInfo;
35 class TargetFrameLowering;
36 class TargetInstrInfo;
37 class TargetIntrinsicInfo;
38 class TargetJITInfo;
39 class TargetLowering;
40 class TargetPassConfig;
41 class TargetRegisterInfo;
42 class TargetSelectionDAGInfo;
43 class TargetSubtargetInfo;
44 class ScalarTargetTransformInfo;
45 class VectorTargetTransformInfo;
46 class formatted_raw_ostream;
47 class raw_ostream;
48
49 // The old pass manager infrastructure is hidden in a legacy namespace now.
50 namespace legacy {
51 class PassManagerBase;
52 }
53 using legacy::PassManagerBase;
54
55 //===----------------------------------------------------------------------===//
56 ///
57 /// TargetMachine - Primary interface to the complete machine description for
58 /// the target machine.  All target-specific information should be accessible
59 /// through this interface.
60 ///
61 class TargetMachine {
62   TargetMachine(const TargetMachine &) LLVM_DELETED_FUNCTION;
63   void operator=(const TargetMachine &) LLVM_DELETED_FUNCTION;
64 protected: // Can only create subclasses.
65   TargetMachine(const Target &T, StringRef TargetTriple,
66                 StringRef CPU, StringRef FS, const TargetOptions &Options);
67
68   /// TheTarget - The Target that this machine was created for.
69   const Target &TheTarget;
70
71   /// TargetTriple, TargetCPU, TargetFS - Triple string, CPU name, and target
72   /// feature strings the TargetMachine instance is created with.
73   std::string TargetTriple;
74   std::string TargetCPU;
75   std::string TargetFS;
76
77   /// CodeGenInfo - Low level target information such as relocation model.
78   /// Non-const to allow resetting optimization level per-function.
79   MCCodeGenInfo *CodeGenInfo;
80
81   /// AsmInfo - Contains target specific asm information.
82   ///
83   const MCAsmInfo *AsmInfo;
84
85   unsigned MCRelaxAll : 1;
86   unsigned MCNoExecStack : 1;
87   unsigned MCSaveTempLabels : 1;
88   unsigned MCUseCFI : 1;
89   unsigned MCUseDwarfDirectory : 1;
90   unsigned RequireStructuredCFG : 1;
91
92 public:
93   virtual ~TargetMachine();
94
95   const Target &getTarget() const { return TheTarget; }
96
97   const StringRef getTargetTriple() const { return TargetTriple; }
98   const StringRef getTargetCPU() const { return TargetCPU; }
99   const StringRef getTargetFeatureString() const { return TargetFS; }
100
101   /// getSubtargetImpl - virtual method implemented by subclasses that returns
102   /// a reference to that target's TargetSubtargetInfo-derived member variable.
103   virtual const TargetSubtargetInfo *getSubtargetImpl() const { return 0; }
104
105   mutable TargetOptions Options;
106
107   /// \brief Reset the target options based on the function's attributes.
108   void resetTargetOptions(const MachineFunction *MF) const;
109
110   // Interfaces to the major aspects of target machine information:
111   //
112   // -- Instruction opcode and operand information
113   // -- Pipelines and scheduling information
114   // -- Stack frame information
115   // -- Selection DAG lowering information
116   //
117   // N.B. These objects may change during compilation. It's not safe to cache
118   // them between functions.
119   virtual const TargetInstrInfo         *getInstrInfo() const { return 0; }
120   virtual const TargetFrameLowering *getFrameLowering() const { return 0; }
121   virtual const TargetLowering    *getTargetLowering() const { return 0; }
122   virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
123   virtual const DataLayout             *getDataLayout() const { return 0; }
124
125   /// getMCAsmInfo - Return target specific asm information.
126   ///
127   const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
128
129   /// getSubtarget - This method returns a pointer to the specified type of
130   /// TargetSubtargetInfo.  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     return *static_cast<const STC*>(getSubtargetImpl());
134   }
135
136   /// getRegisterInfo - If register information is available, return it.  If
137   /// not, return null.  This is kept separate from RegInfo until RegInfo has
138   /// details of graph coloring register allocation removed from it.
139   ///
140   virtual const TargetRegisterInfo *getRegisterInfo() const { return 0; }
141
142   /// getIntrinsicInfo - If intrinsic information is available, return it.  If
143   /// not, return null.
144   ///
145   virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { return 0; }
146
147   /// getJITInfo - If this target supports a JIT, return information for it,
148   /// otherwise return null.
149   ///
150   virtual TargetJITInfo *getJITInfo() { return 0; }
151
152   /// getInstrItineraryData - Returns instruction itinerary data for the target
153   /// or specific subtarget.
154   ///
155   virtual const InstrItineraryData *getInstrItineraryData() const {
156     return 0;
157   }
158
159   bool requiresStructuredCFG() const { return RequireStructuredCFG; }
160   void setRequiresStructuredCFG(bool Value) { RequireStructuredCFG = Value; }
161
162   /// hasMCRelaxAll - Check whether all machine code instructions should be
163   /// relaxed.
164   bool hasMCRelaxAll() const { return MCRelaxAll; }
165
166   /// setMCRelaxAll - Set whether all machine code instructions should be
167   /// relaxed.
168   void setMCRelaxAll(bool Value) { MCRelaxAll = Value; }
169
170   /// hasMCSaveTempLabels - Check whether temporary labels will be preserved
171   /// (i.e., not treated as temporary).
172   bool hasMCSaveTempLabels() const { return MCSaveTempLabels; }
173
174   /// setMCSaveTempLabels - Set whether temporary labels will be preserved
175   /// (i.e., not treated as temporary).
176   void setMCSaveTempLabels(bool Value) { MCSaveTempLabels = Value; }
177
178   /// hasMCNoExecStack - Check whether an executable stack is not needed.
179   bool hasMCNoExecStack() const { return MCNoExecStack; }
180
181   /// setMCNoExecStack - Set whether an executabel stack is not needed.
182   void setMCNoExecStack(bool Value) { MCNoExecStack = Value; }
183
184   /// hasMCUseCFI - Check whether we should use dwarf's .cfi_* directives.
185   bool hasMCUseCFI() const { return MCUseCFI; }
186
187   /// setMCUseCFI - Set whether all we should use dwarf's .cfi_* directives.
188   void setMCUseCFI(bool Value) { MCUseCFI = Value; }
189
190   /// hasMCUseDwarfDirectory - Check whether we should use .file directives with
191   /// explicit directories.
192   bool hasMCUseDwarfDirectory() const { return MCUseDwarfDirectory; }
193
194   /// setMCUseDwarfDirectory - Set whether all we should use .file directives
195   /// with explicit directories.
196   void setMCUseDwarfDirectory(bool Value) { MCUseDwarfDirectory = Value; }
197
198   /// getRelocationModel - Returns the code generation relocation model. The
199   /// choices are static, PIC, and dynamic-no-pic, and target default.
200   Reloc::Model getRelocationModel() const;
201
202   /// getCodeModel - Returns the code model. The choices are small, kernel,
203   /// medium, large, and target default.
204   CodeModel::Model getCodeModel() const;
205
206   /// getTLSModel - Returns the TLS model which should be used for the given
207   /// global variable.
208   TLSModel::Model getTLSModel(const GlobalValue *GV) const;
209
210   /// getOptLevel - Returns the optimization level: None, Less,
211   /// Default, or Aggressive.
212   CodeGenOpt::Level getOptLevel() const;
213
214   /// \brief Overrides the optimization level.
215   void setOptLevel(CodeGenOpt::Level Level) const;
216
217   void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
218
219   bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
220
221   /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
222   ///
223   static bool getAsmVerbosityDefault();
224
225   /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
226   /// is false.
227   static void setAsmVerbosityDefault(bool);
228
229   /// getDataSections - Return true if data objects should be emitted into their
230   /// own section, corresponds to -fdata-sections.
231   static bool getDataSections();
232
233   /// getFunctionSections - Return true if functions should be emitted into
234   /// their own section, corresponding to -ffunction-sections.
235   static bool getFunctionSections();
236
237   /// setDataSections - Set if the data are emit into separate sections.
238   static void setDataSections(bool);
239
240   /// setFunctionSections - Set if the functions are emit into separate
241   /// sections.
242   static void setFunctionSections(bool);
243
244   /// \brief Register analysis passes for this target with a pass manager.
245   virtual void addAnalysisPasses(PassManagerBase &) {}
246
247   /// CodeGenFileType - These enums are meant to be passed into
248   /// addPassesToEmitFile to indicate what type of file to emit, and returned by
249   /// it to indicate what type of file could actually be made.
250   enum CodeGenFileType {
251     CGFT_AssemblyFile,
252     CGFT_ObjectFile,
253     CGFT_Null         // Do not emit any output.
254   };
255
256   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
257   /// specified file emitted.  Typically this will involve several steps of code
258   /// generation.  This method should return true if emission of this file type
259   /// is not supported, or false on success.
260   virtual bool addPassesToEmitFile(PassManagerBase &,
261                                    formatted_raw_ostream &,
262                                    CodeGenFileType,
263                                    bool /*DisableVerify*/ = true,
264                                    AnalysisID /*StartAfter*/ = 0,
265                                    AnalysisID /*StopAfter*/ = 0) {
266     return true;
267   }
268
269   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
270   /// get machine code emitted.  This uses a JITCodeEmitter object to handle
271   /// actually outputting the machine code and resolving things like the address
272   /// of functions.  This method returns true if machine code emission is
273   /// not supported.
274   ///
275   virtual bool addPassesToEmitMachineCode(PassManagerBase &,
276                                           JITCodeEmitter &,
277                                           bool /*DisableVerify*/ = true) {
278     return true;
279   }
280
281   /// addPassesToEmitMC - Add passes to the specified pass manager to get
282   /// machine code emitted with the MCJIT. This method returns true if machine
283   /// code is not supported. It fills the MCContext Ctx pointer which can be
284   /// used to build custom MCStreamer.
285   ///
286   virtual bool addPassesToEmitMC(PassManagerBase &,
287                                  MCContext *&,
288                                  raw_ostream &,
289                                  bool /*DisableVerify*/ = true) {
290     return true;
291   }
292 };
293
294 /// LLVMTargetMachine - This class describes a target machine that is
295 /// implemented with the LLVM target-independent code generator.
296 ///
297 class LLVMTargetMachine : public TargetMachine {
298 protected: // Can only create subclasses.
299   LLVMTargetMachine(const Target &T, StringRef TargetTriple,
300                     StringRef CPU, StringRef FS, TargetOptions Options,
301                     Reloc::Model RM, CodeModel::Model CM,
302                     CodeGenOpt::Level OL);
303
304   void initAsmInfo();
305 public:
306   /// \brief Register analysis passes for this target with a pass manager.
307   ///
308   /// This registers target independent analysis passes.
309   virtual void addAnalysisPasses(PassManagerBase &PM);
310
311   /// createPassConfig - Create a pass configuration object to be used by
312   /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
313   virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
314
315   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
316   /// specified file emitted.  Typically this will involve several steps of code
317   /// generation.
318   virtual bool addPassesToEmitFile(PassManagerBase &PM,
319                                    formatted_raw_ostream &Out,
320                                    CodeGenFileType FileType,
321                                    bool DisableVerify = true,
322                                    AnalysisID StartAfter = 0,
323                                    AnalysisID StopAfter = 0);
324
325   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
326   /// get machine code emitted.  This uses a JITCodeEmitter object to handle
327   /// actually outputting the machine code and resolving things like the address
328   /// of functions.  This method returns true if machine code emission is
329   /// not supported.
330   ///
331   virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
332                                           JITCodeEmitter &MCE,
333                                           bool DisableVerify = true);
334
335   /// addPassesToEmitMC - Add passes to the specified pass manager to get
336   /// machine code emitted with the MCJIT. This method returns true if machine
337   /// code is not supported. It fills the MCContext Ctx pointer which can be
338   /// used to build custom MCStreamer.
339   ///
340   virtual bool addPassesToEmitMC(PassManagerBase &PM,
341                                  MCContext *&Ctx,
342                                  raw_ostream &OS,
343                                  bool DisableVerify = true);
344
345   /// addCodeEmitter - This pass should be overridden by the target to add a
346   /// code emitter, if supported.  If this is not supported, 'true' should be
347   /// returned.
348   virtual bool addCodeEmitter(PassManagerBase &,
349                               JITCodeEmitter &) {
350     return true;
351   }
352 };
353
354 } // End llvm namespace
355
356 #endif