1 //===-- llvm/CodeGen/MachineFunction.h --------------------------*- C++ -*-===//
3 // Collect native machine code information for a method. This allows
4 // target-specific information about the generated code to be stored with each
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CODEGEN_MACHINEFUNCTION_H
10 #define LLVM_CODEGEN_MACHINEFUNCTION_H
12 #include "llvm/Annotation.h"
13 #include "Support/NonCopyable.h"
14 #include "Support/HashExtras.h"
15 #include <Support/hash_set>
23 Pass *createMachineCodeConstructionPass(TargetMachine &Target);
24 Pass *createMachineCodeDestructionPass();
26 class MachineFunction : private Annotation {
27 hash_set<const Constant*> constantsForConstPool;
28 hash_map<const Value*, int> offsets;
29 const Function* method;
31 // FIXME: State should be held elsewhere...
32 unsigned staticStackSize;
33 unsigned automaticVarsSize;
34 unsigned regSpillsSize;
35 unsigned maxOptionalArgsSize;
36 unsigned maxOptionalNumArgs;
37 unsigned currentTmpValuesSize;
38 unsigned maxTmpValuesSize;
40 bool spillsAreaFrozen;
41 bool automaticVarsAreaFrozen;
44 MachineFunction(const Function* function,
45 const TargetMachine& target);
47 // The next two methods are used to construct and to retrieve
48 // the MachineFunction object for the given method.
49 // construct() -- Allocates and initializes for a given method and target
50 // get() -- Returns a handle to the object.
51 // This should not be called before "construct()"
52 // for a given Method.
54 static MachineFunction& construct(const Function *method,
55 const TargetMachine &target);
56 static void destruct(const Function *F);
57 static MachineFunction& get(const Function* function);
61 //===--------------------------------------------------------------------===//
63 // FIXME: Most of the following state should be moved out to passes that use
64 // it, instead of being put here.
68 // Accessors for global information about generated code for a method.
70 inline bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
71 inline unsigned getStaticStackSize() const { return staticStackSize; }
72 inline unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
73 inline unsigned getRegSpillsSize() const { return regSpillsSize; }
74 inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
75 inline unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;}
76 inline const hash_set<const Constant*>&
77 getConstantPoolValues() const {return constantsForConstPool;}
80 // Modifiers used during code generation
82 void initializeFrameLayout (const TargetMachine& target);
84 void addToConstantPool (const Constant* constVal)
85 { constantsForConstPool.insert(constVal); }
87 inline void markAsLeafMethod() { compiledAsLeaf = true; }
89 int computeOffsetforLocalVar (const TargetMachine& target,
91 unsigned int& getPaddedSize,
92 unsigned int sizeToUse = 0);
93 int allocateLocalVar (const TargetMachine& target,
95 unsigned int sizeToUse = 0);
97 int allocateSpilledValue (const TargetMachine& target,
100 int pushTempValue (const TargetMachine& target,
103 void popAllTempValues (const TargetMachine& target);
105 void freezeSpillsArea () { spillsAreaFrozen = true; }
106 void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; }
108 int getOffset (const Value* val) const;
110 // int getOffsetFromFP (const Value* val) const;
115 inline void incrementAutomaticVarsSize(int incr) {
116 automaticVarsSize+= incr;
117 staticStackSize += incr;
119 inline void incrementRegSpillsSize(int incr) {
120 regSpillsSize+= incr;
121 staticStackSize += incr;
123 inline void incrementTmpAreaSize(int incr) {
124 currentTmpValuesSize += incr;
125 if (maxTmpValuesSize < currentTmpValuesSize)
127 staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
128 maxTmpValuesSize = currentTmpValuesSize;
131 inline void resetTmpAreaSize() {
132 currentTmpValuesSize = 0;
134 int allocateOptionalArg (const TargetMachine& target,