3ef4b10d3ff3d9216c34b8457b99ab5cbca70c1a
[oota-llvm.git] / include / llvm / CodeGen / MachineFunction.h
1 //===-- llvm/CodeGen/MachineCodeForMethod.h ----------------------*- C++ -*--=//
2 // 
3 // Purpose:
4 //   Collect native machine code information for a method.
5 //   This allows target-specific information about the generated code
6 //   to be stored with each method.
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CODEGEN_MACHINECODEFORMETHOD_H
10 #define LLVM_CODEGEN_MACHINECODEFORMETHOD_H
11
12 #include "llvm/Annotation.h"
13 #include "Support/NonCopyable.h"
14 #include "Support/HashExtras.h"
15 #include <ext/hash_set>
16 class Value;
17 class Method;
18 class Constant;
19 class Type;
20 class TargetMachine;
21
22
23 class MachineCodeForMethod : private Annotation {
24   const Method* method;
25   bool          compiledAsLeaf;
26   unsigned      staticStackSize;
27   unsigned      automaticVarsSize;
28   unsigned      regSpillsSize;
29   unsigned      currentOptionalArgsSize;
30   unsigned      maxOptionalArgsSize;
31   unsigned      currentTmpValuesSize;
32   std::hash_set<const Constant*> constantsForConstPool;
33   std::hash_map<const Value*, int> offsets;
34   // hash_map<const Value*, int> offsetsFromSP;
35   
36 public:
37   /*ctor*/      MachineCodeForMethod(const Method* method,
38                                      const TargetMachine& target);
39   
40   // The next two methods are used to construct and to retrieve
41   // the MachineCodeForMethod object for the given method.
42   // construct() -- Allocates and initializes for a given method and target
43   // get()       -- Returns a handle to the object.
44   //                This should not be called before "construct()"
45   //                for a given Method.
46   // 
47   static MachineCodeForMethod& construct(const Method *method,
48                                          const TargetMachine &target);
49   static void destruct(const Method *M);
50   static MachineCodeForMethod& get(const Method* method);
51   
52   //
53   // Accessors for global information about generated code for a method.
54   // 
55   inline bool     isCompiledAsLeafMethod() const { return compiledAsLeaf; }
56   inline unsigned getStaticStackSize()     const { return staticStackSize; }
57   inline unsigned getAutomaticVarsSize()   const { return automaticVarsSize; }
58   inline unsigned getRegSpillsSize()       const { return regSpillsSize; }
59   inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
60   inline unsigned getCurrentOptionalArgsSize() const
61                                              { return currentOptionalArgsSize;}
62   inline const std::hash_set<const Constant*>&
63                   getConstantPoolValues() const {return constantsForConstPool;}
64   
65   //
66   // Modifiers used during code generation
67   // 
68   void            initializeFrameLayout    (const TargetMachine& target);
69   
70   void            addToConstantPool        (const Constant* constVal)
71                                     { constantsForConstPool.insert(constVal); }
72   
73   inline void     markAsLeafMethod()              { compiledAsLeaf = true; }
74   
75   int             allocateLocalVar         (const TargetMachine& target,
76                                             const Value* local,
77                                             unsigned int size = 0);
78   
79   int             allocateSpilledValue     (const TargetMachine& target,
80                                             const Type* type);
81   
82   int             allocateOptionalArg      (const TargetMachine& target,
83                                             const Type* type);
84   
85   void            resetOptionalArgs        (const TargetMachine& target);
86   
87   int             pushTempValue            (const TargetMachine& target,
88                                             unsigned int size);
89   
90   void            popAllTempValues         (const TargetMachine& target);
91   
92   int             getOffset                (const Value* val) const;
93   
94   // int          getOffsetFromFP       (const Value* val) const;
95   
96   void            dump                     () const;
97
98 private:
99   inline void     incrementAutomaticVarsSize(int incr) {
100     automaticVarsSize+= incr;
101     staticStackSize += incr;
102   }
103   inline void     incrementRegSpillsSize(int incr) {
104     regSpillsSize+= incr;
105     staticStackSize += incr;
106   }
107   inline void     incrementCurrentOptionalArgsSize(int incr) {
108     currentOptionalArgsSize+= incr;     // stack size already includes this!
109   }
110 };
111
112 #endif