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"
22 class TargetSubtarget;
23 class TargetInstrInfo;
24 class TargetInstrDescriptor;
26 class TargetSchedInfo;
28 class TargetFrameInfo;
29 class MachineCodeEmitter;
31 class FunctionPassManager;
34 class IntrinsicLowering;
36 //===----------------------------------------------------------------------===//
38 /// TargetMachine - Primary interface to the complete machine description for
39 /// the target machine. All target-specific information should be accessible
40 /// through this interface.
43 const std::string Name;
44 const TargetData DataLayout; // Calculates type size & alignment
45 IntrinsicLowering *IL; // Specifies how to lower intrinsic calls
47 TargetMachine(const TargetMachine&); // DO NOT IMPLEMENT
48 void operator=(const TargetMachine&); // DO NOT IMPLEMENT
49 protected: // Can only create subclasses...
50 TargetMachine(const std::string &name, IntrinsicLowering *IL,
51 bool LittleEndian = false,
52 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
53 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
54 unsigned char LongAl = 8, unsigned char IntAl = 4,
55 unsigned char ShortAl = 2, unsigned char ByteAl = 1,
56 unsigned char BoolAl = 1);
58 TargetMachine(const std::string &name, IntrinsicLowering *IL,
59 const TargetData &TD);
61 /// This constructor is used for targets that support arbitrary TargetData
62 /// layouts, like the C backend. It initializes the TargetData to match that
63 /// of the specified module.
65 TargetMachine(const std::string &name, IntrinsicLowering *IL,
68 /// getSubtargetImpl - virtual method implemented by subclasses that returns
69 /// a reference to that target's TargetSubtarget-derived member variable.
70 virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
72 virtual ~TargetMachine();
74 /// getModuleMatchQuality - This static method should be implemented by
75 /// targets to indicate how closely they match the specified module. This is
76 /// used by the LLC tool to determine which target to use when an explicit
77 /// -march option is not specified. If a target returns zero, it will never
78 /// be chosen without an explicit -march option.
79 static unsigned getModuleMatchQuality(const Module &M) { return 0; }
81 /// getJITMatchQuality - This static method should be implemented by targets
82 /// that provide JIT capabilities to indicate how suitable they are for
83 /// execution on the current host. If a value of 0 is returned, the target
84 /// will not be used unless an explicit -march option is used.
85 static unsigned getJITMatchQuality() { return 0; }
88 const std::string &getName() const { return Name; }
90 /// getIntrinsicLowering - This method returns a reference to an
91 /// IntrinsicLowering instance which should be used by the code generator to
92 /// lower unknown intrinsic functions to the equivalent LLVM expansion.
94 IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
96 // Interfaces to the major aspects of target machine information:
97 // -- Instruction opcode and operand information
98 // -- Pipelines and scheduling information
99 // -- Stack frame information
101 virtual const TargetInstrInfo *getInstrInfo() const { return 0; }
102 virtual const TargetFrameInfo *getFrameInfo() const { return 0; }
103 const TargetData &getTargetData() const { return DataLayout; }
105 /// getSubtarget - This method returns a pointer to the specified type of
106 /// TargetSubtarget. In debug builds, it verifies that the object being
107 /// returned is of the correct type.
108 template<typename STC> STC *getSubtarget() const {
109 const TargetSubtarget *TST = getSubtargetImpl();
110 assert(getSubtargetImpl() && dynamic_cast<STC*>(TST) &&
111 "Not the right kind of subtarget!");
115 /// getRegisterInfo - If register information is available, return it. If
116 /// not, return null. This is kept separate from RegInfo until RegInfo has
117 /// details of graph coloring register allocation removed from it.
119 virtual const MRegisterInfo* getRegisterInfo() const { return 0; }
121 /// getJITInfo - If this target supports a JIT, return information for it,
122 /// otherwise return null.
124 virtual TargetJITInfo *getJITInfo() { return 0; }
126 // These are deprecated interfaces.
127 virtual const TargetSchedInfo *getSchedInfo() const { return 0; }
128 virtual const SparcV9RegInfo *getRegInfo() const { return 0; }
130 /// CodeGenFileType - These enums are meant to be passed into
131 /// addPassesToEmitFile to indicate what type of file to emit.
132 enum CodeGenFileType {
133 AssemblyFile, ObjectFile, DynamicLibrary
136 /// addPassesToEmitFile - Add passes to the specified pass manager to get
137 /// the specified file emitted. Typically this will involve several steps of
138 /// code generation. This method should return true if emission of this file
139 /// type is not supported.
141 virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
142 CodeGenFileType FileType) {
146 /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
147 /// get machine code emitted. This uses a MachineCodeEmitter object to handle
148 /// actually outputting the machine code and resolving things like the address
149 /// of functions. This method should returns true if machine code emission is
152 virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
153 MachineCodeEmitter &MCE) {
158 } // End llvm namespace