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