Include temp. values when computing max. size of stack frame!
[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 Function;
18 class Constant;
19 class Type;
20 class TargetMachine;
21
22
23 class MachineCodeForMethod : private Annotation {
24   const Function* method;
25   bool          compiledAsLeaf;
26   unsigned      staticStackSize;
27   unsigned      automaticVarsSize;
28   unsigned      regSpillsSize;
29   unsigned      currentOptionalArgsSize;
30   unsigned      maxOptionalArgsSize;
31   unsigned      currentTmpValuesSize;
32   unsigned      maxTmpValuesSize;
33   std::hash_set<const Constant*> constantsForConstPool;
34   std::hash_map<const Value*, int> offsets;
35   
36 public:
37   /*ctor*/      MachineCodeForMethod(const Function* function,
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 Function *method,
48                                          const TargetMachine &target);
49   static void destruct(const Function *F);
50   static MachineCodeForMethod& get(const Function* function);
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             computeOffsetforLocalVar (const TargetMachine& target,
76                                             const Value* local,
77                                             unsigned int& getPaddedSize,
78                                             unsigned int  sizeToUse = 0);
79   
80   int             allocateLocalVar         (const TargetMachine& target,
81                                             const Value* local,
82                                             unsigned int sizeToUse = 0);
83   
84   int             allocateSpilledValue     (const TargetMachine& target,
85                                             const Type* type);
86   
87   int             allocateOptionalArg      (const TargetMachine& target,
88                                             const Type* type);
89   
90   void            resetOptionalArgs        (const TargetMachine& target);
91   
92   int             pushTempValue            (const TargetMachine& target,
93                                             unsigned int size);
94   
95   void            popAllTempValues         (const TargetMachine& target);
96   
97   int             getOffset                (const Value* val) const;
98   
99   // int          getOffsetFromFP       (const Value* val) const;
100   
101   void            dump                     () const;
102
103 private:
104   inline void     incrementAutomaticVarsSize(int incr) {
105     automaticVarsSize+= incr;
106     staticStackSize += incr;
107   }
108   inline void     incrementRegSpillsSize(int incr) {
109     regSpillsSize+= incr;
110     staticStackSize += incr;
111   }
112   inline void     incrementTmpAreaSize(int incr) {
113     currentTmpValuesSize += incr;
114     if (maxTmpValuesSize < currentTmpValuesSize)
115       {
116         staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
117         maxTmpValuesSize = currentTmpValuesSize;
118       }
119   }
120   inline void     resetTmpAreaSize() {
121     currentTmpValuesSize = 0;
122   }
123   inline void     incrementCurrentOptionalArgsSize(int incr) {
124     currentOptionalArgsSize+= incr;     // stack size already includes this!
125   }
126 };
127
128 #endif