0772c13755fefd6f0920911f245b5a4c36d17e30
[oota-llvm.git] / include / llvm / Target / TargetMachine.h
1 //===-- llvm/Target/TargetMachine.h - General Target Information -*- C++ -*-==//
2 //
3 // This file describes the general parts of a Target machine.
4 //
5 //===----------------------------------------------------------------------===//
6
7 #ifndef LLVM_TARGET_TARGETMACHINE_H
8 #define LLVM_TARGET_TARGETMACHINE_H
9
10 #include "llvm/Target/TargetData.h"
11
12 class TargetInstrInfo;
13 class TargetInstrDescriptor;
14 class TargetSchedInfo;
15 class TargetRegInfo;
16 class TargetFrameInfo;
17 class TargetCacheInfo;
18 class MachineCodeEmitter;
19 class MRegisterInfo;
20 class FunctionPassManager;
21 class PassManager;
22 class Pass;
23
24 //===----------------------------------------------------------------------===//
25 ///
26 /// TargetMachine - Primary interface to the complete machine description for
27 /// the target machine.  All target-specific information should be accessible
28 /// through this interface.
29 /// 
30 class TargetMachine {
31   const std::string Name;
32   const TargetData DataLayout;           // Calculates type size & alignment
33   
34   TargetMachine(const TargetMachine&);   // DO NOT IMPLEMENT
35   void operator=(const TargetMachine&);  // DO NOT IMPLEMENT
36 protected:
37   TargetMachine(const std::string &name, // Can only create subclasses...
38                 bool LittleEndian = false,
39                 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
40                 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
41                 unsigned char LongAl = 8, unsigned char IntAl = 4,
42                 unsigned char ShortAl = 2, unsigned char ByteAl = 1)
43     : Name(name), DataLayout(name, LittleEndian,
44                              PtrSize, PtrAl, DoubleAl, FloatAl, LongAl,
45                              IntAl, ShortAl, ByteAl) {}
46 public:
47   virtual ~TargetMachine() {}
48
49   const std::string &getName() const { return Name; }
50   
51   // Interfaces to the major aspects of target machine information:
52   // -- Instruction opcode and operand information
53   // -- Pipelines and scheduling information
54   // -- Register information
55   // -- Stack frame information
56   // -- Cache hierarchy information
57   // -- Machine-level optimization information (peephole only)
58   // 
59   virtual const TargetInstrInfo&        getInstrInfo() const = 0;
60   virtual const TargetSchedInfo&        getSchedInfo() const = 0;
61   virtual const TargetRegInfo&          getRegInfo()   const = 0;
62   virtual const TargetFrameInfo&        getFrameInfo() const = 0;
63   virtual const TargetCacheInfo&        getCacheInfo() const = 0;
64   const TargetData &getTargetData() const { return DataLayout; }
65
66   /// getRegisterInfo - If register information is available, return it.  If
67   /// not, return null.  This is kept separate from RegInfo until RegInfo has
68   /// details of graph coloring register allocation removed from it.
69   ///
70   virtual const MRegisterInfo*          getRegisterInfo() const { return 0; }
71
72   // Data storage information
73   // 
74   virtual unsigned findOptimalStorageSize(const Type* ty) const;
75   
76   /// addPassesToJITCompile - Add passes to the specified pass manager to
77   /// implement a fast dynamic compiler for this target.  Return true if this is
78   /// not supported for this target.
79   ///
80   virtual bool addPassesToJITCompile(FunctionPassManager &PM) { return true; }
81
82   /// addPassesToEmitAssembly - Add passes to the specified pass manager to get
83   /// assembly langage code emitted.  Typically this will involve several steps
84   /// of code generation.  This method should return true if assembly emission
85   /// is not supported.
86   ///
87   virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
88     return true;
89   }
90
91   /// addPassesToEmitMachineCode - Add passes to the specified pass manager to
92   /// get machine code emitted.  This uses a MachineCodeEmitter object to handle
93   /// actually outputting the machine code and resolving things like the address
94   /// of functions.  This method should returns true if machine code emission is
95   /// not supported.
96   ///
97   virtual bool addPassesToEmitMachineCode(FunctionPassManager &PM,
98                                           MachineCodeEmitter &MCE) {
99     return true;
100   }
101 };
102
103 #endif