188db3a1ca55857f8afc12a06111c843282014ee
[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 "llvm/Target/TargetInstrItineraries.h"
19 #include <cassert>
20
21 namespace llvm {
22
23 class TargetSubtarget;
24 class TargetInstrInfo;
25 class TargetInstrDescriptor;
26 class TargetJITInfo;
27 class TargetLowering;
28 class TargetSchedInfo;
29 class SparcV9RegInfo;
30 class TargetFrameInfo;
31 class MachineCodeEmitter;
32 class MRegisterInfo;
33 class FunctionPassManager;
34 class PassManager;
35 class Pass;
36
37 // Relocation model types.
38 namespace Reloc {
39   enum Model {
40     Default,
41     Static,
42     PIC,
43     DynamicNoPIC
44   };
45 }
46
47 //===----------------------------------------------------------------------===//
48 ///
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.
52 ///
53 class TargetMachine {
54   const std::string Name;
55   const TargetData DataLayout;       // Calculates type size & alignment
56
57   TargetMachine(const TargetMachine&);   // DO NOT IMPLEMENT
58   void operator=(const TargetMachine&);  // DO NOT IMPLEMENT
59 protected: // Can only create subclasses...
60   TargetMachine(const std::string &name, bool LittleEndian = false,
61                 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
62                 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
63                 unsigned char LongAl = 8, unsigned char IntAl = 4,
64                 unsigned char ShortAl = 2, unsigned char ByteAl = 1,
65                 unsigned char BoolAl = 1);
66
67   TargetMachine(const std::string &name, const TargetData &TD);
68
69   /// This constructor is used for targets that support arbitrary TargetData
70   /// layouts, like the C backend.  It initializes the TargetData to match that
71   /// of the specified module.
72   ///
73   TargetMachine(const std::string &name, const Module &M);
74
75   /// getSubtargetImpl - virtual method implemented by subclasses that returns
76   /// a reference to that target's TargetSubtarget-derived member variable.
77   virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
78 public:
79   virtual ~TargetMachine();
80
81   /// getModuleMatchQuality - This static method should be implemented by
82   /// targets to indicate how closely they match the specified module.  This is
83   /// used by the LLC tool to determine which target to use when an explicit
84   /// -march option is not specified.  If a target returns zero, it will never
85   /// be chosen without an explicit -march option.
86   static unsigned getModuleMatchQuality(const Module &M) { return 0; }
87
88   /// getJITMatchQuality - This static method should be implemented by targets
89   /// that provide JIT capabilities to indicate how suitable they are for
90   /// execution on the current host.  If a value of 0 is returned, the target
91   /// will not be used unless an explicit -march option is used.
92   static unsigned getJITMatchQuality() { return 0; }
93
94
95   const std::string &getName() const { return Name; }
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   // -- Selection DAG lowering information
102   //
103   virtual const TargetInstrInfo        *getInstrInfo() const { return 0; }
104   virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
105   virtual       TargetLowering    *getTargetLowering() const { return 0; }
106   const TargetData &getTargetData() const { return DataLayout; }
107
108   /// getSubtarget - This method returns a pointer to the specified type of
109   /// TargetSubtarget.  In debug builds, it verifies that the object being
110   /// returned is of the correct type.
111   template<typename STC> const STC &getSubtarget() const {
112     const TargetSubtarget *TST = getSubtargetImpl();
113     assert(TST && dynamic_cast<const STC*>(TST) &&
114            "Not the right kind of subtarget!");
115     return *static_cast<const STC*>(TST);
116   }
117
118   /// getRegisterInfo - If register information is available, return it.  If
119   /// not, return null.  This is kept separate from RegInfo until RegInfo has
120   /// details of graph coloring register allocation removed from it.
121   ///
122   virtual const MRegisterInfo*          getRegisterInfo() const { return 0; }
123
124   /// getJITInfo - If this target supports a JIT, return information for it,
125   /// otherwise return null.
126   ///
127   virtual TargetJITInfo *getJITInfo() { return 0; }
128   
129   /// getInstrItineraryData - Returns instruction itinerary data for the target
130   /// or specific subtarget.
131   ///
132   virtual const InstrItineraryData getInstrItineraryData() const {  
133     return InstrItineraryData();
134   }
135
136   // These are deprecated interfaces.
137   virtual const TargetSchedInfo        *getSchedInfo() const { return 0; }
138   virtual const SparcV9RegInfo         *getRegInfo()   const { return 0; }
139
140   /// getRelocationModel - Returns the code generation relocation model. The
141   /// choices are static, PIC, and dynamic-no-pic, and target default.
142   static Reloc::Model getRelocationModel();
143
144   /// setRelocationModel - Sets the code generation relocation model.
145   static void setRelocationModel(Reloc::Model Model);
146
147   /// CodeGenFileType - These enums are meant to be passed into
148   /// addPassesToEmitFile to indicate what type of file to emit.
149   enum CodeGenFileType {
150     AssemblyFile, ObjectFile, DynamicLibrary
151   };
152
153   /// addPassesToEmitFile - Add passes to the specified pass manager to get
154   /// the specified file emitted.  Typically this will involve several steps of
155   /// code generation.  If Fast is set to true, the code generator should emit
156   /// code as fast as possible, without regard for compile time.  This method
157   /// should return true if emission of this file type is not supported.
158   ///
159   virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
160                                    CodeGenFileType FileType, bool Fast) {
161     return true;
162   }
163
164   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
165   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
166   /// actually outputting the machine code and resolving things like the address
167   /// of functions.  This method should returns true if machine code emission is
168   /// not supported.
169   ///
170   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
171                                           MachineCodeEmitter &MCE) {
172     return true;
173   }
174 };
175
176 } // End llvm namespace
177
178 #endif