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