blob: db7332227862b3a42f0de908a9ca126048bcf747 [file] [log] [blame]
Chris Lattner1951c5b2002-12-28 20:07:33 +00001//===-- llvm/CodeGen/MachineFunctionInfo.h ----------------------*- C++ -*-===//
2//
John Criswell6fbcc262003-10-20 20:19:47 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner1951c5b2002-12-28 20:07:33 +000010// This class keeps track of information about the stack frame and about the
11// per-function constant pool.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_MACHINEFUNCTIONINFO_H
16#define LLVM_CODEGEN_MACHINEFUNCTIONINFO_H
17
18#include "Support/HashExtras.h"
19#include "Support/hash_set"
20class MachineFunction;
21class Value;
22class Constant;
23class Type;
24
25class MachineFunctionInfo {
26 hash_set<const Constant*> constantsForConstPool;
27 hash_map<const Value*, int> offsets;
28 unsigned staticStackSize;
29 unsigned automaticVarsSize;
30 unsigned regSpillsSize;
31 unsigned maxOptionalArgsSize;
32 unsigned maxOptionalNumArgs;
33 unsigned currentTmpValuesSize;
34 unsigned maxTmpValuesSize;
35 bool compiledAsLeaf;
36 bool spillsAreaFrozen;
37 bool automaticVarsAreaFrozen;
38
39 MachineFunction &MF;
40public:
41 MachineFunctionInfo(MachineFunction &mf) : MF(mf) {
42 staticStackSize = automaticVarsSize = regSpillsSize = 0;
43 maxOptionalArgsSize = maxOptionalNumArgs = currentTmpValuesSize = 0;
44 maxTmpValuesSize = 0;
45 compiledAsLeaf = spillsAreaFrozen = automaticVarsAreaFrozen = false;
46 }
47
48 /// CalculateArgSize - Call this method to fill in the maxOptionalArgsSize &
49 /// staticStackSize fields...
50 ///
51 void CalculateArgSize();
52
53 //
54 // Accessors for global information about generated code for a method.
55 //
56 bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
57 unsigned getStaticStackSize() const { return staticStackSize; }
58 unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
59 unsigned getRegSpillsSize() const { return regSpillsSize; }
60 unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
61 unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;}
62 const hash_set<const Constant*> &getConstantPoolValues() const {
63 return constantsForConstPool;
64 }
65
66 //
67 // Modifiers used during code generation
68 //
69 void initializeFrameLayout ();
70
71 void addToConstantPool (const Constant* constVal) {
72 constantsForConstPool.insert(constVal);
73 }
74
75 void markAsLeafMethod() { compiledAsLeaf = true; }
76
77 int computeOffsetforLocalVar (const Value* local,
78 unsigned& getPaddedSize,
79 unsigned sizeToUse = 0);
80 int allocateLocalVar (const Value* local,
81 unsigned sizeToUse = 0);
82
83 int allocateSpilledValue (const Type* type);
84 int pushTempValue (unsigned size);
85 void popAllTempValues ();
86
87 void freezeSpillsArea () { spillsAreaFrozen = true; }
88 void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; }
89
90 int getOffset (const Value* val) const;
91
92private:
93 void incrementAutomaticVarsSize(int incr) {
94 automaticVarsSize+= incr;
95 staticStackSize += incr;
96 }
97 void incrementRegSpillsSize(int incr) {
98 regSpillsSize+= incr;
99 staticStackSize += incr;
100 }
101 void incrementTmpAreaSize(int incr) {
102 currentTmpValuesSize += incr;
103 if (maxTmpValuesSize < currentTmpValuesSize)
104 {
105 staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
106 maxTmpValuesSize = currentTmpValuesSize;
107 }
108 }
109 void resetTmpAreaSize() {
110 currentTmpValuesSize = 0;
111 }
112 int allocateOptionalArg(const Type* type);
113};
114
115#endif