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

Reid Spencer reid at x10sys.com
Fri Jan 5 23:25:20 PST 2007



Changes in directory llvm/lib/Bytecode/Writer:

SlotCalculator.cpp updated: 1.77 -> 1.78
SlotCalculator.h updated: 1.23 -> 1.24
Writer.cpp updated: 1.141 -> 1.142
WriterInternals.h updated: 1.27 -> 1.28
---
Log message:

For PR411: http://llvm.org/PR411 :
Take an incremental step towards type plane elimination. This change 
separates types from values in the symbol tables by finally making use
of the TypeSymbolTable class. This yields more natural interfaces for
dealing with types and unclutters the SymbolTable class.


---
Diffs of the changes:  (+45 -34)

 SlotCalculator.cpp |   36 +++++++++++++++---------------------
 SlotCalculator.h   |    4 +++-
 Writer.cpp         |   35 ++++++++++++++++++++++++-----------
 WriterInternals.h  |    4 +++-
 4 files changed, 45 insertions(+), 34 deletions(-)


Index: llvm/lib/Bytecode/Writer/SlotCalculator.cpp
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.77 llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.78
--- llvm/lib/Bytecode/Writer/SlotCalculator.cpp:1.77	Sat Dec 30 23:44:24 2006
+++ llvm/lib/Bytecode/Writer/SlotCalculator.cpp	Sat Jan  6 01:24:43 2007
@@ -22,6 +22,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
 #include "llvm/Type.h"
 #include "llvm/Analysis/ConstantsScanner.h"
 #include "llvm/ADT/PostOrderIterator.h"
@@ -189,13 +190,14 @@
       }
       getOrCreateSlot(I->getType());
     }
-    processSymbolTableConstants(&F->getSymbolTable());
+    processSymbolTableConstants(&F->getValueSymbolTable());
   }
 
   // Insert constants that are named at module level into the slot pool so that
   // the module symbol table can refer to them...
   SC_DEBUG("Inserting SymbolTable values:\n");
-  processSymbolTable(&TheModule->getSymbolTable());
+  processTypeSymbolTable(&TheModule->getTypeSymbolTable());
+  processValueSymbolTable(&TheModule->getValueSymbolTable());
 
   // Now that we have collected together all of the information relevant to the
   // module, compactify the type table if it is particularly big and outputting
@@ -233,16 +235,18 @@
   SC_DEBUG("end processModule!\n");
 }
 
+// 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(); 
+       TI != TE; ++TI )
+    getOrCreateSlot(TI->second);
+}
+
 // processSymbolTable - Insert all of the values in the specified symbol table
 // into the values table...
 //
-void SlotCalculator::processSymbolTable(const SymbolTable *ST) {
-  // Do the types first.
-  for (SymbolTable::type_const_iterator TI = ST->type_begin(),
-       TE = ST->type_end(); TI != TE; ++TI )
-    getOrCreateSlot(TI->second);
-
-  // Now do the values.
+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(),
@@ -251,11 +255,6 @@
 }
 
 void SlotCalculator::processSymbolTableConstants(const SymbolTable *ST) {
-  // Do the types first
-  for (SymbolTable::type_const_iterator TI = ST->type_begin(),
-       TE = ST->type_end(); TI != TE; ++TI )
-    getOrCreateSlot(TI->second);
-
   // Now do the constant values in all planes
   for (SymbolTable::plane_const_iterator PI = ST->plane_begin(),
        PE = ST->plane_end(); PI != PE; ++PI)
@@ -306,7 +305,7 @@
     // symbol table references to constants not in the output.  Scan for these
     // constants now.
     //
-    processSymbolTableConstants(&F->getSymbolTable());
+    processSymbolTableConstants(&F->getValueSymbolTable());
   }
 
   SC_DEBUG("Inserting Instructions:\n");
@@ -468,13 +467,8 @@
         getOrCreateCompactionTableSlot(I->getOperand(op));
   }
 
-  // Do the types in the symbol table
-  const SymbolTable &ST = F->getSymbolTable();
-  for (SymbolTable::type_const_iterator TI = ST.type_begin(),
-       TE = ST.type_end(); TI != TE; ++TI)
-    getOrCreateCompactionTableSlot(TI->second);
-
   // Now do the constants and global values
+  const SymbolTable &ST = F->getValueSymbolTable();
   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(),


Index: llvm/lib/Bytecode/Writer/SlotCalculator.h
diff -u llvm/lib/Bytecode/Writer/SlotCalculator.h:1.23 llvm/lib/Bytecode/Writer/SlotCalculator.h:1.24
--- llvm/lib/Bytecode/Writer/SlotCalculator.h:1.23	Wed Jan 25 17:08:15 2006
+++ llvm/lib/Bytecode/Writer/SlotCalculator.h	Sat Jan  6 01:24:43 2007
@@ -30,6 +30,7 @@
 class Module;
 class Function;
 class SymbolTable;
