forked from OSchip/llvm-project
PM: Port DCE to the new pass manager
Also add a very basic test, since apparently there aren't any tests for DCE whatsoever to add the new pass version to. llvm-svn: 267196
This commit is contained in:
parent
8bf71066c5
commit
395c2127ed
|
@ -104,7 +104,7 @@ void initializeCorrelatedValuePropagationPass(PassRegistry&);
|
|||
void initializeCrossDSOCFIPass(PassRegistry&);
|
||||
void initializeDAEPass(PassRegistry&);
|
||||
void initializeDAHPass(PassRegistry&);
|
||||
void initializeDCEPass(PassRegistry&);
|
||||
void initializeDCELegacyPassPass(PassRegistry&);
|
||||
void initializeDSEPass(PassRegistry&);
|
||||
void initializeDeadInstEliminationPass(PassRegistry&);
|
||||
void initializeDeadMachineInstructionElimPass(PassRegistry&);
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
//===- DCE.h - Dead code elimination ----------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This file provides the interface for the Dead Code Elimination pass.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_SCALAR_DCE_H
|
||||
#define LLVM_TRANSFORMS_SCALAR_DCE_H
|
||||
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
/// Basic Dead Code Elimination pass.
|
||||
class DCEPass : public PassInfoMixin<DCEPass> {
|
||||
public:
|
||||
PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM);
|
||||
};
|
||||
}
|
||||
|
||||
#endif // LLVM_TRANSFORMS_SCALAR_DCE_H
|
|
@ -117,7 +117,7 @@ void LTOCodeGenerator::initializeLTOPasses() {
|
|||
initializeMergedLoadStoreMotionPass(R);
|
||||
initializeGVNLegacyPassPass(R);
|
||||
initializeMemCpyOptPass(R);
|
||||
initializeDCEPass(R);
|
||||
initializeDCELegacyPassPass(R);
|
||||
initializeCFGSimplifyPassPass(R);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "llvm/Transforms/InstCombine/InstCombine.h"
|
||||
#include "llvm/Transforms/InstrProfiling.h"
|
||||
#include "llvm/Transforms/Scalar/ADCE.h"
|
||||
#include "llvm/Transforms/Scalar/DCE.h"
|
||||
#include "llvm/Transforms/Scalar/EarlyCSE.h"
|
||||
#include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
|
||||
#include "llvm/Transforms/Scalar/GVN.h"
|
||||
|
|
|
@ -96,6 +96,7 @@ FUNCTION_ALIAS_ANALYSIS("type-based-aa", TypeBasedAA())
|
|||
#endif
|
||||
FUNCTION_PASS("aa-eval", AAEvaluator())
|
||||
FUNCTION_PASS("adce", ADCEPass())
|
||||
FUNCTION_PASS("dce", DCEPass())
|
||||
FUNCTION_PASS("early-cse", EarlyCSEPass())
|
||||
FUNCTION_PASS("instcombine", InstCombinePass())
|
||||
FUNCTION_PASS("invalidate<all>", InvalidateAllAnalysesPass())
|
||||
|
|
|
@ -16,13 +16,14 @@
|
|||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Scalar/DCE.h"
|
||||
#include "llvm/ADT/SetVector.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/IR/InstIterator.h"
|
||||
#include "llvm/IR/Instruction.h"
|
||||
#include "llvm/Pass.h"
|
||||
#include "llvm/Analysis/TargetLibraryInfo.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Utils/Local.h"
|
||||
using namespace llvm;
|
||||
|
||||
|
@ -71,28 +72,6 @@ Pass *llvm::createDeadInstEliminationPass() {
|
|||
return new DeadInstElimination();
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
//===--------------------------------------------------------------------===//
|
||||
// DeadCodeElimination pass implementation
|
||||
//
|
||||
struct DCE : public FunctionPass {
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
DCE() : FunctionPass(ID) {
|
||||
initializeDCEPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) override;
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.setPreservesCFG();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
char DCE::ID = 0;
|
||||
INITIALIZE_PASS(DCE, "dce", "Dead Code Elimination", false, false)
|
||||
|
||||
static bool DCEInstruction(Instruction *I,
|
||||
SmallSetVector<Instruction *, 16> &WorkList,
|
||||
const TargetLibraryInfo *TLI) {
|
||||
|
@ -121,13 +100,7 @@ static bool DCEInstruction(Instruction *I,
|
|||
return false;
|
||||
}
|
||||
|
||||
bool DCE::runOnFunction(Function &F) {
|
||||
if (skipOptnoneFunction(F))
|
||||
return false;
|
||||
|
||||
auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
|
||||
TargetLibraryInfo *TLI = TLIP ? &TLIP->getTLI() : nullptr;
|
||||
|
||||
bool eliminateDeadCode(Function &F, TargetLibraryInfo *TLI) {
|
||||
bool MadeChange = false;
|
||||
SmallSetVector<Instruction *, 16> WorkList;
|
||||
// Iterate over the original function, only adding insts to the worklist
|
||||
|
@ -150,7 +123,38 @@ bool DCE::runOnFunction(Function &F) {
|
|||
return MadeChange;
|
||||
}
|
||||
|
||||
FunctionPass *llvm::createDeadCodeEliminationPass() {
|
||||
return new DCE();
|
||||
PreservedAnalyses DCEPass::run(Function &F, AnalysisManager<Function> &AM) {
|
||||
if (eliminateDeadCode(F, AM.getCachedResult<TargetLibraryAnalysis>(F)))
|
||||
return PreservedAnalyses::none();
|
||||
return PreservedAnalyses::all();
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct DCELegacyPass : public FunctionPass {
|
||||
static char ID; // Pass identification, replacement for typeid
|
||||
DCELegacyPass() : FunctionPass(ID) {
|
||||
initializeDCELegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) override {
|
||||
if (skipOptnoneFunction(F))
|
||||
return false;
|
||||
|
||||
auto *TLIP = getAnalysisIfAvailable<TargetLibraryInfoWrapperPass>();
|
||||
TargetLibraryInfo *TLI = TLIP ? &TLIP->getTLI() : nullptr;
|
||||
|
||||
return eliminateDeadCode(F, TLI);
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.setPreservesCFG();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
char DCELegacyPass::ID = 0;
|
||||
INITIALIZE_PASS(DCELegacyPass, "dce", "Dead Code Elimination", false, false)
|
||||
|
||||
FunctionPass *llvm::createDeadCodeEliminationPass() {
|
||||
return new DCELegacyPass();
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
|||
initializeConstantHoistingPass(Registry);
|
||||
initializeConstantPropagationPass(Registry);
|
||||
initializeCorrelatedValuePropagationPass(Registry);
|
||||
initializeDCEPass(Registry);
|
||||
initializeDCELegacyPassPass(Registry);
|
||||
initializeDeadInstEliminationPass(Registry);
|
||||
initializeScalarizerPass(Registry);
|
||||
initializeDSEPass(Registry);
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
; RUN: opt -dce -S < %s | FileCheck %s
|
||||
; RUN: opt -passes=dce -S < %s | FileCheck %s
|
||||
|
||||
; CHECK-LABEL: @test
|
||||
define void @test() {
|
||||
; CHECK-NOT: add
|
||||
%add = add i32 1, 2
|
||||
; CHECK-NOT: sub
|
||||
%sub = sub i32 %add, 1
|
||||
ret void
|
||||
}
|
Loading…
Reference in New Issue