1eb8cd27b43361f6ff1c3c66ec216f33fc6b3f64
[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 Module;
20 class Method;
21
22 //---------------------------------------------------------------------------
23 // class TargetMachine
24 // 
25 // Purpose:
26 //   Primary interface to the complete machine description for the
27 //   target machine.  All target-specific information should be
28 //   accessible through this interface.
29 // 
30 //---------------------------------------------------------------------------
31
32 class TargetMachine : public NonCopyableV {
33 public:
34   const std::string TargetName;
35   const TargetData DataLayout;          // Calculates type size & alignment
36   int              optSizeForSubWordData;
37   int              minMemOpWordSize;
38   int              maxAtomicMemOpWordSize;
39   
40 protected:
41   TargetMachine(const std::string &targetname, // Can only create subclasses...
42                 unsigned char PtrSize = 8, unsigned char PtrAl = 8,
43                 unsigned char DoubleAl = 8, unsigned char FloatAl = 4,
44                 unsigned char LongAl = 8, unsigned char IntAl = 4,
45                 unsigned char ShortAl = 2, unsigned char ByteAl = 1)
46     : TargetName(targetname), DataLayout(targetname, PtrSize, PtrAl,
47                                          DoubleAl, FloatAl, LongAl, IntAl, 
48                                          ShortAl, ByteAl) { }
49 public:
50   virtual ~TargetMachine() {}
51   
52   // 
53   // Interfaces to the major aspects of target machine information:
54   // -- Instruction opcode and operand information
55   // -- Pipelines and scheduling information
56   // -- Register information
57   // 
58   virtual const MachineInstrInfo&       getInstrInfo() const = 0;
59   virtual const MachineSchedInfo&       getSchedInfo() const = 0;
60   virtual const MachineRegInfo&         getRegInfo()   const = 0;
61   virtual const MachineFrameInfo&       getFrameInfo() const = 0;
62   virtual const MachineCacheInfo&       getCacheInfo() const = 0;
63   
64   //
65   // Data storage information
66   // 
67   virtual unsigned int  findOptimalStorageSize  (const Type* ty) const;
68   
69   //
70   // compileMethod - Everything neccesary to compile a method into the
71   // built in representation.  This allows the target to have complete control
72   // over how it does compilation.  This does not emit assembly or output
73   // machine code, however; those are done later.
74   //
75   virtual bool compileMethod(Method *M) = 0;
76
77   //
78   // emitAssembly - Output assembly language code (a .s file) for the specified
79   // method. The specified method must have been compiled before this may be
80   // used.
81   //
82   virtual void emitAssembly(const Method *M, std::ostream &OutStr) const = 0;
83
84   //
85   // emitAssembly - Output assembly language code (a .s file) for global
86   // components of the specified module.  This assumes that methods have been
87   // previously output.
88   //
89   virtual void emitAssembly(const Module *M, std::ostream &OutStr) const = 0;
90
91   //
92   // freeCompiledMethod - Release all memory associated with the compiled image
93   // for this method.
94   //
95   virtual void freeCompiledMethod(Method *M) = 0;
96 };
97
98 #endif