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 <Support/hash_set>
23 class MachineCodeForMethod : private Annotation {
24 std::hash_set<const Constant*> constantsForConstPool;
25 std::hash_map<const Value*, int> offsets;
26 const Function* method;
27 unsigned staticStackSize;
28 unsigned automaticVarsSize;
29 unsigned regSpillsSize;
30 unsigned maxOptionalArgsSize;
31 unsigned maxOptionalNumArgs;
32 unsigned currentTmpValuesSize;
33 unsigned maxTmpValuesSize;
35 bool spillsAreaFrozen;
36 bool automaticVarsAreaFrozen;
39 /*ctor*/ MachineCodeForMethod(const Function* function,
40 const TargetMachine& target);
42 // The next two methods are used to construct and to retrieve
43 // the MachineCodeForMethod object for the given method.
44 // construct() -- Allocates and initializes for a given method and target
45 // get() -- Returns a handle to the object.
46 // This should not be called before "construct()"
47 // for a given Method.
49 static MachineCodeForMethod& construct(const Function *method,
50 const TargetMachine &target);
51 static void destruct(const Function *F);
52 static MachineCodeForMethod& get(const Function* function);
55 // Accessors for global information about generated code for a method.
57 inline bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
58 inline unsigned getStaticStackSize() const { return staticStackSize; }
59 inline unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
60 inline unsigned getRegSpillsSize() const { return regSpillsSize; }
61 inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
62 inline unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;}
63 inline const std::hash_set<const Constant*>&
64 getConstantPoolValues() const {return constantsForConstPool;}
67 // Modifiers used during code generation
69 void initializeFrameLayout (const TargetMachine& target);
71 void addToConstantPool (const Constant* constVal)
72 { constantsForConstPool.insert(constVal); }
74 inline void markAsLeafMethod() { compiledAsLeaf = true; }
76 int computeOffsetforLocalVar (const TargetMachine& target,
78 unsigned int& getPaddedSize,
79 unsigned int sizeToUse = 0);
80 int allocateLocalVar (const TargetMachine& target,
82 unsigned int sizeToUse = 0);
84 int allocateSpilledValue (const TargetMachine& target,
87 int pushTempValue (const TargetMachine& target,
90 void popAllTempValues (const TargetMachine& target);
92 void freezeSpillsArea () { spillsAreaFrozen = true; }
93 void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; }
95 int getOffset (const Value* val) const;
97 // int getOffsetFromFP (const Value* val) const;
102 inline void incrementAutomaticVarsSize(int incr) {
103 automaticVarsSize+= incr;
104 staticStackSize += incr;
106 inline void incrementRegSpillsSize(int incr) {
107 regSpillsSize+= incr;
108 staticStackSize += incr;
110 inline void incrementTmpAreaSize(int incr) {
111 currentTmpValuesSize += incr;
112 if (maxTmpValuesSize < currentTmpValuesSize)
114 staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
115 maxTmpValuesSize = currentTmpValuesSize;
118 inline void resetTmpAreaSize() {
119 currentTmpValuesSize = 0;
121 int allocateOptionalArg (const TargetMachine& target,