1 //===-- StripDeadPrototypes.cpp - Removed unused function declarations ----===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This pass loops over all of the functions in the input module, looking for
11 // dead declarations and removes them.
13 //===----------------------------------------------------------------------===//
15 #define DEBUG_TYPE "strip-dead-prototypes"
16 #include "llvm/Transforms/IPO.h"
17 #include "llvm/Pass.h"
18 #include "llvm/Module.h"
19 #include "llvm/ADT/Statistic.h"
20 #include "llvm/Support/Compiler.h"
23 STATISTIC(NumDeadPrototypes, "Number of dead prototypes removed");
27 /// @brief Pass to remove unused function declarations.
28 class VISIBILITY_HIDDEN StripDeadPrototypesPass : public ModulePass {
30 StripDeadPrototypesPass() { }
31 virtual bool runOnModule(Module &M);
33 RegisterPass<StripDeadPrototypesPass> X("strip-dead-prototypes",
34 "Strip Unused Function Prototypes");
36 } // end anonymous namespace
38 bool StripDeadPrototypesPass::runOnModule(Module &M) {
39 bool MadeChange = false;
41 // Erase dead function prototypes.
42 for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
44 // Function must be a prototype and unused.
45 if (F->isDeclaration() && F->use_empty()) {
52 // Erase dead function prototypes.
53 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
55 GlobalVariable *GV = I++;
56 // Global must be a prototype and unused.
57 if (GV->isDeclaration() && GV->use_empty())
58 GV->eraseFromParent();
61 // Return an indication of whether we changed anything or not.
65 ModulePass *llvm::createStripDeadPrototypesPass() {
66 return new StripDeadPrototypesPass();