mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-07 12:28:24 +00:00
Cleanup and simplify code
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3036 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1,58 +1,41 @@
|
|||||||
//===- CleanupGCCOutput.cpp - Cleanup GCC Output --------------------------===//
|
//===- DeadTypeElimination.cpp - Eliminate unused types for symbol table --===//
|
||||||
//
|
//
|
||||||
// This pass is used to cleanup the output of GCC. GCC's output is
|
// This pass is used to cleanup the output of GCC. It eliminate names for types
|
||||||
// unneccessarily gross for a couple of reasons. This pass does the following
|
// that are unused in the entire translation unit, using the FindUsedTypes pass.
|
||||||
// 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
|
|
||||||
// * Fix various problems that we might have in PHI nodes and casts
|
|
||||||
//
|
|
||||||
// Note: This code produces dead declarations, it is a good idea to run DCE
|
|
||||||
// after this pass.
|
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Transforms/CleanupGCCOutput.h"
|
#include "llvm/Transforms/IPO.h"
|
||||||
#include "llvm/Analysis/FindUsedTypes.h"
|
#include "llvm/Analysis/FindUsedTypes.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/SymbolTable.h"
|
#include "llvm/SymbolTable.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
#include "Support/StatisticReporter.h"
|
#include "Support/StatisticReporter.h"
|
||||||
|
|
||||||
static Statistic<> NumTypeSymtabEntriesKilled("cleangcc\t- Number of unused typenames removed from symtab");
|
|
||||||
|
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct CleanupGCCOutput : public FunctionPass {
|
struct DTE : public Pass {
|
||||||
// doPassInitialization - For this pass, it removes global symbol table
|
// doPassInitialization - For this pass, it removes global symbol table
|
||||||
// entries for primitive types. These are never used for linking in GCC and
|
// entries for primitive types. These are never used for linking in GCC and
|
||||||
// they make the output uglier to look at, so we nuke them.
|
// they make the output uglier to look at, so we nuke them.
|
||||||
//
|
//
|
||||||
// Also, initialize instance variables.
|
// Also, initialize instance variables.
|
||||||
//
|
//
|
||||||
bool doInitialization(Module &M);
|
bool run(Module &M);
|
||||||
|
|
||||||
// FIXME:
|
|
||||||
// FIXME: This FunctionPass should be a PASS!
|
|
||||||
// FIXME:
|
|
||||||
bool runOnFunction(Function &F) { return false; }
|
|
||||||
|
|
||||||
// doPassFinalization - Strip out type names that are unused by the program
|
|
||||||
bool doFinalization(Module &M);
|
|
||||||
|
|
||||||
// getAnalysisUsage - This function needs FindUsedTypes to do its job...
|
// getAnalysisUsage - This function needs FindUsedTypes to do its job...
|
||||||
//
|
//
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
AU.addRequired(FindUsedTypes::ID);
|
AU.addRequired(FindUsedTypes::ID);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
RegisterPass<CleanupGCCOutput> X("cleangcc", "Cleanup GCC Output");
|
RegisterPass<DTE> X("deadtypeelim", "Dead Type Elimination");
|
||||||
|
Statistic<> NumKilled("deadtypeelim\t- Number of unused typenames removed from symtab");
|
||||||
}
|
}
|
||||||
|
|
||||||
Pass *createCleanupGCCOutputPass() {
|
Pass *createDeadTypeEliminationPass() {
|
||||||
return new CleanupGCCOutput();
|
return new DTE();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -71,14 +54,18 @@ static inline bool ShouldNukeSymtabEntry(const std::pair<std::string,Value*>&E){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// doInitialization - For this pass, it removes global symbol table
|
// run - For this pass, it removes global symbol table entries for primitive
|
||||||
// entries for primitive types. These are never used for linking in GCC and
|
// types. These are never used for linking in GCC and they make the output
|
||||||
// they make the output uglier to look at, so we nuke them.
|
// uglier to look at, so we nuke them. Also eliminate types that are never used
|
||||||
|
// in the entire program as indicated by FindUsedTypes.
|
||||||
//
|
//
|
||||||
bool CleanupGCCOutput::doInitialization(Module &M) {
|
bool DTE::run(Module &M) {
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
|
|
||||||
if (SymbolTable *ST = M.getSymbolTable()) {
|
if (SymbolTable *ST = M.getSymbolTable()) {
|
||||||
|
const std::set<const Type *> &UsedTypes =
|
||||||
|
getAnalysis<FindUsedTypes>().getTypes();
|
||||||
|
|
||||||
// Check the symbol table for superfluous type entries...
|
// Check the symbol table for superfluous type entries...
|
||||||
//
|
//
|
||||||
// Grab the 'type' plane of the module symbol...
|
// Grab the 'type' plane of the module symbol...
|
||||||
@@ -94,46 +81,22 @@ bool CleanupGCCOutput::doInitialization(Module &M) {
|
|||||||
Plane.erase(PI); // Alas, GCC 2.95.3 doesn't *SIGH*
|
Plane.erase(PI); // Alas, GCC 2.95.3 doesn't *SIGH*
|
||||||
PI = Plane.begin();
|
PI = Plane.begin();
|
||||||
#endif
|
#endif
|
||||||
++NumTypeSymtabEntriesKilled;
|
++NumKilled;
|
||||||
Changed = true;
|
Changed = true;
|
||||||
} else {
|
} else if (!UsedTypes.count(cast<Type>(PI->second))) {
|
||||||
++PI;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Changed;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool CleanupGCCOutput::doFinalization(Module &M) {
|
|
||||||
bool Changed = false;
|
|
||||||
|
|
||||||
if (SymbolTable *ST = M.getSymbolTable()) {
|
|
||||||
const std::set<const Type *> &UsedTypes =
|
|
||||||
getAnalysis<FindUsedTypes>().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
|
#if MAP_IS_NOT_BRAINDEAD
|
||||||
PI = Plane.erase(PI); // STD C++ Map should support this!
|
PI = Plane.erase(PI); // STD C++ Map should support this!
|
||||||
#else
|
#else
|
||||||
Plane.erase(PI); // Alas, GCC 2.95.3 doesn't *SIGH*
|
Plane.erase(PI); // Alas, GCC 2.95.3 doesn't *SIGH*
|
||||||
PI = Plane.begin(); // N^2 algorithms are fun. :(
|
PI = Plane.begin(); // N^2 algorithms are fun. :(
|
||||||
#endif
|
#endif
|
||||||
|
++NumKilled;
|
||||||
Changed = true;
|
Changed = true;
|
||||||
} else {
|
} else {
|
||||||
++PI;
|
++PI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user