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