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/TargetData.h"
18 #include "llvm/Target/TargetInstrItineraries.h"
23 class TargetSubtarget;
24 class TargetInstrInfo;
25 class TargetInstrDescriptor;
28 class TargetSchedInfo;
30 class TargetFrameInfo;
31 class MachineCodeEmitter;
33 class FunctionPassManager;
37 // Relocation model types.
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 const std::string Name;
55 const TargetData DataLayout; // Calculates type size & alignment
57 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT
58 void operator=(const TargetMachine&); // DO NOT IMPLEMENT
59 protected: // Can only create subclasses...
60 TargetMachine(const std::string &name, bool LittleEndian = false,
61 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
62 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
63 unsigned char LongAl = 8, unsigned char IntAl = 4,
64 unsigned char ShortAl = 2, unsigned char ByteAl = 1,
65 unsigned char BoolAl = 1);
67 TargetMachine(const std::string &name, const TargetData &TD);
69 /// This constructor is used for targets that support arbitrary TargetData
70 /// layouts, like the C backend. It initializes the TargetData to match that
71 /// of the specified module.
73 TargetMachine(const std::string &name, const Module &M);
75 /// getSubtargetImpl - virtual method implemented by subclasses that returns
76 /// a reference to that target's TargetSubtarget-derived member variable.
77 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
79 virtual ~TargetMachine();
81 /// getModuleMatchQuality - This static method should be implemented by
82 /// targets to indicate how closely they match the specified module. This is
83 /// used by the LLC tool to determine which target to use when an explicit
84 /// -march option is not specified. If a target returns zero, it will never
85 /// be chosen without an explicit -march option.
86 static unsigned getModuleMatchQuality(const Module &M) { return 0; }
88 /// getJITMatchQuality - This static method should be implemented by targets
89 /// that provide JIT capabilities to indicate how suitable they are for
90 /// execution on the current host. If a value of 0 is returned, the target
91 /// will not be used unless an explicit -march option is used.
92 static unsigned getJITMatchQuality() { return 0; }
95 const std::string &getName() const { return Name; }
97 // Interfaces to the major aspects of target machine information:
98 // -- Instruction opcode and operand information
99 // -- Pipelines and scheduling information
100 // -- Stack frame information
101 // -- Selection DAG lowering information
103 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
104 virtual const TargetFrameInfo *getFrameInfo() const { return 0; }
105 virtual TargetLowering *getTargetLowering() const { return 0; }
106 const TargetData &getTargetData() const { return DataLayout; }
108 /// getSubtarget - This method returns a pointer to the specified type of
109 /// TargetSubtarget. In debug builds, it verifies that the object being
110 /// returned is of the correct type.
111 template<typename STC> const STC &getSubtarget() const {
112 const TargetSubtarget *TST = getSubtargetImpl();
113 assert(TST && dynamic_cast<const STC*>(TST) &&
114 "Not the right kind of subtarget!");
115 return *static_cast<const STC*>(TST);
118 /// getRegisterInfo - If register information is available, return it. If
119 /// not, return null. This is kept separate from RegInfo until RegInfo has
120 /// details of graph coloring register allocation removed from it.
122 virtual const MRegisterInfo* getRegisterInfo() const { return 0; }
124 /// getJITInfo - If this target supports a JIT, return information for it,
125 /// otherwise return null.
127 virtual TargetJITInfo *getJITInfo() { return 0; }
129 /// getInstrItineraryData - Returns instruction itinerary data for the target
130 /// or specific subtarget.
132 virtual const InstrItineraryData getInstrItineraryData() const {
133 return InstrItineraryData();
136 // These are deprecated interfaces.
137 virtual const TargetSchedInfo *getSchedInfo() const { return 0; }
138 virtual const SparcV9RegInfo *getRegInfo() const { return 0; }
140 /// getRelocationModel - Returns the code generation relocation model. The
141 /// choices are static, PIC, and dynamic-no-pic, and target default.
142 static Reloc::Model getRelocationModel();
144 /// setRelocationModel - Sets the code generation relocation model.
145 static void setRelocationModel(Reloc::Model Model);
147 /// CodeGenFileType - These enums are meant to be passed into
148 /// addPassesToEmitFile to indicate what type of file to emit.
149 enum CodeGenFileType {
150 AssemblyFile, ObjectFile, DynamicLibrary
153 /// addPassesToEmitFile - Add passes to the specified pass manager to get
154 /// the specified file emitted. Typically this will involve several steps of
155 /// code generation. If Fast is set to true, the code generator should emit
156 /// code as fast as possible, without regard for compile time. This method
157 /// should return true if emission of this file type is not supported.
159 virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
160 CodeGenFileType FileType, bool Fast) {
164 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
165 /// get machine code emitted. This uses a MachineCodeEmitter object to handle
166 /// actually outputting the machine code and resolving things like the address
167 /// of functions. This method should returns true if machine code emission is
170 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
171 MachineCodeEmitter &MCE) {
176 } // End llvm namespace