2007-02-05 20:24:25 +00:00
|
|
|
//===-- StripDeadPrototypes.cpp - Removed unused function declarations ----===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by Reid Spencer and is distributed under the
|
|
|
|
// University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This pass loops over all of the functions in the input module, looking for
|
|
|
|
// dead declarations and removes them.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-02-18 22:10:34 +00:00
|
|
|
#define DEBUG_TYPE "strip-dead-prototypes"
|
2007-02-05 20:24:25 +00:00
|
|
|
#include "llvm/Transforms/IPO.h"
|
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Module.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
2007-02-05 21:47:39 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2007-02-05 20:24:25 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
STATISTIC(NumDeadPrototypes, "Number of dead prototypes removed");
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// @brief Pass to remove unused function declarations.
|
2007-02-05 21:45:12 +00:00
|
|
|
class VISIBILITY_HIDDEN StripDeadPrototypesPass : public ModulePass {
|
2007-02-05 20:24:25 +00:00
|
|
|
public:
|
2007-05-06 13:37:16 +00:00
|
|
|
static char ID; // Pass identification, replacement for typeid
|
2007-05-01 21:15:47 +00:00
|
|
|
StripDeadPrototypesPass() : ModulePass((intptr_t)&ID) { }
|
2007-02-05 20:24:25 +00:00
|
|
|
virtual bool runOnModule(Module &M);
|
|
|
|
};
|
2007-05-01 21:15:47 +00:00
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
char StripDeadPrototypesPass::ID = 0;
|
2007-02-05 20:24:25 +00:00
|
|
|
RegisterPass<StripDeadPrototypesPass> X("strip-dead-prototypes",
|
|
|
|
"Strip Unused Function Prototypes");
|
|
|
|
|
2007-02-05 21:45:12 +00:00
|
|
|
} // end anonymous namespace
|
|
|
|
|
2007-02-05 20:24:25 +00:00
|
|
|
bool StripDeadPrototypesPass::runOnModule(Module &M) {
|
2007-02-18 22:10:34 +00:00
|
|
|
bool MadeChange = false;
|
|
|
|
|
|
|
|
// Erase dead function prototypes.
|
|
|
|
for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
|
|
|
|
Function *F = I++;
|
|
|
|
// Function must be a prototype and unused.
|
|
|
|
if (F->isDeclaration() && F->use_empty()) {
|
|
|
|
F->eraseFromParent();
|
|
|
|
++NumDeadPrototypes;
|
|
|
|
MadeChange = true;
|
2007-02-05 20:24:25 +00:00
|
|
|
}
|
2007-02-18 22:10:34 +00:00
|
|
|
}
|
2007-02-05 20:24:25 +00:00
|
|
|
|
2007-02-18 22:10:58 +00:00
|
|
|
// Erase dead global var prototypes.
|
2007-02-18 22:10:34 +00:00
|
|
|
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
|
|
|
|
I != E; ) {
|
|
|
|
GlobalVariable *GV = I++;
|
|
|
|
// Global must be a prototype and unused.
|
|
|
|
if (GV->isDeclaration() && GV->use_empty())
|
|
|
|
GV->eraseFromParent();
|
|
|
|
}
|
2007-02-05 20:24:25 +00:00
|
|
|
|
|
|
|
// Return an indication of whether we changed anything or not.
|
2007-02-18 22:10:34 +00:00
|
|
|
return MadeChange;
|
2007-02-05 20:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModulePass *llvm::createStripDeadPrototypesPass() {
|
|
|
|
return new StripDeadPrototypesPass();
|
|
|
|
}
|