blob: 3596bc2fa1befc416fbe648ed09e1d1b00b36de2 [file] [log] [blame]
Chris Lattnera1e51ff2004-08-18 18:13:37 +00001//===-- SparcV9FunctionInfo.h -----------------------------------*- C++ -*-===//
Chris Lattner1951c5b2002-12-28 20:07:33 +00002//
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.
Chris Lattner4aa5b2a2004-06-27 18:50:30 +000012//
13// FIXME: This class is completely SparcV9 specific. Do not use it for future
14// targets. This file will be eliminated in future versions of LLVM.
Chris Lattner1951c5b2002-12-28 20:07:33 +000015//
16//===----------------------------------------------------------------------===//
17
Chris Lattner85015a02004-08-16 21:55:02 +000018#ifndef MACHINEFUNCTIONINFO_H
19#define MACHINEFUNCTIONINFO_H
Chris Lattner1951c5b2002-12-28 20:07:33 +000020
Chris Lattner85015a02004-08-16 21:55:02 +000021#include "MachineCodeForInstruction.h"
Chris Lattner6b9a5e62004-08-16 22:37:18 +000022#include "llvm/CodeGen/MachineFunction.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000023#include "llvm/ADT/HashExtras.h"
24#include "llvm/ADT/hash_set"
Brian Gaeked0fde302003-11-11 22:41:34 +000025
26namespace llvm {
27
Chris Lattner1951c5b2002-12-28 20:07:33 +000028class MachineFunction;
Chris Lattner1951c5b2002-12-28 20:07:33 +000029class Constant;
30class Type;
31
Chris Lattnera1e51ff2004-08-18 18:13:37 +000032class SparcV9FunctionInfo : public MachineFunctionInfo {
Chris Lattner1951c5b2002-12-28 20:07:33 +000033 hash_set<const Constant*> constantsForConstPool;
34 hash_map<const Value*, int> offsets;
Chris Lattner4aa5b2a2004-06-27 18:50:30 +000035
Chris Lattner1951c5b2002-12-28 20:07:33 +000036 unsigned staticStackSize;
37 unsigned automaticVarsSize;
38 unsigned regSpillsSize;
39 unsigned maxOptionalArgsSize;
40 unsigned maxOptionalNumArgs;
41 unsigned currentTmpValuesSize;
42 unsigned maxTmpValuesSize;
43 bool compiledAsLeaf;
44 bool spillsAreaFrozen;
45 bool automaticVarsAreaFrozen;
46
47 MachineFunction &MF;
48public:
Chris Lattner4aa5b2a2004-06-27 18:50:30 +000049 hash_map<const Instruction*, MachineCodeForInstruction> MCFIEntries;
50
Chris Lattnera1e51ff2004-08-18 18:13:37 +000051 SparcV9FunctionInfo(MachineFunction &mf) : MF(mf) {
Chris Lattner1951c5b2002-12-28 20:07:33 +000052 staticStackSize = automaticVarsSize = regSpillsSize = 0;
53 maxOptionalArgsSize = maxOptionalNumArgs = currentTmpValuesSize = 0;
54 maxTmpValuesSize = 0;
55 compiledAsLeaf = spillsAreaFrozen = automaticVarsAreaFrozen = false;
56 }
57
58 /// CalculateArgSize - Call this method to fill in the maxOptionalArgsSize &
59 /// staticStackSize fields...
60 ///
61 void CalculateArgSize();
62
63 //
64 // Accessors for global information about generated code for a method.
65 //
66 bool isCompiledAsLeafMethod() const { return compiledAsLeaf; }
67 unsigned getStaticStackSize() const { return staticStackSize; }
68 unsigned getAutomaticVarsSize() const { return automaticVarsSize; }
69 unsigned getRegSpillsSize() const { return regSpillsSize; }
70 unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
71 unsigned getMaxOptionalNumArgs() const { return maxOptionalNumArgs;}
72 const hash_set<const Constant*> &getConstantPoolValues() const {
73 return constantsForConstPool;
74 }
75
76 //
77 // Modifiers used during code generation
78 //
79 void initializeFrameLayout ();
80
81 void addToConstantPool (const Constant* constVal) {
82 constantsForConstPool.insert(constVal);
83 }
84
85 void markAsLeafMethod() { compiledAsLeaf = true; }
86
87 int computeOffsetforLocalVar (const Value* local,
88 unsigned& getPaddedSize,
89 unsigned sizeToUse = 0);
90 int allocateLocalVar (const Value* local,
91 unsigned sizeToUse = 0);
92
93 int allocateSpilledValue (const Type* type);
94 int pushTempValue (unsigned size);
95 void popAllTempValues ();
96
97 void freezeSpillsArea () { spillsAreaFrozen = true; }
98 void freezeAutomaticVarsArea () { automaticVarsAreaFrozen=true; }
99
Chris Lattner1951c5b2002-12-28 20:07:33 +0000100private:
101 void incrementAutomaticVarsSize(int incr) {
102 automaticVarsSize+= incr;
103 staticStackSize += incr;
104 }
105 void incrementRegSpillsSize(int incr) {
106 regSpillsSize+= incr;
107 staticStackSize += incr;
108 }
109 void incrementTmpAreaSize(int incr) {
110 currentTmpValuesSize += incr;
111 if (maxTmpValuesSize < currentTmpValuesSize)
112 {
113 staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
114 maxTmpValuesSize = currentTmpValuesSize;
115 }
116 }
117 void resetTmpAreaSize() {
118 currentTmpValuesSize = 0;
119 }
120 int allocateOptionalArg(const Type* type);
121};
122
Brian Gaeked0fde302003-11-11 22:41:34 +0000123} // End llvm namespace
124
Chris Lattner1951c5b2002-12-28 20:07:33 +0000125#endif