[llvm-commits] CVS: llvm/lib/Bytecode/Writer/SlotCalculator.cpp SlotCalculator.h Writer.cpp WriterInternals.h

Reid Spencer reid at x10sys.com
Mon Feb 5 12:48:29 PST 2007



Changes in directory llvm/lib/Bytecode/Writer:

SlotCalculator.cpp updated: 1.81 -> 1.82
SlotCalculator.h updated: 1.26 -> 1.27
Writer.cpp updated: 1.155 -> 1.156
WriterInternals.h updated: 1.28 -> 1.29
---
Log message:

For PR411: http://llvm.org/PR411 :
This patch replaces the SymbolTable class with ValueSymbolTable which does
not support types planes. This means that all symbol names in LLVM must now
be unique. The patch addresses the necessary changes to deal with this and
removes code no longer needed as a result. This completes the bulk of the
changes for this PR. Some cleanup patches will follow.


---
Diffs of the changes:  (+35 -28)

 SlotCalculator.cpp |   29 ++++++++++++-----------------
 SlotCalculator.h   |    5 +++--
 Writer.cpp         |   26 ++++++++++++++++++--------
 WriterInternals.h  |    3 ++-
 4 files changed, 35 insertions(+), 28 deletions(-)


Index: llvm/lib/Bytecode/Writer/SlotCalculator.cpp
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.81 llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.82
--- llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.81	Tue Jan 30 13:36:46 2007
+++ llvm/lib/Bytecode/Writer/SlotCalculator.cpp	Mon Feb  5 14:47:20 2007
@@ -21,9 +21,9 @@
 #include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
 #include "llvm/TypeSymbolTable.h"
 #include "llvm/Type.h"
+#include "llvm/ValueSymbolTable.h"
 #include "llvm/Analysis/ConstantsScanner.h"
 #include "llvm/ADT/PostOrderIterator.h"
 #include "llvm/ADT/STLExtras.h"
@@ -218,8 +218,8 @@
 
 // processTypeSymbolTable - Insert all of the type sin the specified symbol
 // table.
