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 std::hash_set<const Constant*> constantsForConstPool;
33 std::hash_map<const Value*, int> offsets;
36 /*ctor*/ MachineCodeForMethod(const Function* function,
37 const TargetMachine& target);
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.
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);
52 // Accessors for global information about generated code for a method.
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;}
65 // Modifiers used during code generation
67 void initializeFrameLayout (const TargetMachine& target);
69 void addToConstantPool (const Constant* constVal)
70 { constantsForConstPool.insert(constVal); }
72 inline void markAsLeafMethod() { compiledAsLeaf = true; }
74 int computeOffsetforLocalVar (const TargetMachine& target,
76 unsigned int size = 0);
78 int allocateLocalVar (const TargetMachine& target,
80 unsigned int size = 0);
82 int allocateSpilledValue (const TargetMachine& target,
85 int allocateOptionalArg (const TargetMachine& target,
88 void resetOptionalArgs (const TargetMachine& target);
90 int pushTempValue (const TargetMachine& target,
93 void popAllTempValues (const TargetMachine& target);
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 incrementCurrentOptionalArgsSize(int incr) {
111 currentOptionalArgsSize+= incr; // stack size already includes this!