[llvm-commits] CVS: llvm/lib/Transforms/IPO/DeadTypeElimination.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Feb 26 14:03:01 PST 2004


Changes in directory llvm/lib/Transforms/IPO:

DeadTypeElimination.cpp updated: 1.48 -> 1.49

---
Log message:

Since LLVM uses structure type equivalence, it isn't useful to keep around
multiple type names for the same structural type.  Make DTE eliminate all
but one of the type names


---
Diffs of the changes:  (+11 -10)

Index: llvm/lib/Transforms/IPO/DeadTypeElimination.cpp
diff -u llvm/lib/Transforms/IPO/DeadTypeElimination.cpp:1.48 llvm/lib/Transforms/IPO/DeadTypeElimination.cpp:1.49
--- llvm/lib/Transforms/IPO/DeadTypeElimination.cpp:1.48	Fri Nov 21 15:54:21 2003
+++ llvm/lib/Transforms/IPO/DeadTypeElimination.cpp	Thu Feb 26 14:02:23 2004
@@ -49,12 +49,12 @@
 // ShouldNukeSymtabEntry - Return true if this module level symbol table entry
 // should be eliminated.
 //
-static inline bool ShouldNukeSymtabEntry(const std::pair<std::string,Value*>&E){
+static inline bool ShouldNukeSymtabEntry(const Type *Ty){
   // Nuke all names for primitive types!
-  if (cast<Type>(E.second)->isPrimitiveType()) return true;
+  if (Ty->isPrimitiveType()) return true;
 
   // Nuke all pointers to primitive types as well...
-  if (const PointerType *PT = dyn_cast<PointerType>(E.second))
+  if (const PointerType *PT = dyn_cast<PointerType>(Ty))
     if (PT->getElementType()->isPrimitiveType()) return true;
 
   return false;
@@ -69,8 +69,7 @@
   bool Changed = false;
 
   SymbolTable &ST = M.getSymbolTable();
-  const std::set<const Type *> &UsedTypes =
-    getAnalysis<FindUsedTypes>().getTypes();
+  std::set<const Type *> UsedTypes = getAnalysis<FindUsedTypes>().getTypes();
 
   // Check the symbol table for superfluous type entries...
   //
@@ -79,18 +78,20 @@
   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();)
+    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))) {
-        SymbolTable::VarMap::iterator PJ = PI++;
-        Plane.erase(PJ);
+      const Type *RHS = cast<Type>(PI->second);
+      if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) {
+        Plane.erase(PI++);
         ++NumKilled;
         Changed = true;
       } else {
         ++PI;
+        // We only need to leave one name for each type.
+        UsedTypes.erase(RHS);
       }
+    }
   }
 
   return Changed;





More information about the llvm-commits mailing list