7d9586c2f86b652648c35df02a3560a4daeb8c37
[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 TargetInstrInfo;
23 class TargetInstrDescriptor;
24 class TargetJITInfo;
25 class TargetSchedInfo;
26 class TargetRegInfo;
27 class TargetFrameInfo;
28 class MachineCodeEmitter;
29 class MRegisterInfo;
30 class FunctionPassManager;
31 class PassManager;
32 class Pass;
33 class IntrinsicLowering;
34
35 //===----------------------------------------------------------------------===//
36 ///
37 /// TargetMachine - Primary interface to the complete machine description for
38 /// the target machine.  All target-specific information should be accessible
39 /// through this interface.
40 /// 
41 class TargetMachine {
42   const std::string Name;
43   const TargetData DataLayout;       // Calculates type size & alignment
44   IntrinsicLowering *IL;             // Specifies how to lower intrinsic calls
45   
46   TargetMachine(const TargetMachine&);   // DO NOT IMPLEMENT
47   void operator=(const TargetMachine&);  // DO NOT IMPLEMENT
48 protected: // Can only create subclasses...
49   TargetMachine(const std::string &name, IntrinsicLowering *IL,                
50                 bool LittleEndian = false,
51                 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
52                 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
53                 unsigned char LongAl = 8, unsigned char IntAl = 4,
54                 unsigned char ShortAl = 2, unsigned char ByteAl = 1);
55 public:
56   virtual ~TargetMachine();
57
58   const std::string &getName() const { return Name; }
59
60   // getIntrinsicLowering - This method returns a reference to an
61   // IntrinsicLowering instance which should be used by the code generator to
62   // lower unknown intrinsic functions to the equivalent LLVM expansion.
63   IntrinsicLowering &getIntrinsicLowering() const { return *IL; }
64   
65   // Interfaces to the major aspects of target machine information:
66   // -- Instruction opcode and operand information
67   // -- Pipelines and scheduling information
68   // -- Register information
69   // -- Stack frame information
70   // -- Cache hierarchy information
71   // -- Machine-level optimization information (peephole only)
72   // 
73   virtual const TargetInstrInfo&        getInstrInfo() const = 0;
74   virtual const TargetSchedInfo&        getSchedInfo() const = 0;
75   virtual const TargetRegInfo&          getRegInfo()   const = 0;
76   virtual const TargetFrameInfo&        getFrameInfo() const = 0;
77   const TargetData &getTargetData() const { return DataLayout; }
78
79   /// getRegisterInfo - If register information is available, return it.  If
80   /// not, return null.  This is kept separate from RegInfo until RegInfo has
81   /// details of graph coloring register allocation removed from it.
82   ///
83   virtual const MRegisterInfo*          getRegisterInfo() const { return 0; }
84
85   /// getJITInfo - If this target supports a JIT, return information for it,
86   /// otherwise return null.
87   ///
88   virtual TargetJITInfo *getJITInfo() { return 0; }
89
90   // Data storage information.  FIXME, this should be moved out to sparc
91   // specific code.
92   // 
93   virtual unsigned findOptimalStorageSize(const Type* ty) const;
94   
95   /// addPassesToEmitAssembly - Add passes to the specified pass manager to get
96   /// assembly langage code emitted.  Typically this will involve several steps
97   /// of code generation.  This method should return true if assembly emission
98   /// is not supported.
99   ///
100   virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
101     return true;
102   }
103
104   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
105   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
106   /// actually outputting the machine code and resolving things like the address
107   /// of functions.  This method should returns true if machine code emission is
108   /// not supported.
109   ///
110   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
111                                           MachineCodeEmitter &MCE) {
112     return true;
113   }
114 };
115
116 } // End llvm namespace
117
118 #endif