[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp BasicBlock.cpp Function.cpp Instruction.cpp Module.cpp SlotCalculator.cpp SymbolTableListTraitsImpl.h Verifier.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Nov 20 12:35:09 PST 2002


Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.79 -> 1.80
BasicBlock.cpp updated: 1.28 -> 1.29
Function.cpp updated: 1.35 -> 1.36
Instruction.cpp updated: 1.20 -> 1.21
Module.cpp updated: 1.32 -> 1.33
SlotCalculator.cpp updated: 1.24 -> 1.25
SymbolTableListTraitsImpl.h updated: 1.2 -> 1.3
Verifier.cpp updated: 1.41 -> 1.42

---
Log message:

  - Eliminated the deferred symbol table stuff in Module & Function, it really
    wasn't an optimization and it was causing lots of bugs.


---
Diffs of the changes:

Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.79 llvm/lib/VMCore/AsmWriter.cpp:1.80
--- llvm/lib/VMCore/AsmWriter.cpp:1.79	Sun Oct 13 15:57:00 2002
+++ llvm/lib/VMCore/AsmWriter.cpp	Wed Nov 20 12:33:41 2002
@@ -74,20 +74,19 @@
 //
 static void fillTypeNameTable(const Module *M,
                               map<const Type *, string> &TypeNames) {
-  if (M && M->hasSymbolTable()) {
-    const SymbolTable *ST = M->getSymbolTable();
-    SymbolTable::const_iterator PI = ST->find(Type::TypeTy);
-    if (PI != ST->end()) {
-      SymbolTable::type_const_iterator I = PI->second.begin();
-      for (; I != PI->second.end(); ++I) {
-        // As a heuristic, don't insert pointer to primitive types, because
-        // they are used too often to have a single useful name.
-        //
-        const Type *Ty = cast<const Type>(I->second);
-        if (!isa<PointerType>(Ty) ||
-            !cast<PointerType>(Ty)->getElementType()->isPrimitiveType())
-          TypeNames.insert(std::make_pair(Ty, "%"+I->first));
-      }
+  if (!M) return;
+  const SymbolTable &ST = M->getSymbolTable();
+  SymbolTable::const_iterator PI = ST.find(Type::TypeTy);
+  if (PI != ST.end()) {
+    SymbolTable::type_const_iterator I = PI->second.begin();
+    for (; I != PI->second.end(); ++I) {
+      // As a heuristic, don't insert pointer to primitive types, because
+      // they are used too often to have a single useful name.
+      //
+      const Type *Ty = cast<const Type>(I->second);
+      if (!isa<PointerType>(Ty) ||
+          !cast<PointerType>(Ty)->getElementType()->isPrimitiveType())
+        TypeNames.insert(std::make_pair(Ty, "%"+I->first));
     }
   }
 }
@@ -200,7 +199,7 @@
 
   // If they want us to print out a type, attempt to make it symbolic if there
   // is a symbol table in the module...
-  if (M && M->hasSymbolTable()) {
+  if (M) {
     map<const Type *, string> TypeNames;
     fillTypeNameTable(M, TypeNames);
     
@@ -406,7 +405,7 @@
   map<const Type *, string> TypeNames;
   if (Context == 0) Context = getModuleFromVal(V);
 
-  if (Context && Context->hasSymbolTable())
+  if (Context)
     fillTypeNameTable(Context, TypeNames);
 
   if (PrintType)
@@ -524,8 +523,7 @@
 
 void AssemblyWriter::printModule(const Module *M) {
   // Loop over the symbol table, emitting all named constants...
-  if (M->hasSymbolTable())
-    printSymbolTable(*M->getSymbolTable());
+  printSymbolTable(M->getSymbolTable());
   
   for (Module::const_giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
     printGlobal(I);


Index: llvm/lib/VMCore/BasicBlock.cpp
diff -u llvm/lib/VMCore/BasicBlock.cpp:1.28 llvm/lib/VMCore/BasicBlock.cpp:1.29
--- llvm/lib/VMCore/BasicBlock.cpp:1.28	Sun Oct 13 14:39:16 2002
+++ llvm/lib/VMCore/BasicBlock.cpp	Wed Nov 20 12:33:41 2002
@@ -105,11 +105,11 @@
 // Specialize setName to take care of symbol table majik
 void BasicBlock::setName(const std::string &name, SymbolTable *ST) {
   Function *P;
-  assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
+  assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) &&
 	 "Invalid symtab argument!");
-  if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
+  if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this);
   Value::setName(name);
-  if (P && hasName()) P->getSymbolTable()->insert(this);
+  if (P && hasName()) P->getSymbolTable().insert(this);
 }
 
 TerminatorInst *BasicBlock::getTerminator() {


Index: llvm/lib/VMCore/Function.cpp
diff -u llvm/lib/VMCore/Function.cpp:1.35 llvm/lib/VMCore/Function.cpp:1.36
--- llvm/lib/VMCore/Function.cpp:1.35	Wed Nov 20 12:07:48 2002
+++ llvm/lib/VMCore/Function.cpp	Wed Nov 20 12:33:41 2002
@@ -57,11 +57,11 @@
 // Specialize setName to take care of symbol table majik
 void Argument::setName(const std::string &name, SymbolTable *ST) {
   Function *P;
-  assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
+  assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) &&
 	 "Invalid symtab argument!");
-  if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
+  if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this);
   Value::setName(name);
-  if (P && hasName()) P->getSymbolTableSure()->insert(this);
+  if (P && hasName()) P->getSymbolTable().insert(this);
 }
 
 void Argument::setParent(Function *parent) {
@@ -114,11 +114,11 @@
 // Specialize setName to take care of symbol table majik
 void Function::setName(const std::string &name, SymbolTable *ST) {
   Module *P;
-  assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
+  assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) &&
 	 "Invalid symtab argument!");
-  if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
+  if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this);
   Value::setName(name);
-  if (P && getName() != "") P->getSymbolTableSure()->insert(this);
+  if (P && getName() != "") P->getSymbolTable().insert(this);
 }
 
 void Function::setParent(Module *parent) {
@@ -178,9 +178,9 @@
 // Specialize setName to take care of symbol table majik
 void GlobalVariable::setName(const std::string &name, SymbolTable *ST) {
   Module *P;
-  assert((ST == 0 || (!getParent() || ST == getParent()->getSymbolTable())) &&
+  assert((ST == 0 || (!getParent() || ST == &getParent()->getSymbolTable())) &&
 	 "Invalid symtab argument!");
-  if ((P = getParent()) && hasName()) P->getSymbolTable()->remove(this);
+  if ((P = getParent()) && hasName()) P->getSymbolTable().remove(this);
   Value::setName(name);
-  if (P && getName() != "") P->getSymbolTableSure()->insert(this);
+  if (P && getName() != "") P->getSymbolTable().insert(this);
 }


Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.20 llvm/lib/VMCore/Instruction.cpp:1.21
--- llvm/lib/VMCore/Instruction.cpp:1.20	Wed Oct 30 22:14:01 2002
+++ llvm/lib/VMCore/Instruction.cpp	Wed Nov 20 12:33:41 2002
@@ -40,12 +40,12 @@
 void Instruction::setName(const std::string &name, SymbolTable *ST) {
   BasicBlock *P = 0; Function *PP = 0;
   assert((ST == 0 || !getParent() || !getParent()->getParent() || 
-	  ST == getParent()->getParent()->getSymbolTable()) &&
+	  ST == &getParent()->getParent()->getSymbolTable()) &&
 	 "Invalid symtab argument!");
   if ((P = getParent()) && (PP = P->getParent()) && hasName())
-    PP->getSymbolTable()->remove(this);
+    PP->getSymbolTable().remove(this);
   Value::setName(name);
-  if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
+  if (PP && hasName()) PP->getSymbolTable().insert(this);
 }
 
 


Index: llvm/lib/VMCore/Module.cpp
diff -u llvm/lib/VMCore/Module.cpp:1.32 llvm/lib/VMCore/Module.cpp:1.33
--- llvm/lib/VMCore/Module.cpp:1.32	Tue Nov 19 12:41:44 2002
+++ llvm/lib/VMCore/Module.cpp	Wed Nov 20 12:33:41 2002
@@ -57,7 +57,7 @@
   GlobalList.setItemParent(this);
   GlobalList.setParent(this);
   GVRefMap = 0;
-  SymTab = 0;
+  SymTab = new SymbolTable();
 }
 
 Module::~Module() {
@@ -74,26 +74,6 @@
   print(std::cerr);
 }
 
