[PM] Port StripDeadPrototypes to the new pass manager

This is a really straightforward port. Also adds a test for the pass,
since it only seemed to be tested tangentially before.

llvm-svn: 251726
This commit is contained in:
Justin Bogner 2015-10-30 23:28:12 +00:00
parent 19b679963f
commit 21e153748a
8 changed files with 83 additions and 25 deletions

View File

@ -260,7 +260,7 @@ void initializeStackColoringPass(PassRegistry&);
void initializeStackSlotColoringPass(PassRegistry&);
void initializeStraightLineStrengthReducePass(PassRegistry &);
void initializeStripDeadDebugInfoPass(PassRegistry&);
void initializeStripDeadPrototypesPassPass(PassRegistry&);
void initializeStripDeadPrototypesLegacyPassPass(PassRegistry&);
void initializeStripDebugDeclarePass(PassRegistry&);
void initializeStripNonDebugSymbolsPass(PassRegistry&);
void initializeStripSymbolsPass(PassRegistry&);

View File

@ -0,0 +1,34 @@
//===-- StripDeadPrototypes.h - Remove unused function declarations -------===//
//
// The LLVM Compiler Infrastructure
//
// This file 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. Dead declarations are declarations of
// functions for which no implementation is available (i.e., declarations for
// unused library functions).
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_TRANSFORMS_IPO_STRIPDEADPROTOTYPES_H
#define LLVM_TRANSFORMS_IPO_STRIPDEADPROTOTYPES_H
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
namespace llvm {
/// Pass to remove unused function declarations.
class StripDeadPrototypesPass {
public:
static StringRef name() { return "StripDeadPrototypesPass"; }
PreservedAnalyses run(Module &M);
};
}
#endif // LLVM_TRANSFORMS_IPO_STRIPDEADPROTOTYPES_H

View File

@ -30,6 +30,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
#include "llvm/Transforms/Scalar/ADCE.h"
#include "llvm/Transforms/Scalar/EarlyCSE.h"
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"

View File

@ -31,6 +31,7 @@ MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
MODULE_PASS("no-op-module", NoOpModulePass())
MODULE_PASS("print", PrintModulePass(dbgs()))
MODULE_PASS("print-cg", LazyCallGraphPrinterPass(dbgs()))
MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass())
MODULE_PASS("verify", VerifierPass())
#undef MODULE_PASS

View File

@ -40,7 +40,7 @@ void llvm::initializeIPO(PassRegistry &Registry) {
initializeMergeFunctionsPass(Registry);
initializePartialInlinerPass(Registry);
initializePruneEHPass(Registry);
initializeStripDeadPrototypesPassPass(Registry);
initializeStripDeadPrototypesLegacyPassPass(Registry);
initializeStripSymbolsPass(Registry);
initializeStripDebugDeclarePass(Registry);
initializeStripDeadDebugInfoPass(Registry);

View File

@ -14,35 +14,19 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"
#include "llvm/Transforms/IPO.h"
using namespace llvm;
#define DEBUG_TYPE "strip-dead-prototypes"
STATISTIC(NumDeadPrototypes, "Number of dead prototypes removed");
namespace {
/// @brief Pass to remove unused function declarations.
class StripDeadPrototypesPass : public ModulePass {
public:
static char ID; // Pass identification, replacement for typeid
StripDeadPrototypesPass() : ModulePass(ID) {
initializeStripDeadPrototypesPassPass(*PassRegistry::getPassRegistry());
}
bool runOnModule(Module &M) override;
};
} // end anonymous namespace
char StripDeadPrototypesPass::ID = 0;
INITIALIZE_PASS(StripDeadPrototypesPass, "strip-dead-prototypes",
"Strip Unused Function Prototypes", false, false)
bool StripDeadPrototypesPass::runOnModule(Module &M) {
static bool stripDeadPrototypes(Module &M) {
bool MadeChange = false;
// Erase dead function prototypes.
@ -69,6 +53,32 @@ bool StripDeadPrototypesPass::runOnModule(Module &M) {
return MadeChange;
}
ModulePass *llvm::createStripDeadPrototypesPass() {
return new StripDeadPrototypesPass();
PreservedAnalyses StripDeadPrototypesPass::run(Module &M) {
if (stripDeadPrototypes(M))
return PreservedAnalyses::none();
return PreservedAnalyses::all();
}
namespace {
class StripDeadPrototypesLegacyPass : public ModulePass {
public:
static char ID; // Pass identification, replacement for typeid
StripDeadPrototypesLegacyPass() : ModulePass(ID) {
initializeStripDeadPrototypesLegacyPassPass(
*PassRegistry::getPassRegistry());
}
bool runOnModule(Module &M) override {
return stripDeadPrototypes(M);
}
};
} // end anonymous namespace
char StripDeadPrototypesLegacyPass::ID = 0;
INITIALIZE_PASS(StripDeadPrototypesLegacyPass, "strip-dead-prototypes",
"Strip Unused Function Prototypes", false, false)
ModulePass *llvm::createStripDeadPrototypesPass() {
return new StripDeadPrototypesLegacyPass();
}

View File

@ -1,5 +1,5 @@
; RUN: opt -lower-expect -strip-dead-prototypes -S -o - < %s | FileCheck %s
; RUN: opt -S -passes=lower-expect < %s | opt -strip-dead-prototypes -S | FileCheck %s
; RUN: opt -S -passes='function(lower-expect),strip-dead-prototypes' < %s | FileCheck %s
; CHECK-LABEL: @test1(
define i32 @test1(i32 %x) nounwind uwtable ssp {

View File

@ -0,0 +1,12 @@
; RUN: opt -strip-dead-prototypes -S -o - < %s | FileCheck %s
; RUN: opt -S -passes=strip-dead-prototypes < %s | FileCheck %s
; CHECK: declare i32 @f
declare i32 @f()
; CHECK-NOT: declare i32 @g
declare i32 @g()
define i32 @foo() {
%call = call i32 @f()
ret i32 %call
}