From: Chris Lattner Date: Thu, 26 Feb 2004 20:02:23 +0000 (+0000) Subject: Since LLVM uses structure type equivalence, it isn't useful to keep around X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4f77caaa3d2265d69a52bd6a4e5905504896c220;p=oota-llvm.git 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@11879 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp index 8849a025a0a..c3a9f6edc5b 100644 --- a/lib/Transforms/IPO/DeadTypeElimination.cpp +++ b/lib/Transforms/IPO/DeadTypeElimination.cpp @@ -49,12 +49,12 @@ Pass *llvm::createDeadTypeEliminationPass() { // ShouldNukeSymtabEntry - Return true if this module level symbol table entry // should be eliminated. // -static inline bool ShouldNukeSymtabEntry(const std::pair&E){ +static inline bool ShouldNukeSymtabEntry(const Type *Ty){ // Nuke all names for primitive types! - if (cast(E.second)->isPrimitiveType()) return true; + if (Ty->isPrimitiveType()) return true; // Nuke all pointers to primitive types as well... - if (const PointerType *PT = dyn_cast(E.second)) + if (const PointerType *PT = dyn_cast(Ty)) if (PT->getElementType()->isPrimitiveType()) return true; return false; @@ -69,8 +69,7 @@ bool DTE::run(Module &M) { bool Changed = false; SymbolTable &ST = M.getSymbolTable(); - const std::set &UsedTypes = - getAnalysis().getTypes(); + std::set UsedTypes = getAnalysis().getTypes(); // Check the symbol table for superfluous type entries... // @@ -79,18 +78,20 @@ bool DTE::run(Module &M) { 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(PI->second))) { - SymbolTable::VarMap::iterator PJ = PI++; - Plane.erase(PJ); + const Type *RHS = cast(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;