State for frame and constant pool information pulled out of MachineFunction
authorChris Lattner <sabre@nondot.org>
Sat, 28 Dec 2002 20:07:33 +0000 (20:07 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 28 Dec 2002 20:07:33 +0000 (20:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5165 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineFunctionInfo.h [new file with mode: 0644]
lib/Target/SparcV9/MachineFunctionInfo.h [new file with mode: 0644]

diff --git a/include/llvm/CodeGen/MachineFunctionInfo.h b/include/llvm/CodeGen/MachineFunctionInfo.h
new file mode 100644 (file)
index 0000000..53df8bd
--- /dev/null
@@ -0,0 +1,108 @@
+//===-- llvm/CodeGen/MachineFunctionInfo.h ----------------------*- C++ -*-===//
+// 
+// This class keeps track of information about the stack frame and about the
+// per-function constant pool.
+//   
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_MACHINEFUNCTIONINFO_H
+#define LLVM_CODEGEN_MACHINEFUNCTIONINFO_H
+
+#include "Support/HashExtras.h"
+#include "Support/hash_set"
+class MachineFunction;
+class Value;
+class Constant;
+class Type;
+
+class MachineFunctionInfo {
+  hash_set<const Constant*> constantsForConstPool;
+  hash_map<const Value*, int> offsets;
+  unsigned     staticStackSize;
+  unsigned     automaticVarsSize;
+  unsigned     regSpillsSize;
+  unsigned     maxOptionalArgsSize;
+  unsigned     maxOptionalNumArgs;
+  unsigned     currentTmpValuesSize;
+  unsigned     maxTmpValuesSize;
+  bool          compiledAsLeaf;
+  bool          spillsAreaFrozen;
+  bool          automaticVarsAreaFrozen;
+
+  MachineFunction &MF;
+public:
+  MachineFunctionInfo(MachineFunction &mf) : MF(mf) {
+    staticStackSize = automaticVarsSize = regSpillsSize = 0;
+    maxOptionalArgsSize = maxOptionalNumArgs = currentTmpValuesSize = 0;
+    maxTmpValuesSize = 0;
+    compiledAsLeaf = spillsAreaFrozen = automaticVarsAreaFrozen = false;
+  }
+
+  /// CalculateArgSize - Call this method to fill in the maxOptionalArgsSize &
+  /// staticStackSize fields...
+  ///
+  void CalculateArgSize();
+
+  //
+  // Accessors for global information about generated code for a method.
+  // 
+  bool     isCompiledAsLeafMethod() const { return compiledAsLeaf; }
+  unsigned getStaticStackSize()     const { return staticStackSize; }
+  unsigned getAutomaticVarsSize()   const { return automaticVarsSize; }
+  unsigned getRegSpillsSize()       const { return regSpillsSize; }
+  unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
+  unsigned getMaxOptionalNumArgs()  const { return maxOptionalNumArgs;}
+  const hash_set<const Constant*> &getConstantPoolValues() const {
+    return constantsForConstPool;
+  }
+  
+  //
+  // Modifiers used during code generation
+  // 
+  void            initializeFrameLayout    ();
+  
+  void            addToConstantPool        (const Constant* constVal) {
+    constantsForConstPool.insert(constVal);
+  }
+  
+  void markAsLeafMethod() { compiledAsLeaf = true; }
+  
+  int             computeOffsetforLocalVar (const Value*  local,
+                                            unsigned& getPaddedSize,
+                                            unsigned  sizeToUse = 0);
+  int             allocateLocalVar         (const Value* local,
+                                            unsigned sizeToUse = 0);
+  
+  int             allocateSpilledValue     (const Type* type);
+  int             pushTempValue            (unsigned size);
+  void            popAllTempValues         ();
+  
+  void            freezeSpillsArea         () { spillsAreaFrozen = true; } 
+  void            freezeAutomaticVarsArea  () { automaticVarsAreaFrozen=true; }
+  
+  int             getOffset                (const Value* val) const;
+  
+private:
+  void incrementAutomaticVarsSize(int incr) {
+    automaticVarsSize+= incr;
+    staticStackSize += incr;
+  }
+  void incrementRegSpillsSize(int incr) {
+    regSpillsSize+= incr;
+    staticStackSize += incr;
+  }
+  void incrementTmpAreaSize(int incr) {
+    currentTmpValuesSize += incr;
+    if (maxTmpValuesSize < currentTmpValuesSize)
+      {
+        staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
+        maxTmpValuesSize = currentTmpValuesSize;
+      }
+  }
+  void resetTmpAreaSize() {
+    currentTmpValuesSize = 0;
+  }
+  int allocateOptionalArg(const Type* type);
+};
+
+#endif
diff --git a/lib/Target/SparcV9/MachineFunctionInfo.h b/lib/Target/SparcV9/MachineFunctionInfo.h
new file mode 100644 (file)
index 0000000..53df8bd
--- /dev/null
@@ -0,0 +1,108 @@
+//===-- llvm/CodeGen/MachineFunctionInfo.h ----------------------*- C++ -*-===//
+// 
+// This class keeps track of information about the stack frame and about the
+// per-function constant pool.
+//   
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_MACHINEFUNCTIONINFO_H
+#define LLVM_CODEGEN_MACHINEFUNCTIONINFO_H
+
+#include "Support/HashExtras.h"
+#include "Support/hash_set"
+class MachineFunction;
+class Value;
+class Constant;
+class Type;
+
+class MachineFunctionInfo {
+  hash_set<const Constant*> constantsForConstPool;
+  hash_map<const Value*, int> offsets;
+  unsigned     staticStackSize;
+  unsigned     automaticVarsSize;
+  unsigned     regSpillsSize;
+  unsigned     maxOptionalArgsSize;
+  unsigned     maxOptionalNumArgs;
+  unsigned     currentTmpValuesSize;
+  unsigned     maxTmpValuesSize;
+  bool          compiledAsLeaf;
+  bool          spillsAreaFrozen;
+  bool          automaticVarsAreaFrozen;
+
+  MachineFunction &MF;
+public:
+  MachineFunctionInfo(MachineFunction &mf) : MF(mf) {
+    staticStackSize = automaticVarsSize = regSpillsSize = 0;
+    maxOptionalArgsSize = maxOptionalNumArgs = currentTmpValuesSize = 0;
+    maxTmpValuesSize = 0;
+    compiledAsLeaf = spillsAreaFrozen = automaticVarsAreaFrozen = false;
+  }
+
+  /// CalculateArgSize - Call this method to fill in the maxOptionalArgsSize &
+  /// staticStackSize fields...
+  ///
+  void CalculateArgSize();
+
+  //
+  // Accessors for global information about generated code for a method.
+  // 
+  bool     isCompiledAsLeafMethod() const { return compiledAsLeaf; }
+  unsigned getStaticStackSize()     const { return staticStackSize; }
+  unsigned getAutomaticVarsSize()   const { return automaticVarsSize; }
+  unsigned getRegSpillsSize()       const { return regSpillsSize; }
+  unsigned getMaxOptionalArgsSize() const { return maxOptionalArgsSize;}
+  unsigned getMaxOptionalNumArgs()  const { return maxOptionalNumArgs;}
+  const hash_set<const Constant*> &getConstantPoolValues() const {
+    return constantsForConstPool;
+  }
+  
+  //
+  // Modifiers used during code generation
+  // 
+  void            initializeFrameLayout    ();
+  
+  void            addToConstantPool        (const Constant* constVal) {
+    constantsForConstPool.insert(constVal);
+  }
+  
+  void markAsLeafMethod() { compiledAsLeaf = true; }
+  
+  int             computeOffsetforLocalVar (const Value*  local,
+                                            unsigned& getPaddedSize,
+                                            unsigned  sizeToUse = 0);
+  int             allocateLocalVar         (const Value* local,
+                                            unsigned sizeToUse = 0);
+  
+  int             allocateSpilledValue     (const Type* type);
+  int             pushTempValue            (unsigned size);
+  void            popAllTempValues         ();
+  
+  void            freezeSpillsArea         () { spillsAreaFrozen = true; } 
+  void            freezeAutomaticVarsArea  () { automaticVarsAreaFrozen=true; }
+  
+  int             getOffset                (const Value* val) const;
+  
+private:
+  void incrementAutomaticVarsSize(int incr) {
+    automaticVarsSize+= incr;
+    staticStackSize += incr;
+  }
+  void incrementRegSpillsSize(int incr) {
+    regSpillsSize+= incr;
+    staticStackSize += incr;
+  }
+  void incrementTmpAreaSize(int incr) {
+    currentTmpValuesSize += incr;
+    if (maxTmpValuesSize < currentTmpValuesSize)
+      {
+        staticStackSize += currentTmpValuesSize - maxTmpValuesSize;
+        maxTmpValuesSize = currentTmpValuesSize;
+      }
+  }
+  void resetTmpAreaSize() {
+    currentTmpValuesSize = 0;
+  }
+  int allocateOptionalArg(const Type* type);
+};
+
+#endif