Clean up and add comments to the newly implemented subtarget code.
[oota-llvm.git] / include / llvm / Target / TargetMachine.h
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 <cassert>
19
20 namespace llvm {
21
22 class TargetSubtarget;
23 class TargetInstrInfo;
24 class TargetInstrDescriptor;
25 class TargetJITInfo;
26 class TargetSchedInfo;
27 class SparcV9RegInfo;
28 class TargetFrameInfo;
29 class MachineCodeEmitter;
30 class MRegisterInfo;
31 class FunctionPassManager;
32 class PassManager;
33 class Pass;
34 class IntrinsicLowering;
35
36 //===----------------------------------------------------------------------===//
37 ///
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.
41 ///
42 class TargetMachine {
43   const std::string Name;
44   const TargetData DataLayout;       // Calculates type size & alignment
45   IntrinsicLowering *IL;             // Specifies how to lower intrinsic calls
46
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);
57
58   TargetMachine(const std::string &name, IntrinsicLowering *IL,
59                 const TargetData &TD);
60
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.
64   ///
65   TargetMachine(const std::string &name, IntrinsicLowering *IL,
66                 const Module &M);
67
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; }
71 public:
72   virtual ~TargetMachine();
73
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; }
80
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; }
86
87
88   const std::string &getName() const { return Name; }
89
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.
93   ///
94   IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
95
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
100   //
101   virtual const TargetInstrInfo        *getInstrInfo() const { return 0; }
102   virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
103   const TargetData &getTargetData() const { return DataLayout; }
104
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!");
112     return (STC*)TST;
113   }
114
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.
118   ///
119   virtual const MRegisterInfo*          getRegisterInfo() const { return 0; }
120
121   /// getJITInfo - If this target supports a JIT, return information for it,
122   /// otherwise return null.
123   ///
124   virtual TargetJITInfo *getJITInfo() { return 0; }
125
126   // These are deprecated interfaces.
127   virtual const TargetSchedInfo        *getSchedInfo() const { return 0; }
128   virtual const SparcV9RegInfo         *getRegInfo()   const { return 0; }
129
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
134   };
135
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.
140   ///
141   virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
142                                    CodeGenFileType FileType) {
143     return true;
144   }
145
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
150   /// not supported.
151   ///
152   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
153                                           MachineCodeEmitter &MCE) {
154     return true;
155   }
156 };
157
158 } // End llvm namespace
159
160 #endif