1 //===-- llvm/CodeGen/MachineCodeForMethod.h ----------------------*- C++ -*--=//
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CODEGEN_MACHINECODEFORMETHOD_H
10 #define LLVM_CODEGEN_MACHINECODEFORMETHOD_H
12 #include "llvm/Annotation.h"
13 #include "Support/NonCopyable.h"
14 #include "Support/HashExtras.h"
15 #include <ext/hash_set>
23 class MachineCodeForMethod : private Annotation {
24 const Function* method;
26 unsigned staticStackSize;
27 unsigned automaticVarsSize;
28 unsigned regSpillsSize;
29 unsigned currentOptionalArgsSize;
30 unsigned maxOptionalArgsSize;
31 unsigned currentTmpValuesSize;
32 unsigned maxTmpValuesSize;
33 std::hash_set<const Constant*> constantsForConstPool;
34 std::hash_map<const Value*, int> offsets;
37 /*ctor*/ MachineCodeForMethod(const Function* function,
38 const TargetMachine& target);
40 // The next two methods are used to construct and to retrieve
41 // the MachineCodeForMethod object for the given method.
42 // construct() -- Allocates and initializes for a given method and target
43 // get() -- Returns a handle to the object.
44 // This should not be called before "construct()"
45 // for a given Method.
47 static MachineCodeForMethod& construct(const Function *method,
48 const TargetMachine &target);
49 static void destruct(const Function *F);
50 static MachineCodeForMethod& get(const Function* function);
53 // Accessors for global information about generated code for a method.
55 inline bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
56 inline unsigned getStaticStackSize() const { return staticStackSize; }
57 inline unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
58 inline unsigned getRegSpillsSize() const { return regSpillsSize; }
59 inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
60 inline unsigned getCurrentOptionalArgsSize() const
61 { return currentOptionalArgsSize;}
62 inline const std::hash_set<const Constant*>&
63 getConstantPoolValues() const {return constantsForConstPool;}
66 // Modifiers used during code generation
68 void initializeFrameLayout (const TargetMachine& target);
70 void addToConstantPool (const Constant* constVal)
71 { constantsForConstPool.insert(constVal); }
73 inline void markAsLeafMethod() { compiledAsLeaf = true; }
75 int computeOffsetforLocalVar (const TargetMachine& target,
77 unsigned int& getPaddedSize,
78 unsigned int sizeToUse = 0);
80 int allocateLocalVar (const TargetMachine& target,
82 unsigned int sizeToUse = 0);
84 int allocateSpilledValue (const TargetMachine& target,
87 int allocateOptionalArg (const TargetMachine& target,
90 void resetOptionalArgs (const TargetMachine& target);
92 int pushTempValue (const TargetMachine& target,
95 void popAllTempValues (const TargetMachine& target);
97 int getOffset (const Value* val) const;
99 // int getOffsetFromFP (const Value* val) const;
104 inline void incrementAutomaticVarsSize(int incr) {
105 automaticVarsSize+= incr;
106 staticStackSize += incr;
108 inline void incrementRegSpillsSize(int incr) {
109 regSpillsSize+= incr;
110 staticStackSize += incr;
112 inline void incrementTmpAreaSize(int incr) {
113 currentTmpValuesSize += incr;
114 if (maxTmpValuesSize < currentTmpValuesSize)
116 staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
117 maxTmpValuesSize = currentTmpValuesSize;
120 inline void resetTmpAreaSize() {
121 currentTmpValuesSize = 0;
123 inline void incrementCurrentOptionalArgsSize(int incr) {
124 currentOptionalArgsSize+= incr; // stack size already includes this!