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