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 TargetFrameLowering;
38 class TargetInstrInfo;
39 class TargetIntrinsicInfo;
42 class TargetPassConfig;
43 class TargetRegisterInfo;
44 class TargetSelectionDAGInfo;
45 class TargetSubtargetInfo;
46 class formatted_raw_ostream;
49 //===----------------------------------------------------------------------===//
51 /// TargetMachine - Primary interface to the complete machine description for
52 /// the target machine. All target-specific information should be accessible
53 /// through this interface.
56 TargetMachine(const TargetMachine &) LLVM_DELETED_FUNCTION;
57 void operator=(const TargetMachine &) LLVM_DELETED_FUNCTION;
58 protected: // Can only create subclasses.
59 TargetMachine(const Target &T, StringRef TargetTriple,
60 StringRef CPU, StringRef FS, const TargetOptions &Options);
62 /// getSubtargetImpl - virtual method implemented by subclasses that returns
63 /// a reference to that target's TargetSubtargetInfo-derived member variable.
64 virtual const TargetSubtargetInfo *getSubtargetImpl() const { return 0; }
66 /// TheTarget - The Target that this machine was created for.
67 const Target &TheTarget;
69 /// TargetTriple, TargetCPU, TargetFS - Triple string, CPU name, and target
70 /// feature strings the TargetMachine instance is created with.
71 std::string TargetTriple;
72 std::string TargetCPU;
75 /// CodeGenInfo - Low level target information such as relocation model.
76 const MCCodeGenInfo *CodeGenInfo;
78 /// AsmInfo - Contains target specific asm information.
80 const MCAsmInfo *AsmInfo;
82 unsigned MCRelaxAll : 1;
83 unsigned MCNoExecStack : 1;
84 unsigned MCSaveTempLabels : 1;
85 unsigned MCUseLoc : 1;
86 unsigned MCUseCFI : 1;
87 unsigned MCUseDwarfDirectory : 1;
90 virtual ~TargetMachine();
92 const Target &getTarget() const { return TheTarget; }
94 const StringRef getTargetTriple() const { return TargetTriple; }
95 const StringRef getTargetCPU() const { return TargetCPU; }
96 const StringRef getTargetFeatureString() const { return TargetFS; }
98 TargetOptions Options;
100 // Interfaces to the major aspects of target machine information:
101 // -- Instruction opcode and operand information
102 // -- Pipelines and scheduling information
103 // -- Stack frame information
104 // -- Selection DAG lowering information
106 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
107 virtual const TargetFrameLowering *getFrameLowering() const { return 0; }
108 virtual const TargetLowering *getTargetLowering() const { return 0; }
109 virtual const TargetSelectionDAGInfo *getSelectionDAGInfo() const{ return 0; }
110 virtual const DataLayout *getDataLayout() const { return 0; }
111 virtual const ScalarTargetTransformInfo*
112 getScalarTargetTransformInfo() const { return 0; }
113 virtual const VectorTargetTransformInfo*
114 getVectorTargetTransformInfo() const { return 0; }
116 /// getMCAsmInfo - Return target specific asm information.
118 const MCAsmInfo *getMCAsmInfo() const { return AsmInfo; }
120 /// getSubtarget - This method returns a pointer to the specified type of
121 /// TargetSubtargetInfo. In debug builds, it verifies that the object being
122 /// returned is of the correct type.
123 template<typename STC> const STC &getSubtarget() const {
124 return *static_cast<const STC*>(getSubtargetImpl());
127 /// getRegisterInfo - If register information is available, return it. If
128 /// not, return null. This is kept separate from RegInfo until RegInfo has
129 /// details of graph coloring register allocation removed from it.
131 virtual const TargetRegisterInfo *getRegisterInfo() const { return 0; }
133 /// getIntrinsicInfo - If intrinsic information is available, return it. If
134 /// not, return null.
136 virtual const TargetIntrinsicInfo *getIntrinsicInfo() const { return 0; }
138 /// getJITInfo - If this target supports a JIT, return information for it,
139 /// otherwise return null.
141 virtual TargetJITInfo *getJITInfo() { return 0; }
143 /// getInstrItineraryData - Returns instruction itinerary data for the target
144 /// or specific subtarget.
146 virtual const InstrItineraryData *getInstrItineraryData() const {
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 /// getTLSModel - Returns the TLS model which should be used for the given
202 TLSModel::Model getTLSModel(const GlobalValue *GV) const;
204 /// getOptLevel - Returns the optimization level: None, Less,
205 /// Default, or Aggressive.
206 CodeGenOpt::Level getOptLevel() const;
208 void setFastISel(bool Enable) { Options.EnableFastISel = Enable; }
210 bool shouldPrintMachineCode() const { return Options.PrintMachineCode; }
212 /// getAsmVerbosityDefault - Returns the default value of asm verbosity.
214 static bool getAsmVerbosityDefault();
216 /// setAsmVerbosityDefault - Set the default value of asm verbosity. Default
218 static void setAsmVerbosityDefault(bool);
220 /// getDataSections - Return true if data objects should be emitted into their
221 /// own section, corresponds to -fdata-sections.
222 static bool getDataSections();
224 /// getFunctionSections - Return true if functions should be emitted into
225 /// their own section, corresponding to -ffunction-sections.
226 static bool getFunctionSections();
228 /// setDataSections - Set if the data are emit into separate sections.
229 static void setDataSections(bool);
231 /// setFunctionSections - Set if the functions are emit into separate
233 static void setFunctionSections(bool);
235 /// CodeGenFileType - These enums are meant to be passed into
236 /// addPassesToEmitFile to indicate what type of file to emit, and returned by
237 /// it to indicate what type of file could actually be made.
238 enum CodeGenFileType {
241 CGFT_Null // Do not emit any output.
244 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
245 /// specified file emitted. Typically this will involve several steps of code
246 /// generation. This method should return true if emission of this file type
247 /// is not supported, or false on success.
248 virtual bool addPassesToEmitFile(PassManagerBase &,
249 formatted_raw_ostream &,
251 bool /*DisableVerify*/ = true,
252 AnalysisID StartAfter = 0,
253 AnalysisID StopAfter = 0) {
257 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
258 /// get machine code emitted. This uses a JITCodeEmitter object to handle
259 /// actually outputting the machine code and resolving things like the address
260 /// of functions. This method returns true if machine code emission is
263 virtual bool addPassesToEmitMachineCode(PassManagerBase &,
265 bool /*DisableVerify*/ = true) {
269 /// addPassesToEmitMC - Add passes to the specified pass manager to get
270 /// machine code emitted with the MCJIT. This method returns true if machine
271 /// code is not supported. It fills the MCContext Ctx pointer which can be
272 /// used to build custom MCStreamer.
274 virtual bool addPassesToEmitMC(PassManagerBase &,
277 bool /*DisableVerify*/ = true) {
282 /// LLVMTargetMachine - This class describes a target machine that is
283 /// implemented with the LLVM target-independent code generator.
285 class LLVMTargetMachine : public TargetMachine {
286 protected: // Can only create subclasses.
287 LLVMTargetMachine(const Target &T, StringRef TargetTriple,
288 StringRef CPU, StringRef FS, TargetOptions Options,
289 Reloc::Model RM, CodeModel::Model CM,
290 CodeGenOpt::Level OL);
293 /// createPassConfig - Create a pass configuration object to be used by
294 /// addPassToEmitX methods for generating a pipeline of CodeGen passes.
295 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
297 /// addPassesToEmitFile - Add passes to the specified pass manager to get the
298 /// specified file emitted. Typically this will involve several steps of code
300 virtual bool addPassesToEmitFile(PassManagerBase &PM,
301 formatted_raw_ostream &Out,
302 CodeGenFileType FileType,
303 bool DisableVerify = true,
304 AnalysisID StartAfter = 0,
305 AnalysisID StopAfter = 0);
307 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
308 /// get machine code emitted. This uses a JITCodeEmitter object to handle
309 /// actually outputting the machine code and resolving things like the address
310 /// of functions. This method returns true if machine code emission is
313 virtual bool addPassesToEmitMachineCode(PassManagerBase &PM,
315 bool DisableVerify = true);
317 /// addPassesToEmitMC - Add passes to the specified pass manager to get
318 /// machine code emitted with the MCJIT. This method returns true if machine
319 /// code is not supported. It fills the MCContext Ctx pointer which can be
320 /// used to build custom MCStreamer.
322 virtual bool addPassesToEmitMC(PassManagerBase &PM,
325 bool DisableVerify = true);
327 /// addCodeEmitter - This pass should be overridden by the target to add a
328 /// code emitter, if supported. If this is not supported, 'true' should be
330 virtual bool addCodeEmitter(PassManagerBase &,
336 } // End llvm namespace