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 TargetPassConfig;
42 class TargetRegisterInfo;
43 class TargetSelectionDAGInfo;
44 class TargetSubtargetInfo;
45 class formatted_raw_ostream;
48 //===----------------------------------------------------------------------===//
50 /// TargetMachine - Primary interface to the complete machine description for
51 /// the target machine. All target-specific information should be accessible
52 /// through this interface.
55 TargetMachine(const TargetMachine &); // DO NOT IMPLEMENT
56 void operator=(const TargetMachine &); // DO NOT IMPLEMENT
57 protected: // Can only create subclasses.
58 TargetMachine(const Target &T, StringRef TargetTriple,
59 StringRef CPU, StringRef FS, const TargetOptions &Options);
61 /// getSubtargetImpl - virtual method implemented by subclasses that returns
62 /// a reference to that target's TargetSubtargetInfo-derived member variable.
63 virtual const TargetSubtargetInfo *getSubtargetImpl() const { return 0; }
65 /// TheTarget - The Target that this machine was created for.
66 const Target &TheTarget;
68 /// TargetTriple, TargetCPU, TargetFS - Triple string, CPU name, and target
69 /// feature strings the TargetMachine instance is created with.
70 std::string TargetTriple;
71 std::string TargetCPU;
74 /// CodeGenInfo - Low level target information such as relocation model.
75 const MCCodeGenInfo *CodeGenInfo;
77 /// AsmInfo - Contains target specific asm information.
79 const MCAsmInfo *AsmInfo;
81 unsigned MCRelaxAll : 1;
82 unsigned MCNoExecStack : 1;
83 unsigned MCSaveTempLabels : 1;
84 unsigned MCUseLoc : 1;
85 unsigned MCUseCFI : 1;
86 unsigned MCUseDwarfDirectory : 1;
89 virtual ~TargetMachine();
91 const Target &getTarget() const { return TheTarget; }
93 const StringRef getTargetTriple() const { return TargetTriple; }
94 const StringRef getTargetCPU() const { return TargetCPU; }
95 const StringRef getTargetFeatureString() const { return TargetFS; }
97 TargetOptions Options;
99 // Interfaces to the major aspects of target machine information:
100 // -- Instruction opcode and operand information
101 // -- Pipelines and scheduling information
102 // -- Stack frame information
103 // -- Selection DAG lowering information
105 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
106 virtual const TargetFrameLowering *getFrameLowering() const { return 0; }
107 virtual const TargetLowering *getTargetLowering() const { return 0; }
108 virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
109 virtual const TargetData *getTargetData() const { return 0; }
111 /// getMCAsmInfo - Return target specific asm information.
113 const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
115 /// getSubtarget - This method returns a pointer to the specified type of
116 /// TargetSubtargetInfo. In debug builds, it verifies that the object being
117 /// returned is of the correct type.
118 template<typename STC> const STC &getSubtarget() const {
119 return *static_cast<const STC*>(getSubtargetImpl());
122 /// getRegisterInfo - If register information is available, return it. If
123 /// not, return null. This is kept separate from RegInfo until RegInfo has
124 /// details of graph coloring register allocation removed from it.
126 virtual const TargetRegisterInfo *getRegisterInfo() const { return 0; }
128 /// getIntrinsicInfo - If intrinsic information is available, return it. If
129 /// not, return null.
131 virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { return 0; }
133 /// getJITInfo - If this target supports a JIT, return information for it,
134 /// otherwise return null.
136 virtual TargetJITInfo *getJITInfo() { return 0; }
138 /// getInstrItineraryData - Returns instruction itinerary data for the target
139 /// or specific subtarget.
141 virtual const InstrItineraryData *getInstrItineraryData() const {
145 /// getELFWriterInfo - If this target supports an ELF writer, return
146 /// information for it, otherwise return null.
148 virtual const TargetELFWriterInfo *getELFWriterInfo() const { return 0; }
150 /// hasMCRelaxAll - Check whether all machine code instructions should be
152 bool hasMCRelaxAll() const { return MCRelaxAll; }
154 /// setMCRelaxAll - Set whether all machine code instructions should be
156 void setMCRelaxAll(bool Value) { MCRelaxAll = Value; }
158 /// hasMCSaveTempLabels - Check whether temporary labels will be preserved
159 /// (i.e., not treated as temporary).
160 bool hasMCSaveTempLabels() const { return MCSaveTempLabels; }
162 /// setMCSaveTempLabels - Set whether temporary labels will be preserved
163 /// (i.e., not treated as temporary).
164 void setMCSaveTempLabels(bool Value) { MCSaveTempLabels = Value; }
166 /// hasMCNoExecStack - Check whether an executable stack is not needed.
167 bool hasMCNoExecStack() const { return MCNoExecStack; }
169 /// setMCNoExecStack - Set whether an executabel stack is not needed.
170 void setMCNoExecStack(bool Value) { MCNoExecStack = Value; }
172 /// hasMCUseLoc - Check whether we should use dwarf's .loc directive.
173 bool hasMCUseLoc() const { return MCUseLoc; }
175 /// setMCUseLoc - Set whether all we should use dwarf's .loc directive.
176 void setMCUseLoc(bool Value) { MCUseLoc = Value; }
178 /// hasMCUseCFI - Check whether we should use dwarf's .cfi_* directives.
179 bool hasMCUseCFI() const { return MCUseCFI; }
181 /// setMCUseCFI - Set whether all we should use dwarf's .cfi_* directives.
182 void setMCUseCFI(bool Value) { MCUseCFI = Value; }
184 /// hasMCUseDwarfDirectory - Check whether we should use .file directives with
185 /// explicit directories.
186 bool hasMCUseDwarfDirectory() const { return MCUseDwarfDirectory; }
188 /// setMCUseDwarfDirectory - Set whether all we should use .file directives
189 /// with explicit directories.
190 void setMCUseDwarfDirectory(bool Value) { MCUseDwarfDirectory = Value; }
192 /// getRelocationModel - Returns the code generation relocation model. The
193 /// choices are static, PIC, and dynamic-no-pic, and target default.
194 Reloc::Model getRelocationModel() const;
196 /// getCodeModel - Returns the code model. The choices are small, kernel,
197 /// medium, large, and target default.
198 CodeModel::Model getCodeModel() const;
200 /// getOptLevel - Returns the optimization level: None, Less,
201 /// Default, or Aggressive.
202 CodeGenOpt::Level getOptLevel() const;
204 void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
206 bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
208 /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
210 static bool getAsmVerbosityDefault();
212 /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
214 static void setAsmVerbosityDefault(bool);
216 /// getDataSections - Return true if data objects should be emitted into their
217 /// own section, corresponds to -fdata-sections.
218 static bool getDataSections();
220 /// getFunctionSections - Return true if functions should be emitted into
221 /// their own section, corresponding to -ffunction-sections.
222 static bool getFunctionSections();
224 /// setDataSections - Set if the data are emit into separate sections.
225 static void setDataSections(bool);
227 /// setFunctionSections - Set if the functions are emit into separate
229 static void setFunctionSections(bool);
231 /// CodeGenFileType - These enums are meant to be passed into
232 /// addPassesToEmitFile to indicate what type of file to emit, and returned by
233 /// it to indicate what type of file could actually be made.
234 enum CodeGenFileType {
237 CGFT_Null // Do not emit any output.
240 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
241 /// specified file emitted. Typically this will involve several steps of code
242 /// generation. This method should return true if emission of this file type
243 /// is not supported, or false on success.
244 virtual bool addPassesToEmitFile(PassManagerBase &,
245 formatted_raw_ostream &,
247 bool /*DisableVerify*/ = true) {
251 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
252 /// get machine code emitted. This uses a JITCodeEmitter object to handle
253 /// actually outputting the machine code and resolving things like the address
254 /// of functions. This method returns true if machine code emission is
257 virtual bool addPassesToEmitMachineCode(PassManagerBase &,
259 bool /*DisableVerify*/ = true) {
263 /// addPassesToEmitMC - Add passes to the specified pass manager to get
264 /// machine code emitted with the MCJIT. This method returns true if machine
265 /// code is not supported. It fills the MCContext Ctx pointer which can be
266 /// used to build custom MCStreamer.
268 virtual bool addPassesToEmitMC(PassManagerBase &,
271 bool /*DisableVerify*/ = true) {
276 /// LLVMTargetMachine - This class describes a target machine that is
277 /// implemented with the LLVM target-independent code generator.
279 class LLVMTargetMachine : public TargetMachine {
280 protected: // Can only create subclasses.
281 LLVMTargetMachine(const Target &T, StringRef TargetTriple,
282 StringRef CPU, StringRef FS, TargetOptions Options,
283 Reloc::Model RM, CodeModel::Model CM,
284 CodeGenOpt::Level OL);
287 /// createPassConfig - Create a pass configuration object to be used by
288 /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
289 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM,
292 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
293 /// specified file emitted. Typically this will involve several steps of code
295 virtual bool addPassesToEmitFile(PassManagerBase &PM,
296 formatted_raw_ostream &Out,
297 CodeGenFileType FileType,
298 bool DisableVerify = true);
300 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
301 /// get machine code emitted. This uses a JITCodeEmitter object to handle
302 /// actually outputting the machine code and resolving things like the address
303 /// of functions. This method returns true if machine code emission is
306 virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
308 bool DisableVerify = true);
310 /// addPassesToEmitMC - Add passes to the specified pass manager to get
311 /// machine code emitted with the MCJIT. This method returns true if machine
312 /// code is not supported. It fills the MCContext Ctx pointer which can be
313 /// used to build custom MCStreamer.
315 virtual bool addPassesToEmitMC(PassManagerBase &PM,
318 bool DisableVerify = true);
320 /// addCodeEmitter - This pass should be overridden by the target to add a
321 /// code emitter, if supported. If this is not supported, 'true' should be
323 virtual bool addCodeEmitter(PassManagerBase &,
329 } // End llvm namespace