[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Constants.cpp Function.cpp Globals.cpp Instruction.cpp Module.cpp SymbolTableListTraitsImpl.h Type.cpp Value.cpp ValueSymbolTable.cpp Verifier.cpp SymbolTable.cpp

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



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.259 -> 1.260
Constants.cpp updated: 1.207 -> 1.208
Function.cpp updated: 1.110 -> 1.111
Globals.cpp updated: 1.14 -> 1.15
Instruction.cpp updated: 1.62 -> 1.63
Module.cpp updated: 1.75 -> 1.76
SymbolTableListTraitsImpl.h updated: 1.8 -> 1.9
Type.cpp updated: 1.167 -> 1.168
Value.cpp updated: 1.60 -> 1.61
ValueSymbolTable.cpp updated: 1.3 -> 1.4
Verifier.cpp updated: 1.189 -> 1.190
SymbolTable.cpp (r1.66) removed
---
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:  (+57 -144)

 AsmWriter.cpp               |    2 
 Constants.cpp               |    2 
 Function.cpp                |    6 --
 Globals.cpp                 |    1 
 Instruction.cpp             |    1 
 Module.cpp                  |  112 +++++++-------------------------------------
 SymbolTableListTraitsImpl.h |    6 +-
 Type.cpp                    |    1 
 Value.cpp                   |   15 +++--
 ValueSymbolTable.cpp        |   27 +++-------
 Verifier.cpp                |   28 +++++------
 11 files changed, 57 insertions(+), 144 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.259 llvm/lib/VMCore/AsmWriter.cpp:1.260
--- llvm/lib/VMCore/AsmWriter.cpp:1.259	Fri Feb  2 07:54:55 2007
+++ llvm/lib/VMCore/AsmWriter.cpp	Mon Feb  5 14:47:20 2007
@@ -24,7 +24,7 @@
 #include "llvm/Instruction.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
 #include "llvm/TypeSymbolTable.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/STLExtras.h"


Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.207 llvm/lib/VMCore/Constants.cpp:1.208
--- llvm/lib/VMCore/Constants.cpp:1.207	Thu Feb  1 20:16:22 2007
+++ llvm/lib/VMCore/Constants.cpp	Mon Feb  5 14:47:20 2007
@@ -16,7 +16,6 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/GlobalValue.h"
 #include "llvm/Instructions.h"
-#include "llvm/SymbolTable.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Compiler.h"
@@ -24,6 +23,7 @@
 #include "llvm/Support/ManagedStatic.h"
 #include "llvm/Support/MathExtras.h"
 #include <algorithm>
+#include <map>
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//


Index: llvm/lib/VMCore/Function.cpp
diff -u llvm/lib/VMCore/Function.cpp:1.110 llvm/lib/VMCore/Function.cpp:1.111
--- llvm/lib/VMCore/Function.cpp:1.110	Fri Jan 26 02:01:30 2007
+++ llvm/lib/VMCore/Function.cpp	Mon Feb  5 14:47:20 2007
@@ -7,8 +7,7 @@
 //
 //===----------------------------------------------------------------------===//
 //
-// This file implements the Function & GlobalVariable classes for the VMCore
-// library.
+// This file implements the Function class for the VMCore library.
 //
 //===----------------------------------------------------------------------===//
 
@@ -82,7 +81,7 @@
   BasicBlocks.setParent(this);
   ArgumentList.setItemParent(this);
   ArgumentList.setParent(this);
-  SymTab = new SymbolTable();
+  SymTab = new ValueSymbolTable();
 
   assert((getReturnType()->isFirstClassType() ||getReturnType() == Type::VoidTy)
          && "LLVM functions cannot return aggregate values!");
@@ -138,7 +137,6 @@
   getParent()->getFunctionList().erase(this);
 }
 
-
 // dropAllReferences() - This function causes all the subinstructions to "let
 // go" of all references that they are maintaining.  This allows one to
 // 'delete' a whole class at a time, even though there may be circular


