blob: 1d3c668a6caead48f652aa61150d93cd03fcfa76 [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"
Brian Gaeked0fde302003-11-11 22:41:34 +000020
21namespace llvm {
22
Chris Lattner1951c5b2002-12-28 20:07:33 +000023class MachineFunction;
24class Value;
25class Constant;
26class Type;
27
28class MachineFunctionInfo {
29 hash_set<const Constant*> constantsForConstPool;
30 hash_map<const Value*, int> offsets;
31 unsigned staticStackSize;
32 unsigned automaticVarsSize;
33 unsigned regSpillsSize;
34 unsigned maxOptionalArgsSize;
35 unsigned maxOptionalNumArgs;
36 unsigned currentTmpValuesSize;
37 unsigned maxTmpValuesSize;
38 bool compiledAsLeaf;
39 bool spillsAreaFrozen;
40 bool automaticVarsAreaFrozen;
41
42 MachineFunction &MF;
43public:
44 MachineFunctionInfo(MachineFunction &mf) : MF(mf) {
45 staticStackSize = automaticVarsSize = regSpillsSize = 0;
46 maxOptionalArgsSize = maxOptionalNumArgs = currentTmpValuesSize = 0;
47 maxTmpValuesSize = 0;
48 compiledAsLeaf = spillsAreaFrozen = automaticVarsAreaFrozen = false;
49 }
50
51 /// CalculateArgSize - Call this method to fill in the maxOptionalArgsSize &
52 /// staticStackSize fields...
53 ///
54 void CalculateArgSize();
55
56 //
57 // Accessors for global information about generated code for a method.
58 //
59 bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
60 unsigned getStaticStackSize() const { return staticStackSize; }
61 unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
62 unsigned getRegSpillsSize() const { return regSpillsSize; }
63 unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
64 unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;}
65 const hash_set<const Constant*> &getConstantPoolValues() const {
66 return constantsForConstPool;
67 }
68
69 //
70 // Modifiers used during code generation
71 //
72 void initializeFrameLayout ();
73
74 void addToConstantPool (const Constant* constVal) {
75 constantsForConstPool.insert(constVal);
76 }
77
78 void markAsLeafMethod() { compiledAsLeaf = true; }
79
80 int computeOffsetforLocalVar (const Value* local,
81 unsigned& getPaddedSize,
82 unsigned sizeToUse = 0);
83 int allocateLocalVar (const Value* local,
84 unsigned sizeToUse = 0);
85
86 int allocateSpilledValue (const Type* type);
87 int pushTempValue (unsigned size);
88 void popAllTempValues ();
89
90 void freezeSpillsArea () { spillsAreaFrozen = true; }
91 void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; }
92
Chris Lattner1951c5b2002-12-28 20:07:33 +000093private:
94 void incrementAutomaticVarsSize(int incr) {
95 automaticVarsSize+= incr;
96 staticStackSize += incr;
97 }
98 void incrementRegSpillsSize(int incr) {
99 regSpillsSize+= incr;
100 staticStackSize += incr;
101 }
102 void incrementTmpAreaSize(int incr) {
103 currentTmpValuesSize += incr;
104 if (maxTmpValuesSize < currentTmpValuesSize)
105 {
106 staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
107 maxTmpValuesSize = currentTmpValuesSize;
108 }
109 }
110 void resetTmpAreaSize() {
111 currentTmpValuesSize = 0;
112 }
113 int allocateOptionalArg(const Type* type);
114};
115
Brian Gaeked0fde302003-11-11 22:41:34 +0000116} // End llvm namespace
117
Chris Lattner1951c5b2002-12-28 20:07:33 +0000118#endif