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/Support/CodeGen.h"
18 #include "llvm/Target/TargetOptions.h"
19 #include "llvm/ADT/StringRef.h"
25 class InstrItineraryData;
31 class PassManagerBase;
34 class TargetELFWriterInfo;
35 class TargetFrameLowering;
36 class TargetInstrInfo;
37 class TargetIntrinsicInfo;
40 class TargetPassConfig;
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 /// getTLSModel - Returns the TLS model which should be used for the given
201 TLSModel::Model getTLSModel(const GlobalValue *GV) const;
203 /// getOptLevel - Returns the optimization level: None, Less,
204 /// Default, or Aggressive.
205 CodeGenOpt::Level getOptLevel() const;
207 void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
209 bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
211 /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
213 static bool getAsmVerbosityDefault();
215 /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
217 static void setAsmVerbosityDefault(bool);
219 /// getDataSections - Return true if data objects should be emitted into their
220 /// own section, corresponds to -fdata-sections.
221 static bool getDataSections();
223 /// getFunctionSections - Return true if functions should be emitted into
224 /// their own section, corresponding to -ffunction-sections.
225 static bool getFunctionSections();
227 /// setDataSections - Set if the data are emit into separate sections.
228 static void setDataSections(bool);
230 /// setFunctionSections - Set if the functions are emit into separate
232 static void setFunctionSections(bool);
234 /// CodeGenFileType - These enums are meant to be passed into
235 /// addPassesToEmitFile to indicate what type of file to emit, and returned by
236 /// it to indicate what type of file could actually be made.
237 enum CodeGenFileType {
240 CGFT_Null // Do not emit any output.
243 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
244 /// specified file emitted. Typically this will involve several steps of code
245 /// generation. This method should return true if emission of this file type
246 /// is not supported, or false on success.
247 virtual bool addPassesToEmitFile(PassManagerBase &,
248 formatted_raw_ostream &,
250 bool /*DisableVerify*/ = true) {
254 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
255 /// get machine code emitted. This uses a JITCodeEmitter object to handle
256 /// actually outputting the machine code and resolving things like the address
257 /// of functions. This method returns true if machine code emission is
260 virtual bool addPassesToEmitMachineCode(PassManagerBase &,
262 bool /*DisableVerify*/ = true) {
266 /// addPassesToEmitMC - Add passes to the specified pass manager to get
267 /// machine code emitted with the MCJIT. This method returns true if machine
268 /// code is not supported. It fills the MCContext Ctx pointer which can be
269 /// used to build custom MCStreamer.
271 virtual bool addPassesToEmitMC(PassManagerBase &,
274 bool /*DisableVerify*/ = true) {
279 /// LLVMTargetMachine - This class describes a target machine that is
280 /// implemented with the LLVM target-independent code generator.
282 class LLVMTargetMachine : public TargetMachine {
283 protected: // Can only create subclasses.
284 LLVMTargetMachine(const Target &T, StringRef TargetTriple,
285 StringRef CPU, StringRef FS, TargetOptions Options,
286 Reloc::Model RM, CodeModel::Model CM,
287 CodeGenOpt::Level OL);
290 /// createPassConfig - Create a pass configuration object to be used by
291 /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
292 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
294 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
295 /// specified file emitted. Typically this will involve several steps of code
297 virtual bool addPassesToEmitFile(PassManagerBase &PM,
298 formatted_raw_ostream &Out,
299 CodeGenFileType FileType,
300 bool DisableVerify = true);
302 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
303 /// get machine code emitted. This uses a JITCodeEmitter object to handle
304 /// actually outputting the machine code and resolving things like the address
305 /// of functions. This method returns true if machine code emission is
308 virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
310 bool DisableVerify = true);
312 /// addPassesToEmitMC - Add passes to the specified pass manager to get
313 /// machine code emitted with the MCJIT. This method returns true if machine
314 /// code is not supported. It fills the MCContext Ctx pointer which can be
315 /// used to build custom MCStreamer.
317 virtual bool addPassesToEmitMC(PassManagerBase &PM,
320 bool DisableVerify = true);
322 /// addCodeEmitter - This pass should be overridden by the target to add a
323 /// code emitter, if supported. If this is not supported, 'true' should be
325 virtual bool addCodeEmitter(PassManagerBase &,
331 } // End llvm namespace