diff options
| author | Chris Lattner <sabre@nondot.org> | 2001-11-15 04:34:46 +0000 | 
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2001-11-15 04:34:46 +0000 | 
| commit | 02c43c8609e393f95af72025ba7fcaf233a6ee4d (patch) | |
| tree | f81bdc329bfbe90c689f1e2e00793a3ddf6ac767 /llvm/lib/Transforms | |
| parent | c5989f645bcec6a4c85b2f342e1e88d579507eaf (diff) | |
| download | bcm5719-llvm-02c43c8609e393f95af72025ba7fcaf233a6ee4d.tar.gz bcm5719-llvm-02c43c8609e393f95af72025ba7fcaf233a6ee4d.zip | |
-cleangcc pass now remove type names that are never referenced and type names for pointers to primitive types.
llvm-svn: 1312
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/IPO/DeadTypeElimination.cpp | 46 | 
1 files changed, 43 insertions, 3 deletions
| diff --git a/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp b/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp index 8e705ebff56..e02c022dbb2 100644 --- a/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp +++ b/llvm/lib/Transforms/IPO/DeadTypeElimination.cpp @@ -5,9 +5,8 @@  // things to try to clean it up:  //  // * Eliminate names for GCC types that we know can't be needed by the user. -// - Eliminate names for types that are unused in the entire translation unit -//    but only if they do not name a structure type! -// - Replace calls to 'sbyte *%malloc(uint)' and 'void %free(sbyte *)' with +// * Eliminate names for types that are unused in the entire translation unit +// * Replace calls to 'sbyte *%malloc(uint)' and 'void %free(sbyte *)' with  //   malloc and free instructions.  //  // Note:  This code produces dead declarations, it is a good idea to run DCE @@ -206,6 +205,10 @@ static inline bool ShouldNukeSymtabEntry(const pair<string, Value*> &E) {    // Nuke all names for primitive types!    if (cast<Type>(E.second)->isPrimitiveType()) return true; +  // Nuke all pointers to primitive types as well... +  if (const PointerType *PT = dyn_cast<PointerType>(E.second)) +    if (PT->getValueType()->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; @@ -220,6 +223,8 @@ static inline bool ShouldNukeSymtabEntry(const pair<string, Value*> &E) {  bool CleanupGCCOutput::doPassInitialization(Module *M) {    bool Changed = false; +  FUT.doPassInitialization(M); +    if (PtrArrSByte == 0) {      PtrArrSByte = PointerType::get(ArrayType::get(Type::SByteTy));      PtrSByte    = PointerType::get(Type::SByteTy); @@ -547,5 +552,40 @@ static bool fixLocalProblems(Method *M) {  bool CleanupGCCOutput::doPerMethodWork(Method *M) {    bool Changed = fixLocalProblems(M);    while (doOneCleanupPass(M)) Changed = true; + +  FUT.doPerMethodWork(M); +  return Changed; +} + +bool CleanupGCCOutput::doPassFinalization(Module *M) { +  bool Changed = false; +  FUT.doPassFinalization(M); + +  if (M->hasSymbolTable()) { +    SymbolTable *ST = M->getSymbolTable(); +    const set<const Type *> &UsedTypes = FUT.getTypes(); + +    // Check the symbol table for superfluous type entries that aren't used in +    // the program +    // +    // Grab the 'type' plane of the module symbol... +    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 (!UsedTypes.count(cast<Type>(PI->second))) { +#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();       // N^2 algorithms are fun.  :( +#endif +          Changed = true; +        } else { +          ++PI; +        } +    } +  }    return Changed;  } | 

