[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Function.cpp Module.cpp SymbolTable.cpp SymbolTableListTraitsImpl.h TypeSymbolTable.cpp Value.cpp Verifier.cpp

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



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.234 -> 1.235
Function.cpp updated: 1.108 -> 1.109
Module.cpp updated: 1.70 -> 1.71
SymbolTable.cpp updated: 1.64 -> 1.65
SymbolTableListTraitsImpl.h updated: 1.7 -> 1.8
TypeSymbolTable.cpp updated: 1.5 -> 1.6
Value.cpp updated: 1.59 -> 1.60
Verifier.cpp updated: 1.181 -> 1.182
---
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:  (+55 -154)

 AsmWriter.cpp               |   28 ++++++-----
 Function.cpp                |    4 -
 Module.cpp                  |   27 ++++++----
 SymbolTable.cpp             |  110 --------------------------------------------
 SymbolTableListTraitsImpl.h |   12 ++--
 TypeSymbolTable.cpp         |    8 +--
 Value.cpp                   |    8 +--
 Verifier.cpp                |   12 +++-
 8 files changed, 55 insertions(+), 154 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.234 llvm/lib/VMCore/AsmWriter.cpp:1.235
--- llvm/lib/VMCore/AsmWriter.cpp:1.234	Fri Jan  5 11:06:19 2007
+++ llvm/lib/VMCore/AsmWriter.cpp	Sat Jan  6 01:24:44 2007
@@ -25,6 +25,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/CFG.h"
@@ -216,9 +217,9 @@
 static void fillTypeNameTable(const Module *M,
                               std::map<const Type *, std::string> &TypeNames) {
   if (!M) return;
-  const SymbolTable &ST = M->getSymbolTable();
-  SymbolTable::type_const_iterator TI = ST.type_begin();
-  for (; TI != ST.type_end(); ++TI) {
+  const TypeSymbolTable &ST = M->getTypeSymbolTable();
+  TypeSymbolTable::const_iterator TI = ST.begin();
+  for (; TI != ST.end(); ++TI) {
     // As a heuristic, don't insert pointer to primitive types, because
     // they are used too often to have a single useful name.
     //
@@ -666,7 +667,8 @@
 
 private:
   void printModule(const Module *M);
-  void printSymbolTable(const SymbolTable &ST);
+  void printTypeSymbolTable(const TypeSymbolTable &ST);
+  void printValueSymbolTable(const SymbolTable &ST);
   void printConstant(const Constant *CPV);
   void printGlobal(const GlobalVariable *GV);
   void printFunction(const Function *F);
@@ -818,7 +820,8 @@
   }
 
   // Loop over the symbol table, emitting all named constants.
-  printSymbolTable(M->getSymbolTable());
+  printTypeSymbolTable(M->getTypeSymbolTable());
+  printValueSymbolTable(M->getValueSymbolTable());
 
   for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
        I != E; ++I)
@@ -873,14 +876,10 @@
   Out << "\n";
 }
 
-
-// printSymbolTable - Run through symbol table looking for constants
-// and types. Emit their declarations.
-void AssemblyWriter::printSymbolTable(const SymbolTable &ST) {
-
+void AssemblyWriter::printTypeSymbolTable(const TypeSymbolTable &ST) {
   // Print the types.
-  for (SymbolTable::type_const_iterator TI = ST.type_begin();
-       TI != ST.type_end(); ++TI) {
+  for (TypeSymbolTable::const_iterator TI = ST.begin(), TE = ST.end();
+       TI != TE; ++TI) {
     Out << "\t" << getLLVMName(TI->first) << " = type ";
 
     // Make sure we print out at least one level of the type structure, so
@@ -888,6 +887,11 @@
     //
     printTypeAtLeastOneLevel(TI->second) << "\n";
   }
+}
+
+// printSymbolTable - Run through symbol table looking for constants
+// and types. Emit their declarations.
+void AssemblyWriter::printValueSymbolTable(const SymbolTable &ST) {
 
   // Print the constants, in type plane order.
   for (SymbolTable::plane_const_iterator PI = ST.plane_begin();


Index: llvm/lib/VMCore/Function.cpp
diff -u llvm/lib/VMCore/Function.cpp:1.108 llvm/lib/VMCore/Function.cpp:1.109
--- llvm/lib/VMCore/Function.cpp:1.108	Sat Dec 30 23:26:44 2006
+++ llvm/lib/VMCore/Function.cpp	Sat Jan  6 01:24:44 2007
@@ -144,8 +144,8 @@
 /// required before printing out to a textual form, to ensure that there is no
 /// ambiguity when parsing.
 void Function::renameLocalSymbols() {
-  SymbolTable &LST = getSymbolTable();                 // Local Symtab
-  SymbolTable &GST = getParent()->getSymbolTable();    // Global Symtab
+  SymbolTable &LST = getValueSymbolTable();                 // Local Symtab
+  SymbolTable &GST = getParent()->getValueSymbolTable();    // Global Symtab
 
   for (SymbolTable::plane_iterator LPI = LST.plane_begin(), E = LST.plane_end();
        LPI != E; ++LPI)


Index: llvm/lib/VMCore/Module.cpp
diff -u llvm/lib/VMCore/Module.cpp:1.70 llvm/lib/VMCore/Module.cpp:1.71
--- llvm/lib/VMCore/Module.cpp:1.70	Sat Dec 30 23:26:44 2006
+++ llvm/lib/VMCore/Module.cpp	Sat Jan  6 01:24:44 2007
@@ -19,6 +19,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/LeakDetector.h"
 #include "SymbolTableListTraitsImpl.h"
+#include "llvm/TypeSymbolTable.h"
 #include <algorithm>
 #include <cstdarg>
 #include <cstdlib>
@@ -68,7 +69,8 @@
   FunctionList.setParent(this);
   GlobalList.setItemParent(this);
   GlobalList.setParent(this);
-  SymTab = new SymbolTable();
+  ValSymTab = new SymbolTable();
+  TypeSymTab = new TypeSymbolTable();
 }
 
 Module::~Module() {
@@ -78,7 +80,8 @@
   FunctionList.clear();
   FunctionList.setParent(0);
   LibraryList.clear();
-  delete SymTab;
+  delete ValSymTab;
+  delete TypeSymTab;
 }
 
 // Module::dump() - Allow printing from debugger
@@ -156,7 +159,7 @@
 //
 Function *Module::getOrInsertFunction(const std::string &Name,
                                       const FunctionType *Ty) {
-  SymbolTable &SymTab = getSymbolTable();
+  SymbolTable &SymTab = getValueSymbolTable();
 
   // See if we have a definitions for the specified function already...
   if (Value *V = SymTab.lookup(PointerType::get(Ty), Name)) {
@@ -194,7 +197,7 @@
 // If it does not exist, return null.
 //
 Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) {
-  SymbolTable &SymTab = getSymbolTable();
+  SymbolTable &SymTab = getValueSymbolTable();
   return cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name));
 }
 
@@ -275,7 +278,7 @@
 ///
 GlobalVariable *Module::getGlobalVariable(const std::string &Name,
                                           const Type *Ty, bool AllowInternal) {
-  if (Value *V = getSymbolTable().lookup(PointerType::get(Ty), Name)) {
+  if (Value *V = getValueSymbolTable().lookup(PointerType::get(Ty), Name)) {
     GlobalVariable *Result = cast<GlobalVariable>(V);
     if (AllowInternal || !Result->hasInternalLinkage())
       return Result;
@@ -309,9 +312,9 @@
 // table is not modified.
 //
 bool Module::addTypeName(const std::string &Name, const Type *Ty) {
-  SymbolTable &ST = getSymbolTable();
+  TypeSymbolTable &ST = getTypeSymbolTable();
 
-  if (ST.lookupType(Name)) return true;  // Already in symtab...
+  if (ST.lookup(Name)) return true;  // Already in symtab...
 
   // Not in symbol table?  Set the name with the Symtab as an argument so the
   // type knows what to update...
@@ -323,18 +326,18 @@
 /// getTypeByName - Return the type with the specified name in this module, or
 /// null if there is none by that name.
 const Type *Module::getTypeByName(const std::string &Name) const {
-  const SymbolTable &ST = getSymbolTable();
-  return cast_or_null<Type>(ST.lookupType(Name));
+  const TypeSymbolTable &ST = getTypeSymbolTable();
+  return cast_or_null<Type>(ST.lookup(Name));
 }
 
 // getTypeName - If there is at least one entry in the symbol table for the
 // specified type, return it.
 //
 std::string Module::getTypeName(const Type *Ty) const {
-  const SymbolTable &ST = getSymbolTable();
+  const TypeSymbolTable &ST = getTypeSymbolTable();
 
-  SymbolTable::type_const_iterator TI = ST.type_begin();
-  SymbolTable::type_const_iterator TE = ST.type_end();
+  TypeSymbolTable::const_iterator TI = ST.begin();
+  TypeSymbolTable::const_iterator TE = ST.end();
   if ( TI == TE ) return ""; // No names for types
 
   while (TI != TE && TI->second != Ty)


Index: llvm/lib/VMCore/SymbolTable.cpp
diff -u llvm/lib/VMCore/SymbolTable.cpp:1.64 llvm/lib/VMCore/SymbolTable.cpp:1.65
--- llvm/lib/VMCore/SymbolTable.cpp:1.64	Sat Dec 23 00:05:41 2006
+++ llvm/lib/VMCore/SymbolTable.cpp	Sat Jan  6 01:24:44 2007
@@ -24,12 +24,6 @@
 #define DEBUG_ABSTYPE 0
 
 SymbolTable::~SymbolTable() {
-  // Drop all abstract type references in the type plane...
-  for (type_iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) {
-    if (TI->second->isAbstract())   // If abstract, drop the reference...
-      cast<DerivedType>(TI->second)->removeAbstractTypeUser(this);
-  }
-
  // TODO: FIXME: BIG ONE: This doesn't unreference abstract types for the
  // planes that could still have entries!
 
@@ -82,14 +76,6 @@
 }
 
 
-// lookup a type by name - returns null on failure
-Type* SymbolTable::lookupType(const std::string& Name) const {
-  type_const_iterator TI = tmap.find(Name);
-  if (TI != tmap.end())
-    return const_cast<Type*>(TI->second);
-  return 0;
-}
-
 /// changeName - Given a value with a non-empty name, remove its existing entry
 /// from the symbol table and insert a new one for Name.  This is equivalent to
 /// doing "remove(V), V->Name = Name, insert(V)", but is faster, and will not
@@ -158,32 +144,6 @@
   }
 }
 
-// remove - Remove a type from the symbol table...
-Type* SymbolTable::remove(type_iterator Entry) {
-  assert(Entry != tmap.end() && "Invalid entry to remove!");
-
-  const Type* Result = Entry->second;
-
-#if DEBUG_SYMBOL_TABLE
-  dump();
-  DOUT << " Removing type: " << Entry->first << "\n";
-#endif
-
-  tmap.erase(Entry);
-
-  // If we are removing an abstract type, remove the symbol table from it's use
-  // list...
-  if (Result->isAbstract()) {
-#if DEBUG_ABSTYPE
-    DOUT  << "Removing abstract type from symtab"
-          << Result->getDescription() << "\n";
-#endif
-    cast<DerivedType>(Result)->removeAbstractTypeUser(this);
-  }
-
-  return const_cast<Type*>(Result);
-}
-
 
 // insertEntry - Insert a value into the symbol table with the specified name.
 void SymbolTable::insertEntry(const std::string &Name, const Type *VTy,
@@ -230,34 +190,6 @@
 }
 
 
-// insertEntry - Insert a type into the symbol table with the specified
-// name...
-//
-void SymbolTable::insert(const std::string& Name, const Type* T) {
-  assert(T && "Can't insert null type into symbol table!");
-
-  // Check to see if there is a naming conflict.  If so, rename this type!
-  std::string UniqueName = Name;
-  if (lookupType(Name))
-    UniqueName = getUniqueName(T, Name);
-
-#if DEBUG_SYMBOL_TABLE
-  dump();
-  DOUT << " Inserting type: " << UniqueName << ": "
-       << T->getDescription() << "\n";
-#endif
-
-  // Insert the tmap entry
-  tmap.insert(make_pair(UniqueName, T));
-
-  // If we are adding an abstract type, add the symbol table to it's use list.
-  if (T->isAbstract()) {
-    cast<DerivedType>(T)->addAbstractTypeUser(this);
-#if DEBUG_ABSTYPE
-    DOUT << "Added abstract type to ST: " << T->getDescription() << "\n";
-#endif
-  }
-}
 
 // Strip the symbol table of its names.
 bool SymbolTable::strip() {
@@ -278,11 +210,6 @@
     }
   }
 
-  for (type_iterator TI = tmap.begin(); TI != tmap.end(); ) {
-    remove(TI++);
-    RemovedSymbol = true;
-  }
-
   return RemovedSymbol;
 }
 
@@ -375,28 +302,6 @@
     // Remove the plane that is no longer used
     pmap.erase(PI);
   }
-
-  // Loop over all of the types in the symbol table, replacing any references
-  // to OldType with references to NewType.  Note that there may be multiple
-  // occurrences, and although we only need to remove one at a time, it's
-  // faster to remove them all in one pass.
-  //
-  for (type_iterator I = type_begin(), E = type_end(); I != E; ++I) {
-    if (I->second == (Type*)OldType) {  // FIXME when Types aren't const.
-#if DEBUG_ABSTYPE
-      DOUT << "Removing type " << OldType->getDescription() << "\n";
-#endif
-      OldType->removeAbstractTypeUser(this);
-
-      I->second = (Type*)NewType;  // TODO FIXME when types aren't const
-      if (NewType->isAbstract()) {
-#if DEBUG_ABSTYPE
-        DOUT << "Added type " << NewType->getDescription() << "\n";
-#endif
-        cast<DerivedType>(NewType)->addAbstractTypeUser(this);
-      }
-    }
-  }
 }
 
 
@@ -408,13 +313,6 @@
   // plane is a use of the abstract type which must be dropped.
   if (PI != pmap.end())
     AbsTy->removeAbstractTypeUser(this);
-
-  // Loop over all of the types in the symbol table, dropping any abstract
-  // type user entries for AbsTy which occur because there are names for the
-  // type.
-  for (type_iterator TI = type_begin(), TE = type_end(); TI != TE; ++TI)
-    if (TI->second == (Type*)AbsTy)   // FIXME when Types aren't const.
-      AbsTy->removeAbstractTypeUser(this);
 }
 
 static void DumpVal(const std::pair<const std::string, Value *> &V) {
@@ -430,17 +328,9 @@
   for_each(P.second.begin(), P.second.end(), DumpVal);
 }
 
-static void DumpTypes(const std::pair<const std::string, const Type*>& T ) {
-  DOUT << "  '" << T.first << "' = ";
-  T.second->dump();
-  DOUT << "\n";
-}
-
 void SymbolTable::dump() const {
   DOUT << "Symbol table dump:\n  Plane:";
   for_each(pmap.begin(), pmap.end(), DumpPlane);
-  DOUT << "  Types: ";
-  for_each(tmap.begin(), tmap.end(), DumpTypes);
 }
 
 // vim: sw=2 ai


Index: llvm/lib/VMCore/SymbolTableListTraitsImpl.h
diff -u llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.7 llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.8
--- llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.7	Thu Apr 21 18:46:51 2005
+++ llvm/lib/VMCore/SymbolTableListTraitsImpl.h	Sat Jan  6 01:24:44 2007
@@ -29,7 +29,7 @@
 
   // Remove all of the items from the old symtab..
   if (SymTabObject && !List.empty()) {
-    SymbolTable &SymTab = SymTabObject->getSymbolTable();
+    SymbolTable &SymTab = SymTabObject->getValueSymbolTable();
     for (typename iplist<ValueSubClass>::iterator I = List.begin();
          I != List.end(); ++I)
       if (I->hasName()) SymTab.remove(I);
@@ -39,7 +39,7 @@
 
   // Add all of the items to the new symtab...
   if (SymTabObject && !List.empty()) {
-    SymbolTable &SymTab = SymTabObject->getSymbolTable();
+    SymbolTable &SymTab = SymTabObject->getValueSymbolTable();
     for (typename iplist<ValueSubClass>::iterator I = List.begin();
          I != List.end(); ++I)
       if (I->hasName()) SymTab.insert(I);
@@ -53,7 +53,7 @@
   assert(V->getParent() == 0 && "Value already in a container!!");
   V->setParent(ItemParent);
   if (V->hasName() && SymTabObject)
-    SymTabObject->getSymbolTable().insert(V);
+    SymTabObject->getValueSymbolTable().insert(V);
 }
 
 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
@@ -62,7 +62,7 @@
 ::removeNodeFromList(ValueSubClass *V) {
   V->setParent(0);
   if (V->hasName() && SymTabObject)
-    SymTabObject->getSymbolTable().remove(V);
+    SymTabObject->getValueSymbolTable().remove(V);
 }
 
 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
@@ -83,10 +83,10 @@
       ValueSubClass &V = *first;
       bool HasName = V.hasName();
       if (OldSTO && HasName)
-        OldSTO->getSymbolTable().remove(&V);
+        OldSTO->getValueSymbolTable().remove(&V);
       V.setParent(NewIP);
       if (NewSTO && HasName)
-        NewSTO->getSymbolTable().insert(&V);
+        NewSTO->getValueSymbolTable().insert(&V);
     }
   } else {
     // Just transferring between blocks in the same function, simply update the


Index: llvm/lib/VMCore/TypeSymbolTable.cpp
diff -u llvm/lib/VMCore/TypeSymbolTable.cpp:1.5 llvm/lib/VMCore/TypeSymbolTable.cpp:1.6
--- llvm/lib/VMCore/TypeSymbolTable.cpp:1.5	Wed Dec  6 19:30:31 2006
+++ llvm/lib/VMCore/TypeSymbolTable.cpp	Sat Jan  6 01:24:44 2007
@@ -48,10 +48,10 @@
 }
 
 // Erase a specific type from the symbol table
-bool TypeSymbolTable::erase(Type *N) {
+bool TypeSymbolTable::remove(Type *N) {
   for (iterator TI = tmap.begin(), TE = tmap.end(); TI != TE; ++TI) {
     if (TI->second == N) {
-      this->erase(TI);
+      this->remove(TI);
       return true;
     }
   }
@@ -59,7 +59,7 @@
 }
 
 // remove - Remove a type from the symbol table...
-Type* TypeSymbolTable::erase(iterator Entry) {
+Type* TypeSymbolTable::remove(iterator Entry) {
   assert(Entry != tmap.end() && "Invalid entry to remove!");
 
   const Type* Result = Entry->second;
@@ -115,7 +115,7 @@
 bool TypeSymbolTable::strip() {
   bool RemovedSymbol = false;
   for (iterator TI = tmap.begin(); TI != tmap.end(); ) {
-    erase(TI++);
+    remove(TI++);
     RemovedSymbol = true;
   }
 


Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.59 llvm/lib/VMCore/Value.cpp:1.60
--- llvm/lib/VMCore/Value.cpp:1.59	Fri Nov 17 02:03:48 2006
+++ llvm/lib/VMCore/Value.cpp	Sat Jan  6 01:24:44 2007
@@ -101,13 +101,13 @@
   if (Instruction *I = dyn_cast<Instruction>(this)) {
     if (BasicBlock *P = I->getParent())
       if (Function *PP = P->getParent())
-        ST = &PP->getSymbolTable();
+        ST = &PP->getValueSymbolTable();
   } else if (BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
-    if (Function *P = BB->getParent()) ST = &P->getSymbolTable();
+    if (Function *P = BB->getParent()) ST = &P->getValueSymbolTable();
   } else if (GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
-    if (Module *P = GV->getParent()) ST = &P->getSymbolTable();
+    if (Module *P = GV->getParent()) ST = &P->getValueSymbolTable();
   } else if (Argument *A = dyn_cast<Argument>(this)) {
-    if (Function *P = A->getParent()) ST = &P->getSymbolTable();
+    if (Function *P = A->getParent()) ST = &P->getValueSymbolTable();
   } else {
     assert(isa<Constant>(this) && "Unknown value type!");
     return;  // no name is setable for this.


Index: llvm/lib/VMCore/Verifier.cpp
diff -u llvm/lib/VMCore/Verifier.cpp:1.181 llvm/lib/VMCore/Verifier.cpp:1.182
--- llvm/lib/VMCore/Verifier.cpp:1.181	Wed Jan  3 23:22:18 2007
+++ llvm/lib/VMCore/Verifier.cpp	Sat Jan  6 01:24:44 2007
@@ -99,7 +99,8 @@
 
     bool doInitialization(Module &M) {
       Mod = &M;
-      verifySymbolTable(M.getSymbolTable());
+      verifyTypeSymbolTable(M.getTypeSymbolTable());
+      verifyValueSymbolTable(M.getValueSymbolTable());
 
       // If this is a real pass, in a pass manager, we must abort before
       // returning back to the pass manager, or else the pass manager may try to
@@ -173,7 +174,8 @@
 
 
     // Verification methods...
-    void verifySymbolTable(SymbolTable &ST);
+    void verifyTypeSymbolTable(TypeSymbolTable &ST);
+    void verifyValueSymbolTable(SymbolTable &ST);
     void visitGlobalValue(GlobalValue &GV);
     void visitGlobalVariable(GlobalVariable &GV);
     void visitFunction(Function &F);
@@ -301,10 +303,12 @@
   visitGlobalValue(GV);
 }
 
+void Verifier::verifyTypeSymbolTable(TypeSymbolTable &ST) {
+}
 
 // verifySymbolTable - Verify that a function or module symbol table is ok
 //
-void Verifier::verifySymbolTable(SymbolTable &ST) {
+void Verifier::verifyValueSymbolTable(SymbolTable &ST) {
 
   // Loop over all of the values in all type planes in the symbol table.
   for (SymbolTable::plane_const_iterator PI = ST.plane_begin(),
@@ -372,7 +376,7 @@
       Assert1(F.getName().substr(0, 5) != "llvm.",
               "llvm intrinsics cannot be defined!", &F);
     
-    verifySymbolTable(F.getSymbolTable());
+    verifyValueSymbolTable(F.getValueSymbolTable());
 
     // Check the entry node
     BasicBlock *Entry = &F.getEntryBlock();






More information about the llvm-commits mailing list