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;
27 class TargetSchedInfo;
29 class TargetFrameInfo;
30 class MachineCodeEmitter;
32 class FunctionPassManager;
35 class IntrinsicLowering;
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
56 IntrinsicLowering *IL; // Specifies how to lower intrinsic calls
58 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT
59 void operator=(const TargetMachine&); // DO NOT IMPLEMENT
60 protected: // Can only create subclasses...
61 TargetMachine(const std::string &name, IntrinsicLowering *IL,
62 bool LittleEndian = false,
63 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
64 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
65 unsigned char LongAl = 8, unsigned char IntAl = 4,
66 unsigned char ShortAl = 2, unsigned char ByteAl = 1,
67 unsigned char BoolAl = 1);
69 TargetMachine(const std::string &name, IntrinsicLowering *IL,
70 const TargetData &TD);
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, IntrinsicLowering *IL,
79 /// getSubtargetImpl - virtual method implemented by subclasses that returns
80 /// a reference to that target's TargetSubtarget-derived member variable.
81 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
83 virtual ~TargetMachine();
85 /// getModuleMatchQuality - This static method should be implemented by
86 /// targets to indicate how closely they match the specified module. This is
87 /// used by the LLC tool to determine which target to use when an explicit
88 /// -march option is not specified. If a target returns zero, it will never
89 /// be chosen without an explicit -march option.
90 static unsigned getModuleMatchQuality(const Module &M) { return 0; }
92 /// getJITMatchQuality - This static method should be implemented by targets
93 /// that provide JIT capabilities to indicate how suitable they are for
94 /// execution on the current host. If a value of 0 is returned, the target
95 /// will not be used unless an explicit -march option is used.
96 static unsigned getJITMatchQuality() { return 0; }
99 const std::string &getName() const { return Name; }
101 /// getIntrinsicLowering - This method returns a reference to an
102 /// IntrinsicLowering instance which should be used by the code generator to
103 /// lower unknown intrinsic functions to the equivalent LLVM expansion.
105 IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
107 // Interfaces to the major aspects of target machine information:
108 // -- Instruction opcode and operand information
109 // -- Pipelines and scheduling information
110 // -- Stack frame information
112 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
113 virtual const TargetFrameInfo *getFrameInfo() const { return 0; }
114 const TargetData &getTargetData() const { return DataLayout; }
116 /// getSubtarget - This method returns a pointer to the specified type of
117 /// TargetSubtarget. In debug builds, it verifies that the object being
118 /// returned is of the correct type.
119 template<typename STC> const STC &getSubtarget() const {
120 const TargetSubtarget *TST = getSubtargetImpl();
121 assert(TST && dynamic_cast<const STC*>(TST) &&
122 "Not the right kind of subtarget!");
123 return *static_cast<const STC*>(TST);
126 /// getRegisterInfo - If register information is available, return it. If
127 /// not, return null. This is kept separate from RegInfo until RegInfo has
128 /// details of graph coloring register allocation removed from it.
130 virtual const MRegisterInfo* getRegisterInfo() 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 {
141 return InstrItineraryData();
144 // These are deprecated interfaces.
145 virtual const TargetSchedInfo *getSchedInfo() const { return 0; }
146 virtual const SparcV9RegInfo *getRegInfo() const { return 0; }
148 /// getRelocationModel - Returns the code generation relocation model. The
149 /// choices are static, PIC, and dynamic-no-pic, and target default.
150 static Reloc::Model getRelocationModel();
152 /// setRelocationModel - Sets the code generation relocation model.
153 static void setRelocationModel(Reloc::Model Model);
155 /// CodeGenFileType - These enums are meant to be passed into
156 /// addPassesToEmitFile to indicate what type of file to emit.
157 enum CodeGenFileType {
158 AssemblyFile, ObjectFile, DynamicLibrary
161 /// addPassesToEmitFile - Add passes to the specified pass manager to get
162 /// the specified file emitted. Typically this will involve several steps of
163 /// code generation. If Fast is set to true, the code generator should emit
164 /// code as fast as possible, without regard for compile time. This method
165 /// should return true if emission of this file type is not supported.
167 virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
168 CodeGenFileType FileType, bool Fast) {
172 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
173 /// get machine code emitted. This uses a MachineCodeEmitter object to handle
174 /// actually outputting the machine code and resolving things like the address
175 /// of functions. This method should returns true if machine code emission is
178 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
179 MachineCodeEmitter &MCE) {
184 } // End llvm namespace