Minor changes
[oota-llvm.git] / lib / Target / SparcV9 / MachineFunctionInfo.h
1 //===-- llvm/CodeGen/MachineFunctionInfo.h ----------------------*- C++ -*-===//
2 // 
3 // This class keeps track of information about the stack frame and about the
4 // per-function constant pool.
5 //   
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_CODEGEN_MACHINEFUNCTIONINFO_H
9 #define LLVM_CODEGEN_MACHINEFUNCTIONINFO_H
10
11 #include "Support/HashExtras.h"
12 #include "Support/hash_set"
13 class MachineFunction;
14 class Value;
15 class Constant;
16 class Type;
17
18 class MachineFunctionInfo {
19   hash_set<const Constant*> constantsForConstPool;
20   hash_map<const Value*, int> offsets;
21   unsigned      staticStackSize;
22   unsigned      automaticVarsSize;
23   unsigned      regSpillsSize;
24   unsigned      maxOptionalArgsSize;
25   unsigned      maxOptionalNumArgs;
26   unsigned      currentTmpValuesSize;
27   unsigned      maxTmpValuesSize;
28   bool          compiledAsLeaf;
29   bool          spillsAreaFrozen;
30   bool          automaticVarsAreaFrozen;
31
32   MachineFunction &MF;
33 public:
34   MachineFunctionInfo(MachineFunction &mf) : MF(mf) {
35     staticStackSize = automaticVarsSize = regSpillsSize = 0;
36     maxOptionalArgsSize = maxOptionalNumArgs = currentTmpValuesSize = 0;
37     maxTmpValuesSize = 0;
38     compiledAsLeaf = spillsAreaFrozen = automaticVarsAreaFrozen = false;
39   }
40
41   /// CalculateArgSize - Call this method to fill in the maxOptionalArgsSize &
42   /// staticStackSize fields...
43   ///
44   void CalculateArgSize();
45
46   //
47   // Accessors for global information about generated code for a method.
48   // 
49   bool     isCompiledAsLeafMethod() const { return compiledAsLeaf; }
50   unsigned getStaticStackSize()     const { return staticStackSize; }
51   unsigned getAutomaticVarsSize()   const { return automaticVarsSize; }
52   unsigned getRegSpillsSize()       const { return regSpillsSize; }
53   unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
54   unsigned getMaxOptionalNumArgs()  const { return maxOptionalNumArgs;}
55   const hash_set<const Constant*> &getConstantPoolValues() const {
56     return constantsForConstPool;
57   }
58   
59   //
60   // Modifiers used during code generation
61   // 
62   void            initializeFrameLayout    ();
63   
64   void            addToConstantPool        (const Constant* constVal) {
65     constantsForConstPool.insert(constVal);
66   }
67   
68   void markAsLeafMethod() { compiledAsLeaf = true; }
69   
70   int             computeOffsetforLocalVar (const Value*  local,
71                                             unsigned& getPaddedSize,
72                                             unsigned  sizeToUse = 0);
73   int             allocateLocalVar         (const Value* local,
74                                             unsigned sizeToUse = 0);
75   
76   int             allocateSpilledValue     (const Type* type);
77   int             pushTempValue            (unsigned size);
78   void            popAllTempValues         ();
79   
80   void            freezeSpillsArea         () { spillsAreaFrozen = true; } 
81   void            freezeAutomaticVarsArea  () { automaticVarsAreaFrozen=true; }
82   
83   int             getOffset                (const Value* val) const;
84   
85 private:
86   void incrementAutomaticVarsSize(int incr) {
87     automaticVarsSize+= incr;
88     staticStackSize += incr;
89   }
90   void incrementRegSpillsSize(int incr) {
91     regSpillsSize+= incr;
92     staticStackSize += incr;
93   }
94   void incrementTmpAreaSize(int incr) {
95     currentTmpValuesSize += incr;
96     if (maxTmpValuesSize < currentTmpValuesSize)
97       {
98         staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
99         maxTmpValuesSize = currentTmpValuesSize;
100       }
101   }
102   void resetTmpAreaSize() {
103     currentTmpValuesSize = 0;
104   }
105   int allocateOptionalArg(const Type* type);
106 };
107
108 #endif