diff options
author | Chris Lattner <sabre@nondot.org> | 2004-02-26 20:02:23 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-02-26 20:02:23 +0000 |
commit | 79636d7cd5fc448bd1de74c93cc26df6fee994a4 (patch) | |
tree | bd2bd1378a94fa4fff3ab5bae2f19b81ecee8ed4 /llvm/lib/Transforms | |
parent | a9908638519a4135a41495ac684a7b7a34f30889 (diff) | |
download | bcm5719-llvm-79636d7cd5fc448bd1de74c93cc26df6fee994a4.tar.gz bcm5719-llvm-79636d7cd5fc448bd1de74c93cc26df6fee994a4.zip |
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
llvm-svn: 11879
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/IPO/DeadTypeElimination.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp b/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp index 8849a025a0a..c3a9f6edc5b 100644 --- a/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp +++ b/llvm/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<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 DTE::run(Module &M) { 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 @@ 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<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; |