-SymbolTable *Module::getSymbolTableSure() {
-  if (!SymTab) SymTab = new SymbolTable();
-  return SymTab;
-}
-
-// hasSymbolTable() - Returns true if there is a symbol table allocated to
-// this object AND if there is at least one name in it!
-//
-bool Module::hasSymbolTable() const {
-  if (!SymTab) return false;
-
-  for (SymbolTable::const_iterator I = SymTab->begin(), E = SymTab->end();
-       I != E; ++I)
-    if (I->second.begin() != I->second.end())
-      return true;                                // Found nonempty type plane!
-  
-  return false;
-}
-
-
 // getOrInsertFunction - Look up the specified function in the module symbol
 // table.  If it does not exist, add a prototype for the function and return
 // it.  This is nice because it allows most passes to get away with not handling
@@ -101,10 +81,10 @@
 //
 Function *Module::getOrInsertFunction(const std::string &Name,
                                       const FunctionType *Ty) {
-  SymbolTable *SymTab = getSymbolTableSure();
+  SymbolTable &SymTab = getSymbolTable();
 
   // See if we have a definitions for the specified function already...
-  if (Value *V = SymTab->lookup(PointerType::get(Ty), Name)) {
+  if (Value *V = SymTab.lookup(PointerType::get(Ty), Name)) {
     return cast<Function>(V);      // Yup, got it
   } else {                         // Nope, add one
     Function *New = new Function(Ty, false, Name);
@@ -117,10 +97,8 @@
 // If it does not exist, return null.
 //
 Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) {
-  SymbolTable *SymTab = getSymbolTable();
-  if (SymTab == 0) return 0;  // No symtab, no symbols...
-
-  return cast_or_null<Function>(SymTab->lookup(PointerType::get(Ty), Name));
+  SymbolTable &SymTab = getSymbolTable();
+  return cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name));
 }
 
 // addTypeName - Insert an entry in the symbol table mapping Str to Type.  If
