Don't use PassInfo* as a type identifier for passes. Instead, use the address of...
[oota-llvm.git] / lib / Transforms / IPO / DeadTypeElimination.cpp
index e2d475daf9fe79cc585fbbb76d2a88d31dd4053c..5dc50c5bef32fe0ad67ed4d3de1d80de54e73c92 100644 (file)
@@ -1,10 +1,10 @@
 //===- DeadTypeElimination.cpp - Eliminate unused types for symbol table --===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
 //===----------------------------------------------------------------------===//
 //
 // This pass is used to cleanup the output of GCC.  It eliminate names for types
 //
 //===----------------------------------------------------------------------===//
 
+#define DEBUG_TYPE "deadtypeelim"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Analysis/FindUsedTypes.h"
 #include "llvm/Module.h"
-#include "llvm/SymbolTable.h"
+#include "llvm/TypeSymbolTable.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/ADT/Statistic.h"
 using namespace llvm;
 
+STATISTIC(NumKilled, "Number of unused typenames removed from symtab");
+
 namespace {
-  struct DTE : public Pass {
+  struct DTE : public ModulePass {
+    static char ID; // Pass identification, replacement for typeid
+    DTE() : ModulePass(ID) {}
+
     // 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.
     //
     // Also, initialize instance variables.
     //
-    bool run(Module &M);
+    bool runOnModule(Module &M);
 
     // getAnalysisUsage - This function needs FindUsedTypes to do its job...
     //
@@ -36,12 +42,12 @@ namespace {
       AU.addRequired<FindUsedTypes>();
     }
   };
-  RegisterOpt<DTE> X("deadtypeelim", "Dead Type Elimination");
-  Statistic<>
-  NumKilled("deadtypeelim", "Number of unused typenames removed from symtab");
 }
 
-Pass *llvm::createDeadTypeEliminationPass() {
+char DTE::ID = 0;
+INITIALIZE_PASS(DTE, "deadtypeelim", "Dead Type Elimination", false, false);
+
+ModulePass *llvm::createDeadTypeEliminationPass() {
   return new DTE();
 }
 
@@ -51,11 +57,14 @@ Pass *llvm::createDeadTypeEliminationPass() {
 //
 static inline bool ShouldNukeSymtabEntry(const Type *Ty){
   // Nuke all names for primitive types!
-  if (Ty->isPrimitiveType()) return true;
+  if (Ty->isPrimitiveType() || Ty->isIntegerTy()) 
+    return true;
 
   // Nuke all pointers to primitive types as well...
   if (const PointerType *PT = dyn_cast<PointerType>(Ty))
-    if (PT->getElementType()->isPrimitiveType()) return true;
+    if (PT->getElementType()->isPrimitiveType() ||
+        PT->getElementType()->isIntegerTy()) 
+      return true;
 
   return false;
 }
@@ -65,23 +74,23 @@ static inline bool ShouldNukeSymtabEntry(const Type *Ty){
 // uglier to look at, so we nuke them.  Also eliminate types that are never used
 // in the entire program as indicated by FindUsedTypes.
 //
-bool DTE::run(Module &M) {
+bool DTE::runOnModule(Module &M) {
   bool Changed = false;
 
-  SymbolTable &ST = M.getSymbolTable();
+  TypeSymbolTable &ST = M.getTypeSymbolTable();
   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::type_iterator TI = ST.type_begin();
-  while ( TI != ST.type_end() ) {
+  TypeSymbolTable::iterator TI = ST.begin();
+  TypeSymbolTable::iterator TE = ST.end();
+  while ( TI != TE ) {
     // If this entry should be unconditionally removed, or if we detect that
     // the type is not used, remove it.
     const Type *RHS = TI->second;
     if (ShouldNukeSymtabEntry(RHS) || !UsedTypes.count(RHS)) {
-      SymbolTable::type_iterator ToRemove = TI++;
-      ST.remove(ToRemove->second);
+      ST.remove(TI++);
       ++NumKilled;
       Changed = true;
     } else {