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;
30 unsigned staticStackSize;
31 unsigned automaticVarsSize;
32 unsigned regSpillsSize;
33 unsigned maxOptionalArgsSize;
34 unsigned maxOptionalNumArgs;
35 unsigned currentTmpValuesSize;
36 unsigned maxTmpValuesSize;
38 bool spillsAreaFrozen;
39 bool automaticVarsAreaFrozen;
42 /*ctor*/ MachineFunction(const Function* function,
43 const TargetMachine& target);
45 // The next two methods are used to construct and to retrieve
46 // the MachineFunction object for the given method.
47 // construct() -- Allocates and initializes for a given method and target
48 // get() -- Returns a handle to the object.
49 // This should not be called before "construct()"
50 // for a given Method.
52 static MachineFunction& construct(const Function *method,
53 const TargetMachine &target);
54 static void destruct(const Function *F);
55 static MachineFunction& get(const Function* function);
58 // Accessors for global information about generated code for a method.
60 inline bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
61 inline unsigned getStaticStackSize() const { return staticStackSize; }
62 inline unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
63 inline unsigned getRegSpillsSize() const { return regSpillsSize; }
64 inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
65 inline unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;}
66 inline const hash_set<const Constant*>&
67 getConstantPoolValues() const {return constantsForConstPool;}
70 // Modifiers used during code generation
72 void initializeFrameLayout (const TargetMachine& target);
74 void addToConstantPool (const Constant* constVal)
75 { constantsForConstPool.insert(constVal); }
77 inline void markAsLeafMethod() { compiledAsLeaf = true; }
79 int computeOffsetforLocalVar (const TargetMachine& target,
81 unsigned int& getPaddedSize,
82 unsigned int sizeToUse = 0);
83 int allocateLocalVar (const TargetMachine& target,
85 unsigned int sizeToUse = 0);
87 int allocateSpilledValue (const TargetMachine& target,
90 int pushTempValue (const TargetMachine& target,
93 void popAllTempValues (const TargetMachine& target);
95 void freezeSpillsArea () { spillsAreaFrozen = true; }
96 void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; }
98 int getOffset (const Value* val) const;
100 // int getOffsetFromFP (const Value* val) const;
105 inline void incrementAutomaticVarsSize(int incr) {
106 automaticVarsSize+= incr;
107 staticStackSize += incr;
109 inline void incrementRegSpillsSize(int incr) {
110 regSpillsSize+= incr;
111 staticStackSize += incr;
113 inline void incrementTmpAreaSize(int incr) {
114 currentTmpValuesSize += incr;
115 if (maxTmpValuesSize < currentTmpValuesSize)
117 staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
118 maxTmpValuesSize = currentTmpValuesSize;
121 inline void resetTmpAreaSize() {
122 currentTmpValuesSize = 0;
124 int allocateOptionalArg (const TargetMachine& target,