MachineFunction.h now includes MachineBasicBlock.h in preparation for
[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/CodeGen/MachineBasicBlock.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
31   // FIXME: State should be held elsewhere...
32   unsigned      staticStackSize;
33   unsigned      automaticVarsSize;
34   unsigned      regSpillsSize;
35   unsigned      maxOptionalArgsSize;
36   unsigned      maxOptionalNumArgs;
37   unsigned      currentTmpValuesSize;
38   unsigned      maxTmpValuesSize;
39   bool          compiledAsLeaf;
40   bool          spillsAreaFrozen;
41   bool          automaticVarsAreaFrozen;
42   
43 public:
44   MachineFunction(const Function* function,
45                   const TargetMachine& target);
46   
47   // The next two methods are used to construct and to retrieve
48   // the MachineFunction object for the given method.
49   // construct() -- Allocates and initializes for a given method and target
50   // get()       -- Returns a handle to the object.
51   //                This should not be called before "construct()"
52   //                for a given Method.
53   // 
54   static MachineFunction& construct(const Function *method,
55                                          const TargetMachine &target);
56   static void destruct(const Function *F);
57   static MachineFunction& get(const Function* function);
58   
59
60
61   //===--------------------------------------------------------------------===//
62   //
63   // FIXME: Most of the following state should be moved out to passes that use
64   // it, instead of being put here.
65   //
66
67   //
68   // Accessors for global information about generated code for a method.
69   // 
70   inline bool     isCompiledAsLeafMethod() const { return compiledAsLeaf; }
71   inline unsigned getStaticStackSize()     const { return staticStackSize; }
72   inline unsigned getAutomaticVarsSize()   const { return automaticVarsSize; }
73   inline unsigned getRegSpillsSize()       const { return regSpillsSize; }
74   inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
75   inline unsigned getMaxOptionalNumArgs()  const { return maxOptionalNumArgs;}
76   inline const hash_set<const Constant*>&
77                   getConstantPoolValues() const {return constantsForConstPool;}
78   
79   //
80   // Modifiers used during code generation
81   // 
82   void            initializeFrameLayout    (const TargetMachine& target);
83   
84   void            addToConstantPool        (const Constant* constVal)
85                                     { constantsForConstPool.insert(constVal); }
86   
87   inline void     markAsLeafMethod()              { compiledAsLeaf = true; }
88   
89   int             computeOffsetforLocalVar (const TargetMachine& target,
90                                             const Value*  local,
91                                             unsigned int& getPaddedSize,
92                                             unsigned int  sizeToUse = 0);
93   int             allocateLocalVar         (const TargetMachine& target,
94                                             const Value* local,
95                                             unsigned int sizeToUse = 0);
96   
97   int             allocateSpilledValue     (const TargetMachine& target,
98                                             const Type* type);
99   
100   int             pushTempValue            (const TargetMachine& target,
101                                             unsigned int size);
102   
103   void            popAllTempValues         (const TargetMachine& target);
104   
105   void            freezeSpillsArea         () { spillsAreaFrozen = true; } 
106   void            freezeAutomaticVarsArea  () { automaticVarsAreaFrozen=true; }
107   
108   int             getOffset                (const Value* val) const;
109   
110   // int          getOffsetFromFP       (const Value* val) const;
111   
112   void            dump                     () const;
113
114 private:
115   inline void     incrementAutomaticVarsSize(int incr) {
116     automaticVarsSize+= incr;
117     staticStackSize += incr;
118   }
119   inline void     incrementRegSpillsSize(int incr) {
120     regSpillsSize+= incr;
121     staticStackSize += incr;
122   }
123   inline void     incrementTmpAreaSize(int incr) {
124     currentTmpValuesSize += incr;
125     if (maxTmpValuesSize < currentTmpValuesSize)
126       {
127         staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
128         maxTmpValuesSize = currentTmpValuesSize;
129       }
130   }
131   inline void     resetTmpAreaSize() {
132     currentTmpValuesSize = 0;
133   }
134   int             allocateOptionalArg      (const TargetMachine& target,
135                                             const Type* type);
136 };
137
138 #endif