- Eliminated the deferred symbol table stuff in Module & Function, it really
authorChris Lattner <sabre@nondot.org>
Wed, 20 Nov 2002 18:36:02 +0000 (18:36 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 20 Nov 2002 18:36:02 +0000 (18:36 +0000)
    wasn't an optimization and it was causing lots of bugs.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4779 91177308-0d34-0410-b5e6-96231b3b80d8

27 files changed:
docs/ProgrammersManual.html
include/llvm/Function.h
include/llvm/Module.h
lib/AsmParser/llvmAsmParser.y
lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Writer/SlotCalculator.cpp
lib/Bytecode/Writer/Writer.cpp
lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp
lib/ExecutionEngine/Interpreter/Support.cpp
lib/Linker/LinkModules.cpp
lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp
lib/Transforms/IPO/DeadTypeElimination.cpp
lib/Transforms/IPO/FunctionResolution.cpp
lib/Transforms/LevelRaise.cpp
lib/Transforms/Scalar/SymbolStripping.cpp
lib/Transforms/Utils/BasicBlockUtils.cpp
lib/Transforms/Utils/Linker.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/BasicBlock.cpp
lib/VMCore/Function.cpp
lib/VMCore/Instruction.cpp
lib/VMCore/Linker.cpp
lib/VMCore/Module.cpp
lib/VMCore/SlotCalculator.cpp
lib/VMCore/SymbolTableListTraitsImpl.h
lib/VMCore/Verifier.cpp

index 26d4550087d4f2e6414b7838b577f04db95a338f..2e14c6bebaab43036efaf4dfa911681279d8207b 100644 (file)
@@ -1441,26 +1441,10 @@ This traverses the <a href="#Type"><tt>Type</tt></a> of the <tt>Function</tt>
 and returns the return type of the function, or the <a
 href="#FunctionType"><tt>FunctionType</tt></a> of the actual function.<p>
 
-
-<li><tt>bool hasSymbolTable() const</tt><p>
-
-Return true if the <tt>Function</tt> has a symbol table allocated to it and if
-there is at least one entry in it.<p>
-
 <li><tt><a href="#SymbolTable">SymbolTable</a> *getSymbolTable()</tt><p>
 
 Return a pointer to the <a href="#SymbolTable"><tt>SymbolTable</tt></a> for this
-<tt>Function</tt> or a null pointer if one has not been allocated (because there
-are no named values in the function).<p>
-
-<li><tt><a href="#SymbolTable">SymbolTable</a> *getSymbolTableSure()</tt><p>
-
-Return a pointer to the <a href="#SymbolTable"><tt>SymbolTable</tt></a> for this
-<tt>Function</tt> or allocate a new <a
-href="#SymbolTable"><tt>SymbolTable</tt></a> if one is not already around.  This
-should only be used when adding elements to the <a
-href="#SymbolTable"><tt>SymbolTable</tt></a>, so that empty symbol tables are
-not left laying around.<p>
+<tt>Function</tt>.<p>
 
 
 
@@ -1580,25 +1564,10 @@ action that doesn't have a forwarding method.<p>
 <!--  Symbol table stuff -->
 <hr size=0>
 
-<li><tt>bool hasSymbolTable() const</tt><p>
-
-Return true if the <tt>Module</tt> has a symbol table allocated to it and if
-there is at least one entry in it.<p>
-
 <li><tt><a href="#SymbolTable">SymbolTable</a> *getSymbolTable()</tt><p>
 
-Return a pointer to the <a href="#SymbolTable"><tt>SymbolTable</tt></a> for this
-<tt>Module</tt> or a null pointer if one has not been allocated (because there
-are no named values in the function).<p>
-
-<li><tt><a href="#SymbolTable">SymbolTable</a> *getSymbolTableSure()</tt><p>
-
-Return a pointer to the <a href="#SymbolTable"><tt>SymbolTable</tt></a> for this
-<tt>Module</tt> or allocate a new <a
-href="#SymbolTable"><tt>SymbolTable</tt></a> if one is not already around.  This
-should only be used when adding elements to the <a
-href="#SymbolTable"><tt>SymbolTable</tt></a>, so that empty symbol tables are
-not left laying around.<p>
+Return a reference to the <a href="#SymbolTable"><tt>SymbolTable</tt></a> for
+this <tt>Module</tt>.<p>
 
 
 <!--  Convenience methods -->
@@ -1776,6 +1745,6 @@ pointer to the parent Function.
 <a href="mailto:sabre@nondot.org">Chris Lattner</a></address>
 <!-- Created: Tue Aug  6 15:00:33 CDT 2002 -->
 <!-- hhmts start -->
-Last modified: Fri Nov  8 00:48:37 CST 2002
+Last modified: Wed Nov 20 12:21:34 CST 2002
 <!-- hhmts end -->
 </font></body></html>
index 34b6c0f252160f9f666ccd5825d8f131b5d92f05..885824d4f7e7f191873dfa7e96834c68f1950953 100644 (file)
@@ -113,10 +113,8 @@ public:
 
   /// getSymbolTable() - Return the symbol table...
   ///
-  inline       SymbolTable *getSymbolTable()       { return SymTab; }
-  inline const SymbolTable *getSymbolTable() const { return SymTab; }
-  SymbolTable *getSymbolTableSure() { return SymTab; }
-  bool hasSymbolTable() const { return true; }
+  inline       SymbolTable &getSymbolTable()       { return *SymTab; }
+  inline const SymbolTable &getSymbolTable() const { return *SymTab; }
 
   
   //===--------------------------------------------------------------------===//
index 4d2edceb73d193535c0c28515f87d04f73f705ee..0bb23f9d409bc1829aa20e5276aca401746b31ef 100644 (file)
@@ -113,22 +113,11 @@ public:
   //===--------------------------------------------------------------------===//
   // Symbol table support functions...
   
-  /// hasSymbolTable() - Returns true if there is a symbol table allocated to
-  /// this object AND if there is at least one name in it!
+  /// getSymbolTable() - Get access to the symbol table for the module, where
+  /// global variables and functions are identified.
   ///
-  bool hasSymbolTable() const;
-
-  /// getSymbolTable() - CAUTION: The current symbol table may be null if there
-  /// are no names (ie, the symbol table is empty)
-  ///
-  inline       SymbolTable *getSymbolTable()       { return SymTab; }
-  inline const SymbolTable *getSymbolTable() const { return SymTab; }
-  
-  /// getSymbolTableSure is guaranteed to not return a null pointer, because if
-  /// the method does not already have a symtab, one is created.  Use this if
-  /// you intend to put something into the symbol table for the method.
-  ///
-  SymbolTable *getSymbolTableSure();
+  inline       SymbolTable &getSymbolTable()       { return *SymTab; }
+  inline const SymbolTable &getSymbolTable() const { return *SymTab; }
 
 
   //===--------------------------------------------------------------------===//
index f71fa585da1684a94de3584d3d28072b949b2b16..1c990e72aa009fd29bda3ce1d61630e5b2626982 100644 (file)
@@ -211,16 +211,18 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
   case ValID::NameVal: {                // Is it a named definition?
     string Name(D.Name);
     SymbolTable *SymTab = 0;
-    if (inFunctionScope()) SymTab = CurMeth.CurrentFunction->getSymbolTable();
-    Value *N = SymTab ? SymTab->lookup(Type::TypeTy, Name) : 0;
+    Value *N = 0;
+    if (inFunctionScope()) {
+      SymTab = &CurMeth.CurrentFunction->getSymbolTable();
+      N = SymTab->lookup(Type::TypeTy, Name);
+    }
 
     if (N == 0) {
       // Symbol table doesn't automatically chain yet... because the function
       // hasn't been added to the module...
       //
-      SymTab = CurModule.CurrentModule->getSymbolTable();
-      if (SymTab)
-        N = SymTab->lookup(Type::TypeTy, Name);
+      SymTab = &CurModule.CurrentModule->getSymbolTable();
+      N = SymTab->lookup(Type::TypeTy, Name);
       if (N == 0) break;
     }
 
@@ -251,10 +253,10 @@ static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
 }
 
 static Value *lookupInSymbolTable(const Type *Ty, const string &Name) {
-  SymbolTable *SymTab = 
+  SymbolTable &SymTab = 
     inFunctionScope() ? CurMeth.CurrentFunction->getSymbolTable() :
                         CurModule.CurrentModule->getSymbolTable();
-  return SymTab ? SymTab->lookup(Ty, Name) : 0;
+  return SymTab.lookup(Ty, Name);
 }
 
 // getValNonImprovising - Look up the value specified by the provided type and
@@ -481,11 +483,11 @@ static bool setValueName(Value *V, char *NameStr) {
     ThrowException("Can't assign name '" + Name + 
                   "' to a null valued instruction!");
 
-  SymbolTable *ST = inFunctionScope() ? 
-    CurMeth.CurrentFunction->getSymbolTableSure() : 
-    CurModule.CurrentModule->getSymbolTableSure();
+  SymbolTable &ST = inFunctionScope() ? 
+    CurMeth.CurrentFunction->getSymbolTable() : 
+    CurModule.CurrentModule->getSymbolTable();
 
-  Value *Existing = ST->lookup(V->getType(), Name);
+  Value *Existing = ST.lookup(V->getType(), Name);
   if (Existing) {    // Inserting a name that is already defined???
     // There is only one case where this is allowed: when we are refining an
     // opaque type.  In this case, Existing will be an opaque type.
@@ -528,7 +530,7 @@ static bool setValueName(Value *V, char *NameStr) {
                   V->getType()->getDescription() + "' type plane!");
   }
 
-  V->setName(Name, ST);
+  V->setName(Name, &ST);
   return false;
 }
 
index 0f9889c4c8eff14a46b7146a02f608260a9a3711..14445013081d127794d956c263917d5747cbf583 100644 (file)
@@ -338,7 +338,7 @@ bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf,
 
     case BytecodeFormat::SymbolTable:
       BCR_TRACE(2, "BLOCK BytecodeFormat::SymbolTable: {\n");
-      if (ParseSymbolTable(Buf, Buf+Size, M->getSymbolTableSure())) {
+      if (ParseSymbolTable(Buf, Buf+Size, &M->getSymbolTable())) {
        delete M; return true;
       }
       break;
@@ -543,7 +543,7 @@ bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf,
 
     case BytecodeFormat::SymbolTable:
       BCR_TRACE(1, "BLOCK BytecodeFormat::SymbolTable: {\n");
-      if (ParseSymbolTable(Buf, Buf+Size, Mod->getSymbolTableSure())) {
+      if (ParseSymbolTable(Buf, Buf+Size, &Mod->getSymbolTable())) {
        delete Mod; return true;
       }
       break;
index ca74711b4816e0f095af59180db87146ae9d987e..5f6f2e78359d27246afe927e3769d6b155ae489b 100644 (file)
@@ -90,9 +90,9 @@ void SlotCalculator::processModule() {
   // 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 @@ void SlotCalculator::incorporateFunction(const Function *M) {
     // 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 @@ void SlotCalculator::incorporateFunction(const Function *M) {
   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 e85498ce5fd12c6ad7b618999841c43f485a79cf..92b6a62cc6011cec7792e38fe4bc1dd6d85b9673 100644 (file)
@@ -58,8 +58,7 @@ BytecodeWriter::BytecodeWriter(std::deque<unsigned char> &o, const Module *M)
     processMethod(I);
 
   // If needed, output the symbol table for the module...
-  if (M->hasSymbolTable())
-    outputSymbolTable(*M->getSymbolTable());
+  outputSymbolTable(M->getSymbolTable());
 }
 
 // Helper function for outputConstants().
@@ -187,8 +186,7 @@ void BytecodeWriter::processMethod(const Function *F) {
       processBasicBlock(*I);
     
     // If needed, output the symbol table for the function...
-    if (F->hasSymbolTable())
-      outputSymbolTable(*F->getSymbolTable());
+    outputSymbolTable(F->getSymbolTable());
     
     Table.purgeFunction();
   }
index bc873e290eb2017725aba7bcfe711db6060bd32c..89f64b1b9b465d9d7d153aab99a02aa6e667b0b7 100644 (file)
@@ -437,16 +437,15 @@ static FILE *getFILE(PointerTy Ptr) {
 
     // Check to see if the currently loaded module contains an __iob symbol...
     GlobalVariable *IOB = 0;
-    if (SymbolTable *ST = M->getSymbolTable()) {
-      for (SymbolTable::iterator I = ST->begin(), E = ST->end(); I != E; ++I) {
-        SymbolTable::VarMap &M = I->second;
-        for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end();
-             J != E; ++J)
-          if (J->first == "__iob")
-            if ((IOB = dyn_cast<GlobalVariable>(J->second)))
-              break;
-        if (IOB) break;
-      }
+    SymbolTable &ST = M->getSymbolTable();
+    for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I) {
+      SymbolTable::VarMap &M = I->second;
+      for (SymbolTable::VarMap::iterator J = M.begin(), E = M.end();
+           J != E; ++J)
+        if (J->first == "__iob")
+          if ((IOB = dyn_cast<GlobalVariable>(J->second)))
+            break;
+      if (IOB) break;
     }
 
     // If we found an __iob symbol now, find out what the actual address it's
index aa97621214a1cb4bb7ff0086f973ce6b57382e45..4c31d2692ad5299d8c694a1d8e8c28c21dc631e3 100644 (file)
@@ -15,13 +15,10 @@ using std::cout;
 // LookupMatchingNames helper - Search a symbol table for values matching Name.
 //
 static inline void LookupMatchingNames(const std::string &Name,
-                                       SymbolTable *SymTab,
+                                       SymbolTable &SymTab,
                                       std::vector<Value*> &Results) {
-  if (SymTab == 0) return;                         // No symbolic values :(
-
   // Loop over all of the type planes in the symbol table...
-  for (SymbolTable::iterator I = SymTab->begin(), E = SymTab->end();
-       I != E; ++I) {
+  for (SymbolTable::iterator I = SymTab.begin(), E = SymTab.end(); I != E; ++I){
     SymbolTable::VarMap &Plane = I->second;
     
     // Search the symbol table plane for this name...
index 8fe9113d8215907b9f90610069e3cd9e388974ef..0d3cc9bfa9f5cb64762f91f9791b9b8e3b4e98fd 100644 (file)
@@ -32,11 +32,8 @@ static inline bool Error(string *E, string Message) {
 // Make sure there are no type name conflicts.
 //
 static bool LinkTypes(Module *Dest, const Module *Src, string *Err = 0) {
-  // No symbol table?  Can't have named types.
-  if (!Src->hasSymbolTable()) return false;
-
-  SymbolTable       *DestST = Dest->getSymbolTableSure();
-  const SymbolTable *SrcST  = Src->getSymbolTable();
+  SymbolTable       *DestST = &Dest->getSymbolTable();
+  const SymbolTable *SrcST  = &Src->getSymbolTable();
 
   // Look for a type plane for Type's...
   SymbolTable::const_iterator PI = SrcST->find(Type::TypeTy);
@@ -176,7 +173,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
                         map<const Value*, Value*> &ValueMap, string *Err = 0) {
   // We will need a module level symbol table if the src module has a module
   // level symbol table...
-  SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0;
+  SymbolTable *ST = (SymbolTable*)&Src->getSymbolTable();
   
   // Loop over all of the globals in the src module, mapping them over as we go
   //
@@ -266,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
                                string *Err = 0) {
   // We will need a module level symbol table if the src module has a module
   // level symbol table...
-  SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0;
+  SymbolTable *ST = (SymbolTable*)&Src->getSymbolTable();
   
   // Loop over all of the functions in the src module, mapping them over as we
   // go
index fcfda5d15a0d2a7b20059a15761822b8b6def370..8d9b314695fb039da92b6aa642278b293d232baa 100644 (file)
@@ -485,10 +485,10 @@ bool CWriter::nameAllUsedStructureTypes(Module &M) {
   // Loop over the module symbol table, removing types from UT that are already
   // named.
   //
-  SymbolTable *MST = M.getSymbolTableSure();
-  if (MST->find(Type::TypeTy) != MST->end())
-    for (SymbolTable::type_iterator I = MST->type_begin(Type::TypeTy),
-           E = MST->type_end(Type::TypeTy); I != E; ++I)
+  SymbolTable &MST = M.getSymbolTable();
+  if (MST.find(Type::TypeTy) != MST.end())
+    for (SymbolTable::type_iterator I = MST.type_begin(Type::TypeTy),
+           E = MST.type_end(Type::TypeTy); I != E; ++I)
       UT.erase(cast<Type>(I->second));
 
   // UT now contains types that are not named.  Loop over it, naming structure
@@ -498,7 +498,7 @@ bool CWriter::nameAllUsedStructureTypes(Module &M) {
   for (std::set<const Type *>::const_iterator I = UT.begin(), E = UT.end();
        I != E; ++I)
     if (const StructType *ST = dyn_cast<StructType>(*I)) {
-      ((Value*)ST)->setName("unnamed", MST);
+      ((Value*)ST)->setName("unnamed", &MST);
       Changed = true;
     }
   return Changed;
@@ -547,8 +547,7 @@ void CWriter::printModule(Module *M) {
   //
 
   // Loop over the symbol table, emitting all named constants...
-  if (M->hasSymbolTable())
-    printSymbolTable(*M->getSymbolTable());
+  printSymbolTable(M->getSymbolTable());
 
   // Global variable declarations...
   if (!M->gempty()) {
index fcfda5d15a0d2a7b20059a15761822b8b6def370..8d9b314695fb039da92b6aa642278b293d232baa 100644 (file)
@@ -485,10 +485,10 @@ bool CWriter::nameAllUsedStructureTypes(Module &M) {
   // Loop over the module symbol table, removing types from UT that are already
   // named.
   //
-  SymbolTable *MST = M.getSymbolTableSure();
-  if (MST->find(Type::TypeTy) != MST->end())
-    for (SymbolTable::type_iterator I = MST->type_begin(Type::TypeTy),
-           E = MST->type_end(Type::TypeTy); I != E; ++I)
+  SymbolTable &MST = M.getSymbolTable();
+  if (MST.find(Type::TypeTy) != MST.end())
+    for (SymbolTable::type_iterator I = MST.type_begin(Type::TypeTy),
+           E = MST.type_end(Type::TypeTy); I != E; ++I)
       UT.erase(cast<Type>(I->second));
 
   // UT now contains types that are not named.  Loop over it, naming structure
@@ -498,7 +498,7 @@ bool CWriter::nameAllUsedStructureTypes(Module &M) {
   for (std::set<const Type *>::const_iterator I = UT.begin(), E = UT.end();
        I != E; ++I)
     if (const StructType *ST = dyn_cast<StructType>(*I)) {
-      ((Value*)ST)->setName("unnamed", MST);
+      ((Value*)ST)->setName("unnamed", &MST);
       Changed = true;
     }
   return Changed;
@@ -547,8 +547,7 @@ void CWriter::printModule(Module *M) {
   //
 
   // Loop over the symbol table, emitting all named constants...
-  if (M->hasSymbolTable())
-    printSymbolTable(*M->getSymbolTable());
+  printSymbolTable(M->getSymbolTable());
 
   // Global variable declarations...
   if (!M->gempty()) {
index a1860a92e959dcb30859b6ebf0019e4f153eb711..2ea9ac2a56ab599005e96e49d11913e5499df5f5 100644 (file)
@@ -63,35 +63,34 @@ static inline bool ShouldNukeSymtabEntry(const std::pair<std::string,Value*>&E){
 bool DTE::run(Module &M) {
   bool Changed = false;
 
-  if (SymbolTable *ST = M.getSymbolTable()) {
-    const std::set<const Type *> &UsedTypes =
-      getAnalysis<FindUsedTypes>().getTypes();
+  SymbolTable &ST = M.getSymbolTable();
+  const std::set<const Type *> &UsedTypes =
+    getAnalysis<FindUsedTypes>().getTypes();
 
-    // Check the symbol table for superfluous type entries...
-    //
-    // Grab the 'type' plane of the module symbol...
-    SymbolTable::iterator STI = ST->find(Type::TypeTy);
-    if (STI != ST->end()) {
-      // Loop over all entries in the type plane...
-      SymbolTable::VarMap &Plane = STI->second;
-      for (SymbolTable::VarMap::iterator PI = Plane.begin(); PI != Plane.end();)
-        // If this entry should be unconditionally removed, or if we detect that
-        // the type is not used, remove it.
-        //
-        if (ShouldNukeSymtabEntry(*PI) ||
-            !UsedTypes.count(cast<Type>(PI->second))) {
+  // Check the symbol table for superfluous type entries...
+  //
+  // Grab the 'type' plane of the module symbol...
+  SymbolTable::iterator STI = ST.find(Type::TypeTy);
+  if (STI != ST.end()) {
+    // Loop over all entries in the type plane...
+    SymbolTable::VarMap &Plane = STI->second;
+    for (SymbolTable::VarMap::iterator PI = Plane.begin(); PI != Plane.end();)
+      // If this entry should be unconditionally removed, or if we detect that
+      // the type is not used, remove it.
+      //
+      if (ShouldNukeSymtabEntry(*PI) ||
+          !UsedTypes.count(cast<Type>(PI->second))) {
 #if MAP_IS_NOT_BRAINDEAD
-          PI = Plane.erase(PI);     // STD C++ Map should support this!
+        PI = Plane.erase(PI);     // STD C++ Map should support this!
 #else
-          Plane.erase(PI);          // Alas, GCC 2.95.3 doesn't  *SIGH*
-          PI = Plane.begin();
+        Plane.erase(PI);          // Alas, GCC 2.95.3 doesn't  *SIGH*
+        PI = Plane.begin();
 #endif
-          ++NumKilled;
-          Changed = true;
-        } else {
-          ++PI;
-        }
-    }
+        ++NumKilled;
+        Changed = true;
+      } else {
+        ++PI;
+      }
   }
 
   return Changed;
index cbcfa2aba853c74070765c57ade30b5319fac846..bb3a9af659507bcf4665cc4b516dd52e3d768a37 100644 (file)
@@ -304,8 +304,7 @@ static bool ProcessGlobalsWithSameName(Module &M,
 }
 
 bool FunctionResolvingPass::run(Module &M) {
-  SymbolTable *ST = M.getSymbolTable();
-  if (!ST) return false;
+  SymbolTable &ST = M.getSymbolTable();
 
   std::map<string, vector<GlobalValue*> > Globals;
 
@@ -313,7 +312,7 @@ bool FunctionResolvingPass::run(Module &M) {
   // then add it to the Functions map.  We do a two pass algorithm here to avoid
   // problems with iterators getting invalidated if we did a one pass scheme.
   //
-  for (SymbolTable::iterator I = ST->begin(), E = ST->end(); I != E; ++I)
+  for (SymbolTable::iterator I = ST.begin(), E = ST.end(); I != E; ++I)
     if (const PointerType *PT = dyn_cast<PointerType>(I->first)) {
       SymbolTable::VarMap &Plane = I->second;
       for (SymbolTable::type_iterator PI = Plane.begin(), PE = Plane.end();
index 84f57852cdcdee426f8341aeb4b881788526ffb0..952082320635046f6a4bb87acccaecea81f43082 100644 (file)
@@ -209,7 +209,7 @@ static bool PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
       if (!Src->hasName() && CI->hasName()) {
         std::string Name = CI->getName();
         CI->setName("");
-        Src->setName(Name, BB->getParent()->getSymbolTable());
+        Src->setName(Name, &BB->getParent()->getSymbolTable());
       }
 
       // DCE the instruction now, to avoid having the iterative version of DCE
index 5f5296907559d7cdbae27f3a87fd8d50887fec40..99e596e8f2afe5abc31d80bfafe901373e4d1921 100644 (file)
 #include "llvm/SymbolTable.h"
 #include "llvm/Pass.h"
 
-static bool StripSymbolTable(SymbolTable *SymTab) {
-  if (SymTab == 0) return false;    // No symbol table?  No problem.
+static bool StripSymbolTable(SymbolTable &SymTab) {
   bool RemovedSymbol = false;
 
-  for (SymbolTable::iterator I = SymTab->begin(); I != SymTab->end(); ++I) {
+  for (SymbolTable::iterator I = SymTab.begin(); I != SymTab.end(); ++I) {
     std::map<const std::string, Value *> &Plane = I->second;
     
     SymbolTable::type_iterator B;
     while ((B = Plane.begin()) != Plane.end()) {   // Found nonempty type plane!
       Value *V = B->second;
       if (isa<Constant>(V) || isa<Type>(V))
-       SymTab->type_remove(B);
+       SymTab.type_remove(B);
       else 
-       V->setName("", SymTab);   // Set name to "", removing from symbol table!
+       V->setName("", &SymTab);  // Set name to "", removing from symbol table!
       RemovedSymbol = true;
       assert(Plane.begin() != B && "Symbol not removed from table!");
     }
index 22377ba3edc5a029bb47dda4bdd9e2e25deb9c15..33834277b7d847f5f56d886c8e3ebf9958511b01 100644 (file)
@@ -28,7 +28,7 @@ void ReplaceInstWithValue(BasicBlock::InstListType &BIL,
 
   // Make sure to propagate a name if there is one already...
   if (OldName.size() && !V->hasName())
-    V->setName(OldName, BIL.getParent()->getSymbolTable());
+    V->setName(OldName, &BIL.getParent()->getSymbolTable());
 }
 
 
index 8fe9113d8215907b9f90610069e3cd9e388974ef..0d3cc9bfa9f5cb64762f91f9791b9b8e3b4e98fd 100644 (file)
@@ -32,11 +32,8 @@ static inline bool Error(string *E, string Message) {
 // Make sure there are no type name conflicts.
 //
 static bool LinkTypes(Module *Dest, const Module *Src, string *Err = 0) {
-  // No symbol table?  Can't have named types.
-  if (!Src->hasSymbolTable()) return false;
-
-  SymbolTable       *DestST = Dest->getSymbolTableSure();
-  const SymbolTable *SrcST  = Src->getSymbolTable();
+  SymbolTable       *DestST = &Dest->getSymbolTable();
+  const SymbolTable *SrcST  = &Src->getSymbolTable();
 
   // Look for a type plane for Type's...
   SymbolTable::const_iterator PI = SrcST->find(Type::TypeTy);
@@ -176,7 +173,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
                         map<const Value*, Value*> &ValueMap, string *Err = 0) {
   // We will need a module level symbol table if the src module has a module
   // level symbol table...
-  SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0;
+  SymbolTable *ST = (SymbolTable*)&Src->getSymbolTable();
   
   // Loop over all of the globals in the src module, mapping them over as we go
   //
@@ -266,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
                                string *Err = 0) {
   // We will need a module level symbol table if the src module has a module
   // level symbol table...
-  SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0;
+  SymbolTable *ST = (SymbolTable*)&Src->getSymbolTable();
   
   // Loop over all of the functions in the src module, mapping them over as we
   // go
index e27bd26ba27e7e621547245dffbf27ee7edb1071..2c9a77c834fb909e9fe668868fbaa40444ea3b64 100644 (file)
@@ -74,20 +74,19 @@ static SlotCalculator *createSlotCalculator(const Value *V) {
 //
 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 @@ ostream &WriteTypeSymbolic(ostream &Out, const Type *Ty, const Module *M) {
 
   // 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 @@ ostream &WriteAsOperand(ostream &Out, const Value *V, bool PrintType,
   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::writeOperand(const Value *Operand, bool PrintType,
 
 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 6ddcc08c8287a3f876a6b06e69851c7cc114c44c..89f9a27f8da8279bc0075b4df3ef0f707649e352 100644 (file)
@@ -105,11 +105,11 @@ void BasicBlock::setParent(Function *parent) {
 // 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 9b837dcaa1308054ed0cf9fcc8a819de2a940db1..70569c0f67ce7539f0e878921347b0fd5260ee95 100644 (file)
@@ -57,11 +57,11 @@ Argument::Argument(const Type *Ty, const std::string &Name, Function *Par)
 // 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 @@ Function::~Function() {
 // 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 @@ void GlobalVariable::setParent(Module *parent) {
 // 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 95267aacd02154a5bdfaefdfd0208aa44014f53b..01381faed6e14b375b9f332ed36f774cd4702b7a 100644 (file)
@@ -40,12 +40,12 @@ void Instruction::setParent(BasicBlock *P) {
 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 8fe9113d8215907b9f90610069e3cd9e388974ef..0d3cc9bfa9f5cb64762f91f9791b9b8e3b4e98fd 100644 (file)
@@ -32,11 +32,8 @@ static inline bool Error(string *E, string Message) {
 // Make sure there are no type name conflicts.
 //
 static bool LinkTypes(Module *Dest, const Module *Src, string *Err = 0) {
-  // No symbol table?  Can't have named types.
-  if (!Src->hasSymbolTable()) return false;
-
-  SymbolTable       *DestST = Dest->getSymbolTableSure();
-  const SymbolTable *SrcST  = Src->getSymbolTable();
+  SymbolTable       *DestST = &Dest->getSymbolTable();
+  const SymbolTable *SrcST  = &Src->getSymbolTable();
 
   // Look for a type plane for Type's...
   SymbolTable::const_iterator PI = SrcST->find(Type::TypeTy);
@@ -176,7 +173,7 @@ static bool LinkGlobals(Module *Dest, const Module *Src,
                         map<const Value*, Value*> &ValueMap, string *Err = 0) {
   // We will need a module level symbol table if the src module has a module
   // level symbol table...
-  SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0;
+  SymbolTable *ST = (SymbolTable*)&Src->getSymbolTable();
   
   // Loop over all of the globals in the src module, mapping them over as we go
   //
@@ -266,7 +263,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
                                string *Err = 0) {
   // We will need a module level symbol table if the src module has a module
   // level symbol table...
-  SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0;
+  SymbolTable *ST = (SymbolTable*)&Src->getSymbolTable();
   
   // Loop over all of the functions in the src module, mapping them over as we
   // go
index c12b32d7c1395b6e1aae88970e0df52b0f360137..f54a6f390be7d61c3abd5a18780a9cc6362ff29c 100644 (file)
@@ -57,7 +57,7 @@ Module::Module() {
   GlobalList.setItemParent(this);
   GlobalList.setParent(this);
   GVRefMap = 0;
-  SymTab = 0;
+  SymTab = new SymbolTable();
 }
 
 Module::~Module() {
@@ -74,26 +74,6 @@ void Module::dump() const {
   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 @@ bool Module::hasSymbolTable() const {
 //
 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 @@ Function *Module::getOrInsertFunction(const std::string &Name,
 // 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 @@ Function *Module::getFunction(const std::string &Name, const FunctionType *Ty) {
 // 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 @@ Function *Module::getNamedFunction(const std::string &Name) {
 // 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 ca74711b4816e0f095af59180db87146ae9d987e..5f6f2e78359d27246afe927e3769d6b155ae489b 100644 (file)
@@ -90,9 +90,9 @@ void SlotCalculator::processModule() {
   // 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 @@ void SlotCalculator::incorporateFunction(const Function *M) {
     // 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 @@ void SlotCalculator::incorporateFunction(const Function *M) {
   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 36b08ab9f6fa9090f6fc4c88873670ec9dce715b..682ea23d1666b91d3a9704c1a8e1eb805acb07a6 100644 (file)
@@ -20,20 +20,20 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
 
   // 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 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
   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 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
 ::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 @@ void SymbolTableListTraits<ValueSubClass,ItemParentClass,SymTabClass,SubClass>
       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 da3449b95c02542dacb4e75c3b8659be4d4f9409..812ca4a86845d5c4720cb5112e064974be9b416c 100644 (file)
@@ -124,7 +124,7 @@ namespace {  // Anonymous namespace for class
     }
 
     // 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 @@ namespace {  // Anonymous namespace for class
 
 // 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;