-void SlotCalculator::processTypeSymbolTable(const TypeSymbolTable *ST) {
-  for (TypeSymbolTable::const_iterator TI = ST->begin(), TE = ST->end(); 
+void SlotCalculator::processTypeSymbolTable(const TypeSymbolTable *TST) {
+  for (TypeSymbolTable::const_iterator TI = TST->begin(), TE = TST->end(); 
        TI != TE; ++TI )
     getOrCreateSlot(TI->second);
 }
@@ -227,23 +227,18 @@
 // processSymbolTable - Insert all of the values in the specified symbol table
 // into the values table...
 //
-void SlotCalculator::processValueSymbolTable(const SymbolTable *ST) {
-  for (SymbolTable::plane_const_iterator PI = ST->plane_begin(),
-       PE = ST->plane_end(); PI != PE; ++PI)
-    for (SymbolTable::value_const_iterator VI = PI->second.begin(),
-           VE = PI->second.end(); VI != VE; ++VI)
-      getOrCreateSlot(VI->second);
+void SlotCalculator::processValueSymbolTable(const ValueSymbolTable *VST) {
+  for (ValueSymbolTable::const_iterator VI = VST->begin(), VE = VST->end(); 
+       VI != VE; ++VI)
+    getOrCreateSlot(VI->second);
 }
 
-void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
+void SlotCalculator::processSymbolTableConstants(const ValueSymbolTable *VST) {
   // Now do the constant values in all planes
-  for (SymbolTable::plane_const_iterator PI = ST->plane_begin(),
-       PE = ST->plane_end(); PI != PE; ++PI)
-    for (SymbolTable::value_const_iterator VI = PI->second.begin(),
-           VE = PI->second.end(); VI != VE; ++VI)
-      if (isa<Constant>(VI->second) &&
-          !isa<GlobalValue>(VI->second))
-        getOrCreateSlot(VI->second);
+  for (ValueSymbolTable::const_iterator VI = VST->begin(), VE = VST->end(); 
+       VI != VE; ++VI)
+    if (isa<Constant>(VI->second) && !isa<GlobalValue>(VI->second))
+      getOrCreateSlot(VI->second);
 }
 
 


Index: llvm/lib/Bytecode/Writer/SlotCalculator.h
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.h:1.26 llvm/lib/Bytecode/Writer/SlotCalculator.h:1.27
--- llvm/lib/Bytecode/Writer/SlotCalculator.h:1.26	Tue Jan 30 13:36:46 2007
+++ llvm/lib/Bytecode/Writer/SlotCalculator.h	Mon Feb  5 14:47:20 2007
@@ -31,6 +31,7 @@
 class Function;
 class SymbolTable;
 class TypeSymbolTable;
+class ValueSymbolTable;
 class ConstantArray;
 
 class SlotCalculator {
@@ -130,8 +131,8 @@
   // into the values table...
   //
   void processTypeSymbolTable(const TypeSymbolTable *ST);
-  void processValueSymbolTable(const SymbolTable *ST);
-  void processSymbolTableConstants(const SymbolTable *ST);
+  void processValueSymbolTable(const ValueSymbolTable *ST);
+  void processSymbolTableConstants(const ValueSymbolTable *ST);
 
   // insertPrimitives - helper for constructors to insert primitive types.
   void insertPrimitives();


Index: llvm/lib/Bytecode/Writer/Writer.cpp
diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.155 llvm/lib/Bytecode/Writer/Writer.cpp:1.156
--- llvm/lib/Bytecode/Writer/Writer.cpp:1.155	Tue Jan 30 14:08:37 2007
+++ llvm/lib/Bytecode/Writer/Writer.cpp	Mon Feb  5 14:47:20 2007
@@ -26,8 +26,8 @@
 #include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
 #include "llvm/TypeSymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Support/Compressor.h"
 #include "llvm/Support/MathExtras.h"
@@ -1144,21 +1144,31 @@
   }
 }
 
-void BytecodeWriter::outputValueSymbolTable(const SymbolTable &MST) {
+void BytecodeWriter::outputValueSymbolTable(const ValueSymbolTable &VST) {
   // Do not output the Bytecode block for an empty symbol table, it just wastes
   // space!
-  if (MST.isEmpty()) return;
+  if (VST.empty()) return;
 
   BytecodeBlock SymTabBlock(BytecodeFormat::ValueSymbolTableBlockID, *this,
                             true/*ElideIfEmpty*/);
 
-  // Now do each of the type planes in order.
-  for (SymbolTable::plane_const_iterator PI = MST.plane_begin(),
-       PE = MST.plane_end(); PI != PE;  ++PI) {
-    SymbolTable::value_const_iterator I = MST.value_begin(PI->first);
-    SymbolTable::value_const_iterator End = MST.value_end(PI->first);
+  // Organize the symbol table by type
+  typedef std::pair<std::string, const Value*> PlaneMapEntry;
+  typedef std::vector<PlaneMapEntry> PlaneMapVector;
+  typedef std::map<const Type*, PlaneMapVector > PlaneMap;
+  PlaneMap Planes;
+  for (ValueSymbolTable::const_iterator SI = VST.begin(), SE = VST.end();
+       SI != SE; ++SI) 
+    Planes[SI->second->getType()].push_back(
+        std::make_pair(SI->first,SI->second));
+
+  for (PlaneMap::const_iterator PI = Planes.begin(), PE = Planes.end();
+       PI != PE; ++PI) {
     int Slot;
 
+    PlaneMapVector::const_iterator I = PI->second.begin(); 
+    PlaneMapVector::const_iterator End = PI->second.end(); 
+
     if (I == End) continue;  // Don't mess with an absent type...
 
     // Write the number of values in this plane


Index: llvm/lib/Bytecode/Writer/WriterInternals.h
diff -u llvm/lib/Bytecode/Writer/WriterInternals.h:1.28 llvm/lib/Bytecode/Writer/WriterInternals.h:1.29
--- llvm/lib/Bytecode/Writer/WriterInternals.h:1.28	Sat Jan  6 01:24:43 2007
+++ llvm/lib/Bytecode/Writer/WriterInternals.h	Mon Feb  5 14:47:20 2007
@@ -26,6 +26,7 @@
 namespace llvm {
   class InlineAsm;
   class TypeSymbolTable;
+  class ValueSymbolTable;
 
 class BytecodeWriter {
   std::vector<unsigned char> &Out;
@@ -66,7 +67,7 @@
 
   void outputModuleInfoBlock(const Module *C);
   void outputTypeSymbolTable(const TypeSymbolTable &TST);
-  void outputValueSymbolTable(const SymbolTable &ST);
+  void outputValueSymbolTable(const ValueSymbolTable &ST);
   void outputTypes(unsigned StartNo);
   void outputConstantsInPlane(const std::vector<const Value*> &Plane,
                               unsigned StartNo);






More information about the llvm-commits mailing list