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/Pass.h"
18 #include "llvm/Support/CodeGen.h"
19 #include "llvm/Target/TargetOptions.h"
20 #include "llvm/TargetTransformInfo.h"
21 #include "llvm/Target/TargetTransformImpl.h"
22 #include "llvm/ADT/StringRef.h"
28 class InstrItineraryData;
34 class PassManagerBase;
37 class TargetELFWriterInfo;
38 class TargetFrameLowering;
39 class TargetInstrInfo;
40 class TargetIntrinsicInfo;
43 class TargetPassConfig;
44 class TargetRegisterInfo;
45 class TargetSelectionDAGInfo;
46 class TargetSubtargetInfo;
47 class formatted_raw_ostream;
50 //===----------------------------------------------------------------------===//
52 /// TargetMachine - Primary interface to the complete machine description for
53 /// the target machine. All target-specific information should be accessible
54 /// through this interface.
57 TargetMachine(const TargetMachine &) LLVM_DELETED_FUNCTION;
58 void operator=(const TargetMachine &) LLVM_DELETED_FUNCTION;
59 protected: // Can only create subclasses.
60 TargetMachine(const Target &T, StringRef TargetTriple,
61 StringRef CPU, StringRef FS, const TargetOptions &Options);
63 /// getSubtargetImpl - virtual method implemented by subclasses that returns
64 /// a reference to that target's TargetSubtargetInfo-derived member variable.
65 virtual const TargetSubtargetInfo *getSubtargetImpl() const { return 0; }
67 /// TheTarget - The Target that this machine was created for.
68 const Target &TheTarget;
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;
76 /// CodeGenInfo - Low level target information such as relocation model.
77 const MCCodeGenInfo *CodeGenInfo;
79 /// AsmInfo - Contains target specific asm information.
81 const MCAsmInfo *AsmInfo;
83 unsigned MCRelaxAll : 1;
84 unsigned MCNoExecStack : 1;
85 unsigned MCSaveTempLabels : 1;
86 unsigned MCUseLoc : 1;
87 unsigned MCUseCFI : 1;
88 unsigned MCUseDwarfDirectory : 1;
91 virtual ~TargetMachine();
93 const Target &getTarget() const { return TheTarget; }
95 const StringRef getTargetTriple() const { return TargetTriple; }
96 const StringRef getTargetCPU() const { return TargetCPU; }
97 const StringRef getTargetFeatureString() const { return TargetFS; }
99 TargetOptions Options;
101 // Interfaces to the major aspects of target machine information:
102 // -- Instruction opcode and operand information
103 // -- Pipelines and scheduling information
104 // -- Stack frame information
105 // -- Selection DAG lowering information
107 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
108 virtual const TargetFrameLowering *getFrameLowering() const { return 0; }
109 virtual const TargetLowering *getTargetLowering() const { return 0; }
110 virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
111 virtual const DataLayout *getDataLayout() const { return 0; }
112 virtual const ScalarTargetTransformInfo*
113 getScalarTargetTransformInfo() const { return 0; }
114 virtual const VectorTargetTransformInfo*
115 getVectorTargetTransformInfo() const { return 0; }
117 /// getMCAsmInfo - Return target specific asm information.
119 const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
121 /// getSubtarget - This method returns a pointer to the specified type of
122 /// TargetSubtargetInfo. In debug builds, it verifies that the object being
123 /// returned is of the correct type.
124 template<typename STC> const STC &getSubtarget() const {
125 return *static_cast<const STC*>(getSubtargetImpl());
128 /// getRegisterInfo - If register information is available, return it. If
129 /// not, return null. This is kept separate from RegInfo until RegInfo has
130 /// details of graph coloring register allocation removed from it.
132 virtual const TargetRegisterInfo *getRegisterInfo() const { return 0; }
134 /// getIntrinsicInfo - If intrinsic information is available, return it. If
135 /// not, return null.
137 virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { return 0; }
139 /// getJITInfo - If this target supports a JIT, return information for it,
140 /// otherwise return null.
142 virtual TargetJITInfo *getJITInfo() { return 0; }
144 /// getInstrItineraryData - Returns instruction itinerary data for the target
145 /// or specific subtarget.
147 virtual const InstrItineraryData *getInstrItineraryData() const {
151 /// getELFWriterInfo - If this target supports an ELF writer, return
152 /// information for it, otherwise return null.
154 virtual const TargetELFWriterInfo *getELFWriterInfo() const { return 0; }
156 /// hasMCRelaxAll - Check whether all machine code instructions should be
158 bool hasMCRelaxAll() const { return MCRelaxAll; }
160 /// setMCRelaxAll - Set whether all machine code instructions should be
162 void setMCRelaxAll(bool Value) { MCRelaxAll = Value; }
164 /// hasMCSaveTempLabels - Check whether temporary labels will be preserved
165 /// (i.e., not treated as temporary).
166 bool hasMCSaveTempLabels() const { return MCSaveTempLabels; }
168 /// setMCSaveTempLabels - Set whether temporary labels will be preserved
169 /// (i.e., not treated as temporary).
170 void setMCSaveTempLabels(bool Value) { MCSaveTempLabels = Value; }
172 /// hasMCNoExecStack - Check whether an executable stack is not needed.
173 bool hasMCNoExecStack() const { return MCNoExecStack; }
175 /// setMCNoExecStack - Set whether an executabel stack is not needed.
176 void setMCNoExecStack(bool Value) { MCNoExecStack = Value; }
178 /// hasMCUseLoc - Check whether we should use dwarf's .loc directive.
179 bool hasMCUseLoc() const { return MCUseLoc; }
181 /// setMCUseLoc - Set whether all we should use dwarf's .loc directive.
182 void setMCUseLoc(bool Value) { MCUseLoc = Value; }
184 /// hasMCUseCFI - Check whether we should use dwarf's .cfi_* directives.
185 bool hasMCUseCFI() const { return MCUseCFI; }
187 /// setMCUseCFI - Set whether all we should use dwarf's .cfi_* directives.
188 void setMCUseCFI(bool Value) { MCUseCFI = Value; }
190 /// hasMCUseDwarfDirectory - Check whether we should use .file directives with
191 /// explicit directories.
192 bool hasMCUseDwarfDirectory() const { return MCUseDwarfDirectory; }
194 /// setMCUseDwarfDirectory - Set whether all we should use .file directives
195 /// with explicit directories.
196 void setMCUseDwarfDirectory(bool Value) { MCUseDwarfDirectory = Value; }
198 /// getRelocationModel - Returns the code generation relocation model. The
199 /// choices are static, PIC, and dynamic-no-pic, and target default.
200 Reloc::Model getRelocationModel() const;
202 /// getCodeModel - Returns the code model. The choices are small, kernel,
203 /// medium, large, and target default.
204 CodeModel::Model getCodeModel() const;
206 /// getTLSModel - Returns the TLS model which should be used for the given
208 TLSModel::Model getTLSModel(const GlobalValue *GV) const;
210 /// getOptLevel - Returns the optimization level: None, Less,
211 /// Default, or Aggressive.
212 CodeGenOpt::Level getOptLevel() const;
214 void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
216 bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
218 /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
220 static bool getAsmVerbosityDefault();
222 /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
224 static void setAsmVerbosityDefault(bool);
226 /// getDataSections - Return true if data objects should be emitted into their
227 /// own section, corresponds to -fdata-sections.
228 static bool getDataSections();
230 /// getFunctionSections - Return true if functions should be emitted into
231 /// their own section, corresponding to -ffunction-sections.
232 static bool getFunctionSections();
234 /// setDataSections - Set if the data are emit into separate sections.
235 static void setDataSections(bool);
237 /// setFunctionSections - Set if the functions are emit into separate
239 static void setFunctionSections(bool);
241 /// CodeGenFileType - These enums are meant to be passed into
242 /// addPassesToEmitFile to indicate what type of file to emit, and returned by
243 /// it to indicate what type of file could actually be made.
244 enum CodeGenFileType {
247 CGFT_Null // Do not emit any output.
250 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
251 /// specified file emitted. Typically this will involve several steps of code
252 /// generation. This method should return true if emission of this file type
253 /// is not supported, or false on success.
254 virtual bool addPassesToEmitFile(PassManagerBase &,
255 formatted_raw_ostream &,
257 bool /*DisableVerify*/ = true,
258 AnalysisID StartAfter = 0,
259 AnalysisID StopAfter = 0) {
263 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
264 /// get machine code emitted. This uses a JITCodeEmitter object to handle
265 /// actually outputting the machine code and resolving things like the address
266 /// of functions. This method returns true if machine code emission is
269 virtual bool addPassesToEmitMachineCode(PassManagerBase &,
271 bool /*DisableVerify*/ = true) {
275 /// addPassesToEmitMC - Add passes to the specified pass manager to get
276 /// machine code emitted with the MCJIT. This method returns true if machine
277 /// code is not supported. It fills the MCContext Ctx pointer which can be
278 /// used to build custom MCStreamer.
280 virtual bool addPassesToEmitMC(PassManagerBase &,
283 bool /*DisableVerify*/ = true) {
288 /// LLVMTargetMachine - This class describes a target machine that is
289 /// implemented with the LLVM target-independent code generator.
291 class LLVMTargetMachine : public TargetMachine {
292 protected: // Can only create subclasses.
293 LLVMTargetMachine(const Target &T, StringRef TargetTriple,
294 StringRef CPU, StringRef FS, TargetOptions Options,
295 Reloc::Model RM, CodeModel::Model CM,
296 CodeGenOpt::Level OL);
299 /// createPassConfig - Create a pass configuration object to be used by
300 /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
301 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
303 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
304 /// specified file emitted. Typically this will involve several steps of code
306 virtual bool addPassesToEmitFile(PassManagerBase &PM,
307 formatted_raw_ostream &Out,
308 CodeGenFileType FileType,
309 bool DisableVerify = true,
310 AnalysisID StartAfter = 0,
311 AnalysisID StopAfter = 0);
313 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
314 /// get machine code emitted. This uses a JITCodeEmitter object to handle
315 /// actually outputting the machine code and resolving things like the address
316 /// of functions. This method returns true if machine code emission is
319 virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
321 bool DisableVerify = true);
323 /// addPassesToEmitMC - Add passes to the specified pass manager to get
324 /// machine code emitted with the MCJIT. This method returns true if machine
325 /// code is not supported. It fills the MCContext Ctx pointer which can be
326 /// used to build custom MCStreamer.
328 virtual bool addPassesToEmitMC(PassManagerBase &PM,
331 bool DisableVerify = true);
333 /// addCodeEmitter - This pass should be overridden by the target to add a
334 /// code emitter, if supported. If this is not supported, 'true' should be
336 virtual bool addCodeEmitter(PassManagerBase &,
342 } // End llvm namespace