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