TargetMachine.h revision 6cee630070b1a7183ed56a8404e812629f5ca538
1//===-- llvm/Target/TargetMachine.h - Target Information --------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
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.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the general parts of a Target machine.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_TARGET_TARGETMACHINE_H
15#define LLVM_TARGET_TARGETMACHINE_H
16
17#include "llvm/Target/TargetData.h"
18#include "llvm/Target/TargetInstrItineraries.h"
19#include <cassert>
20
21namespace llvm {
22
23class TargetSubtarget;
24class TargetInstrInfo;
25class TargetInstrDescriptor;
26class TargetJITInfo;
27class TargetSchedInfo;
28class SparcV9RegInfo;
29class TargetFrameInfo;
30class MachineCodeEmitter;
31class MRegisterInfo;
32class FunctionPassManager;
33class PassManager;
34class Pass;
35class IntrinsicLowering;
36
37//===----------------------------------------------------------------------===//
38///
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.
42///
43class TargetMachine {
44  const std::string Name;
45  const TargetData DataLayout;       // Calculates type size & alignment
46  IntrinsicLowering *IL;             // Specifies how to lower intrinsic calls
47
48  TargetMachine(const TargetMachine&);   // DO NOT IMPLEMENT
49  void operator=(const TargetMachine&);  // DO NOT IMPLEMENT
50protected: // 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);
58
59  TargetMachine(const std::string &name, IntrinsicLowering *IL,
60                const TargetData &TD);
61
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.
65  ///
66  TargetMachine(const std::string &name, IntrinsicLowering *IL,
67                const Module &M);
68
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; }
72public:
73  virtual ~TargetMachine();
74
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; }
81
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; }
87
88
89  const std::string &getName() const { return Name; }
90
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.
94  ///
95  IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
96
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  //
102  virtual const TargetInstrInfo        *getInstrInfo() const { return 0; }
103  virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
104  const TargetData &getTargetData() const { return DataLayout; }
105
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);
114  }
115
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.
119  ///
120  virtual const MRegisterInfo*          getRegisterInfo() const { return 0; }
121
122  /// getJITInfo - If this target supports a JIT, return information for it,
123  /// otherwise return null.
124  ///
125  virtual TargetJITInfo *getJITInfo() { return 0; }
126
127  /// getInstrItineraryData - Returns instruction itinerary data for the target
128  /// or specific subtarget.
129  ///
130  virtual const InstrItineraryData getInstrItineraryData() const {
131    return InstrItineraryData();
132  }
133
134  // These are deprecated interfaces.
135  virtual const TargetSchedInfo        *getSchedInfo() const { return 0; }
136  virtual const SparcV9RegInfo         *getRegInfo()   const { return 0; }
137
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
142  };
143
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.  This method should return true if emission of this file
147  /// type is not supported.
148  ///
149  virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
150                                   CodeGenFileType FileType) {
151    return true;
152  }
153
154  /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
155  /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
156  /// actually outputting the machine code and resolving things like the address
157  /// of functions.  This method should returns true if machine code emission is
158  /// not supported.
159  ///
160  virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
161                                          MachineCodeEmitter &MCE) {
162    return true;
163  }
164};
165
166} // End llvm namespace
167
168#endif
169