9fd912a1adc9461dc289795f6fdcb1bea0bd023e
[oota-llvm.git] / lib / Transforms / IPO / DeadTypeElimination.cpp
1 //===- CleanupGCCOutput.cpp - Cleanup GCC Output ----------------------------=//
2 //
3 // This pass is used to cleanup the output of GCC.  GCC's output is
4 // unneccessarily gross for a couple of reasons. This pass does the following
5 // things to try to clean it up:
6 //
7 // Note:  This code produces dead declarations, it is a good idea to run DCE
8 //        after this pass.
9 //
10 //===----------------------------------------------------------------------===//
11
12 #include "llvm/Transforms/CleanupGCCOutput.h"
13 #include "llvm/SymbolTable.h"
14
15 static inline bool ShouldNukeSymtabEntry(const pair<string, Value*> &E) {
16   // Nuke all names for primitive types!
17   if (cast<Type>(E.second)->isPrimitiveType()) return true;
18
19   // The only types that could contain .'s in the program are things generated
20   // by GCC itself, including "complex.float" and friends.  Nuke them too.
21   if (E.first.find('.') != string::npos) return true;
22
23   return false;
24 }
25
26
27 // doPassInitialization - For this pass, it removes global symbol table
28 // entries for primitive types.  These are never used for linking in GCC and
29 // they make the output uglier to look at, so we nuke them.
30 //
31 bool CleanupGCCOutput::doPassInitialization(Module *M) {
32   bool Changed = false;
33
34   if (M->hasSymbolTable()) {
35     // Grab the type plane of the module...
36     SymbolTable *ST = M->getSymbolTable();
37     SymbolTable::iterator STI = ST->find(Type::TypeTy);
38     if (STI != ST->end()) {
39       // Loop over all entries in the type plane...
40       SymbolTable::VarMap &Plane = STI->second;
41       for (SymbolTable::VarMap::iterator PI = Plane.begin(); PI != Plane.end();)
42         if (ShouldNukeSymtabEntry(*PI)) {    // Should we remove this entry?
43 #if MAP_IS_NOT_BRAINDEAD
44           PI = Plane.erase(PI);     // STD C++ Map should support this!
45 #else
46           Plane.erase(PI);          // Alas, GCC 2.95.3 doesn't  *SIGH*
47           PI = Plane.begin();
48 #endif
49           Changed = true;
50         } else {
51           ++PI;
52         }
53     }
54     
55   }
56
57   return Changed;
58 }
59
60
61 // doPerMethodWork - This method simplifies the specified method hopefully.
62 //
63 bool CleanupGCCOutput::doPerMethodWork(Method *M) {
64   bool Changed = false;
65
66   return Changed;
67 }