Remove unneeded #include
[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 "llvm/Annotation.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 *Fn;
30   const TargetMachine &Target;
31
32   // List of machine basic blocks in function
33   iplist<MachineBasicBlock> BasicBlocks;
34
35   // FIXME: State should be held elsewhere...
36   hash_set<const Constant*> constantsForConstPool;
37   hash_map<const Value*, int> offsets;
38   unsigned      staticStackSize;
39   unsigned      automaticVarsSize;
40   unsigned      regSpillsSize;
41   unsigned      maxOptionalArgsSize;
42   unsigned      maxOptionalNumArgs;
43   unsigned      currentTmpValuesSize;
44   unsigned      maxTmpValuesSize;
45   bool          compiledAsLeaf;
46   bool          spillsAreaFrozen;
47   bool          automaticVarsAreaFrozen;
48   
49 public:
50   MachineFunction(const Function *Fn, const TargetMachine& target);
51
52   /// getFunction - Return the LLVM function that this machine code represents
53   ///
54   const Function *getFunction() const { return Fn; }
55
56   /// getTarget - Return the target machine this machine code is compiled with
57   ///
58   const TargetMachine &getTarget() const { return Target; }
59   
60   // The next two methods are used to construct and to retrieve
61   // the MachineFunction object for the given method.
62   // construct() -- Allocates and initializes for a given method and target
63   // get()       -- Returns a handle to the object.
64   //                This should not be called before "construct()"
65   //                for a given Method.
66   // 
67   static MachineFunction& construct(const Function *Fn,
68                                     const TargetMachine &target);
69   static void destruct(const Function *F);
70   static MachineFunction& get(const Function *F);
71
72   // Provide accessors for the MachineBasicBlock list...
73   typedef iplist<MachineBasicBlock> BasicBlockListType;
74   typedef BasicBlockListType::iterator iterator;
75   typedef BasicBlockListType::const_iterator const_iterator;
76   typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
77   typedef std::reverse_iterator<iterator>             reverse_iterator;
78
79   // Provide accessors for basic blocks...
80   const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; }
81         BasicBlockListType &getBasicBlockList()       { return BasicBlocks; }
82  
83   //===--------------------------------------------------------------------===//
84   // BasicBlock iterator forwarding functions
85   //
86   iterator                 begin()       { return BasicBlocks.begin(); }
87   const_iterator           begin() const { return BasicBlocks.begin(); }
88   iterator                 end  ()       { return BasicBlocks.end();   }
89   const_iterator           end  () const { return BasicBlocks.end();   }
90
91   reverse_iterator        rbegin()       { return BasicBlocks.rbegin(); }
92   const_reverse_iterator  rbegin() const { return BasicBlocks.rbegin(); }
93   reverse_iterator        rend  ()       { return BasicBlocks.rend();   }
94   const_reverse_iterator  rend  () const { return BasicBlocks.rend();   }
95
96   unsigned                  size() const { return BasicBlocks.size(); }
97   bool                     empty() const { return BasicBlocks.empty(); }
98   const MachineBasicBlock &front() const { return BasicBlocks.front(); }
99         MachineBasicBlock &front()       { return BasicBlocks.front(); }
100   const MachineBasicBlock & back() const { return BasicBlocks.back(); }
101         MachineBasicBlock & back()       { return BasicBlocks.back(); }
102
103   //===--------------------------------------------------------------------===//
104   //
105   // FIXME: Most of the following state should be moved out to passes that use
106   // it, instead of being put here.
107   //
108
109   //
110   // Accessors for global information about generated code for a method.
111   // 
112   inline bool     isCompiledAsLeafMethod() const { return compiledAsLeaf; }
113   inline unsigned getStaticStackSize()     const { return staticStackSize; }
114   inline unsigned getAutomaticVarsSize()   const { return automaticVarsSize; }
115   inline unsigned getRegSpillsSize()       const { return regSpillsSize; }
116   inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
117   inline unsigned getMaxOptionalNumArgs()  const { return maxOptionalNumArgs;}
118   inline const hash_set<const Constant*>&
119                   getConstantPoolValues() const {return constantsForConstPool;}
120   
121   //
122   // Modifiers used during code generation
123   // 
124   void            initializeFrameLayout    (const TargetMachine& target);
125   
126   void            addToConstantPool        (const Constant* constVal)
127                                     { constantsForConstPool.insert(constVal); }
128   
129   inline void     markAsLeafMethod()              { compiledAsLeaf = true; }
130   
131   int             computeOffsetforLocalVar (const TargetMachine& target,
132                                             const Value*  local,
133                                             unsigned int& getPaddedSize,
134                                             unsigned int  sizeToUse = 0);
135   int             allocateLocalVar         (const TargetMachine& target,
136                                             const Value* local,
137                                             unsigned int sizeToUse = 0);
138   
139   int             allocateSpilledValue     (const TargetMachine& target,
140                                             const Type* type);
141   
142   int             pushTempValue            (const TargetMachine& target,
143                                             unsigned int size);
144   
145   void            popAllTempValues         (const TargetMachine& target);
146   
147   void            freezeSpillsArea         () { spillsAreaFrozen = true; } 
148   void            freezeAutomaticVarsArea  () { automaticVarsAreaFrozen=true; }
149   
150   int             getOffset                (const Value* val) const;
151   
152   // int          getOffsetFromFP       (const Value* val) const;
153   
154   void            dump                     () const;
155
156 private:
157   inline void     incrementAutomaticVarsSize(int incr) {
158     automaticVarsSize+= incr;
159     staticStackSize += incr;
160   }
161   inline void     incrementRegSpillsSize(int incr) {
162     regSpillsSize+= incr;
163     staticStackSize += incr;
164   }
165   inline void     incrementTmpAreaSize(int incr) {
166     currentTmpValuesSize += incr;
167     if (maxTmpValuesSize < currentTmpValuesSize)
168       {
169         staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
170         maxTmpValuesSize = currentTmpValuesSize;
171       }
172   }
173   inline void     resetTmpAreaSize() {
174     currentTmpValuesSize = 0;
175   }
176   int             allocateOptionalArg      (const TargetMachine& target,
177                                             const Type* type);
178 };
179
180 #endif