DebugInfo: Move DISubprogram::is*() queries to MDSubprogram
[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/IR/DataLayout.h"
19 #include "llvm/Pass.h"
20 #include "llvm/Support/CodeGen.h"
21 #include "llvm/Target/TargetOptions.h"
22 #include <cassert>
23 #include <string>
24
25 namespace llvm {
26
27 class InstrItineraryData;
28 class GlobalValue;
29 class Mangler;
30 class MCAsmInfo;
31 class MCCodeGenInfo;
32 class MCContext;
33 class MCInstrInfo;
34 class MCRegisterInfo;
35 class MCSubtargetInfo;
36 class MCSymbol;
37 class Target;
38 class DataLayout;
39 class TargetLibraryInfo;
40 class TargetFrameLowering;
41 class TargetIRAnalysis;
42 class TargetIntrinsicInfo;
43 class TargetLowering;
44 class TargetPassConfig;
45 class TargetRegisterInfo;
46 class TargetSelectionDAGInfo;
47 class TargetSubtargetInfo;
48 class TargetTransformInfo;
49 class formatted_raw_ostream;
50 class raw_ostream;
51 class TargetLoweringObjectFile;
52
53 // The old pass manager infrastructure is hidden in a legacy namespace now.
54 namespace legacy {
55 class PassManagerBase;
56 }
57 using legacy::PassManagerBase;
58
59 //===----------------------------------------------------------------------===//
60 ///
61 /// TargetMachine - Primary interface to the complete machine description for
62 /// the target machine.  All target-specific information should be accessible
63 /// through this interface.
64 ///
65 class TargetMachine {
66   TargetMachine(const TargetMachine &) = delete;
67   void operator=(const TargetMachine &) = delete;
68 protected: // Can only create subclasses.
69   TargetMachine(const Target &T, StringRef DataLayoutString,
70                 StringRef TargetTriple, StringRef CPU, StringRef FS,
71                 const TargetOptions &Options);
72
73   /// TheTarget - The Target that this machine was created for.
74   const Target &TheTarget;
75
76   /// DataLayout - For ABI type size and alignment.
77   const DataLayout DL;
78
79   /// TargetTriple, TargetCPU, TargetFS - Triple string, CPU name, and target
80   /// feature strings the TargetMachine instance is created with.
81   std::string TargetTriple;
82   std::string TargetCPU;
83   std::string TargetFS;
84
85   /// CodeGenInfo - Low level target information such as relocation model.
86   /// Non-const to allow resetting optimization level per-function.
87   MCCodeGenInfo *CodeGenInfo;
88
89   /// AsmInfo - Contains target specific asm information.
90   ///
91   const MCAsmInfo *AsmInfo;
92   const MCRegisterInfo *MRI;
93   const MCInstrInfo *MII;
94   const MCSubtargetInfo *STI;
95
96   unsigned RequireStructuredCFG : 1;
97
98 public:
99   mutable TargetOptions Options;
100
101   virtual ~TargetMachine();
102
103   const Target &getTarget() const { return TheTarget; }
104
105   StringRef getTargetTriple() const { return TargetTriple; }
106   StringRef getTargetCPU() const { return TargetCPU; }
107   StringRef getTargetFeatureString() const { return TargetFS; }
108
109   /// getSubtargetImpl - virtual method implemented by subclasses that returns
110   /// a reference to that target's TargetSubtargetInfo-derived member variable.
111   virtual const TargetSubtargetInfo *getSubtargetImpl(const Function &) const {
112     return nullptr;
113   }
114   virtual TargetLoweringObjectFile *getObjFileLowering() const {
115     return nullptr;
116   }
117
118   /// getSubtarget - This method returns a pointer to the specified type of
119   /// TargetSubtargetInfo.  In debug builds, it verifies that the object being
120   /// returned is of the correct type.
121   template <typename STC> const STC &getSubtarget(const Function &F) const {
122     return *static_cast<const STC*>(getSubtargetImpl(F));
123   }
124
125   /// getDataLayout - This method returns a pointer to the DataLayout for
126   /// the target. It should be unchanging for every subtarget.
127   const DataLayout *getDataLayout() const { return &DL; }
128
129   /// \brief Reset the target options based on the function's attributes.
130   // FIXME: Remove TargetOptions that affect per-function code generation
131   // from TargetMachine.
132   void resetTargetOptions(const Function &F) const;
133
134   /// getMCAsmInfo - Return target specific asm information.
135   ///
136   const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
137   const MCRegisterInfo *getMCRegisterInfo() const { return MRI; }
138   const MCInstrInfo *getMCInstrInfo() const { return MII; }
139   const MCSubtargetInfo *getMCSubtargetInfo() const { return STI; }
140
141   /// getIntrinsicInfo - If intrinsic information is available, return it.  If
142   /// not, return null.
143   ///
144   virtual const TargetIntrinsicInfo *getIntrinsicInfo() const {
145     return nullptr;
146   }
147
148   bool requiresStructuredCFG() const { return RequireStructuredCFG; }
149   void setRequiresStructuredCFG(bool Value) { RequireStructuredCFG = Value; }
150
151   /// getRelocationModel - Returns the code generation relocation model. The
152   /// choices are static, PIC, and dynamic-no-pic, and target default.
153   Reloc::Model getRelocationModel() const;
154
155   /// getCodeModel - Returns the code model. The choices are small, kernel,
156   /// medium, large, and target default.
157   CodeModel::Model getCodeModel() const;
158
159   /// getTLSModel - Returns the TLS model which should be used for the given
160   /// global variable.
161   TLSModel::Model getTLSModel(const GlobalValue *GV) const;
162
163   /// getOptLevel - Returns the optimization level: None, Less,
164   /// Default, or Aggressive.
165   CodeGenOpt::Level getOptLevel() const;
166
167   /// \brief Overrides the optimization level.
168   void setOptLevel(CodeGenOpt::Level Level) const;
169
170   void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
171
172   bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
173
174   /// Returns the default value of asm verbosity.
175   ///
176   bool getAsmVerbosityDefault() const {
177     return Options.MCOptions.AsmVerbose;
178   }
179
180   bool getUniqueSectionNames() const { return Options.UniqueSectionNames; }
181
182   /// Return true if data objects should be emitted into their own section,
183   /// corresponds to -fdata-sections.
184   bool getDataSections() const {
185     return Options.DataSections;
186   }
187
188   /// Return true if functions should be emitted into their own section,
189   /// corresponding to -ffunction-sections.
190   bool getFunctionSections() const {
191     return Options.FunctionSections;
192   }
193
194   /// \brief Get a \c TargetIRAnalysis appropriate for the target.
195   ///
196   /// This is used to construct the new pass manager's target IR analysis pass,
197   /// set up appropriately for this target machine. Even the old pass manager
198   /// uses this to answer queries about the IR.
199   virtual TargetIRAnalysis getTargetIRAnalysis();
200
201   /// CodeGenFileType - These enums are meant to be passed into
202   /// addPassesToEmitFile to indicate what type of file to emit, and returned by
203   /// it to indicate what type of file could actually be made.
204   enum CodeGenFileType {
205     CGFT_AssemblyFile,
206     CGFT_ObjectFile,
207     CGFT_Null         // Do not emit any output.
208   };
209
210   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
211   /// specified file emitted.  Typically this will involve several steps of code
212   /// generation.  This method should return true if emission of this file type
213   /// is not supported, or false on success.
214   virtual bool addPassesToEmitFile(PassManagerBase &,
215                                    formatted_raw_ostream &,
216                                    CodeGenFileType,
217                                    bool /*DisableVerify*/ = true,
218                                    AnalysisID /*StartAfter*/ = nullptr,
219                                    AnalysisID /*StopAfter*/ = nullptr) {
220     return true;
221   }
222
223   /// addPassesToEmitMC - Add passes to the specified pass manager to get
224   /// machine code emitted with the MCJIT. This method returns true if machine
225   /// code is not supported. It fills the MCContext Ctx pointer which can be
226   /// used to build custom MCStreamer.
227   ///
228   virtual bool addPassesToEmitMC(PassManagerBase &,
229                                  MCContext *&,
230                                  raw_ostream &,
231                                  bool /*DisableVerify*/ = true) {
232     return true;
233   }
234
235   void getNameWithPrefix(SmallVectorImpl<char> &Name, const GlobalValue *GV,
236                          Mangler &Mang, bool MayAlwaysUsePrivate = false) const;
237   MCSymbol *getSymbol(const GlobalValue *GV, Mangler &Mang) const;
238 };
239
240 /// LLVMTargetMachine - This class describes a target machine that is
241 /// implemented with the LLVM target-independent code generator.
242 ///
243 class LLVMTargetMachine : public TargetMachine {
244 protected: // Can only create subclasses.
245   LLVMTargetMachine(const Target &T, StringRef DataLayoutString,
246                     StringRef TargetTriple, StringRef CPU, StringRef FS,
247                     TargetOptions Options, Reloc::Model RM, CodeModel::Model CM,
248                     CodeGenOpt::Level OL);
249
250   void initAsmInfo();
251 public:
252   /// \brief Get a TargetIRAnalysis implementation for the target.
253   ///
254   /// This analysis will produce a TTI result which uses the common code
255   /// generator to answer queries about the IR.
256   TargetIRAnalysis getTargetIRAnalysis() override;
257
258   /// createPassConfig - Create a pass configuration object to be used by
259   /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
260   virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
261
262   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
263   /// specified file emitted.  Typically this will involve several steps of code
264   /// generation.
265   bool addPassesToEmitFile(PassManagerBase &PM, formatted_raw_ostream &Out,
266                            CodeGenFileType FileType, bool DisableVerify = true,
267                            AnalysisID StartAfter = nullptr,
268                            AnalysisID StopAfter = nullptr) override;
269
270   /// addPassesToEmitMC - Add passes to the specified pass manager to get
271   /// machine code emitted with the MCJIT. This method returns true if machine
272   /// code is not supported. It fills the MCContext Ctx pointer which can be
273   /// used to build custom MCStreamer.
274   ///
275   bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
276                          raw_ostream &OS, bool DisableVerify = true) override;
277 };
278
279 } // End llvm namespace
280
281 #endif