From a70ba1098be90a82209552292eb90ef72ebf4cf1 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Thu, 8 Oct 2020 08:53:00 -0700 Subject: [PATCH] [FixIrreducible][NewPM] Port -fix-irreducible to NPM In the NPM, a pass cannot depend on another non-analysis pass. So pin the test that tests that -lowerswitch is run automatically to legacy PM. Reviewed By: sameerds Differential Revision: https://reviews.llvm.org/D89051 --- .../llvm/Transforms/Utils/FixIrreducible.h | 20 ++++++++++++++++ lib/Passes/PassBuilder.cpp | 1 + lib/Passes/PassRegistry.def | 1 + lib/Transforms/Utils/FixIrreducible.cpp | 23 ++++++++++++++++--- test/Transforms/FixIrreducible/basic.ll | 1 + test/Transforms/FixIrreducible/switch.ll | 2 +- 6 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 include/llvm/Transforms/Utils/FixIrreducible.h diff --git a/include/llvm/Transforms/Utils/FixIrreducible.h b/include/llvm/Transforms/Utils/FixIrreducible.h new file mode 100644 index 00000000000..0c00b7bdbaf --- /dev/null +++ b/include/llvm/Transforms/Utils/FixIrreducible.h @@ -0,0 +1,20 @@ +//===- FixIrreducible.h - Convert irreducible control-flow into loops -----===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_TRANSFORMS_UTILS_FIXIRREDUCIBLE_H +#define LLVM_TRANSFORMS_UTILS_FIXIRREDUCIBLE_H + +#include "llvm/IR/PassManager.h" + +namespace llvm { +struct FixIrreduciblePass : PassInfoMixin { + PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); +}; +} // namespace llvm + +#endif // LLVM_TRANSFORMS_UTILS_FIXIRREDUCIBLE_H diff --git a/lib/Passes/PassBuilder.cpp b/lib/Passes/PassBuilder.cpp index 0b7ad476939..4423a12c256 100644 --- a/lib/Passes/PassBuilder.cpp +++ b/lib/Passes/PassBuilder.cpp @@ -196,6 +196,7 @@ #include "llvm/Transforms/Utils/CanonicalizeAliases.h" #include "llvm/Transforms/Utils/CanonicalizeFreezeInLoops.h" #include "llvm/Transforms/Utils/EntryExitInstrumenter.h" +#include "llvm/Transforms/Utils/FixIrreducible.h" #include "llvm/Transforms/Utils/InjectTLIMappings.h" #include "llvm/Transforms/Utils/LCSSA.h" #include "llvm/Transforms/Utils/LibCallsShrinkWrap.h" diff --git a/lib/Passes/PassRegistry.def b/lib/Passes/PassRegistry.def index 6f2f9bb25bf..d1f0767a97d 100644 --- a/lib/Passes/PassRegistry.def +++ b/lib/Passes/PassRegistry.def @@ -205,6 +205,7 @@ FUNCTION_PASS("dot-cfg-only", CFGOnlyPrinterPass()) FUNCTION_PASS("early-cse", EarlyCSEPass(/*UseMemorySSA=*/false)) FUNCTION_PASS("early-cse-memssa", EarlyCSEPass(/*UseMemorySSA=*/true)) FUNCTION_PASS("ee-instrument", EntryExitInstrumenterPass(/*PostInlining=*/false)) +FUNCTION_PASS("fix-irreducible", FixIrreduciblePass()) FUNCTION_PASS("make-guards-explicit", MakeGuardsExplicitPass()) FUNCTION_PASS("post-inline-ee-instrument", EntryExitInstrumenterPass(/*PostInlining=*/true)) FUNCTION_PASS("gvn-hoist", GVNHoistPass()) diff --git a/lib/Transforms/Utils/FixIrreducible.cpp b/lib/Transforms/Utils/FixIrreducible.cpp index 8d75eea25ba..6e18aab2d5f 100644 --- a/lib/Transforms/Utils/FixIrreducible.cpp +++ b/lib/Transforms/Utils/FixIrreducible.cpp @@ -66,6 +66,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Transforms/Utils/FixIrreducible.h" #include "llvm/ADT/SCCIterator.h" #include "llvm/Analysis/LoopIterator.h" #include "llvm/InitializePasses.h" @@ -304,11 +305,9 @@ static bool makeReducible(LoopInfo &LI, DominatorTree &DT, Graph &&G) { return Changed; } -bool FixIrreducible::runOnFunction(Function &F) { +static bool FixIrreducibleImpl(Function &F, LoopInfo &LI, DominatorTree &DT) { LLVM_DEBUG(dbgs() << "===== Fix irreducible control-flow in function: " << F.getName() << "\n"); - auto &LI = getAnalysis().getLoopInfo(); - auto &DT = getAnalysis().getDomTree(); bool Changed = false; SmallVector WorkList; @@ -335,3 +334,21 @@ bool FixIrreducible::runOnFunction(Function &F) { return Changed; } + +bool FixIrreducible::runOnFunction(Function &F) { + auto &LI = getAnalysis().getLoopInfo(); + auto &DT = getAnalysis().getDomTree(); + return FixIrreducibleImpl(F, LI, DT); +} + +PreservedAnalyses FixIrreduciblePass::run(Function &F, + FunctionAnalysisManager &AM) { + auto &LI = AM.getResult(F); + auto &DT = AM.getResult(F); + if (!FixIrreducibleImpl(F, LI, DT)) + return PreservedAnalyses::all(); + PreservedAnalyses PA; + PA.preserve(); + PA.preserve(); + return PA; +} diff --git a/test/Transforms/FixIrreducible/basic.ll b/test/Transforms/FixIrreducible/basic.ll index ed04c1bf78c..fe34ac9b93b 100644 --- a/test/Transforms/FixIrreducible/basic.ll +++ b/test/Transforms/FixIrreducible/basic.ll @@ -1,5 +1,6 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -fix-irreducible -S | FileCheck %s -check-prefix=CHECK +; RUN: opt < %s -passes=fix-irreducible -S | FileCheck %s -check-prefix=CHECK define i32 @basic(i1 %PredEntry, i1 %PredLeft, i1 %PredRight, i32 %X, i32 %Y) { ; CHECK-LABEL: @basic( diff --git a/test/Transforms/FixIrreducible/switch.ll b/test/Transforms/FixIrreducible/switch.ll index 0073560af88..a906d04c4b9 100644 --- a/test/Transforms/FixIrreducible/switch.ll +++ b/test/Transforms/FixIrreducible/switch.ll @@ -1,5 +1,5 @@ ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py -; RUN: opt < %s -fix-irreducible -S | FileCheck %s +; RUN: opt < %s -fix-irreducible -enable-new-pm=0 -S | FileCheck %s define void @loop_1(i32 %Value, i1 %PredEntry, i1 %PredD) { ; CHECK-LABEL: @loop_1(