Be a bit more efficient when processing the active and inactive
[oota-llvm.git] / lib / Target / SparcV9 / MachineFunctionInfo.h
1 //===-- SparcV9FunctionInfo.h -----------------------------------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 // 
10 // This class keeps track of information about the stack frame and about the
11 // per-function constant pool.
12 //
13 // FIXME: This class is completely SparcV9 specific.  Do not use it for future
14 // targets.  This file will be eliminated in future versions of LLVM.
15 //   
16 //===----------------------------------------------------------------------===//
17
18 #ifndef MACHINEFUNCTIONINFO_H
19 #define MACHINEFUNCTIONINFO_H
20
21 #include "MachineCodeForInstruction.h"
22 #include "llvm/CodeGen/MachineFunction.h"
23 #include "Support/HashExtras.h"
24 #include "Support/hash_set"
25
26 namespace llvm {
27
28 class MachineFunction;
29 class Constant;
30 class Type;
31
32 class SparcV9FunctionInfo : public MachineFunctionInfo {
33   hash_set<const Constant*> constantsForConstPool;
34   hash_map<const Value*, int> offsets;
35
36   unsigned      staticStackSize;
37   unsigned      automaticVarsSize;
38   unsigned      regSpillsSize;
39   unsigned      maxOptionalArgsSize;
40   unsigned      maxOptionalNumArgs;
41   unsigned      currentTmpValuesSize;
42   unsigned      maxTmpValuesSize;
43   bool          compiledAsLeaf;
44   bool          spillsAreaFrozen;
45   bool          automaticVarsAreaFrozen;
46
47   MachineFunction &MF;
48 public:
49   hash_map<const Instruction*, MachineCodeForInstruction> MCFIEntries;
50
51   SparcV9FunctionInfo(MachineFunction &mf) : MF(mf) {
52     staticStackSize = automaticVarsSize = regSpillsSize = 0;
53     maxOptionalArgsSize = maxOptionalNumArgs = currentTmpValuesSize = 0;
54     maxTmpValuesSize = 0;
55     compiledAsLeaf = spillsAreaFrozen = automaticVarsAreaFrozen = false;
56   }
57
58   /// CalculateArgSize - Call this method to fill in the maxOptionalArgsSize &
59   /// staticStackSize fields...
60   ///
61   void CalculateArgSize();
62
63   //
64   // Accessors for global information about generated code for a method.
65   // 
66   bool     isCompiledAsLeafMethod() const { return compiledAsLeaf; }
67   unsigned getStaticStackSize()     const { return staticStackSize; }
68   unsigned getAutomaticVarsSize()   const { return automaticVarsSize; }
69   unsigned getRegSpillsSize()       const { return regSpillsSize; }
70   unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
71   unsigned getMaxOptionalNumArgs()  const { return maxOptionalNumArgs;}
72   const hash_set<const Constant*> &getConstantPoolValues() const {
73     return constantsForConstPool;
74   }
75   
76   //
77   // Modifiers used during code generation
78   // 
79   void            initializeFrameLayout    ();
80   
81   void            addToConstantPool        (const Constant* constVal) {
82     constantsForConstPool.insert(constVal);
83   }
84   
85   void markAsLeafMethod() { compiledAsLeaf = true; }
86   
87   int             computeOffsetforLocalVar (const Value*  local,
88                                             unsigned& getPaddedSize,
89                                             unsigned  sizeToUse = 0);
90   int             allocateLocalVar         (const Value* local,
91                                             unsigned sizeToUse = 0);
92   
93   int             allocateSpilledValue     (const Type* type);
94   int             pushTempValue            (unsigned size);
95   void            popAllTempValues         ();
96   
97   void            freezeSpillsArea         () { spillsAreaFrozen = true; } 
98   void            freezeAutomaticVarsArea  () { automaticVarsAreaFrozen=true; }
99   
100 private:
101   void incrementAutomaticVarsSize(int incr) {
102     automaticVarsSize+= incr;
103     staticStackSize += incr;
104   }
105   void incrementRegSpillsSize(int incr) {
106     regSpillsSize+= incr;
107     staticStackSize += incr;
108   }
109   void incrementTmpAreaSize(int incr) {
110     currentTmpValuesSize += incr;
111     if (maxTmpValuesSize < currentTmpValuesSize)
112       {
113         staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
114         maxTmpValuesSize = currentTmpValuesSize;
115       }
116   }
117   void resetTmpAreaSize() {
118     currentTmpValuesSize = 0;
119   }
120   int allocateOptionalArg(const Type* type);
121 };
122
123 } // End llvm namespace
124
125 #endif