Add prototypes for creation/destruction passes
[oota-llvm.git] / include / llvm / CodeGen / MachineFunction.h
1 //===-- llvm/CodeGen/MachineFunction.h ---------------------------*- C++ -*--=//
2 // 
3 // Collect native machine code information for a method.  This allows
4 // target-specific information about the generated code to be stored with each
5 // method.
6 //   
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
10 #define LLVM_CODEGEN_MACHINEFUNCTION_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 class Pass;
22
23 Pass *createMachineCodeConstructionPass(TargetMachine &Target);
24 Pass *createMachineCodeDestructionPass();
25
26 class MachineFunction : private Annotation {
27   hash_set<const Constant*> constantsForConstPool;
28   hash_map<const Value*, int> offsets;
29   const         Function* method;
30   unsigned      staticStackSize;
31   unsigned      automaticVarsSize;
32   unsigned      regSpillsSize;
33   unsigned      maxOptionalArgsSize;
34   unsigned      maxOptionalNumArgs;
35   unsigned      currentTmpValuesSize;
36   unsigned      maxTmpValuesSize;
37   bool          compiledAsLeaf;
38   bool          spillsAreaFrozen;
39   bool          automaticVarsAreaFrozen;
40   
41 public:
42   /*ctor*/      MachineFunction(const Function* function,
43                                 const TargetMachine& target);
44   
45   // The next two methods are used to construct and to retrieve
46   // the MachineFunction object for the given method.
47   // construct() -- Allocates and initializes for a given method and target
48   // get()       -- Returns a handle to the object.
49   //                This should not be called before "construct()"
50   //                for a given Method.
51   // 
52   static MachineFunction& construct(const Function *method,
53                                          const TargetMachine &target);
54   static void destruct(const Function *F);
55   static MachineFunction& get(const Function* function);
56   
57   //
58   // Accessors for global information about generated code for a method.
59   // 
60   inline bool     isCompiledAsLeafMethod() const { return compiledAsLeaf; }
61   inline unsigned getStaticStackSize()     const { return staticStackSize; }
62   inline unsigned getAutomaticVarsSize()   const { return automaticVarsSize; }
63   inline unsigned getRegSpillsSize()       const { return regSpillsSize; }
64   inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
65   inline unsigned getMaxOptionalNumArgs()  const { return maxOptionalNumArgs;}
66   inline const hash_set<const Constant*>&
67                   getConstantPoolValues() const {return constantsForConstPool;}
68   
69   //
70   // Modifiers used during code generation
71   // 
72   void            initializeFrameLayout    (const TargetMachine& target);
73   
74   void            addToConstantPool        (const Constant* constVal)
75                                     { constantsForConstPool.insert(constVal); }
76   
77   inline void     markAsLeafMethod()              { compiledAsLeaf = true; }
78   
79   int             computeOffsetforLocalVar (const TargetMachine& target,
80                                             const Value*  local,
81                                             unsigned int& getPaddedSize,
82                                             unsigned int  sizeToUse = 0);
83   int             allocateLocalVar         (const TargetMachine& target,
84                                             const Value* local,
85                                             unsigned int sizeToUse = 0);
86   
87   int             allocateSpilledValue     (const TargetMachine& target,
88                                             const Type* type);
89   
90   int             pushTempValue            (const TargetMachine& target,
91                                             unsigned int size);
92   
93   void            popAllTempValues         (const TargetMachine& target);
94   
95   void            freezeSpillsArea         () { spillsAreaFrozen = true; } 
96   void            freezeAutomaticVarsArea  () { automaticVarsAreaFrozen=true; }
97   
98   int             getOffset                (const Value* val) const;
99   
100   // int          getOffsetFromFP       (const Value* val) const;
101   
102   void            dump                     () const;
103
104 private:
105   inline void     incrementAutomaticVarsSize(int incr) {
106     automaticVarsSize+= incr;
107     staticStackSize += incr;
108   }
109   inline void     incrementRegSpillsSize(int incr) {
110     regSpillsSize+= incr;
111     staticStackSize += incr;
112   }
113   inline void     incrementTmpAreaSize(int incr) {
114     currentTmpValuesSize += incr;
115     if (maxTmpValuesSize < currentTmpValuesSize)
116       {
117         staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
118         maxTmpValuesSize = currentTmpValuesSize;
119       }
120   }
121   inline void     resetTmpAreaSize() {
122     currentTmpValuesSize = 0;
123   }
124   int             allocateOptionalArg      (const TargetMachine& target,
125                                             const Type* type);
126 };
127
128 #endif