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