742d4b5c0f851727fa9d0440213d42c5188316d8
[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 <Support/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   hash_set<const Constant*> constantsForConstPool;
25   hash_map<const Value*, int> offsets;
26   const         Function* method;
27   unsigned      staticStackSize;
28   unsigned      automaticVarsSize;
29   unsigned      regSpillsSize;
30   unsigned      maxOptionalArgsSize;
31   unsigned      maxOptionalNumArgs;
32   unsigned      currentTmpValuesSize;
33   unsigned      maxTmpValuesSize;
34   bool          compiledAsLeaf;
35   bool          spillsAreaFrozen;
36   bool          automaticVarsAreaFrozen;
37   
38 public:
39   /*ctor*/      MachineCodeForMethod(const Function* function,
40                                      const TargetMachine& target);
41   
42   // The next two methods are used to construct and to retrieve
43   // the MachineCodeForMethod object for the given method.
44   // construct() -- Allocates and initializes for a given method and target
45   // get()       -- Returns a handle to the object.
46   //                This should not be called before "construct()"
47   //                for a given Method.
48   // 
49   static MachineCodeForMethod& construct(const Function *method,
50                                          const TargetMachine &target);
51   static void destruct(const Function *F);
52   static MachineCodeForMethod& get(const Function* function);
53   
54   //
55   // Accessors for global information about generated code for a method.
56   // 
57   inline bool     isCompiledAsLeafMethod() const { return compiledAsLeaf; }
58   inline unsigned getStaticStackSize()     const { return staticStackSize; }
59   inline unsigned getAutomaticVarsSize()   const { return automaticVarsSize; }
60   inline unsigned getRegSpillsSize()       const { return regSpillsSize; }
61   inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
62   inline unsigned getMaxOptionalNumArgs()  const { return maxOptionalNumArgs;}
63   inline const hash_set<const Constant*>&
64                   getConstantPoolValues() const {return constantsForConstPool;}
65   
66   //
67   // Modifiers used during code generation
68   // 
69   void            initializeFrameLayout    (const TargetMachine& target);
70   
71   void            addToConstantPool        (const Constant* constVal)
72                                     { constantsForConstPool.insert(constVal); }
73   
74   inline void     markAsLeafMethod()              { compiledAsLeaf = true; }
75   
76   int             computeOffsetforLocalVar (const TargetMachine& target,
77                                             const Value*  local,
78                                             unsigned int& getPaddedSize,
79                                             unsigned int  sizeToUse = 0);
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             pushTempValue            (const TargetMachine& target,
88                                             unsigned int size);
89   
90   void            popAllTempValues         (const TargetMachine& target);
91   
92   void            freezeSpillsArea         () { spillsAreaFrozen = true; } 
93   void            freezeAutomaticVarsArea  () { automaticVarsAreaFrozen=true; }
94   
95   int             getOffset                (const Value* val) const;
96   
97   // int          getOffsetFromFP       (const Value* val) const;
98   
99   void            dump                     () const;
100
101 private:
102   inline void     incrementAutomaticVarsSize(int incr) {
103     automaticVarsSize+= incr;
104     staticStackSize += incr;
105   }
106   inline void     incrementRegSpillsSize(int incr) {
107     regSpillsSize+= incr;
108     staticStackSize += incr;
109   }
110   inline void     incrementTmpAreaSize(int incr) {
111     currentTmpValuesSize += incr;
112     if (maxTmpValuesSize < currentTmpValuesSize)
113       {
114         staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
115         maxTmpValuesSize = currentTmpValuesSize;
116       }
117   }
118   inline void     resetTmpAreaSize() {
119     currentTmpValuesSize = 0;
120   }
121   int             allocateOptionalArg      (const TargetMachine& target,
122                                             const Type* type);
123 };
124
125 #endif