Add std:: to sort calls.
[oota-llvm.git] / lib / Transforms / IPO / DeadTypeElimination.cpp
index e30e0ed38c4c92da69d89526ffdba1624cb6f6d3..87b725ab1d57c795471f447bc0e25650fc98f99e 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#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"
+#include "llvm/Support/Compiler.h"
 using namespace llvm;
 
+STATISTIC(NumKilled, "Number of unused typenames removed from symtab");
+
 namespace {
-  struct DTE : public ModulePass {
+  struct VISIBILITY_HIDDEN DTE : public ModulePass {
+    static char ID; // Pass identification, replacement for typeid
+    DTE() : ModulePass((intptr_t)&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.
@@ -36,9 +43,8 @@ namespace {
       AU.addRequired<FindUsedTypes>();
     }
   };
+  char DTE::ID = 0;
   RegisterPass<DTE> X("deadtypeelim", "Dead Type Elimination");
-  Statistic
-  NumKilled("deadtypeelim", "Number of unused typenames removed from symtab");
 }
 
 ModulePass *llvm::createDeadTypeEliminationPass() {
@@ -51,11 +57,14 @@ ModulePass *llvm::createDeadTypeEliminationPass() {
 //
 static inline bool ShouldNukeSymtabEntry(const Type *Ty){
   // Nuke all names for primitive types!
-  if (Ty->isPrimitiveType()) return true;
+  if (Ty->isPrimitiveType() || Ty->isInteger()) 
+    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()->isInteger()) 
+      return true;
 
   return false;
 }
@@ -68,14 +77,15 @@ static inline bool ShouldNukeSymtabEntry(const Type *Ty){
 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;