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