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