[PATCH] Port ADCE to the new pass manager
Chandler Carruth via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 30 15:58:54 PDT 2015
LGTM
On Mon, Oct 5, 2015 at 1:59 PM Justin Bogner <mail at justinbogner.com> wrote:
> ping.
>
> Justin Bogner <mail at justinbogner.com> writes:
> > The attached patch ports ADCE to the new pass manager. It's basically
> > mechanical and based off of some of the ports you've already done so
> > it's probably good to go in, but I have a couple of questions about
> > parts that seemed a little odd.
> >
> > 1. The legacy pass states it preserves GlobalsAAWrapperPass, but the new
> > pass returns PreservedAnalyses::none when it does work. This seems
> > inconsistent, but maybe I'm missing something.
> >
> > 2. Similarly, some of the other passes you've ported do
> > AU.setPreservesCFG(), but this doesn't seem to be reflected in the
> > new passes. How's this going to work?
> >
> > 3. As per my reply to "Port SimplifyCFG to the new pass manager", it
> > seems like we don't have good testing infrastructure in terms of
> > preserved analyses. Do you have any ideas for how we're going to deal
> > with that?
> >
> > Anyway, let me know if this is good to land. I might tackle a couple
> > more of these in the near future, and some clarity on the above
> > questions would help.
> >
> > commit cef9c843c206159c77d5ccccd2dba3914daa4452
> > Author: Justin Bogner <mail at justinbogner.com>
> > Date: Fri Sep 25 15:35:25 2015 -0700
> >
> > [PM] Port ADCE to the new pass manager
> >
> > diff --git a/include/llvm/InitializePasses.h
> b/include/llvm/InitializePasses.h
> > index 75f9857..f888c97 100644
> > --- a/include/llvm/InitializePasses.h
> > +++ b/include/llvm/InitializePasses.h
> > @@ -61,7 +61,7 @@ void initializeTarget(PassRegistry&);
> >
> > void initializeAAEvalPass(PassRegistry&);
> > void initializeAddDiscriminatorsPass(PassRegistry&);
> > -void initializeADCEPass(PassRegistry&);
> > +void initializeADCELegacyPassPass(PassRegistry&);
> > void initializeBDCEPass(PassRegistry&);
> > void initializeAliasSetPrinterPass(PassRegistry&);
> > void initializeAlwaysInlinerPass(PassRegistry&);
> > diff --git a/include/llvm/Transforms/Scalar/ADCE.h
> b/include/llvm/Transforms/Scalar/ADCE.h
> > new file mode 100644
> > index 0000000..f9bc7b7
> > --- /dev/null
> > +++ b/include/llvm/Transforms/Scalar/ADCE.h
> > @@ -0,0 +1,38 @@
> > +//===- ADCE.h - Aggressive dead code elimination
> --------------------------===//
> > +//
> > +// 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 Aggressive Dead Code
> Elimination
> > +// pass. This pass optimistically assumes that all instructions are
> dead until
> > +// proven otherwise, allowing it to eliminate dead computations that
> other DCE
> > +// passes do not catch, particularly involving loop computations.
> > +//
> >
> +//===----------------------------------------------------------------------===//
> > +
> > +#ifndef LLVM_TRANSFORMS_SCALAR_ADCE_H
> > +#define LLVM_TRANSFORMS_SCALAR_ADCE_H
> > +
> > +#include "llvm/IR/Function.h"
> > +#include "llvm/IR/PassManager.h"
> > +
> > +namespace llvm {
> > +
> > +/// A DCE pass that assumes instructions are dead until proven
> otherwise.
> > +///
> > +/// This pass eliminates dead code by optimistically assuming that all
> > +/// instructions are dead until proven otherwise. This allows it to
> eliminate
> > +/// dead computations that other DCE passes do not catch, particularly
> involving
> > +/// loop computations.
> > +class ADCEPass {
> > +public:
> > + static StringRef name() { return "ADCEPass"; }
> > + PreservedAnalyses run(Function &F);
> > +};
> > +}
> > +
> > +#endif // LLVM_TRANSFORMS_SCALAR_ADCE_H
> > diff --git a/lib/Passes/PassBuilder.cpp b/lib/Passes/PassBuilder.cpp
> > index b8f6e20..f18fcb1 100644
> > --- a/lib/Passes/PassBuilder.cpp
> > +++ b/lib/Passes/PassBuilder.cpp
> > @@ -30,6 +30,7 @@
> > #include "llvm/Support/Debug.h"
> > #include "llvm/Target/TargetMachine.h"
> > #include "llvm/Transforms/InstCombine/InstCombine.h"
> > +#include "llvm/Transforms/Scalar/ADCE.h"
> > #include "llvm/Transforms/Scalar/EarlyCSE.h"
> > #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
> > #include "llvm/Transforms/Scalar/SimplifyCFG.h"
> > diff --git a/lib/Passes/PassRegistry.def b/lib/Passes/PassRegistry.def
> > index da4e63b..6f52330 100644
> > --- a/lib/Passes/PassRegistry.def
> > +++ b/lib/Passes/PassRegistry.def
> > @@ -63,6 +63,7 @@ FUNCTION_ANALYSIS("targetir",
> > #ifndef FUNCTION_PASS
> > #define FUNCTION_PASS(NAME, CREATE_PASS)
> > #endif
> > +FUNCTION_PASS("adce", ADCEPass())
> > FUNCTION_PASS("early-cse", EarlyCSEPass())
> > FUNCTION_PASS("instcombine", InstCombinePass())
> > FUNCTION_PASS("invalidate<all>", InvalidateAllAnalysesPass())
> > diff --git a/lib/Transforms/Scalar/ADCE.cpp
> b/lib/Transforms/Scalar/ADCE.cpp
> > index c73766c..590a52d 100644
> > --- a/lib/Transforms/Scalar/ADCE.cpp
> > +++ b/lib/Transforms/Scalar/ADCE.cpp
> > @@ -14,7 +14,7 @@
> > //
> >
> //===----------------------------------------------------------------------===//
> >
> > -#include "llvm/Transforms/Scalar.h"
> > +#include "llvm/Transforms/Scalar/ADCE.h"
> > #include "llvm/ADT/DepthFirstIterator.h"
> > #include "llvm/ADT/SmallPtrSet.h"
> > #include "llvm/ADT/SmallVector.h"
> > @@ -26,35 +26,14 @@
> > #include "llvm/IR/Instructions.h"
> > #include "llvm/IR/IntrinsicInst.h"
> > #include "llvm/Pass.h"
> > +#include "llvm/Transforms/Scalar.h"
> > using namespace llvm;
> >
> > #define DEBUG_TYPE "adce"
> >
> > STATISTIC(NumRemoved, "Number of instructions removed");
> >
> > -namespace {
> > -struct ADCE : public FunctionPass {
> > - static char ID; // Pass identification, replacement for typeid
> > - ADCE() : FunctionPass(ID) {
> > - initializeADCEPass(*PassRegistry::getPassRegistry());
> > - }
> > -
> > - bool runOnFunction(Function& F) override;
> > -
> > - void getAnalysisUsage(AnalysisUsage& AU) const override {
> > - AU.setPreservesCFG();
> > - AU.addPreserved<GlobalsAAWrapperPass>();
> > - }
> > -};
> > -}
> > -
> > -char ADCE::ID = 0;
> > -INITIALIZE_PASS(ADCE, "adce", "Aggressive Dead Code Elimination",
> false, false)
> > -
> > -bool ADCE::runOnFunction(Function& F) {
> > - if (skipOptnoneFunction(F))
> > - return false;
> > -
> > +static bool aggressiveDCE(Function& F) {
> > SmallPtrSet<Instruction*, 128> Alive;
> > SmallVector<Instruction*, 128> Worklist;
> >
> > @@ -96,6 +75,34 @@ bool ADCE::runOnFunction(Function& F) {
> > return !Worklist.empty();
> > }
> >
> > -FunctionPass *llvm::createAggressiveDCEPass() {
> > - return new ADCE();
> > +PreservedAnalyses ADCEPass::run(Function &F) {
> > + if (aggressiveDCE(F))
> > + return PreservedAnalyses::none();
> > + return PreservedAnalyses::all();
> > }
> > +
> > +namespace {
> > +struct ADCELegacyPass : public FunctionPass {
> > + static char ID; // Pass identification, replacement for typeid
> > + ADCELegacyPass() : FunctionPass(ID) {
> > + initializeADCELegacyPassPass(*PassRegistry::getPassRegistry());
> > + }
> > +
> > + bool runOnFunction(Function& F) override {
> > + if (skipOptnoneFunction(F))
> > + return false;
> > + return aggressiveDCE(F);
> > + }
> > +
> > + void getAnalysisUsage(AnalysisUsage& AU) const override {
> > + AU.setPreservesCFG();
> > + AU.addPreserved<GlobalsAAWrapperPass>();
> > + }
> > +};
> > +}
> > +
> > +char ADCELegacyPass::ID = 0;
> > +INITIALIZE_PASS(ADCELegacyPass, "adce", "Aggressive Dead Code
> Elimination",
> > + false, false)
> > +
> > +FunctionPass *llvm::createAggressiveDCEPass() { return new
> ADCELegacyPass(); }
> > diff --git a/lib/Transforms/Scalar/Scalar.cpp
> b/lib/Transforms/Scalar/Scalar.cpp
> > index f7a6134..fd74fa8 100644
> > --- a/lib/Transforms/Scalar/Scalar.cpp
> > +++ b/lib/Transforms/Scalar/Scalar.cpp
> > @@ -30,7 +30,7 @@ using namespace llvm;
> > /// initializeScalarOptsPasses - Initialize all passes linked into the
> > /// ScalarOpts library.
> > void llvm::initializeScalarOpts(PassRegistry &Registry) {
> > - initializeADCEPass(Registry);
> > + initializeADCELegacyPassPass(Registry);
> > initializeBDCEPass(Registry);
> > initializeAlignmentFromAssumptionsPass(Registry);
> > initializeConstantHoistingPass(Registry);
> > diff --git a/test/Transforms/ADCE/basictest.ll
> b/test/Transforms/ADCE/basictest.ll
> > index 61c4224..aaacc18 100644
> > --- a/test/Transforms/ADCE/basictest.ll
> > +++ b/test/Transforms/ADCE/basictest.ll
> > @@ -1,4 +1,5 @@
> > ; RUN: opt < %s -adce -simplifycfg | llvm-dis
> > +; RUN: opt < %s -passes=adce | llvm-dis
> >
> > define i32 @Test(i32 %A, i32 %B) {
> > BB1:
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151030/b0052b5c/attachment.html>
More information about the llvm-commits
mailing list