efeb61d4997b8dc6963727e89e410d5bbc91a931
[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 public:
68   virtual ~TargetMachine();
69
70   /// getModuleMatchQuality - This static method should be implemented by
71   /// targets to indicate how closely they match the specified module.  This is
72   /// used by the LLC tool to determine which target to use when an explicit
73   /// -march option is not specified.  If a target returns zero, it will never
74   /// be chosen without an explicit -march option.
75   static unsigned getModuleMatchQuality(const Module &M) { return 0; }
76
77   /// getJITMatchQuality - This static method should be implemented by targets
78   /// that provide JIT capabilities to indicate how suitable they are for
79   /// execution on the current host.  If a value of 0 is returned, the target
80   /// will not be used unless an explicit -march option is used.
81   static unsigned getJITMatchQuality() { return 0; }
82
83
84   const std::string &getName() const { return Name; }
85
86   /// getIntrinsicLowering - This method returns a reference to an
87   /// IntrinsicLowering instance which should be used by the code generator to
88   /// lower unknown intrinsic functions to the equivalent LLVM expansion.
89   ///
90   IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
91
92   // Interfaces to the major aspects of target machine information:
93   // -- Instruction opcode and operand information
94   // -- Pipelines and scheduling information
95   // -- Stack frame information
96   //
97   virtual const TargetInstrInfo        *getInstrInfo() const { return 0; }
98   virtual const TargetFrameInfo        *getFrameInfo() const { return 0; }
99   const TargetData &getTargetData() const { return DataLayout; }
100
101   virtual const TargetSubtarget *getSubtargetImpl() const { return 0; }
102   template<typename STC> STC *getSubtarget() const {
103     assert(getSubtargetImpl() && dynamic_cast<STC*>(getSubtargetImpl()) &&
104            "Not the right kind of subtarget!");
105     return (STC*)getSubtargetImpl();
106   }
107
108   /// getRegisterInfo - If register information is available, return it.  If
109   /// not, return null.  This is kept separate from RegInfo until RegInfo has
110   /// details of graph coloring register allocation removed from it.
111   ///
112   virtual const MRegisterInfo*          getRegisterInfo() const { return 0; }
113
114   /// getJITInfo - If this target supports a JIT, return information for it,
115   /// otherwise return null.
116   ///
117   virtual TargetJITInfo *getJITInfo() { return 0; }
118
119   // These are deprecated interfaces.
120   virtual const TargetSchedInfo        *getSchedInfo() const { return 0; }
121   virtual const SparcV9RegInfo         *getRegInfo()   const { return 0; }
122
123   /// CodeGenFileType - These enums are meant to be passed into
124   /// addPassesToEmitFile to indicate what type of file to emit.
125   enum CodeGenFileType {
126     AssemblyFile, ObjectFile, DynamicLibrary
127   };
128
129   /// addPassesToEmitFile - Add passes to the specified pass manager to get
130   /// the specified file emitted.  Typically this will involve several steps of
131   /// code generation.  This method should return true if emission of this file
132   /// type is not supported.
133   ///
134   virtual bool addPassesToEmitFile(PassManager &PM, std::ostream &Out,
135                                    CodeGenFileType FileType) {
136     return true;
137   }
138
139   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
140   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
141   /// actually outputting the machine code and resolving things like the address
142   /// of functions.  This method should returns true if machine code emission is
143   /// not supported.
144   ///
145   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
146                                           MachineCodeEmitter &MCE) {
147     return true;
148   }
149 };
150
151 } // End llvm namespace
152
153 #endif