Index: llvm/lib/VMCore/Globals.cpp
diff -u llvm/lib/VMCore/Globals.cpp:1.14 llvm/lib/VMCore/Globals.cpp:1.15
--- llvm/lib/VMCore/Globals.cpp:1.14	Sat Sep 30 16:31:26 2006
+++ llvm/lib/VMCore/Globals.cpp	Mon Feb  5 14:47:20 2007
@@ -15,7 +15,6 @@
 #include "llvm/GlobalVariable.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
 #include "llvm/Support/LeakDetector.h"
 using namespace llvm;
 


Index: llvm/lib/VMCore/Instruction.cpp
diff -u llvm/lib/VMCore/Instruction.cpp:1.62 llvm/lib/VMCore/Instruction.cpp:1.63
--- llvm/lib/VMCore/Instruction.cpp:1.62	Wed Jan  3 20:15:37 2007
+++ llvm/lib/VMCore/Instruction.cpp	Mon Feb  5 14:47:20 2007
@@ -14,7 +14,6 @@
 #include "llvm/Type.h"
 #include "llvm/Instructions.h"
 #include "llvm/Function.h"
-#include "llvm/SymbolTable.h"
 #include "llvm/Support/LeakDetector.h"
 using namespace llvm;
 


Index: llvm/lib/VMCore/Module.cpp
diff -u llvm/lib/VMCore/Module.cpp:1.75 llvm/lib/VMCore/Module.cpp:1.76
--- llvm/lib/VMCore/Module.cpp:1.75	Sat Feb  3 18:40:42 2007
+++ llvm/lib/VMCore/Module.cpp	Mon Feb  5 14:47:20 2007
@@ -69,7 +69,7 @@
   FunctionList.setParent(this);
   GlobalList.setItemParent(this);
   GlobalList.setParent(this);
-  ValSymTab = new SymbolTable();
+  ValSymTab = new ValueSymbolTable();
   TypeSymTab = new TypeSymbolTable();
 }
 
@@ -132,15 +132,19 @@
 // Methods for easy access to the functions in the module.
 //
 
+// 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
+// the symbol table directly for this common task.
+//
 Constant *Module::getOrInsertFunction(const std::string &Name,
                                       const FunctionType *Ty) {
-  SymbolTable &SymTab = getValueSymbolTable();
+  ValueSymbolTable &SymTab = getValueSymbolTable();
 
-  // See if we have a definitions for the specified function already.
-  Function *F =
-    dyn_cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name));
+  // See if we have a definition for the specified function already.
+  Function *F = dyn_cast_or_null<Function>(SymTab.lookup(Name));
   if (F == 0) {
-    // Nope, add it.
+    // Nope, add it
     Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name);
     FunctionList.push_back(New);
     return New;                    // Return the new prototype.
@@ -149,7 +153,7 @@
   // Okay, the function exists.  Does it have externally visible linkage?
   if (F->hasInternalLinkage()) {
     // Rename the function.
-    F->setName(SymTab.getUniqueName(F->getType(), F->getName()));
+    F->setName(SymTab.getUniqueName(F->getName()));
     // Retry, now there won't be a conflict.
     return getOrInsertFunction(Name, Ty);
   }
@@ -188,73 +192,9 @@
 // getFunction - Look up the specified function in the module symbol table.
 // If it does not exist, return null.
 //
-Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) {
-  SymbolTable &SymTab = getValueSymbolTable();
-  return cast_or_null<Function>(SymTab.lookup(PointerType::get(Ty), Name));
-}
-
-
-/// getMainFunction - This function looks up main efficiently.  This is such a
-/// common case, that it is a method in Module.  If main cannot be found, a
-/// null pointer is returned.
-///
-Function *Module::getMainFunction() {
-  std::vector<const Type*> Params;
-
-  // int main(void)...
-  if (Function *F = getFunction("main", FunctionType::get(Type::Int32Ty,
-                                                          Params, false)))
-    return F;
-
-  // void main(void)...
-  if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy,
-                                                          Params, false)))
-    return F;
-
-  Params.push_back(Type::Int32Ty);
-
-  // int main(int argc)...
-  if (Function *F = getFunction("main", FunctionType::get(Type::Int32Ty,
-                                                          Params, false)))
-    return F;
-
-  // void main(int argc)...
-  if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy,
-                                                          Params, false)))
-    return F;
-
-  for (unsigned i = 0; i != 2; ++i) {  // Check argv and envp
-    Params.push_back(PointerType::get(PointerType::get(Type::Int8Ty)));
-
-    // int main(int argc, char **argv)...
-    if (Function *F = getFunction("main", FunctionType::get(Type::Int32Ty,
-                                                            Params, false)))
-      return F;
-
-    // void main(int argc, char **argv)...
-    if (Function *F = getFunction("main", FunctionType::get(Type::VoidTy,
-                                                            Params, false)))
-      return F;
-  }
-
-  // Ok, try to find main the hard way...
-  return getNamedFunction("main");
-}
-
-/// getNamedFunction - Return the first function in the module with the
-/// specified name, of arbitrary type.  This method returns null if a function
-/// with the specified name is not found.
-///
-Function *Module::getNamedFunction(const std::string &Name) const {
-  // Loop over all of the functions, looking for the function desired
-  const Function *Found = 0;
-  for (const_iterator I = begin(), E = end(); I != E; ++I)
-    if (I->getName() == Name)
-      if (I->isDeclaration())
-        Found = I;
-      else
-        return const_cast<Function*>(&(*I));
-  return const_cast<Function*>(Found); // Non-external function not found...
+Function *Module::getFunction(const std::string &Name) const {
+  const ValueSymbolTable &SymTab = getValueSymbolTable();
+  return dyn_cast_or_null<Function>(SymTab.lookup(Name));
 }
 
 //===----------------------------------------------------------------------===//
@@ -269,31 +209,15 @@
 /// have InternalLinkage. By default, these types are not returned.
 ///
 GlobalVariable *Module::getGlobalVariable(const std::string &Name,
-                                          const Type *Ty, bool AllowInternal) {
-  if (Value *V = getValueSymbolTable().lookup(PointerType::get(Ty), Name)) {
-    GlobalVariable *Result = cast<GlobalVariable>(V);
-    if (AllowInternal || !Result->hasInternalLinkage())
+                                          bool AllowInternal) const {
+  if (Value *V = ValSymTab->lookup(Name)) {
+    GlobalVariable *Result = dyn_cast<GlobalVariable>(V);
+    if (Result && (AllowInternal || !Result->hasInternalLinkage()))
       return Result;
   }
   return 0;
 }
 
-/// getNamedGlobal - Return the first global variable in the module with the
-/// specified name, of arbitrary type.  This method returns null if a global
-/// with the specified name is not found.
-///
-GlobalVariable *Module::getNamedGlobal(const std::string &Name) const {
-  // FIXME: This would be much faster with a symbol table that doesn't
-  // discriminate based on type!
-  for (const_global_iterator I = global_begin(), E = global_end();
-       I != E; ++I)
-    if (I->getName() == Name) 
-      return const_cast<GlobalVariable*>(&(*I));
-  return 0;
-}
-
-
-
 //===----------------------------------------------------------------------===//
 // Methods for easy access to the types in the module.
 //


Index: llvm/lib/VMCore/SymbolTableListTraitsImpl.h
diff -u llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.8 llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.9
--- llvm/lib/VMCore/SymbolTableListTraitsImpl.h:1.8	Sat Jan  6 01:24:44 2007
+++ llvm/lib/VMCore/SymbolTableListTraitsImpl.h	Mon Feb  5 14:47:20 2007
@@ -17,7 +17,7 @@
 #define LLVM_SYMBOLTABLELISTTRAITS_IMPL_H
 
 #include "llvm/SymbolTableListTraits.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
 
 namespace llvm {
 
@@ -29,7 +29,7 @@
 
   // Remove all of the items from the old symtab..
   if (SymTabObject && !List.empty()) {
-    SymbolTable &SymTab = SymTabObject->getValueSymbolTable();
+    ValueSymbolTable &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->getValueSymbolTable();
+    ValueSymbolTable &SymTab = SymTabObject->getValueSymbolTable();
     for (typename iplist<ValueSubClass>::iterator I = List.begin();
          I != List.end(); ++I)
       if (I->hasName()) SymTab.insert(I);


Index: llvm/lib/VMCore/Type.cpp
diff -u llvm/lib/VMCore/Type.cpp:1.167 llvm/lib/VMCore/Type.cpp:1.168
--- llvm/lib/VMCore/Type.cpp:1.167	Sun Jan 28 07:31:35 2007
+++ llvm/lib/VMCore/Type.cpp	Mon Feb  5 14:47:20 2007
@@ -13,7 +13,6 @@
 
 #include "llvm/AbstractTypeUser.h"
 #include "llvm/DerivedTypes.h"
-#include "llvm/SymbolTable.h"
 #include "llvm/Constants.h"
 #include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/StringExtras.h"


Index: llvm/lib/VMCore/Value.cpp
diff -u llvm/lib/VMCore/Value.cpp:1.60 llvm/lib/VMCore/Value.cpp:1.61
--- llvm/lib/VMCore/Value.cpp:1.60	Sat Jan  6 01:24:44 2007
+++ llvm/lib/VMCore/Value.cpp	Mon Feb  5 14:47:20 2007
@@ -15,7 +15,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/InstrTypes.h"
 #include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/LeakDetector.h"
 #include <algorithm>
@@ -97,17 +97,20 @@
   if (Name == name) return;   // Name is already set.
 
   // Get the symbol table to update for this object.
-  SymbolTable *ST = 0;
+  ValueSymbolTable *ST = 0;
   if (Instruction *I = dyn_cast<Instruction>(this)) {
     if (BasicBlock *P = I->getParent())
       if (Function *PP = P->getParent())
         ST = &PP->getValueSymbolTable();
   } else if (BasicBlock *BB = dyn_cast<BasicBlock>(this)) {
-    if (Function *P = BB->getParent()) ST = &P->getValueSymbolTable();
+    if (Function *P = BB->getParent()) 
+      ST = &P->getValueSymbolTable();
   } else if (GlobalValue *GV = dyn_cast<GlobalValue>(this)) {
-    if (Module *P = GV->getParent()) ST = &P->getValueSymbolTable();
+    if (Module *P = GV->getParent()) 
+      ST = &P->getValueSymbolTable();
   } else if (Argument *A = dyn_cast<Argument>(this)) {
-    if (Function *P = A->getParent()) ST = &P->getValueSymbolTable();
+    if (Function *P = A->getParent()) 
+      ST = &P->getValueSymbolTable();
   } else {
     assert(isa<Constant>(this) && "Unknown value type!");
     return;  // no name is setable for this.
@@ -117,7 +120,7 @@
     Name = name;
   else if (hasName()) {
     if (!name.empty()) {    // Replacing name.
-      ST->changeName(this, name);
+      ST->rename(this, name);
     } else {                // Transitioning from hasName -> noname.
       ST->remove(this);
       Name.clear();


Index: llvm/lib/VMCore/ValueSymbolTable.cpp
diff -u llvm/lib/VMCore/ValueSymbolTable.cpp:1.3 llvm/lib/VMCore/ValueSymbolTable.cpp:1.4
--- llvm/lib/VMCore/ValueSymbolTable.cpp:1.3	Fri Nov 17 02:03:48 2006
+++ llvm/lib/VMCore/ValueSymbolTable.cpp	Mon Feb  5 14:47:20 2007
@@ -11,6 +11,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#define DEBUG_TYPE "valuesymtab"
 #include "llvm/GlobalValue.h"
 #include "llvm/Type.h"
 #include "llvm/ValueSymbolTable.h"
@@ -19,18 +20,15 @@
 #include <algorithm>
 using namespace llvm;
 
-#define DEBUG_SYMBOL_TABLE 0
-#define DEBUG_ABSTYPE 0
-
 // Class destructor
 ValueSymbolTable::~ValueSymbolTable() {
 #ifndef NDEBUG   // Only do this in -g mode...
   bool LeftoverValues = true;
   for (iterator VI = vmap.begin(), VE = vmap.end(); VI != VE; ++VI)
     if (!isa<Constant>(VI->second) ) {
-      DOUT << "Value still in symbol table! Type = '"
+      DEBUG(DOUT << "Value still in symbol table! Type = '"
            << VI->second->getType()->getDescription() << "' Name = '"
-           << VI->first << "'\n";
+           << VI->first << "'\n");
       LeftoverValues = false;
     }
   assert(LeftoverValues && "Values remain in symbol table!");
@@ -83,29 +81,24 @@
   assert(V && "Can't insert null Value into symbol table!");
   assert(V->hasName() && "Can't insert nameless Value into symbol table");
 
-  // Check to see if there is a naming conflict.  If so, rename this type!
+  // Check to see if there is a naming conflict.  If so, rename this value
   std::string UniqueName = getUniqueName(V->getName());
 
-#if DEBUG_SYMBOL_TABLE
-  dump();
-  DOUT << " Inserting value: " << UniqueName << ": " << V->dump() << "\n";
-#endif
+  DEBUG(DOUT << " Inserting value: " << UniqueName << ": " << *V << "\n");
 
   // Insert the vmap entry
-  vmap.insert(make_pair(UniqueName, V));
+  V->Name = UniqueName;
+  vmap.insert(make_pair(V->Name, V));
 }
 
 // Remove a value
-bool ValueSymbolTable::erase(Value *V) {
+bool ValueSymbolTable::remove(Value *V) {
   assert(V->hasName() && "Value doesn't have name!");
   iterator Entry = vmap.find(V->getName());
   if (Entry == vmap.end())
     return false;
 
-#if DEBUG_SYMBOL_TABLE
-  dump();
-  DOUT << " Removing Value: " << Entry->second->getName() << "\n";
-#endif
+  DEBUG(DOUT << " Removing Value: " << Entry->second->getName() << "\n");
 
   // Remove the value from the plane...
   vmap.erase(Entry);
@@ -143,7 +136,7 @@
     vmap.insert(make_pair(V->Name, V));
   } else {
     V->Name = name;
-    vmap.insert(VI, make_pair(name, V));
+    vmap.insert(VI, make_pair(V->Name, V));
   }
 
   return true;


Index: llvm/lib/VMCore/Verifier.cpp
diff -u llvm/lib/VMCore/Verifier.cpp:1.189 llvm/lib/VMCore/Verifier.cpp:1.190
--- llvm/lib/VMCore/Verifier.cpp:1.189	Thu Feb  1 20:16:22 2007
+++ llvm/lib/VMCore/Verifier.cpp	Mon Feb  5 14:47:20 2007
@@ -51,7 +51,7 @@
 #include "llvm/Instructions.h"
 #include "llvm/Intrinsics.h"
 #include "llvm/PassManager.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/ValueSymbolTable.h"
 #include "llvm/Analysis/Dominators.h"
 #include "llvm/Support/CFG.h"
 #include "llvm/Support/InstVisitor.h"
@@ -175,7 +175,7 @@
 
     // Verification methods...
     void verifyTypeSymbolTable(TypeSymbolTable &ST);
-    void verifyValueSymbolTable(SymbolTable &ST);
+    void verifyValueSymbolTable(ValueSymbolTable &ST);
     void visitGlobalValue(GlobalValue &GV);
     void visitGlobalVariable(GlobalVariable &GV);
     void visitFunction(Function &F);
@@ -307,20 +307,18 @@
 
 // verifySymbolTable - Verify that a function or module symbol table is ok
 //
-void Verifier::verifyValueSymbolTable(SymbolTable &ST) {
+void Verifier::verifyValueSymbolTable(ValueSymbolTable &ST) {
 
-  // Loop over all of the values in all type planes in the symbol table.
-  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) {
-      Value *V = VI->second;
-      // Check that there are no void typed values in the symbol table.  Values
-      // with a void type cannot be put into symbol tables because they cannot
-      // have names!
-      Assert1(V->getType() != Type::VoidTy,
-        "Values with void type are not allowed to have names!", V);
-    }
+  // Loop over all of the values in the symbol table.
+  for (ValueSymbolTable::const_iterator VI = ST.begin(), VE = ST.end(); 
+       VI != VE; ++VI) {
+    Value *V = VI->second;
+    // Check that there are no void typed values in the symbol table.  Values
+    // with a void type cannot be put into symbol tables because they cannot
+    // have names!
+    Assert1(V->getType() != Type::VoidTy,
+      "Values with void type are not allowed to have names!", V);
+  }
 }
 
 // visitFunction - Verify that a function is ok.






More information about the llvm-commits mailing list