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 describes the general parts of a Target machine.
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 const std::string Name;
67 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT
68 void operator=(const TargetMachine&); // DO NOT IMPLEMENT
69 protected: // Can only create subclasses...
70 TargetMachine(const std::string &name) : Name(name) { };
72 /// This constructor is used for targets that support arbitrary TargetData
73 /// layouts, like the C backend. It initializes the TargetData to match that
74 /// of the specified module.
76 TargetMachine(const std::string &name, const Module &M);
78 /// getSubtargetImpl - virtual method implemented by subclasses that returns
79 /// a reference to that target's TargetSubtarget-derived member variable.
80 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
82 virtual ~TargetMachine();
84 /// getModuleMatchQuality - This static method should be implemented by
85 /// targets to indicate how closely they match the specified module. This is
86 /// used by the LLC tool to determine which target to use when an explicit
87 /// -march option is not specified. If a target returns zero, it will never
88 /// be chosen without an explicit -march option.
89 static unsigned getModuleMatchQuality(const Module &M) { return 0; }
91 /// getJITMatchQuality - This static method should be implemented by targets
92 /// that provide JIT capabilities to indicate how suitable they are for
93 /// execution on the current host. If a value of 0 is returned, the target
94 /// will not be used unless an explicit -march option is used.
95 static unsigned getJITMatchQuality() { return 0; }
98 const std::string &getName() const { return Name; }
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 TargetFrameInfo *getFrameInfo() const { return 0; }
108 virtual TargetLowering *getTargetLowering() const { return 0; }
109 virtual const TargetData *getTargetData() const { return 0; }
111 /// getSubtarget - This method returns a pointer to the specified type of
112 /// TargetSubtarget. In debug builds, it verifies that the object being
113 /// returned is of the correct type.
114 template<typename STC> const STC &getSubtarget() const {
115 const TargetSubtarget *TST = getSubtargetImpl();
116 assert(TST && dynamic_cast<const STC*>(TST) &&
117 "Not the right kind of subtarget!");
118 return *static_cast<const STC*>(TST);
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 MRegisterInfo* getRegisterInfo() const { return 0; }
127 /// getJITInfo - If this target supports a JIT, return information for it,
128 /// otherwise return null.
130 virtual TargetJITInfo *getJITInfo() { return 0; }
132 /// getInstrItineraryData - Returns instruction itinerary data for the target
133 /// or specific subtarget.
135 virtual const InstrItineraryData getInstrItineraryData() const {
136 return InstrItineraryData();
139 /// getRelocationModel - Returns the code generation relocation model. The
140 /// choices are static, PIC, and dynamic-no-pic, and target default.
141 static Reloc::Model getRelocationModel();
143 /// setRelocationModel - Sets the code generation relocation model.
144 static void setRelocationModel(Reloc::Model Model);
146 /// getCodeModel - Returns the code model. The choices are small, kernel,
147 /// medium, large, and target default.
148 static CodeModel::Model getCodeModel();
150 /// setCodeModel - Sets the code model.
151 static void setCodeModel(CodeModel::Model Model);
153 /// CodeGenFileType - These enums are meant to be passed into
154 /// addPassesToEmitFile to indicate what type of file to emit.
155 enum CodeGenFileType {
156 AssemblyFile, ObjectFile, DynamicLibrary
159 /// addPassesToEmitFile - Add passes to the specified pass manager to get
160 /// the specified file emitted. Typically this will involve several steps of
161 /// code generation. If Fast is set to true, the code generator should emit
162 /// code as fast as possible, without regard for compile time. This method
163 /// should return true if emission of this file type is not supported.
165 virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
166 CodeGenFileType FileType, bool Fast) {
170 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
171 /// get machine code emitted. This uses a MachineCodeEmitter object to handle
172 /// actually outputting the machine code and resolving things like the address
173 /// of functions. This method should returns true if machine code emission is
176 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
177 MachineCodeEmitter &MCE) {
182 } // End llvm namespace