Add support for representing the "compaction table"
authorChris Lattner <sabre@nondot.org>
Sun, 18 Jan 2004 21:03:49 +0000 (21:03 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 18 Jan 2004 21:03:49 +0000 (21:03 +0000)
Change protected members to private.  Nothing should subclass SlotCalculator

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10912 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/SlotCalculator.h
include/llvm/SlotCalculator.h
lib/Bytecode/Writer/SlotCalculator.h

index fbd0976c8cbeb385de956647351445b15c6d709f..105e585d852f78fe8e3d0a266d3e017a767914cb 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <vector>
 #include <map>
+#include <cassert>
 
 namespace llvm {
 
@@ -53,22 +54,50 @@ class SlotCalculator {
   ///
   std::vector<unsigned> ModuleLevel;
 
+  /// ModuleContainsAllFunctionConstants - This flag is set to true if all
+  /// function constants are incorporated into the module constant table.  This
+  /// is only possible if building information for a bytecode file.
+  bool ModuleContainsAllFunctionConstants;
+
+  /// CompactionTable/NodeMap - When function compaction has been performed,
+  /// these entries provide a compacted view of the namespace needed to emit
+  /// instructions in a function body.  The 'getSlot()' method automatically
+  /// returns these entries if applicable, or the global entries if not.
+  std::vector<TypePlane> CompactionTable;
+  std::map<const Value*, unsigned> CompactionNodeMap;
+
+  SlotCalculator(const SlotCalculator &);  // DO NOT IMPLEMENT
+  void operator=(const SlotCalculator &);  // DO NOT IMPLEMENT
 public:
   SlotCalculator(const Module *M, bool BuildBytecodeInfo);
   // Start out in incorp state
   SlotCalculator(const Function *F, bool BuildBytecodeInfo);
   
-  /// getSlot returns < 0 on error!
+  /// getSlot - Return the slot number of the specified value in it's type
+  /// plane.  This returns < 0 on error!
   ///
-  int getSlot(const Value *D) const;
+  int getSlot(const Value *V) const;
+
+  /// getGlobalSlot - Return a slot number from the global table.  This can only
+  /// be used when a compaction table is active.
+  unsigned getGlobalSlot(const Value *V) const;
 
-  inline unsigned getNumPlanes() const { return Table.size(); }
+  inline unsigned getNumPlanes() const {
+    if (CompactionTable.empty())
+      return Table.size();
+    else
+      return CompactionTable.size();
+  }
   inline unsigned getModuleLevel(unsigned Plane) const { 
     return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; 
   }
 
   inline const TypePlane &getPlane(unsigned Plane) const { 
-    return Table[Plane]; 
+    if (CompactionTable.empty() || CompactionTable.size() <= Plane ||
+        CompactionTable[Plane].empty())
+      return Table[Plane];
+    else
+      return CompactionTable[Plane];
   }
 
   /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
@@ -84,8 +113,11 @@ public:
   string_iterator string_begin() const { return ConstantStrings.begin(); }
   string_iterator string_end() const   { return ConstantStrings.end(); }
 
+  const std::vector<TypePlane> &getCompactionTable() const {
+    return CompactionTable;
+  }
 
-protected:
+private:
   // getOrCreateSlot - Values can be crammed into here at will... if
   // they haven't been inserted already, they get inserted, otherwise
   // they are ignored.
@@ -111,6 +143,9 @@ protected:
   //
   void processSymbolTable(const SymbolTable *ST);
   void processSymbolTableConstants(const SymbolTable *ST);
+
+  void buildCompactionTable(const Function *F);
+  unsigned getOrCreateCompactionTableSlot(const Value *V);
 };
 
 } // End llvm namespace
index fbd0976c8cbeb385de956647351445b15c6d709f..105e585d852f78fe8e3d0a266d3e017a767914cb 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <vector>
 #include <map>
+#include <cassert>
 
 namespace llvm {
 
@@ -53,22 +54,50 @@ class SlotCalculator {
   ///
   std::vector<unsigned> ModuleLevel;
 
+  /// ModuleContainsAllFunctionConstants - This flag is set to true if all
+  /// function constants are incorporated into the module constant table.  This
+  /// is only possible if building information for a bytecode file.
+  bool ModuleContainsAllFunctionConstants;
+
+  /// CompactionTable/NodeMap - When function compaction has been performed,
+  /// these entries provide a compacted view of the namespace needed to emit
+  /// instructions in a function body.  The 'getSlot()' method automatically
+  /// returns these entries if applicable, or the global entries if not.
+  std::vector<TypePlane> CompactionTable;
+  std::map<const Value*, unsigned> CompactionNodeMap;
+
+  SlotCalculator(const SlotCalculator &);  // DO NOT IMPLEMENT
+  void operator=(const SlotCalculator &);  // DO NOT IMPLEMENT
 public:
   SlotCalculator(const Module *M, bool BuildBytecodeInfo);
   // Start out in incorp state
   SlotCalculator(const Function *F, bool BuildBytecodeInfo);
   
-  /// getSlot returns < 0 on error!
+  /// getSlot - Return the slot number of the specified value in it's type
+  /// plane.  This returns < 0 on error!
   ///
-  int getSlot(const Value *D) const;
+  int getSlot(const Value *V) const;
+
+  /// getGlobalSlot - Return a slot number from the global table.  This can only
+  /// be used when a compaction table is active.
+  unsigned getGlobalSlot(const Value *V) const;
 
-  inline unsigned getNumPlanes() const { return Table.size(); }
+  inline unsigned getNumPlanes() const {
+    if (CompactionTable.empty())
+      return Table.size();
+    else
+      return CompactionTable.size();
+  }
   inline unsigned getModuleLevel(unsigned Plane) const { 
     return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; 
   }
 
   inline const TypePlane &getPlane(unsigned Plane) const { 
-    return Table[Plane]; 
+    if (CompactionTable.empty() || CompactionTable.size() <= Plane ||
+        CompactionTable[Plane].empty())
+      return Table[Plane];
+    else
+      return CompactionTable[Plane];
   }
 
   /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
@@ -84,8 +113,11 @@ public:
   string_iterator string_begin() const { return ConstantStrings.begin(); }
   string_iterator string_end() const   { return ConstantStrings.end(); }
 
+  const std::vector<TypePlane> &getCompactionTable() const {
+    return CompactionTable;
+  }
 
-protected:
+private:
   // getOrCreateSlot - Values can be crammed into here at will... if
   // they haven't been inserted already, they get inserted, otherwise
   // they are ignored.
@@ -111,6 +143,9 @@ protected:
   //
   void processSymbolTable(const SymbolTable *ST);
   void processSymbolTableConstants(const SymbolTable *ST);
+
+  void buildCompactionTable(const Function *F);
+  unsigned getOrCreateCompactionTableSlot(const Value *V);
 };
 
 } // End llvm namespace
index fbd0976c8cbeb385de956647351445b15c6d709f..105e585d852f78fe8e3d0a266d3e017a767914cb 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <vector>
 #include <map>
+#include <cassert>
 
 namespace llvm {
 
@@ -53,22 +54,50 @@ class SlotCalculator {
   ///
   std::vector<unsigned> ModuleLevel;
 
+  /// ModuleContainsAllFunctionConstants - This flag is set to true if all
+  /// function constants are incorporated into the module constant table.  This
+  /// is only possible if building information for a bytecode file.
+  bool ModuleContainsAllFunctionConstants;
+
+  /// CompactionTable/NodeMap - When function compaction has been performed,
+  /// these entries provide a compacted view of the namespace needed to emit
+  /// instructions in a function body.  The 'getSlot()' method automatically
+  /// returns these entries if applicable, or the global entries if not.
+  std::vector<TypePlane> CompactionTable;
+  std::map<const Value*, unsigned> CompactionNodeMap;
+
+  SlotCalculator(const SlotCalculator &);  // DO NOT IMPLEMENT
+  void operator=(const SlotCalculator &);  // DO NOT IMPLEMENT
 public:
   SlotCalculator(const Module *M, bool BuildBytecodeInfo);
   // Start out in incorp state
   SlotCalculator(const Function *F, bool BuildBytecodeInfo);
   
-  /// getSlot returns < 0 on error!
+  /// getSlot - Return the slot number of the specified value in it's type
+  /// plane.  This returns < 0 on error!
   ///
-  int getSlot(const Value *D) const;
+  int getSlot(const Value *V) const;
+
+  /// getGlobalSlot - Return a slot number from the global table.  This can only
+  /// be used when a compaction table is active.
+  unsigned getGlobalSlot(const Value *V) const;
 
-  inline unsigned getNumPlanes() const { return Table.size(); }
+  inline unsigned getNumPlanes() const {
+    if (CompactionTable.empty())
+      return Table.size();
+    else
+      return CompactionTable.size();
+  }
   inline unsigned getModuleLevel(unsigned Plane) const { 
     return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; 
   }
 
   inline const TypePlane &getPlane(unsigned Plane) const { 
-    return Table[Plane]; 
+    if (CompactionTable.empty() || CompactionTable.size() <= Plane ||
+        CompactionTable[Plane].empty())
+      return Table[Plane];
+    else
+      return CompactionTable[Plane];
   }
 
   /// incorporateFunction/purgeFunction - If you'd like to deal with a function,
@@ -84,8 +113,11 @@ public:
   string_iterator string_begin() const { return ConstantStrings.begin(); }
   string_iterator string_end() const   { return ConstantStrings.end(); }
 
+  const std::vector<TypePlane> &getCompactionTable() const {
+    return CompactionTable;
+  }
 
-protected:
+private:
   // getOrCreateSlot - Values can be crammed into here at will... if
   // they haven't been inserted already, they get inserted, otherwise
   // they are ignored.
@@ -111,6 +143,9 @@ protected:
   //
   void processSymbolTable(const SymbolTable *ST);
   void processSymbolTableConstants(const SymbolTable *ST);
+
+  void buildCompactionTable(const Function *F);
+  unsigned getOrCreateCompactionTableSlot(const Value *V);
 };
 
 } // End llvm namespace