1 //===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the TargetMachine and LLVMTargetMachine classes.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_TARGET_TARGETMACHINE_H
15 #define LLVM_TARGET_TARGETMACHINE_H
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Pass.h"
19 #include "llvm/Support/CodeGen.h"
20 #include "llvm/Target/TargetOptions.h"
26 class InstrItineraryData;
34 class TargetLibraryInfo;
35 class TargetFrameLowering;
36 class TargetInstrInfo;
37 class TargetIntrinsicInfo;
40 class TargetPassConfig;
41 class TargetRegisterInfo;
42 class TargetSelectionDAGInfo;
43 class TargetSubtargetInfo;
44 class ScalarTargetTransformInfo;
45 class VectorTargetTransformInfo;
46 class formatted_raw_ostream;
49 // The old pass manager infrastructure is hidden in a legacy namespace now.
51 class PassManagerBase;
53 using legacy::PassManagerBase;
55 //===----------------------------------------------------------------------===//
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.
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);
68 /// TheTarget - The Target that this machine was created for.
69 const Target &TheTarget;
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;
77 /// CodeGenInfo - Low level target information such as relocation model.
78 const MCCodeGenInfo *CodeGenInfo;
80 /// AsmInfo - Contains target specific asm information.
82 const MCAsmInfo *AsmInfo;
84 unsigned MCRelaxAll : 1;
85 unsigned MCNoExecStack : 1;
86 unsigned MCSaveTempLabels : 1;
87 unsigned MCUseLoc : 1;
88 unsigned MCUseCFI : 1;
89 unsigned MCUseDwarfDirectory : 1;
92 virtual ~TargetMachine();
94 const Target &getTarget() const { return TheTarget; }
96 const StringRef getTargetTriple() const { return TargetTriple; }
97 const StringRef getTargetCPU() const { return TargetCPU; }
98 const StringRef getTargetFeatureString() const { return TargetFS; }
100 /// getSubtargetImpl - virtual method implemented by subclasses that returns
101 /// a reference to that target's TargetSubtargetInfo-derived member variable.
102 virtual const TargetSubtargetInfo *getSubtargetImpl() const { return 0; }
104 mutable TargetOptions Options;
106 /// \brief Reset the target options based on the function's attributes.
107 void resetTargetOptions(const MachineFunction *MF) const;
109 // Interfaces to the major aspects of target machine information:
111 // -- Instruction opcode and operand information
112 // -- Pipelines and scheduling information
113 // -- Stack frame information
114 // -- Selection DAG lowering information
116 // N.B. These objects may change during compilation. It's not safe to cache
117 // them between functions.
118 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
119 virtual const TargetFrameLowering *getFrameLowering() const { return 0; }
120 virtual const TargetLowering *getTargetLowering() const { return 0; }
121 virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
122 virtual const DataLayout *getDataLayout() const { return 0; }
124 /// getMCAsmInfo - Return target specific asm information.
126 const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
128 /// getSubtarget - This method returns a pointer to the specified type of
129 /// TargetSubtargetInfo. In debug builds, it verifies that the object being
130 /// returned is of the correct type.
131 template<typename STC> const STC &getSubtarget() const {
132 return *static_cast<const STC*>(getSubtargetImpl());
135 /// getRegisterInfo - If register information is available, return it. If
136 /// not, return null. This is kept separate from RegInfo until RegInfo has
137 /// details of graph coloring register allocation removed from it.
139 virtual const TargetRegisterInfo *getRegisterInfo() const { return 0; }
141 /// getIntrinsicInfo - If intrinsic information is available, return it. If
142 /// not, return null.
144 virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { return 0; }
146 /// getJITInfo - If this target supports a JIT, return information for it,
147 /// otherwise return null.
149 virtual TargetJITInfo *getJITInfo() { return 0; }
151 /// getInstrItineraryData - Returns instruction itinerary data for the target
152 /// or specific subtarget.
154 virtual const InstrItineraryData *getInstrItineraryData() const {
158 /// hasMCRelaxAll - Check whether all machine code instructions should be
160 bool hasMCRelaxAll() const { return MCRelaxAll; }
162 /// setMCRelaxAll - Set whether all machine code instructions should be
164 void setMCRelaxAll(bool Value) { MCRelaxAll = Value; }
166 /// hasMCSaveTempLabels - Check whether temporary labels will be preserved
167 /// (i.e., not treated as temporary).
168 bool hasMCSaveTempLabels() const { return MCSaveTempLabels; }
170 /// setMCSaveTempLabels - Set whether temporary labels will be preserved
171 /// (i.e., not treated as temporary).
172 void setMCSaveTempLabels(bool Value) { MCSaveTempLabels = Value; }
174 /// hasMCNoExecStack - Check whether an executable stack is not needed.
175 bool hasMCNoExecStack() const { return MCNoExecStack; }
177 /// setMCNoExecStack - Set whether an executabel stack is not needed.
178 void setMCNoExecStack(bool Value) { MCNoExecStack = Value; }
180 /// hasMCUseLoc - Check whether we should use dwarf's .loc directive.
181 bool hasMCUseLoc() const { return MCUseLoc; }
183 /// setMCUseLoc - Set whether all we should use dwarf's .loc directive.
184 void setMCUseLoc(bool Value) { MCUseLoc = Value; }
186 /// hasMCUseCFI - Check whether we should use dwarf's .cfi_* directives.
187 bool hasMCUseCFI() const { return MCUseCFI; }
189 /// setMCUseCFI - Set whether all we should use dwarf's .cfi_* directives.
190 void setMCUseCFI(bool Value) { MCUseCFI = Value; }
192 /// hasMCUseDwarfDirectory - Check whether we should use .file directives with
193 /// explicit directories.
194 bool hasMCUseDwarfDirectory() const { return MCUseDwarfDirectory; }
196 /// setMCUseDwarfDirectory - Set whether all we should use .file directives
197 /// with explicit directories.
198 void setMCUseDwarfDirectory(bool Value) { MCUseDwarfDirectory = Value; }
200 /// getRelocationModel - Returns the code generation relocation model. The
201 /// choices are static, PIC, and dynamic-no-pic, and target default.
202 Reloc::Model getRelocationModel() const;
204 /// getCodeModel - Returns the code model. The choices are small, kernel,
205 /// medium, large, and target default.
206 CodeModel::Model getCodeModel() const;
208 /// getTLSModel - Returns the TLS model which should be used for the given
210 TLSModel::Model getTLSModel(const GlobalValue *GV) const;
212 /// getOptLevel - Returns the optimization level: None, Less,
213 /// Default, or Aggressive.
214 CodeGenOpt::Level getOptLevel() const;
216 void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
218 bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
220 /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
222 static bool getAsmVerbosityDefault();
224 /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
226 static void setAsmVerbosityDefault(bool);
228 /// getDataSections - Return true if data objects should be emitted into their
229 /// own section, corresponds to -fdata-sections.
230 static bool getDataSections();
232 /// getFunctionSections - Return true if functions should be emitted into
233 /// their own section, corresponding to -ffunction-sections.
234 static bool getFunctionSections();
236 /// setDataSections - Set if the data are emit into separate sections.
237 static void setDataSections(bool);
239 /// setFunctionSections - Set if the functions are emit into separate
241 static void setFunctionSections(bool);
243 /// \brief Register analysis passes for this target with a pass manager.
244 virtual void addAnalysisPasses(PassManagerBase &) {}
246 /// CodeGenFileType - These enums are meant to be passed into
247 /// addPassesToEmitFile to indicate what type of file to emit, and returned by
248 /// it to indicate what type of file could actually be made.
249 enum CodeGenFileType {
252 CGFT_Null // Do not emit any output.
255 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
256 /// specified file emitted. Typically this will involve several steps of code
257 /// generation. This method should return true if emission of this file type
258 /// is not supported, or false on success.
259 virtual bool addPassesToEmitFile(PassManagerBase &,
260 formatted_raw_ostream &,
262 bool /*DisableVerify*/ = true,
263 AnalysisID /*StartAfter*/ = 0,
264 AnalysisID /*StopAfter*/ = 0) {
268 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
269 /// get machine code emitted. This uses a JITCodeEmitter object to handle
270 /// actually outputting the machine code and resolving things like the address
271 /// of functions. This method returns true if machine code emission is
274 virtual bool addPassesToEmitMachineCode(PassManagerBase &,
276 bool /*DisableVerify*/ = true) {
280 /// addPassesToEmitMC - Add passes to the specified pass manager to get
281 /// machine code emitted with the MCJIT. This method returns true if machine
282 /// code is not supported. It fills the MCContext Ctx pointer which can be
283 /// used to build custom MCStreamer.
285 virtual bool addPassesToEmitMC(PassManagerBase &,
288 bool /*DisableVerify*/ = true) {
293 /// LLVMTargetMachine - This class describes a target machine that is
294 /// implemented with the LLVM target-independent code generator.
296 class LLVMTargetMachine : public TargetMachine {
297 protected: // Can only create subclasses.
298 LLVMTargetMachine(const Target &T, StringRef TargetTriple,
299 StringRef CPU, StringRef FS, TargetOptions Options,
300 Reloc::Model RM, CodeModel::Model CM,
301 CodeGenOpt::Level OL);
305 /// \brief Register analysis passes for this target with a pass manager.
307 /// This registers target independent analysis passes.
308 virtual void addAnalysisPasses(PassManagerBase &PM);
310 /// createPassConfig - Create a pass configuration object to be used by
311 /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
312 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
314 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
315 /// specified file emitted. Typically this will involve several steps of code
317 virtual bool addPassesToEmitFile(PassManagerBase &PM,
318 formatted_raw_ostream &Out,
319 CodeGenFileType FileType,
320 bool DisableVerify = true,
321 AnalysisID StartAfter = 0,
322 AnalysisID StopAfter = 0);
324 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
325 /// get machine code emitted. This uses a JITCodeEmitter object to handle
326 /// actually outputting the machine code and resolving things like the address
327 /// of functions. This method returns true if machine code emission is
330 virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
332 bool DisableVerify = true);
334 /// addPassesToEmitMC - Add passes to the specified pass manager to get
335 /// machine code emitted with the MCJIT. This method returns true if machine
336 /// code is not supported. It fills the MCContext Ctx pointer which can be
337 /// used to build custom MCStreamer.
339 virtual bool addPassesToEmitMC(PassManagerBase &PM,
342 bool DisableVerify = true);
344 /// addCodeEmitter - This pass should be overridden by the target to add a
345 /// code emitter, if supported. If this is not supported, 'true' should be
347 virtual bool addCodeEmitter(PassManagerBase &,
353 } // End llvm namespace