1 //===- CleanupGCCOutput.cpp - Cleanup GCC Output ----------------------------=//
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:
7 // Note: This code produces dead declarations, it is a good idea to run DCE
10 //===----------------------------------------------------------------------===//
12 #include "llvm/Transforms/CleanupGCCOutput.h"
13 #include "llvm/SymbolTable.h"
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;
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;
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.
31 bool CleanupGCCOutput::doPassInitialization(Module *M) {
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!
46 Plane.erase(PI); // Alas, GCC 2.95.3 doesn't *SIGH*
61 // doPerMethodWork - This method simplifies the specified method hopefully.
63 bool CleanupGCCOutput::doPerMethodWork(Method *M) {