@@ -128,13 +106,13 @@
 // table is not modified.
 //
 bool Module::addTypeName(const std::string &Name, const Type *Ty) {
-  SymbolTable *ST = getSymbolTableSure();
+  SymbolTable &ST = getSymbolTable();
 
-  if (ST->lookup(Type::TypeTy, Name)) return true;  // Already in symtab...
+  if (ST.lookup(Type::TypeTy, 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...
-  ((Value*)Ty)->setName(Name, ST);
+  ((Value*)Ty)->setName(Name, &ST);
 
   return false;
 }
@@ -204,13 +182,12 @@
 // specified type, return it.
 //
 std::string Module::getTypeName(const Type *Ty) {
-  const SymbolTable *ST = getSymbolTable();
-  if (ST == 0) return "";  // No symbol table, must not have an entry...
-  if (ST->find(Type::TypeTy) == ST->end())
+  const SymbolTable &ST = getSymbolTable();
+  if (ST.find(Type::TypeTy) == ST.end())
     return ""; // No names for types...
 
-  SymbolTable::type_const_iterator TI = ST->type_begin(Type::TypeTy);
-  SymbolTable::type_const_iterator TE = ST->type_end(Type::TypeTy);
+  SymbolTable::type_const_iterator TI = ST.type_begin(Type::TypeTy);
+  SymbolTable::type_const_iterator TE = ST.type_end(Type::TypeTy);
 
   while (TI != TE && TI->second != (const Value*)Ty)
     ++TI;


Index: llvm/lib/VMCore/SlotCalculator.cpp
diff -u llvm/lib/VMCore/SlotCalculator.cpp:1.24 llvm/lib/VMCore/SlotCalculator.cpp:1.25
--- llvm/lib/VMCore/SlotCalculator.cpp:1.24	Sun Oct 13 19:48:57 2002
+++ llvm/lib/VMCore/SlotCalculator.cpp	Wed Nov 20 12:33:41 2002
@@ -90,9 +90,9 @@
   // Insert constants that are named at module level into the slot pool so that
   // the module symbol table can refer to them...
   //
-  if (TheModule->hasSymbolTable() && !IgnoreNamedNodes) {
+  if (!IgnoreNamedNodes) {
     SC_DEBUG("Inserting SymbolTable values:\n");
-    processSymbolTable(TheModule->getSymbolTable());
+    processSymbolTable(&TheModule->getSymbolTable());
   }
 
   SC_DEBUG("end processModule!\n");
@@ -156,8 +156,7 @@
     // symboltable references to constants not in the output.  Scan for these
     // constants now.
     //
-    if (M->hasSymbolTable())
-      processSymbolTableConstants(M->getSymbolTable());
+    processSymbolTableConstants(&M->getSymbolTable());
   }
 
   SC_DEBUG("Inserting Labels:\n");
@@ -174,9 +173,9 @@
   for_each(inst_begin(M), inst_end(M),
 	   bind_obj(this, &SlotCalculator::insertValue));
 
-  if (M->hasSymbolTable() && !IgnoreNamedNodes) {
+  if (!IgnoreNamedNodes) {
     SC_DEBUG("Inserting SymbolTable values:\n");
-    processSymbolTable(M->getSymbolTable());
+    processSymbolTable(&M->getSymbolTable());
   }
 
   SC_DEBUG("end processFunction!\n");


Index: llvm/lib/VMCore/SymbolTableListTraitsImpl.h
diff -u llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.2 llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.3
--- llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.2	Wed Jul 24 17:08:50 2002
+++ llvm/lib/VMCore/SymbolTableListTraitsImpl.h	Wed Nov 20 12:33:41 2002
@@ -20,20 +20,20 @@
 
   // Remove all of the items from the old symtab..
   if (SymTabObject && !List.empty()) {
-    SymbolTable *SymTab = SymTabObject->getSymbolTable();
+    SymbolTable &SymTab = SymTabObject->getSymbolTable();
     for (typename iplist<ValueSubClass>::iterator I = List.begin();
          I != List.end(); ++I)
-      if (I->hasName()) SymTab->remove(I);
+      if (I->hasName()) SymTab.remove(I);
   }
 
   SymTabObject = STO;
 
   // Add all of the items to the new symtab...
   if (SymTabObject && !List.empty()) {
-    SymbolTable *SymTab = SymTabObject->getSymbolTableSure();
+    SymbolTable &SymTab = SymTabObject->getSymbolTable();
     for (typename iplist<ValueSubClass>::iterator I = List.begin();
          I != List.end(); ++I)
-      if (I->hasName()) SymTab->insert(I);
+      if (I->hasName()) SymTab.insert(I);
   }
 }
 
@@ -44,7 +44,7 @@
   assert(V->getParent() == 0 && "Value already in a container!!");
   V->setParent(ItemParent);
   if (V->hasName() && SymTabObject)
-    SymTabObject->getSymbolTableSure()->insert(V);
+    SymTabObject->getSymbolTable().insert(V);
 }
 
 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
@@ -53,7 +53,7 @@
 ::removeNodeFromList(ValueSubClass *V) {
   V->setParent(0);
   if (V->hasName() && SymTabObject)
-    SymTabObject->getSymbolTable()->remove(V);
+    SymTabObject->getSymbolTable().remove(V);
 }
 
 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
@@ -74,10 +74,10 @@
       ValueSubClass &V = *first;
       bool HasName = V.hasName();
       if (OldSTO && HasName)
-        OldSTO->getSymbolTable()->remove(&V);
+        OldSTO->getSymbolTable().remove(&V);
       V.setParent(NewIP);
       if (NewSTO && HasName)
-        NewSTO->getSymbolTableSure()->insert(&V);
+        NewSTO->getSymbolTable().insert(&V);
     }
   } else {
     // Just transfering between blocks in the same function, simply update the


Index: llvm/lib/VMCore/Verifier.cpp
diff -u llvm/lib/VMCore/Verifier.cpp:1.41 llvm/lib/VMCore/Verifier.cpp:1.42
--- llvm/lib/VMCore/Verifier.cpp:1.41	Sun Oct 13 15:53:14 2002
+++ llvm/lib/VMCore/Verifier.cpp	Wed Nov 20 12:33:41 2002
@@ -124,7 +124,7 @@
     }
 
     // Verification methods...
-    void verifySymbolTable(SymbolTable *ST);
+    void verifySymbolTable(SymbolTable &ST);
     void visitFunction(Function &F);
     void visitBasicBlock(BasicBlock &BB);
     void visitPHINode(PHINode &PN);
@@ -172,11 +172,9 @@
 
 // verifySymbolTable - Verify that a function or module symbol table is ok
 //
-void Verifier::verifySymbolTable(SymbolTable *ST) {
-  if (ST == 0) return;   // No symbol table to process
-
+void Verifier::verifySymbolTable(SymbolTable &ST) {
   // Loop over all of the types in the symbol table...
-  for (SymbolTable::iterator TI = ST->begin(), TE = ST->end(); TI != TE; ++TI)
+  for (SymbolTable::iterator TI = ST.begin(), TE = ST.end(); TI != TE; ++TI)
     for (SymbolTable::type_iterator I = TI->second.begin(),
            E = TI->second.end(); I != E; ++I) {
       Value *V = I->second;





More information about the llvm-commits mailing list