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