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