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 {
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 // hash_map<const Value*, int> offsetsFromSP;
37 /*ctor*/ MachineCodeForMethod(const Method* method,
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 Method *method,
48 const TargetMachine &target);
49 static void destruct(const Method *M);
50 static MachineCodeForMethod& get(const Method* method);
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 allocateLocalVar (const TargetMachine& target,
77 unsigned int size = 0);
79 int allocateSpilledValue (const TargetMachine& target,
82 int allocateOptionalArg (const TargetMachine& target,
85 void resetOptionalArgs (const TargetMachine& target);
87 int pushTempValue (const TargetMachine& target,
90 void popAllTempValues (const TargetMachine& target);
92 int getOffset (const Value* val) const;
94 // int getOffsetFromFP (const Value* val) const;
99 inline void incrementAutomaticVarsSize(int incr) {
100 automaticVarsSize+= incr;
101 staticStackSize += incr;
103 inline void incrementRegSpillsSize(int incr) {
104 regSpillsSize+= incr;
105 staticStackSize += incr;
107 inline void incrementCurrentOptionalArgsSize(int incr) {
108 currentOptionalArgsSize+= incr; // stack size already includes this!