Initial version of GCC cleanup pass: just removes extraneous global symbol table...
authorChris Lattner <sabre@nondot.org>
Wed, 31 Oct 2001 04:33:19 +0000 (04:33 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 31 Oct 2001 04:33:19 +0000 (04:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1062 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/DeadTypeElimination.cpp [new file with mode: 0644]
lib/VMCore/AsmWriter.cpp

diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp
new file mode 100644 (file)
index 0000000..9fd912a
--- /dev/null
@@ -0,0 +1,67 @@
+//===- CleanupGCCOutput.cpp - Cleanup GCC Output ----------------------------=//
+//
+// This pass is used to cleanup the output of GCC.  GCC's output is
+// unneccessarily gross for a couple of reasons. This pass does the following
+// things to try to clean it up:
+//
+// Note:  This code produces dead declarations, it is a good idea to run DCE
+//        after this pass.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/CleanupGCCOutput.h"
+#include "llvm/SymbolTable.h"
+
+static inline bool ShouldNukeSymtabEntry(const pair<string, Value*> &E) {
+  // Nuke all names for primitive types!
+  if (cast<Type>(E.second)->isPrimitiveType()) return true;
+
+  // The only types that could contain .'s in the program are things generated
+  // by GCC itself, including "complex.float" and friends.  Nuke them too.
+  if (E.first.find('.') != string::npos) return true;
+
+  return false;
+}
+
+
+// doPassInitialization - For this pass, it removes global symbol table
+// entries for primitive types.  These are never used for linking in GCC and
+// they make the output uglier to look at, so we nuke them.
+//
+bool CleanupGCCOutput::doPassInitialization(Module *M) {
+  bool Changed = false;
+
+  if (M->hasSymbolTable()) {
+    // Grab the type plane of the module...
+    SymbolTable *ST = M->getSymbolTable();
+    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 (ShouldNukeSymtabEntry(*PI)) {    // Should we remove this entry?
+#if MAP_IS_NOT_BRAINDEAD
+          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();
+#endif
+          Changed = true;
+        } else {
+          ++PI;
+        }
+    }
+    
+  }
+
+  return Changed;
+}
+
+
+// doPerMethodWork - This method simplifies the specified method hopefully.
+//
+bool CleanupGCCOutput::doPerMethodWork(Method *M) {
+  bool Changed = false;
+
+  return Changed;
+}
index a53e484deda581314a91101e46da75bcc199d483..f2dc6bee9f2ab851eadeabda8553337cc5f44d4b 100644 (file)
@@ -218,6 +218,7 @@ static ostream &printTypeInt(ostream &Out, const Type *Ty,
   return Out << TypeName;
 }
 
+
 // WriteTypeSymbolic - This attempts to write the specified type as a symbolic
 // type, iff there is an entry in the modules symbol table for the specified
 // type or one of it's component types.  This is slower than a simple x << Type;