860d67eeae66149f4f2109ff96fbcabba655264a
[oota-llvm.git] / include / llvm / Target / TargetMachine.h
1 //===-- llvm/Target/Machine.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 #include "Support/NonCopyable.h"
12
13 class MachineInstrInfo;
14 class MachineInstrDescriptor;
15 class MachineSchedInfo;
16 class MachineRegInfo;
17 class MachineFrameInfo;
18 class MachineCacheInfo;
19 class MachineOptInfo;
20 class PassManager;
21 class Pass;
22
23 //---------------------------------------------------------------------------
24 // class TargetMachine
25 // 
26 // Purpose:
27 //   Primary interface to the complete machine description for the
28 //   target machine.  All target-specific information should be
29 //   accessible through this interface.
30 // 
31 //---------------------------------------------------------------------------
32
33 class TargetMachine : public NonCopyableV {
34 public:
35   const std::string TargetName;
36   const TargetData DataLayout;          // Calculates type size & alignment
37   int              optSizeForSubWordData;
38   int              minMemOpWordSize;
39   int              maxAtomicMemOpWordSize;
40   
41 protected:
42   TargetMachine(const std::string &targetname, // Can only create subclasses...
43                 unsigned char IntRegSize = 8,
44                 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
45                 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
46                 unsigned char LongAl = 8, unsigned char IntAl = 4,
47                 unsigned char ShortAl = 2, unsigned char ByteAl = 1)
48     : TargetName(targetname), DataLayout(targetname, IntRegSize,
49                                          PtrSize, PtrAl,
50                                          DoubleAl, FloatAl, LongAl, IntAl, 
51                                          ShortAl, ByteAl) { }
52 public:
53   virtual ~TargetMachine() {}
54
55   // 
56   // Interfaces to the major aspects of target machine information:
57   // -- Instruction opcode and operand information
58   // -- Pipelines and scheduling information
59   // -- Register information
60   // -- Stack frame information
61   // -- Cache hierarchy information
62   // -- Machine-level optimization information (peephole only)
63   // 
64   virtual const MachineInstrInfo&       getInstrInfo() const = 0;
65   virtual const MachineSchedInfo&       getSchedInfo() const = 0;
66   virtual const MachineRegInfo&         getRegInfo()   const = 0;
67   virtual const MachineFrameInfo&       getFrameInfo() const = 0;
68   virtual const MachineCacheInfo&       getCacheInfo() const = 0;
69   virtual const MachineOptInfo&         getOptInfo()   const = 0;
70
71   // Data storage information
72   // 
73   virtual unsigned int  findOptimalStorageSize  (const Type* ty) const;
74   
75   /// addPassesToEmitAssembly - Add passes to the specified pass manager to get
76   /// assembly langage code emited.  Typically this will involve several steps
77   /// of code generation.  This method should return true if code generation is
78   /// not supported.
79   ///
80   virtual bool addPassesToEmitAssembly(PassManager &PM, std::ostream &Out) {
81     return true;
82   }
83
84   /// addPassesToJITCompile - Add passes to the specified pass manager to
85   /// implement a fast dynamic compiler for this target.  Return true if this is
86   /// not supported for this target.
87   ///
88   virtual bool addPassesToJITCompile(PassManager &PM) { return true; }
89
90   /// getPrologEpilogCodeInserter - Create pass to insert prolog/epilog code.
91   /// 
92   virtual Pass* getPrologEpilogInsertionPass() = 0;
93
94   /// getFunctionAsmPrinterPass - Create a pass to write out the generated
95   /// machine code for a single function to the generated assembly file.
96   /// 
97   virtual Pass* getFunctionAsmPrinterPass(std::ostream &Out) = 0;
98
99   /// getModuleAsmPrinterPass - Create a pass to write out module-level
100   /// information to the generated assembly file.
101   /// 
102   virtual Pass* getModuleAsmPrinterPass(std::ostream &Out) = 0;
103
104   /// getEmitBytecodeToAsmPass - Create a pass to emit the final LLVM bytecode
105   /// to the generated assembly file.
106   /// 
107   virtual Pass* getEmitBytecodeToAsmPass(std::ostream &Out) = 0;
108 };
109
110 #endif