1
//===-- StripDeadPrototypes.cpp - Remove unused function declarations ----===//
3
// The LLVM Compiler Infrastructure
5
// This file is distributed under the University of Illinois Open Source
6
// 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. Dead declarations are declarations of
12
// functions for which no implementation is available (i.e., declarations for
13
// unused library functions).
15
//===----------------------------------------------------------------------===//
17
#define DEBUG_TYPE "strip-dead-prototypes"
18
#include "llvm/Transforms/IPO.h"
19
#include "llvm/Pass.h"
20
#include "llvm/Module.h"
21
#include "llvm/ADT/Statistic.h"
24
STATISTIC(NumDeadPrototypes, "Number of dead prototypes removed");
28
/// @brief Pass to remove unused function declarations.
29
class StripDeadPrototypesPass : public ModulePass {
31
static char ID; // Pass identification, replacement for typeid
32
StripDeadPrototypesPass() : ModulePass(&ID) { }
33
virtual bool runOnModule(Module &M);
36
} // end anonymous namespace
38
char StripDeadPrototypesPass::ID = 0;
39
static RegisterPass<StripDeadPrototypesPass>
40
X("strip-dead-prototypes", "Strip Unused Function Prototypes");
42
bool StripDeadPrototypesPass::runOnModule(Module &M) {
43
bool MadeChange = false;
45
// Erase dead function prototypes.
46
for (Module::iterator I = M.begin(), E = M.end(); I != E; ) {
48
// Function must be a prototype and unused.
49
if (F->isDeclaration() && F->use_empty()) {
56
// Erase dead global var prototypes.
57
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
59
GlobalVariable *GV = I++;
60
// Global must be a prototype and unused.
61
if (GV->isDeclaration() && GV->use_empty())
62
GV->eraseFromParent();
65
// Return an indication of whether we changed anything or not.
69
ModulePass *llvm::createStripDeadPrototypesPass() {
70
return new StripDeadPrototypesPass();