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