+class TypeSymbolTable;
 class ConstantArray;
 
 class SlotCalculator {
@@ -168,7 +169,8 @@
   // processSymbolTable - Insert all of the values in the specified symbol table
   // into the values table...
   //
-  void processSymbolTable(const SymbolTable *ST);
+  void processTypeSymbolTable(const TypeSymbolTable *ST);
+  void processValueSymbolTable(const SymbolTable *ST);
   void processSymbolTableConstants(const SymbolTable *ST);
 
   void buildCompactionTable(const Function *F);


Index: llvm/lib/Bytecode/Writer/Writer.cpp
diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.141 llvm/lib/Bytecode/Writer/Writer.cpp:1.142
--- llvm/lib/Bytecode/Writer/Writer.cpp:1.141	Sat Dec 30 23:44:24 2006
+++ llvm/lib/Bytecode/Writer/Writer.cpp	Sat Jan  6 01:24:43 2007
@@ -27,6 +27,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
 #include "llvm/Support/Compressor.h"
 #include "llvm/Support/MathExtras.h"
@@ -837,8 +838,11 @@
   for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
     outputFunction(I);
 
-  // If needed, output the symbol table for the module...
-  outputSymbolTable(M->getSymbolTable());
+  // Output the symbole table for types
+  outputTypeSymbolTable(M->getTypeSymbolTable());
+
+  // Output the symbol table for values
+  outputValueSymbolTable(M->getValueSymbolTable());
 }
 
 void BytecodeWriter::outputTypes(unsigned TypeNum) {
@@ -1112,7 +1116,7 @@
   outputInstructions(F);
 
   // If needed, output the symbol table for the function...
-  outputSymbolTable(F->getSymbolTable());
+  outputValueSymbolTable(F->getValueSymbolTable());
 
   Table.purgeFunction();
 }
@@ -1187,24 +1191,33 @@
   }
 }
 
-void BytecodeWriter::outputSymbolTable(const SymbolTable &MST) {
-  // Do not output the Bytecode block for an empty symbol table, it just wastes
+void BytecodeWriter::outputTypeSymbolTable(const TypeSymbolTable &TST) {
+  // Do not output the block for an empty symbol table, it just wastes
   // space!
-  if (MST.isEmpty()) return;
+  if (TST.empty()) return;
 
-  BytecodeBlock SymTabBlock(BytecodeFormat::SymbolTableBlockID, *this,
+  // Create a header for the symbol table
+  BytecodeBlock SymTabBlock(BytecodeFormat::TypeSymbolTableBlockID, *this,
                             true/*ElideIfEmpty*/);
-
   // Write the number of types
-  output_vbr(MST.num_types());
+  output_vbr(TST.size());
 
   // Write each of the types
-  for (SymbolTable::type_const_iterator TI = MST.type_begin(),
-       TE = MST.type_end(); TI != TE; ++TI) {
+  for (TypeSymbolTable::const_iterator TI = TST.begin(), TE = TST.end(); 
+       TI != TE; ++TI) {
     // Symtab entry:[def slot #][name]
     output_typeid((unsigned)Table.getSlot(TI->second));
     output(TI->first);
   }
+}
+
+void BytecodeWriter::outputValueSymbolTable(const SymbolTable &MST) {
+  // Do not output the Bytecode block for an empty symbol table, it just wastes
+  // space!
+  if (MST.isEmpty()) 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(),


Index: llvm/lib/Bytecode/Writer/WriterInternals.h
diff -u llvm/lib/Bytecode/Writer/WriterInternals.h:1.27 llvm/lib/Bytecode/Writer/WriterInternals.h:1.28
--- llvm/lib/Bytecode/Writer/WriterInternals.h:1.27	Wed Jan 25 17:08:15 2006
+++ llvm/lib/Bytecode/Writer/WriterInternals.h	Sat Jan  6 01:24:43 2007
@@ -25,6 +25,7 @@
 
 namespace llvm {
   class InlineAsm;
+  class TypeSymbolTable;
 
 class BytecodeWriter {
   std::vector<unsigned char> &Out;
@@ -64,7 +65,8 @@
                                        unsigned Type) ;
 
   void outputModuleInfoBlock(const Module *C);
-  void outputSymbolTable(const SymbolTable &ST);
+  void outputTypeSymbolTable(const TypeSymbolTable &TST);
+  void outputValueSymbolTable(const SymbolTable &ST);
   void outputTypes(unsigned StartNo);
   void outputConstantsInPlane(const std::vector<const Value*> &Plane,
                               unsigned StartNo);






More information about the llvm-commits mailing list