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/CodeGen/MachineBasicBlock.h"
13 #include "Support/NonCopyable.h"
14 #include "Support/HashExtras.h"
15 #include "Support/hash_set"
16 #include "Support/ilist"
25 Pass *createMachineCodeConstructionPass(TargetMachine &Target);
26 Pass *createMachineCodeDestructionPass();
28 class MachineFunction : private Annotation {
29 const Function *method;
31 // List of machine basic blocks in function
32 iplist<MachineBasicBlock> BasicBlocks;
34 // FIXME: State should be held elsewhere...
35 hash_set<const Constant*> constantsForConstPool;
36 hash_map<const Value*, int> offsets;
37 unsigned staticStackSize;
38 unsigned automaticVarsSize;
39 unsigned regSpillsSize;
40 unsigned maxOptionalArgsSize;
41 unsigned maxOptionalNumArgs;
42 unsigned currentTmpValuesSize;
43 unsigned maxTmpValuesSize;
45 bool spillsAreaFrozen;
46 bool automaticVarsAreaFrozen;
49 MachineFunction(const Function* function,
50 const TargetMachine& target);
52 // The next two methods are used to construct and to retrieve
53 // the MachineFunction object for the given method.
54 // construct() -- Allocates and initializes for a given method and target
55 // get() -- Returns a handle to the object.
56 // This should not be called before "construct()"
57 // for a given Method.
59 static MachineFunction& construct(const Function *method,
60 const TargetMachine &target);
61 static void destruct(const Function *F);
62 static MachineFunction& get(const Function* function);
66 //===--------------------------------------------------------------------===//
68 // FIXME: Most of the following state should be moved out to passes that use
69 // it, instead of being put here.
73 // Accessors for global information about generated code for a method.
75 inline bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
76 inline unsigned getStaticStackSize() const { return staticStackSize; }
77 inline unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
78 inline unsigned getRegSpillsSize() const { return regSpillsSize; }
79 inline unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
80 inline unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;}
81 inline const hash_set<const Constant*>&
82 getConstantPoolValues() const {return constantsForConstPool;}
85 // Modifiers used during code generation
87 void initializeFrameLayout (const TargetMachine& target);
89 void addToConstantPool (const Constant* constVal)
90 { constantsForConstPool.insert(constVal); }
92 inline void markAsLeafMethod() { compiledAsLeaf = true; }
94 int computeOffsetforLocalVar (const TargetMachine& target,
96 unsigned int& getPaddedSize,
97 unsigned int sizeToUse = 0);
98 int allocateLocalVar (const TargetMachine& target,
100 unsigned int sizeToUse = 0);
102 int allocateSpilledValue (const TargetMachine& target,
105 int pushTempValue (const TargetMachine& target,
108 void popAllTempValues (const TargetMachine& target);
110 void freezeSpillsArea () { spillsAreaFrozen = true; }
111 void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; }
113 int getOffset (const Value* val) const;
115 // int getOffsetFromFP (const Value* val) const;
120 inline void incrementAutomaticVarsSize(int incr) {
121 automaticVarsSize+= incr;
122 staticStackSize += incr;
124 inline void incrementRegSpillsSize(int incr) {
125 regSpillsSize+= incr;
126 staticStackSize += incr;
128 inline void incrementTmpAreaSize(int incr) {
129 currentTmpValuesSize += incr;
130 if (maxTmpValuesSize < currentTmpValuesSize)
132 staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
133 maxTmpValuesSize = currentTmpValuesSize;
136 inline void resetTmpAreaSize() {
137 currentTmpValuesSize = 0;
139 int allocateOptionalArg (const TargetMachine& target,