StripDeadPrototypes.cpp [plain text]
#define DEBUG_TYPE "strip-dead-prototypes"
#include "llvm/Transforms/IPO.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
using namespace llvm;
STATISTIC(NumDeadPrototypes, "Number of dead prototypes removed");
namespace {
class StripDeadPrototypesPass : public ModulePass {
public:
static char ID; StripDeadPrototypesPass() : ModulePass(ID) {
initializeStripDeadPrototypesPassPass(*PassRegistry::getPassRegistry());
}
virtual bool runOnModule(Module &M);
};
}
char StripDeadPrototypesPass::ID = 0;
INITIALIZE_PASS(StripDeadPrototypesPass, "strip-dead-prototypes",
"Strip Unused Function Prototypes", false, false)
bool StripDeadPrototypesPass::runOnModule(Module &M) {
bool MadeChange = false;
for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
Function *F = I++;
if (F->isDeclaration() && F->use_empty()) {
F->eraseFromParent();
++NumDeadPrototypes;
MadeChange = true;
}
}
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ) {
GlobalVariable *GV = I++;
if (GV->isDeclaration() && GV->use_empty())
GV->eraseFromParent();
}
return MadeChange;
}
ModulePass *llvm::createStripDeadPrototypesPass() {
return new StripDeadPrototypesPass();
}