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