[llvm] r271846 - [PM] Port IndVarSimplify to the new pass manager
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 5 11:01:20 PDT 2016
Author: sanjoy
Date: Sun Jun 5 13:01:19 2016
New Revision: 271846
URL: http://llvm.org/viewvc/llvm-project?rev=271846&view=rev
Log:
[PM] Port IndVarSimplify to the new pass manager
Summary:
There are some rough corners, since the new pass manager doesn't have
(as far as I can tell) LoopSimplify and LCSSA, so I've updated the
tests to run them separately in the old pass manager in the lit tests.
We also don't have an equivalent for AU.setPreservesCFG() in the new
pass manager, so I've left a FIXME.
Reviewers: bogner, chandlerc, davide
Subscribers: sanjoy, mcrosier, llvm-commits
Differential Revision: http://reviews.llvm.org/D20783
Added:
llvm/trunk/include/llvm/Transforms/Scalar/IndVarSimplify.h
Modified:
llvm/trunk/lib/Passes/PassBuilder.cpp
llvm/trunk/lib/Passes/PassRegistry.def
llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
llvm/trunk/test/Transforms/IndVarSimplify/backedge-on-min-max.ll
llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll
llvm/trunk/test/Transforms/IndVarSimplify/sharpen-range.ll
Added: llvm/trunk/include/llvm/Transforms/Scalar/IndVarSimplify.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/IndVarSimplify.h?rev=271846&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Scalar/IndVarSimplify.h (added)
+++ llvm/trunk/include/llvm/Transforms/Scalar/IndVarSimplify.h Sun Jun 5 13:01:19 2016
@@ -0,0 +1,29 @@
+//===- IndVarSimplify.h - Induction Variable Simplification -----*- 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 Induction Variable
+// Simplification pass.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TRANSFORMS_SCALAR_INDVARSIMPLIFY_H
+#define LLVM_TRANSFORMS_SCALAR_INDVARSIMPLIFY_H
+
+#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/IR/PassManager.h"
+
+namespace llvm {
+
+class IndVarSimplifyPass : public PassInfoMixin<IndVarSimplifyPass> {
+public:
+ PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &AM);
+};
+}
+
+#endif // LLVM_TRANSFORMS_SCALAR_INDVARSIMPLIFY_H
Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=271846&r1=271845&r2=271846&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
+++ llvm/trunk/lib/Passes/PassBuilder.cpp Sun Jun 5 13:01:19 2016
@@ -72,6 +72,7 @@
#include "llvm/Transforms/Scalar/EarlyCSE.h"
#include "llvm/Transforms/Scalar/GuardWidening.h"
#include "llvm/Transforms/Scalar/GVN.h"
+#include "llvm/Transforms/Scalar/IndVarSimplify.h"
#include "llvm/Transforms/Scalar/LoopRotation.h"
#include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
#include "llvm/Transforms/Scalar/LowerAtomic.h"
Modified: llvm/trunk/lib/Passes/PassRegistry.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=271846&r1=271845&r2=271846&view=diff
==============================================================================
--- llvm/trunk/lib/Passes/PassRegistry.def (original)
+++ llvm/trunk/lib/Passes/PassRegistry.def Sun Jun 5 13:01:19 2016
@@ -164,4 +164,5 @@ LOOP_PASS("rotate", LoopRotatePass())
LOOP_PASS("no-op-loop", NoOpLoopPass())
LOOP_PASS("print", PrintLoopPass(dbgs()))
LOOP_PASS("simplify-cfg", LoopSimplifyCFGPass())
+LOOP_PASS("indvars", IndVarSimplifyPass())
#undef LOOP_PASS
Modified: llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp?rev=271846&r1=271845&r2=271846&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/IndVarSimplify.cpp Sun Jun 5 13:01:19 2016
@@ -24,12 +24,14 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Transforms/Scalar/IndVarSimplify.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
+#include "llvm/Analysis/LoopPassManager.h"
#include "llvm/Analysis/ScalarEvolutionExpander.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
@@ -2212,6 +2214,31 @@ bool IndVarSimplify::run(Loop *L) {
return Changed;
}
+PreservedAnalyses IndVarSimplifyPass::run(Loop &L, AnalysisManager<Loop> &AM) {
+ auto &FAM = AM.getResult<FunctionAnalysisManagerLoopProxy>(L).getManager();
+ Function *F = L.getHeader()->getParent();
+ const DataLayout &DL = F->getParent()->getDataLayout();
+
+ auto *LI = FAM.getCachedResult<LoopAnalysis>(*F);
+ auto *SE = FAM.getCachedResult<ScalarEvolutionAnalysis>(*F);
+ auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(*F);
+
+ assert((LI && SE && DT) &&
+ "Analyses required for indvarsimplify not available!");
+
+ // Optional analyses.
+ auto *TTI = FAM.getCachedResult<TargetIRAnalysis>(*F);
+ auto *TLI = FAM.getCachedResult<TargetLibraryAnalysis>(*F);
+
+ IndVarSimplify IVS(LI, SE, DT, DL, TLI, TTI);
+ if (!IVS.run(&L))
+ return PreservedAnalyses::all();
+
+ // FIXME: once we have an equivalent of AU.setPreservesCFG() in the
+ // new pass manager, we should use that here.
+ return getLoopPassPreservedAnalyses();
+}
+
namespace {
struct IndVarSimplifyLegacyPass : public LoopPass {
static char ID; // Pass identification, replacement for typeid
Modified: llvm/trunk/test/Transforms/IndVarSimplify/backedge-on-min-max.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/backedge-on-min-max.ll?rev=271846&r1=271845&r2=271846&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/backedge-on-min-max.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/backedge-on-min-max.ll Sun Jun 5 13:01:19 2016
@@ -1,4 +1,5 @@
; RUN: opt < %s -indvars -S | FileCheck %s
+; RUN: opt -lcssa -loop-simplify -S < %s | opt -S -passes='require<targetir>,require<scalar-evolution>,require<domtree>,loop(indvars)'
;; --- signed ---
Modified: llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll?rev=271846&r1=271845&r2=271846&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/iv-widen.ll Sun Jun 5 13:01:19 2016
@@ -1,4 +1,5 @@
; RUN: opt < %s -indvars -S | FileCheck %s
+; RUN: opt -lcssa -loop-simplify -S < %s | opt -S -passes='require<targetir>,require<scalar-evolution>,require<domtree>,loop(indvars)'
; Provide legal integer types.
target datalayout = "n8:16:32:64"
Modified: llvm/trunk/test/Transforms/IndVarSimplify/sharpen-range.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IndVarSimplify/sharpen-range.ll?rev=271846&r1=271845&r2=271846&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/IndVarSimplify/sharpen-range.ll (original)
+++ llvm/trunk/test/Transforms/IndVarSimplify/sharpen-range.ll Sun Jun 5 13:01:19 2016
@@ -1,4 +1,5 @@
;; RUN: opt -S < %s -indvars | FileCheck %s
+; RUN: opt -lcssa -loop-simplify -S < %s | opt -S -passes='require<targetir>,require<scalar-evolution>,require<domtree>,loop(indvars)'
;; Check if llvm can narrow !range metadata based on loop entry
;; predicates.
More information about the llvm-commits
mailing list