]>
Commit | Line | Data |
---|---|---|
223e47cc LB |
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 | ||
970d7e83 | 17 | #include "llvm/ADT/StringRef.h" |
223e47cc LB |
18 | #include "llvm/Pass.h" |
19 | #include "llvm/Support/CodeGen.h" | |
20 | #include "llvm/Target/TargetOptions.h" | |
223e47cc LB |
21 | #include <cassert> |
22 | #include <string> | |
23 | ||
24 | namespace llvm { | |
25 | ||
26 | class InstrItineraryData; | |
223e47cc | 27 | class GlobalValue; |
1a4d82fc | 28 | class Mangler; |
223e47cc LB |
29 | class MCAsmInfo; |
30 | class MCCodeGenInfo; | |
31 | class MCContext; | |
1a4d82fc | 32 | class MCSymbol; |
223e47cc | 33 | class Target; |
970d7e83 | 34 | class DataLayout; |
1a4d82fc | 35 | class TargetLibraryInfo; |
223e47cc | 36 | class TargetFrameLowering; |
223e47cc | 37 | class TargetIntrinsicInfo; |
223e47cc LB |
38 | class TargetLowering; |
39 | class TargetPassConfig; | |
40 | class TargetRegisterInfo; | |
41 | class TargetSelectionDAGInfo; | |
42 | class TargetSubtargetInfo; | |
970d7e83 LB |
43 | class ScalarTargetTransformInfo; |
44 | class VectorTargetTransformInfo; | |
223e47cc LB |
45 | class formatted_raw_ostream; |
46 | class raw_ostream; | |
85aaf69f | 47 | class TargetLoweringObjectFile; |
223e47cc | 48 | |
1a4d82fc JJ |
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 | ||
223e47cc LB |
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 | ||
223e47cc LB |
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. | |
1a4d82fc JJ |
78 | /// Non-const to allow resetting optimization level per-function. |
79 | MCCodeGenInfo *CodeGenInfo; | |
223e47cc LB |
80 | |
81 | /// AsmInfo - Contains target specific asm information. | |
82 | /// | |
83 | const MCAsmInfo *AsmInfo; | |
84 | ||
1a4d82fc | 85 | unsigned RequireStructuredCFG : 1; |
223e47cc LB |
86 | |
87 | public: | |
1a4d82fc JJ |
88 | mutable TargetOptions Options; |
89 | ||
223e47cc LB |
90 | virtual ~TargetMachine(); |
91 | ||
92 | const Target &getTarget() const { return TheTarget; } | |
93 | ||
1a4d82fc JJ |
94 | StringRef getTargetTriple() const { return TargetTriple; } |
95 | StringRef getTargetCPU() const { return TargetCPU; } | |
96 | StringRef getTargetFeatureString() const { return TargetFS; } | |
223e47cc | 97 | |
970d7e83 LB |
98 | /// getSubtargetImpl - virtual method implemented by subclasses that returns |
99 | /// a reference to that target's TargetSubtargetInfo-derived member variable. | |
1a4d82fc JJ |
100 | virtual const TargetSubtargetInfo *getSubtargetImpl() const { |
101 | return nullptr; | |
102 | } | |
103 | virtual const TargetSubtargetInfo *getSubtargetImpl(const Function &) const { | |
104 | return getSubtargetImpl(); | |
105 | } | |
85aaf69f SL |
106 | virtual TargetLoweringObjectFile *getObjFileLowering() const { |
107 | return nullptr; | |
108 | } | |
223e47cc LB |
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 | } | |
1a4d82fc JJ |
116 | template <typename STC> const STC &getSubtarget(const Function *) const { |
117 | return *static_cast<const STC*>(getSubtargetImpl()); | |
118 | } | |
223e47cc | 119 | |
1a4d82fc JJ |
120 | /// \brief Reset the target options based on the function's attributes. |
121 | // FIXME: Remove TargetOptions that affect per-function code generation | |
122 | // from TargetMachine. | |
123 | void resetTargetOptions(const Function &F) const; | |
124 | ||
125 | /// getMCAsmInfo - Return target specific asm information. | |
223e47cc | 126 | /// |
1a4d82fc | 127 | const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; } |
223e47cc LB |
128 | |
129 | /// getIntrinsicInfo - If intrinsic information is available, return it. If | |
130 | /// not, return null. | |
131 | /// | |
1a4d82fc JJ |
132 | virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { |
133 | return nullptr; | |
223e47cc LB |
134 | } |
135 | ||
1a4d82fc JJ |
136 | bool requiresStructuredCFG() const { return RequireStructuredCFG; } |
137 | void setRequiresStructuredCFG(bool Value) { RequireStructuredCFG = Value; } | |
223e47cc LB |
138 | |
139 | /// getRelocationModel - Returns the code generation relocation model. The | |
140 | /// choices are static, PIC, and dynamic-no-pic, and target default. | |
141 | Reloc::Model getRelocationModel() const; | |
142 | ||
143 | /// getCodeModel - Returns the code model. The choices are small, kernel, | |
144 | /// medium, large, and target default. | |
145 | CodeModel::Model getCodeModel() const; | |
146 | ||
147 | /// getTLSModel - Returns the TLS model which should be used for the given | |
148 | /// global variable. | |
149 | TLSModel::Model getTLSModel(const GlobalValue *GV) const; | |
150 | ||
151 | /// getOptLevel - Returns the optimization level: None, Less, | |
152 | /// Default, or Aggressive. | |
153 | CodeGenOpt::Level getOptLevel() const; | |
154 | ||
1a4d82fc JJ |
155 | /// \brief Overrides the optimization level. |
156 | void setOptLevel(CodeGenOpt::Level Level) const; | |
157 | ||
223e47cc LB |
158 | void setFastISel(bool Enable) { Options.EnableFastISel = Enable; } |
159 | ||
160 | bool shouldPrintMachineCode() const { return Options.PrintMachineCode; } | |
161 | ||
162 | /// getAsmVerbosityDefault - Returns the default value of asm verbosity. | |
163 | /// | |
1a4d82fc | 164 | bool getAsmVerbosityDefault() const ; |
223e47cc LB |
165 | |
166 | /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default | |
167 | /// is false. | |
1a4d82fc | 168 | void setAsmVerbosityDefault(bool); |
223e47cc LB |
169 | |
170 | /// getDataSections - Return true if data objects should be emitted into their | |
171 | /// own section, corresponds to -fdata-sections. | |
1a4d82fc | 172 | bool getDataSections() const; |
223e47cc LB |
173 | |
174 | /// getFunctionSections - Return true if functions should be emitted into | |
175 | /// their own section, corresponding to -ffunction-sections. | |
1a4d82fc | 176 | bool getFunctionSections() const; |
223e47cc LB |
177 | |
178 | /// setDataSections - Set if the data are emit into separate sections. | |
1a4d82fc | 179 | void setDataSections(bool); |
223e47cc LB |
180 | |
181 | /// setFunctionSections - Set if the functions are emit into separate | |
182 | /// sections. | |
1a4d82fc | 183 | void setFunctionSections(bool); |
223e47cc | 184 | |
970d7e83 LB |
185 | /// \brief Register analysis passes for this target with a pass manager. |
186 | virtual void addAnalysisPasses(PassManagerBase &) {} | |
187 | ||
223e47cc LB |
188 | /// CodeGenFileType - These enums are meant to be passed into |
189 | /// addPassesToEmitFile to indicate what type of file to emit, and returned by | |
190 | /// it to indicate what type of file could actually be made. | |
191 | enum CodeGenFileType { | |
192 | CGFT_AssemblyFile, | |
193 | CGFT_ObjectFile, | |
194 | CGFT_Null // Do not emit any output. | |
195 | }; | |
196 | ||
197 | /// addPassesToEmitFile - Add passes to the specified pass manager to get the | |
198 | /// specified file emitted. Typically this will involve several steps of code | |
199 | /// generation. This method should return true if emission of this file type | |
200 | /// is not supported, or false on success. | |
201 | virtual bool addPassesToEmitFile(PassManagerBase &, | |
202 | formatted_raw_ostream &, | |
203 | CodeGenFileType, | |
204 | bool /*DisableVerify*/ = true, | |
1a4d82fc JJ |
205 | AnalysisID /*StartAfter*/ = nullptr, |
206 | AnalysisID /*StopAfter*/ = nullptr) { | |
223e47cc LB |
207 | return true; |
208 | } | |
209 | ||
210 | /// addPassesToEmitMC - Add passes to the specified pass manager to get | |
211 | /// machine code emitted with the MCJIT. This method returns true if machine | |
212 | /// code is not supported. It fills the MCContext Ctx pointer which can be | |
213 | /// used to build custom MCStreamer. | |
214 | /// | |
215 | virtual bool addPassesToEmitMC(PassManagerBase &, | |
216 | MCContext *&, | |
217 | raw_ostream &, | |
218 | bool /*DisableVerify*/ = true) { | |
219 | return true; | |
220 | } | |
1a4d82fc JJ |
221 | |
222 | void getNameWithPrefix(SmallVectorImpl<char> &Name, const GlobalValue *GV, | |
223 | Mangler &Mang, bool MayAlwaysUsePrivate = false) const; | |
224 | MCSymbol *getSymbol(const GlobalValue *GV, Mangler &Mang) const; | |
223e47cc LB |
225 | }; |
226 | ||
227 | /// LLVMTargetMachine - This class describes a target machine that is | |
228 | /// implemented with the LLVM target-independent code generator. | |
229 | /// | |
230 | class LLVMTargetMachine : public TargetMachine { | |
231 | protected: // Can only create subclasses. | |
232 | LLVMTargetMachine(const Target &T, StringRef TargetTriple, | |
233 | StringRef CPU, StringRef FS, TargetOptions Options, | |
234 | Reloc::Model RM, CodeModel::Model CM, | |
235 | CodeGenOpt::Level OL); | |
236 | ||
1a4d82fc | 237 | void initAsmInfo(); |
223e47cc | 238 | public: |
970d7e83 LB |
239 | /// \brief Register analysis passes for this target with a pass manager. |
240 | /// | |
241 | /// This registers target independent analysis passes. | |
1a4d82fc | 242 | void addAnalysisPasses(PassManagerBase &PM) override; |
970d7e83 | 243 | |
223e47cc LB |
244 | /// createPassConfig - Create a pass configuration object to be used by |
245 | /// addPassToEmitX methods for generating a pipeline of CodeGen passes. | |
246 | virtual TargetPassConfig *createPassConfig(PassManagerBase &PM); | |
247 | ||
248 | /// addPassesToEmitFile - Add passes to the specified pass manager to get the | |
249 | /// specified file emitted. Typically this will involve several steps of code | |
250 | /// generation. | |
1a4d82fc JJ |
251 | bool addPassesToEmitFile(PassManagerBase &PM, formatted_raw_ostream &Out, |
252 | CodeGenFileType FileType, bool DisableVerify = true, | |
253 | AnalysisID StartAfter = nullptr, | |
254 | AnalysisID StopAfter = nullptr) override; | |
223e47cc LB |
255 | |
256 | /// addPassesToEmitMC - Add passes to the specified pass manager to get | |
257 | /// machine code emitted with the MCJIT. This method returns true if machine | |
258 | /// code is not supported. It fills the MCContext Ctx pointer which can be | |
259 | /// used to build custom MCStreamer. | |
260 | /// | |
1a4d82fc JJ |
261 | bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx, |
262 | raw_ostream &OS, bool DisableVerify = true) override; | |
223e47cc LB |
263 | }; |
264 | ||
265 | } // End llvm namespace | |
266 | ||
267 | #endif |