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 //===----------------------------------------------------------------------===//
39 /// TargetMachine - Primary interface to the complete machine description for
40 /// the target machine. All target-specific information should be accessible
41 /// through this interface.
44 const std::string Name;
45 const TargetData DataLayout; // Calculates type size & alignment
46 IntrinsicLowering *IL; // Specifies how to lower intrinsic calls
48 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT
49 void operator=(const TargetMachine&); // DO NOT IMPLEMENT
50 protected: // Can only create subclasses...
51 TargetMachine(const std::string &name, IntrinsicLowering *IL,
52 bool LittleEndian = false,
53 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
54 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
55 unsigned char LongAl = 8, unsigned char IntAl = 4,
56 unsigned char ShortAl = 2, unsigned char ByteAl = 1,
57 unsigned char BoolAl = 1);
59 TargetMachine(const std::string &name, IntrinsicLowering *IL,
60 const TargetData &TD);
62 /// This constructor is used for targets that support arbitrary TargetData
63 /// layouts, like the C backend. It initializes the TargetData to match that
64 /// of the specified module.
66 TargetMachine(const std::string &name, IntrinsicLowering *IL,
69 /// getSubtargetImpl - virtual method implemented by subclasses that returns
70 /// a reference to that target's TargetSubtarget-derived member variable.
71 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
73 virtual ~TargetMachine();
75 /// getModuleMatchQuality - This static method should be implemented by
76 /// targets to indicate how closely they match the specified module. This is
77 /// used by the LLC tool to determine which target to use when an explicit
78 /// -march option is not specified. If a target returns zero, it will never
79 /// be chosen without an explicit -march option.
80 static unsigned getModuleMatchQuality(const Module &M) { return 0; }
82 /// getJITMatchQuality - This static method should be implemented by targets
83 /// that provide JIT capabilities to indicate how suitable they are for
84 /// execution on the current host. If a value of 0 is returned, the target
85 /// will not be used unless an explicit -march option is used.
86 static unsigned getJITMatchQuality() { return 0; }
89 const std::string &getName() const { return Name; }
91 /// getIntrinsicLowering - This method returns a reference to an
92 /// IntrinsicLowering instance which should be used by the code generator to
93 /// lower unknown intrinsic functions to the equivalent LLVM expansion.
95 IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
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
102 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
103 virtual const TargetFrameInfo *getFrameInfo() const { return 0; }
104 const TargetData &getTargetData() const { return DataLayout; }
106 /// getSubtarget - This method returns a pointer to the specified type of
107 /// TargetSubtarget. In debug builds, it verifies that the object being
108 /// returned is of the correct type.
109 template<typename STC> const STC &getSubtarget() const {
110 const TargetSubtarget *TST = getSubtargetImpl();
111 assert(TST && dynamic_cast<const STC*>(TST) &&
112 "Not the right kind of subtarget!");
113 return *static_cast<const STC*>(TST);
116 /// getRegisterInfo - If register information is available, return it. If
117 /// not, return null. This is kept separate from RegInfo until RegInfo has
118 /// details of graph coloring register allocation removed from it.
120 virtual const MRegisterInfo* getRegisterInfo() const { return 0; }
122 /// getJITInfo - If this target supports a JIT, return information for it,
123 /// otherwise return null.
125 virtual TargetJITInfo *getJITInfo() { return 0; }
127 /// getInstrItineraryData - Returns instruction itinerary data for the target
128 /// or specific subtarget.
130 virtual const InstrItineraryData getInstrItineraryData() const {
131 return InstrItineraryData();
134 // These are deprecated interfaces.
135 virtual const TargetSchedInfo *getSchedInfo() const { return 0; }
136 virtual const SparcV9RegInfo *getRegInfo() const { return 0; }
138 /// CodeGenFileType - These enums are meant to be passed into
139 /// addPassesToEmitFile to indicate what type of file to emit.
140 enum CodeGenFileType {
141 AssemblyFile, ObjectFile, DynamicLibrary
144 /// addPassesToEmitFile - Add passes to the specified pass manager to get
145 /// the specified file emitted. Typically this will involve several steps of
146 /// code generation. If Fast is set to true, the code generator should emit
147 /// code as fast as possible, without regard for compile time. This method
148 /// should return true if emission of this file type is not supported.
150 virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
151 CodeGenFileType FileType, bool Fast) {
155 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
156 /// get machine code emitted. This uses a MachineCodeEmitter object to handle
157 /// actually outputting the machine code and resolving things like the address
158 /// of functions. This method should returns true if machine code emission is
161 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
162 MachineCodeEmitter &MCE) {
167 } // End llvm namespace