1 //===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/TargetInstrItineraries.h"
24 class TargetSubtarget;
25 class TargetInstrInfo;
26 class TargetInstrDescriptor;
29 class TargetFrameInfo;
30 class MachineCodeEmitter;
33 class FunctionPassManager;
37 // Relocation model types.
42 PIC_, // Cannot be named PIC due to collision with -DPIC
58 //===----------------------------------------------------------------------===//
60 /// TargetMachine - Primary interface to the complete machine description for
61 /// the target machine. All target-specific information should be accessible
62 /// through this interface.
65 TargetMachine(const TargetMachine &); // DO NOT IMPLEMENT
66 void operator=(const TargetMachine &); // DO NOT IMPLEMENT
67 protected: // Can only create subclasses.
70 /// getSubtargetImpl - virtual method implemented by subclasses that returns
71 /// a reference to that target's TargetSubtarget-derived member variable.
72 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
74 virtual ~TargetMachine();
76 /// getModuleMatchQuality - This static method should be implemented by
77 /// targets to indicate how closely they match the specified module. This is
78 /// used by the LLC tool to determine which target to use when an explicit
79 /// -march option is not specified. If a target returns zero, it will never
80 /// be chosen without an explicit -march option.
81 static unsigned getModuleMatchQuality(const Module &M) { return 0; }
83 /// getJITMatchQuality - This static method should be implemented by targets
84 /// that provide JIT capabilities to indicate how suitable they are for
85 /// execution on the current host. If a value of 0 is returned, the target
86 /// will not be used unless an explicit -march option is used.
87 static unsigned getJITMatchQuality() { return 0; }
89 // Interfaces to the major aspects of target machine information:
90 // -- Instruction opcode and operand information
91 // -- Pipelines and scheduling information
92 // -- Stack frame information
93 // -- Selection DAG lowering information
95 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
96 virtual const TargetFrameInfo *getFrameInfo() const { return 0; }
97 virtual TargetLowering *getTargetLowering() const { return 0; }
98 virtual const TargetData *getTargetData() const { return 0; }
100 /// getSubtarget - This method returns a pointer to the specified type of
101 /// TargetSubtarget. In debug builds, it verifies that the object being
102 /// returned is of the correct type.
103 template<typename STC> const STC &getSubtarget() const {
104 const TargetSubtarget *TST = getSubtargetImpl();
105 assert(TST && dynamic_cast<const STC*>(TST) &&
106 "Not the right kind of subtarget!");
107 return *static_cast<const STC*>(TST);
110 /// getRegisterInfo - If register information is available, return it. If
111 /// not, return null. This is kept separate from RegInfo until RegInfo has
112 /// details of graph coloring register allocation removed from it.
114 virtual const MRegisterInfo *getRegisterInfo() const { return 0; }
116 /// getJITInfo - If this target supports a JIT, return information for it,
117 /// otherwise return null.
119 virtual TargetJITInfo *getJITInfo() { return 0; }
121 /// getInstrItineraryData - Returns instruction itinerary data for the target
122 /// or specific subtarget.
124 virtual const InstrItineraryData getInstrItineraryData() const {
125 return InstrItineraryData();
128 /// getRelocationModel - Returns the code generation relocation model. The
129 /// choices are static, PIC, and dynamic-no-pic, and target default.
130 static Reloc::Model getRelocationModel();
132 /// setRelocationModel - Sets the code generation relocation model.
133 static void setRelocationModel(Reloc::Model Model);
135 /// getCodeModel - Returns the code model. The choices are small, kernel,
136 /// medium, large, and target default.
137 static CodeModel::Model getCodeModel();
139 /// setCodeModel - Sets the code model.
140 static void setCodeModel(CodeModel::Model Model);
142 /// CodeGenFileType - These enums are meant to be passed into
143 /// addPassesToEmitFile to indicate what type of file to emit.
144 enum CodeGenFileType {
145 AssemblyFile, ObjectFile, DynamicLibrary
148 /// addPassesToEmitFile - Add passes to the specified pass manager to get
149 /// the specified file emitted. Typically this will involve several steps of
150 /// code generation. If Fast is set to true, the code generator should emit
151 /// code as fast as possible, without regard for compile time. This method
152 /// should return true if emission of this file type is not supported.
154 virtual bool addPassesToEmitFile(FunctionPassManager &PM, std::ostream &Out,
155 CodeGenFileType FileType, bool Fast) {
159 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
160 /// get machine code emitted. This uses a MachineCodeEmitter object to handle
161 /// actually outputting the machine code and resolving things like the address
162 /// of functions. This method returns true if machine code emission is
165 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
166 MachineCodeEmitter &MCE, bool Fast) {
171 /// addPassesToEmitWholeFile - This method can be implemented by targets that
172 /// require having the entire module at once. This is not recommended, do not
174 virtual bool WantsWholeFile() const { return false; }
175 virtual bool addPassesToEmitWholeFile(PassManager &PM, std::ostream &Out,
176 CodeGenFileType FileType, bool Fast) {
181 /// LLVMTargetMachine - This class describes a target machine that is
182 /// implemented with the LLVM target-independent code generator.
184 class LLVMTargetMachine : public TargetMachine {
185 protected: // Can only create subclasses.
186 LLVMTargetMachine() { }
189 /// addPassesToEmitFile - Add passes to the specified pass manager to get
190 /// the specified file emitted. Typically this will involve several steps of
191 /// code generation. If Fast is set to true, the code generator should emit
192 /// code as fast as possible, without regard for compile time. This method
193 /// should return true if emission of this file type is not supported.
195 /// The default implementation of this method adds components from the
196 /// LLVM retargetable code generator, invoking the methods below to get
197 /// target-specific passes in standard locations.
199 virtual bool addPassesToEmitFile(FunctionPassManager &PM, std::ostream &Out,
200 CodeGenFileType FileType, bool Fast);
202 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
203 /// get machine code emitted. This uses a MachineCodeEmitter object to handle
204 /// actually outputting the machine code and resolving things like the address
205 /// of functions. This method returns true if machine code emission is
208 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
209 MachineCodeEmitter &MCE, bool Fast);
211 /// Target-Independent Code Generator Pass Configuration Options.
213 /// addInstSelector - This method should add any "last minute" LLVM->LLVM
214 /// passes, then install an instruction selector pass, which converts from
215 /// LLVM code to machine instructions.
216 virtual bool addInstSelector(FunctionPassManager &PM, bool Fast) {
220 /// addPostRegAllocPasses - This method may be implemented by targets that
221 /// want to run passes after register allocation but before prolog-epilog
222 /// insertion. This should return true if -print-machineinstrs should print
223 /// after these passes.
224 virtual bool addPostRegAlloc(FunctionPassManager &PM, bool Fast) {
228 /// addPreEmitPass - This pass may be implemented by targets that want to run
229 /// passes immediately before machine code is emitted. This should return
230 /// true if -print-machineinstrs should print out the code after the passes.
231 virtual bool addPreEmitPass(FunctionPassManager &PM, bool Fast) {
236 /// addAssemblyEmitter - This pass should be overridden by the target to add
237 /// the asmprinter, if asm emission is supported. If this is not supported,
238 /// 'true' should be returned.
239 virtual bool addAssemblyEmitter(FunctionPassManager &PM, bool Fast,
244 /// addObjectWriter - This pass should be overridden by the target to add
245 /// the object-file writer, if supported. If this is not supported,
246 /// 'true' should be returned.
247 virtual bool addObjectWriter(FunctionPassManager &PM, bool Fast,
252 /// addCodeEmitter - This pass should be overridden by the target to add a
253 /// code emitter, if supported. If this is not supported, 'true' should be
255 virtual bool addCodeEmitter(FunctionPassManager &PM, bool Fast,
256 MachineCodeEmitter &MCE) {
261 } // End llvm namespace