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/Target/TargetOptions.h"
18 #include "llvm/MC/MCCodeGenInfo.h"
19 #include "llvm/ADT/StringRef.h"
25 class InstrItineraryData;
32 class PassManagerBase;
35 class TargetELFWriterInfo;
36 class TargetFrameLowering;
37 class TargetInstrInfo;
38 class TargetIntrinsicInfo;
41 class TargetRegisterInfo;
42 class TargetSelectionDAGInfo;
43 class TargetSubtargetInfo;
44 class formatted_raw_ostream;
47 //===----------------------------------------------------------------------===//
49 /// TargetMachine - Primary interface to the complete machine description for
50 /// the target machine. All target-specific information should be accessible
51 /// through this interface.
54 TargetMachine(const TargetMachine &); // DO NOT IMPLEMENT
55 void operator=(const TargetMachine &); // DO NOT IMPLEMENT
56 protected: // Can only create subclasses.
57 TargetMachine(const Target &T, StringRef TargetTriple,
58 StringRef CPU, StringRef FS, const TargetOptions &Options);
60 /// getSubtargetImpl - virtual method implemented by subclasses that returns
61 /// a reference to that target's TargetSubtargetInfo-derived member variable.
62 virtual const TargetSubtargetInfo *getSubtargetImpl() const { return 0; }
64 /// TheTarget - The Target that this machine was created for.
65 const Target &TheTarget;
67 /// TargetTriple, TargetCPU, TargetFS - Triple string, CPU name, and target
68 /// feature strings the TargetMachine instance is created with.
69 std::string TargetTriple;
70 std::string TargetCPU;
73 /// CodeGenInfo - Low level target information such as relocation model.
74 const MCCodeGenInfo *CodeGenInfo;
76 /// AsmInfo - Contains target specific asm information.
78 const MCAsmInfo *AsmInfo;
80 unsigned MCRelaxAll : 1;
81 unsigned MCNoExecStack : 1;
82 unsigned MCSaveTempLabels : 1;
83 unsigned MCUseLoc : 1;
84 unsigned MCUseCFI : 1;
85 unsigned MCUseDwarfDirectory : 1;
88 virtual ~TargetMachine();
90 const Target &getTarget() const { return TheTarget; }
92 const StringRef getTargetTriple() const { return TargetTriple; }
93 const StringRef getTargetCPU() const { return TargetCPU; }
94 const StringRef getTargetFeatureString() const { return TargetFS; }
96 TargetOptions Options;
98 // Interfaces to the major aspects of target machine information:
99 // -- Instruction opcode and operand information
100 // -- Pipelines and scheduling information
101 // -- Stack frame information
102 // -- Selection DAG lowering information
104 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
105 virtual const TargetFrameLowering *getFrameLowering() const { return 0; }
106 virtual const TargetLowering *getTargetLowering() const { return 0; }
107 virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
108 virtual const TargetData *getTargetData() const { return 0; }
110 /// getMCAsmInfo - Return target specific asm information.
112 const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
114 /// getSubtarget - This method returns a pointer to the specified type of
115 /// TargetSubtargetInfo. In debug builds, it verifies that the object being
116 /// returned is of the correct type.
117 template<typename STC> const STC &getSubtarget() const {
118 return *static_cast<const STC*>(getSubtargetImpl());
121 /// getRegisterInfo - If register information is available, return it. If
122 /// not, return null. This is kept separate from RegInfo until RegInfo has
123 /// details of graph coloring register allocation removed from it.
125 virtual const TargetRegisterInfo *getRegisterInfo() const { return 0; }
127 /// getIntrinsicInfo - If intrinsic information is available, return it. If
128 /// not, return null.
130 virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { return 0; }
132 /// getJITInfo - If this target supports a JIT, return information for it,
133 /// otherwise return null.
135 virtual TargetJITInfo *getJITInfo() { return 0; }
137 /// getInstrItineraryData - Returns instruction itinerary data for the target
138 /// or specific subtarget.
140 virtual const InstrItineraryData *getInstrItineraryData() const {
144 /// getELFWriterInfo - If this target supports an ELF writer, return
145 /// information for it, otherwise return null.
147 virtual const TargetELFWriterInfo *getELFWriterInfo() const { return 0; }
149 /// hasMCRelaxAll - Check whether all machine code instructions should be
151 bool hasMCRelaxAll() const { return MCRelaxAll; }
153 /// setMCRelaxAll - Set whether all machine code instructions should be
155 void setMCRelaxAll(bool Value) { MCRelaxAll = Value; }
157 /// hasMCSaveTempLabels - Check whether temporary labels will be preserved
158 /// (i.e., not treated as temporary).
159 bool hasMCSaveTempLabels() const { return MCSaveTempLabels; }
161 /// setMCSaveTempLabels - Set whether temporary labels will be preserved
162 /// (i.e., not treated as temporary).
163 void setMCSaveTempLabels(bool Value) { MCSaveTempLabels = Value; }
165 /// hasMCNoExecStack - Check whether an executable stack is not needed.
166 bool hasMCNoExecStack() const { return MCNoExecStack; }
168 /// setMCNoExecStack - Set whether an executabel stack is not needed.
169 void setMCNoExecStack(bool Value) { MCNoExecStack = Value; }
171 /// hasMCUseLoc - Check whether we should use dwarf's .loc directive.
172 bool hasMCUseLoc() const { return MCUseLoc; }
174 /// setMCUseLoc - Set whether all we should use dwarf's .loc directive.
175 void setMCUseLoc(bool Value) { MCUseLoc = Value; }
177 /// hasMCUseCFI - Check whether we should use dwarf's .cfi_* directives.
178 bool hasMCUseCFI() const { return MCUseCFI; }
180 /// setMCUseCFI - Set whether all we should use dwarf's .cfi_* directives.
181 void setMCUseCFI(bool Value) { MCUseCFI = Value; }
183 /// hasMCUseDwarfDirectory - Check whether we should use .file directives with
184 /// explicit directories.
185 bool hasMCUseDwarfDirectory() const { return MCUseDwarfDirectory; }
187 /// setMCUseDwarfDirectory - Set whether all we should use .file directives
188 /// with explicit directories.
189 void setMCUseDwarfDirectory(bool Value) { MCUseDwarfDirectory = Value; }
191 /// getRelocationModel - Returns the code generation relocation model. The
192 /// choices are static, PIC, and dynamic-no-pic, and target default.
193 Reloc::Model getRelocationModel() const;
195 /// getCodeModel - Returns the code model. The choices are small, kernel,
196 /// medium, large, and target default.
197 CodeModel::Model getCodeModel() const;
199 /// getOptLevel - Returns the optimization level: None, Less,
200 /// Default, or Aggressive.
201 CodeGenOpt::Level getOptLevel() const;
203 /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
205 static bool getAsmVerbosityDefault();
207 /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
209 static void setAsmVerbosityDefault(bool);
211 /// getDataSections - Return true if data objects should be emitted into their
212 /// own section, corresponds to -fdata-sections.
213 static bool getDataSections();
215 /// getFunctionSections - Return true if functions should be emitted into
216 /// their own section, corresponding to -ffunction-sections.
217 static bool getFunctionSections();
219 /// setDataSections - Set if the data are emit into separate sections.
220 static void setDataSections(bool);
222 /// setFunctionSections - Set if the functions are emit into separate
224 static void setFunctionSections(bool);
226 /// CodeGenFileType - These enums are meant to be passed into
227 /// addPassesToEmitFile to indicate what type of file to emit, and returned by
228 /// it to indicate what type of file could actually be made.
229 enum CodeGenFileType {
232 CGFT_Null // Do not emit any output.
235 /// getEnableTailMergeDefault - the default setting for -enable-tail-merge
236 /// on this target. User flag overrides.
237 virtual bool getEnableTailMergeDefault() const { return true; }
239 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
240 /// specified file emitted. Typically this will involve several steps of code
241 /// generation. This method should return true if emission of this file type
242 /// is not supported, or false on success.
243 virtual bool addPassesToEmitFile(PassManagerBase &,
244 formatted_raw_ostream &,
246 bool /*DisableVerify*/ = true) {
250 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
251 /// get machine code emitted. This uses a JITCodeEmitter object to handle
252 /// actually outputting the machine code and resolving things like the address
253 /// of functions. This method returns true if machine code emission is
256 virtual bool addPassesToEmitMachineCode(PassManagerBase &,
258 bool /*DisableVerify*/ = true) {
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.
267 virtual bool addPassesToEmitMC(PassManagerBase &,
270 bool /*DisableVerify*/ = true) {
275 /// LLVMTargetMachine - This class describes a target machine that is
276 /// implemented with the LLVM target-independent code generator.
278 class LLVMTargetMachine : public TargetMachine {
279 protected: // Can only create subclasses.
280 LLVMTargetMachine(const Target &T, StringRef TargetTriple,
281 StringRef CPU, StringRef FS, TargetOptions Options,
282 Reloc::Model RM, CodeModel::Model CM,
283 CodeGenOpt::Level OL);
285 /// printNoVerify - Add a pass to dump the machine function, if debugging is
288 void printNoVerify(PassManagerBase &PM, const char *Banner) const;
290 /// printAndVerify - Add a pass to dump then verify the machine function, if
291 /// those steps are enabled.
293 void printAndVerify(PassManagerBase &PM, const char *Banner) const;
296 /// addCommonCodeGenPasses - Add standard LLVM codegen passes used for
297 /// both emitting to assembly files or machine code output.
299 bool addCommonCodeGenPasses(PassManagerBase &,
300 bool DisableVerify, MCContext *&OutCtx);
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);
311 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
312 /// get machine code emitted. This uses a JITCodeEmitter object to handle
313 /// actually outputting the machine code and resolving things like the address
314 /// of functions. This method returns true if machine code emission is
317 virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
319 bool DisableVerify = true);
321 /// addPassesToEmitMC - Add passes to the specified pass manager to get
322 /// machine code emitted with the MCJIT. This method returns true if machine
323 /// code is not supported. It fills the MCContext Ctx pointer which can be
324 /// used to build custom MCStreamer.
326 virtual bool addPassesToEmitMC(PassManagerBase &PM,
329 bool DisableVerify = true);
331 /// Target-Independent Code Generator Pass Configuration Options.
333 /// addPreISelPasses - This method should add any "last minute" LLVM->LLVM
334 /// passes (which are run just before instruction selector).
335 virtual bool addPreISel(PassManagerBase &) {
339 /// addInstSelector - This method should install an instruction selector pass,
340 /// which converts from LLVM code to machine instructions.
341 virtual bool addInstSelector(PassManagerBase &) {
345 /// addPreRegAlloc - This method may be implemented by targets that want to
346 /// run passes immediately before register allocation. This should return
347 /// true if -print-machineinstrs should print after these passes.
348 virtual bool addPreRegAlloc(PassManagerBase &) {
352 /// addPostRegAlloc - This method may be implemented by targets that want
353 /// to run passes after register allocation but before prolog-epilog
354 /// insertion. This should return true if -print-machineinstrs should print
355 /// after these passes.
356 virtual bool addPostRegAlloc(PassManagerBase &) {
360 /// addPreSched2 - This method may be implemented by targets that want to
361 /// run passes after prolog-epilog insertion and before the second instruction
362 /// scheduling pass. This should return true if -print-machineinstrs should
363 /// print after these passes.
364 virtual bool addPreSched2(PassManagerBase &) {
368 /// addPreEmitPass - This pass may be implemented by targets that want to run
369 /// passes immediately before machine code is emitted. This should return
370 /// true if -print-machineinstrs should print out the code after the passes.
371 virtual bool addPreEmitPass(PassManagerBase &) {
376 /// addCodeEmitter - This pass should be overridden by the target to add a
377 /// code emitter, if supported. If this is not supported, 'true' should be
379 virtual bool addCodeEmitter(PassManagerBase &,
384 /// getEnableTailMergeDefault - the default setting for -enable-tail-merge
385 /// on this target. User flag overrides.
386 virtual bool getEnableTailMergeDefault() const { return true; }
389 } // End llvm namespace