forked from OSchip/llvm-project
[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:
parent
19b679963f
commit
21e153748a
|
@ -260,7 +260,7 @@ void initializeStackColoringPass(PassRegistry&);
|
||||||
void initializeStackSlotColoringPass(PassRegistry&);
|
void initializeStackSlotColoringPass(PassRegistry&);
|
||||||
void initializeStraightLineStrengthReducePass(PassRegistry &);
|
void initializeStraightLineStrengthReducePass(PassRegistry &);
|
||||||
void initializeStripDeadDebugInfoPass(PassRegistry&);
|
void initializeStripDeadDebugInfoPass(PassRegistry&);
|
||||||
void initializeStripDeadPrototypesPassPass(PassRegistry&);
|
void initializeStripDeadPrototypesLegacyPassPass(PassRegistry&);
|
||||||
void initializeStripDebugDeclarePass(PassRegistry&);
|
void initializeStripDebugDeclarePass(PassRegistry&);
|
||||||
void initializeStripNonDebugSymbolsPass(PassRegistry&);
|
void initializeStripNonDebugSymbolsPass(PassRegistry&);
|
||||||
void initializeStripSymbolsPass(PassRegistry&);
|
void initializeStripSymbolsPass(PassRegistry&);
|
||||||
|
|
|
@ -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
|
|
@ -30,6 +30,7 @@
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
||||||
|
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
|
||||||
#include "llvm/Transforms/Scalar/ADCE.h"
|
#include "llvm/Transforms/Scalar/ADCE.h"
|
||||||
#include "llvm/Transforms/Scalar/EarlyCSE.h"
|
#include "llvm/Transforms/Scalar/EarlyCSE.h"
|
||||||
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
|
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
|
||||||
|
|
|
@ -31,6 +31,7 @@ MODULE_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
||||||
MODULE_PASS("no-op-module", NoOpModulePass())
|
MODULE_PASS("no-op-module", NoOpModulePass())
|
||||||
MODULE_PASS("print", PrintModulePass(dbgs()))
|
MODULE_PASS("print", PrintModulePass(dbgs()))
|
||||||
MODULE_PASS("print-cg", LazyCallGraphPrinterPass(dbgs()))
|
MODULE_PASS("print-cg", LazyCallGraphPrinterPass(dbgs()))
|
||||||
|
MODULE_PASS("strip-dead-prototypes", StripDeadPrototypesPass())
|
||||||
MODULE_PASS("verify", VerifierPass())
|
MODULE_PASS("verify", VerifierPass())
|
||||||
#undef MODULE_PASS
|
#undef MODULE_PASS
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ void llvm::initializeIPO(PassRegistry &Registry) {
|
||||||
initializeMergeFunctionsPass(Registry);
|
initializeMergeFunctionsPass(Registry);
|
||||||
initializePartialInlinerPass(Registry);
|
initializePartialInlinerPass(Registry);
|
||||||
initializePruneEHPass(Registry);
|
initializePruneEHPass(Registry);
|
||||||
initializeStripDeadPrototypesPassPass(Registry);
|
initializeStripDeadPrototypesLegacyPassPass(Registry);
|
||||||
initializeStripSymbolsPass(Registry);
|
initializeStripSymbolsPass(Registry);
|
||||||
initializeStripDebugDeclarePass(Registry);
|
initializeStripDebugDeclarePass(Registry);
|
||||||
initializeStripDeadDebugInfoPass(Registry);
|
initializeStripDeadDebugInfoPass(Registry);
|
||||||
|
|
|
@ -14,35 +14,19 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "llvm/Transforms/IPO.h"
|
#include "llvm/Transforms/IPO/StripDeadPrototypes.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
|
#include "llvm/Transforms/IPO.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
#define DEBUG_TYPE "strip-dead-prototypes"
|
#define DEBUG_TYPE "strip-dead-prototypes"
|
||||||
|
|
||||||
STATISTIC(NumDeadPrototypes, "Number of dead prototypes removed");
|
STATISTIC(NumDeadPrototypes, "Number of dead prototypes removed");
|
||||||
|
|
||||||
namespace {
|
static bool stripDeadPrototypes(Module &M) {
|
||||||
|
|
||||||
/// @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) {
|
|
||||||
bool MadeChange = false;
|
bool MadeChange = false;
|
||||||
|
|
||||||
// Erase dead function prototypes.
|
// Erase dead function prototypes.
|
||||||
|
@ -69,6 +53,32 @@ bool StripDeadPrototypesPass::runOnModule(Module &M) {
|
||||||
return MadeChange;
|
return MadeChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModulePass *llvm::createStripDeadPrototypesPass() {
|
PreservedAnalyses StripDeadPrototypesPass::run(Module &M) {
|
||||||
return new StripDeadPrototypesPass();
|
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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
; RUN: opt -lower-expect -strip-dead-prototypes -S -o - < %s | FileCheck %s
|
; 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(
|
; CHECK-LABEL: @test1(
|
||||||
define i32 @test1(i32 %x) nounwind uwtable ssp {
|
define i32 @test1(i32 %x) nounwind uwtable ssp {
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue