Target: Fix build breakage.
[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   virtual const TargetSubtargetInfo *getSubtargetImpl(const Function &) const {
103     return getSubtargetImpl();
104   }
105
106   /// getSubtarget - This method returns a pointer to the specified type of
107   /// TargetSubtargetInfo.  In debug builds, it verifies that the object being
108   /// returned is of the correct type.
109   template<typename STC> const STC &getSubtarget() const {
110     return *static_cast<const STC*>(getSubtargetImpl());
111   }
112   template <typename STC> const STC &getSubtarget(const Function *) const {
113     return *static_cast<const STC*>(getSubtargetImpl());
114   }
115
116   /// \brief Reset the target options based on the function's attributes.
117   // FIXME: Remove TargetOptions that affect per-function code generation
118   // from TargetMachine.
119   void resetTargetOptions(const Function &F) const;
120
121   /// getMCAsmInfo - Return target specific asm information.
122   ///
123   const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
124
125   /// getIntrinsicInfo - If intrinsic information is available, return it.  If
126   /// not, return null.
127   ///
128   virtual const TargetIntrinsicInfo *getIntrinsicInfo() const {
129     return nullptr;
130   }
131
132   bool requiresStructuredCFG() const { return RequireStructuredCFG; }
133   void setRequiresStructuredCFG(bool Value) { RequireStructuredCFG = Value; }
134
135   /// getRelocationModel - Returns the code generation relocation model. The
136   /// choices are static, PIC, and dynamic-no-pic, and target default.
137   Reloc::Model getRelocationModel() const;
138
139   /// getCodeModel - Returns the code model. The choices are small, kernel,
140   /// medium, large, and target default.
141   CodeModel::Model getCodeModel() const;
142
143   /// getTLSModel - Returns the TLS model which should be used for the given
144   /// global variable.
145   TLSModel::Model getTLSModel(const GlobalValue *GV) const;
146
147   /// getOptLevel - Returns the optimization level: None, Less,
148   /// Default, or Aggressive.
149   CodeGenOpt::Level getOptLevel() const;
150
151   /// \brief Overrides the optimization level.
152   void setOptLevel(CodeGenOpt::Level Level) const;
153
154   void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
155
156   bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
157
158   /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
159   ///
160   bool getAsmVerbosityDefault() const ;
161
162   /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
163   /// is false.
164   void setAsmVerbosityDefault(bool);
165
166   /// getDataSections - Return true if data objects should be emitted into their
167   /// own section, corresponds to -fdata-sections.
168   bool getDataSections() const;
169
170   /// getFunctionSections - Return true if functions should be emitted into
171   /// their own section, corresponding to -ffunction-sections.
172   bool getFunctionSections() const;
173
174   /// setDataSections - Set if the data are emit into separate sections.
175   void setDataSections(bool);
176
177   /// setFunctionSections - Set if the functions are emit into separate
178   /// sections.
179   void setFunctionSections(bool);
180
181   /// \brief Register analysis passes for this target with a pass manager.
182   virtual void addAnalysisPasses(PassManagerBase &) {}
183
184   /// CodeGenFileType - These enums are meant to be passed into
185   /// addPassesToEmitFile to indicate what type of file to emit, and returned by
186   /// it to indicate what type of file could actually be made.
187   enum CodeGenFileType {
188     CGFT_AssemblyFile,
189     CGFT_ObjectFile,
190     CGFT_Null         // Do not emit any output.
191   };
192
193   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
194   /// specified file emitted.  Typically this will involve several steps of code
195   /// generation.  This method should return true if emission of this file type
196   /// is not supported, or false on success.
197   virtual bool addPassesToEmitFile(PassManagerBase &,
198                                    formatted_raw_ostream &,
199                                    CodeGenFileType,
200                                    bool /*DisableVerify*/ = true,
201                                    AnalysisID /*StartAfter*/ = nullptr,
202                                    AnalysisID /*StopAfter*/ = nullptr) {
203     return true;
204   }
205
206   /// addPassesToEmitMC - Add passes to the specified pass manager to get
207   /// machine code emitted with the MCJIT. This method returns true if machine
208   /// code is not supported. It fills the MCContext Ctx pointer which can be
209   /// used to build custom MCStreamer.
210   ///
211   virtual bool addPassesToEmitMC(PassManagerBase &,
212                                  MCContext *&,
213                                  raw_ostream &,
214                                  bool /*DisableVerify*/ = true) {
215     return true;
216   }
217
218   void getNameWithPrefix(SmallVectorImpl<char> &Name, const GlobalValue *GV,
219                          Mangler &Mang, bool MayAlwaysUsePrivate = false) const;
220   MCSymbol *getSymbol(const GlobalValue *GV, Mangler &Mang) const;
221 };
222
223 /// LLVMTargetMachine - This class describes a target machine that is
224 /// implemented with the LLVM target-independent code generator.
225 ///
226 class LLVMTargetMachine : public TargetMachine {
227 protected: // Can only create subclasses.
228   LLVMTargetMachine(const Target &T, StringRef TargetTriple,
229                     StringRef CPU, StringRef FS, TargetOptions Options,
230                     Reloc::Model RM, CodeModel::Model CM,
231                     CodeGenOpt::Level OL);
232
233   void initAsmInfo();
234 public:
235   /// \brief Register analysis passes for this target with a pass manager.
236   ///
237   /// This registers target independent analysis passes.
238   void addAnalysisPasses(PassManagerBase &PM) override;
239
240   /// createPassConfig - Create a pass configuration object to be used by
241   /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
242   virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
243
244   /// addPassesToEmitFile - Add passes to the specified pass manager to get the
245   /// specified file emitted.  Typically this will involve several steps of code
246   /// generation.
247   bool addPassesToEmitFile(PassManagerBase &PM, formatted_raw_ostream &Out,
248                            CodeGenFileType FileType, bool DisableVerify = true,
249                            AnalysisID StartAfter = nullptr,
250                            AnalysisID StopAfter = nullptr) override;
251
252   /// addPassesToEmitMC - Add passes to the specified pass manager to get
253   /// machine code emitted with the MCJIT. This method returns true if machine
254   /// code is not supported. It fills the MCContext Ctx pointer which can be
255   /// used to build custom MCStreamer.
256   ///
257   bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
258                          raw_ostream &OS, bool DisableVerify = true) override;
259 };
260
261 } // End llvm namespace
262
263 #endif