[llvm] r268452 - PM: Port LoopRotation to the new loop pass manager

Sean Silva via llvm-commits llvm-commits at lists.llvm.org
Tue May 10 00:40:54 PDT 2016


On Tue, May 3, 2016 at 3:02 PM, Justin Bogner via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: bogner
> Date: Tue May  3 17:02:31 2016
> New Revision: 268452
>
> URL: http://llvm.org/viewvc/llvm-project?rev=268452&view=rev
> Log:
> PM: Port LoopRotation to the new loop pass manager
>
> Added:
>     llvm/trunk/include/llvm/Transforms/Scalar/LoopRotation.h
> Modified:
>     llvm/trunk/include/llvm/InitializePasses.h
>     llvm/trunk/lib/Passes/PassBuilder.cpp
>     llvm/trunk/lib/Passes/PassRegistry.def
>     llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
>     llvm/trunk/lib/Transforms/Scalar/Scalar.cpp
>     llvm/trunk/test/Transforms/LoopRotate/basic.ll
>
> Modified: llvm/trunk/include/llvm/InitializePasses.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/InitializePasses.h?rev=268452&r1=268451&r2=268452&view=diff
>
> ==============================================================================
> --- llvm/trunk/include/llvm/InitializePasses.h (original)
> +++ llvm/trunk/include/llvm/InitializePasses.h Tue May  3 17:02:31 2016
> @@ -178,7 +178,7 @@ void initializeLoopExtractorPass(PassReg
>  void initializeLoopInfoWrapperPassPass(PassRegistry&);
>  void initializeLoopInterchangePass(PassRegistry &);
>  void initializeLoopInstSimplifyPass(PassRegistry&);
> -void initializeLoopRotatePass(PassRegistry&);
> +void initializeLoopRotateLegacyPassPass(PassRegistry&);
>  void initializeLoopSimplifyPass(PassRegistry&);
>  void initializeLoopSimplifyCFGLegacyPassPass(PassRegistry&);
>  void initializeLoopStrengthReducePass(PassRegistry&);
>
> Added: llvm/trunk/include/llvm/Transforms/Scalar/LoopRotation.h
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Scalar/LoopRotation.h?rev=268452&view=auto
>
> ==============================================================================
> --- llvm/trunk/include/llvm/Transforms/Scalar/LoopRotation.h (added)
> +++ llvm/trunk/include/llvm/Transforms/Scalar/LoopRotation.h Tue May  3
> 17:02:31 2016
> @@ -0,0 +1,32 @@
> +//===- LoopRotation.h - Loop Rotation
> -------------------------------------===//
> +//
> +//                     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 Loop Rotation pass.
> +//
>
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef LLVM_TRANSFORMS_SCALAR_LOOPROTATION_H
> +#define LLVM_TRANSFORMS_SCALAR_LOOPROTATION_H
> +
> +#include "llvm/Analysis/LoopInfo.h"
> +#include "llvm/IR/PassManager.h"
> +
> +namespace llvm {
> +
> +/// A simple loop rotation transformation.
> +class LoopRotatePass : public PassInfoMixin<LoopRotatePass> {
> +  unsigned MaxHeaderSize;
> +public:
> +  LoopRotatePass();
> +  LoopRotatePass(unsigned MaxHeaderSize) : MaxHeaderSize(MaxHeaderSize) {}
> +  PreservedAnalyses run(Loop &L, AnalysisManager<Loop> &AM);
> +};
> +}
> +
> +#endif // LLVM_TRANSFORMS_SCALAR_LOOPROTATION_H
>
> Modified: llvm/trunk/lib/Passes/PassBuilder.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassBuilder.cpp?rev=268452&r1=268451&r2=268452&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Passes/PassBuilder.cpp (original)
> +++ llvm/trunk/lib/Passes/PassBuilder.cpp Tue May  3 17:02:31 2016
> @@ -57,6 +57,7 @@
>  #include "llvm/Transforms/Scalar/ADCE.h"
>  #include "llvm/Transforms/Scalar/DCE.h"
>  #include "llvm/Transforms/Scalar/EarlyCSE.h"
> +#include "llvm/Transforms/Scalar/LoopRotation.h"
>  #include "llvm/Transforms/Scalar/LoopSimplifyCFG.h"
>  #include "llvm/Transforms/Scalar/LowerExpectIntrinsic.h"
>  #include "llvm/Transforms/Scalar/GVN.h"
>
> Modified: llvm/trunk/lib/Passes/PassRegistry.def
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Passes/PassRegistry.def?rev=268452&r1=268451&r2=268452&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Passes/PassRegistry.def (original)
> +++ llvm/trunk/lib/Passes/PassRegistry.def Tue May  3 17:02:31 2016
> @@ -134,6 +134,7 @@ LOOP_ANALYSIS("no-op-loop", NoOpLoopAnal
>  #define LOOP_PASS(NAME, CREATE_PASS)
>  #endif
>  LOOP_PASS("invalidate<all>", InvalidateAllAnalysesPass())
> +LOOP_PASS("rotate", LoopRotatePass())
>  LOOP_PASS("no-op-loop", NoOpLoopPass())
>  LOOP_PASS("print", PrintLoopPass(dbgs()))
>  LOOP_PASS("simplify-cfg", LoopSimplifyCFGPass())
>
> Modified: llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp?rev=268452&r1=268451&r2=268452&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/LoopRotation.cpp Tue May  3 17:02:31
> 2016
> @@ -11,7 +11,7 @@
>  //
>
>  //===----------------------------------------------------------------------===//
>
> -#include "llvm/Transforms/Scalar.h"
> +#include "llvm/Transforms/Scalar/LoopRotation.h"
>  #include "llvm/ADT/Statistic.h"
>  #include "llvm/Analysis/AliasAnalysis.h"
>  #include "llvm/Analysis/BasicAliasAnalysis.h"
> @@ -20,6 +20,7 @@
>  #include "llvm/Analysis/InstructionSimplify.h"
>  #include "llvm/Analysis/GlobalsModRef.h"
>  #include "llvm/Analysis/LoopPass.h"
> +#include "llvm/Analysis/LoopPassManager.h"
>  #include "llvm/Analysis/ScalarEvolution.h"
>  #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
>  #include "llvm/Analysis/TargetTransformInfo.h"
> @@ -32,6 +33,7 @@
>  #include "llvm/Support/CommandLine.h"
>  #include "llvm/Support/Debug.h"
>  #include "llvm/Support/raw_ostream.h"
> +#include "llvm/Transforms/Scalar.h"
>  #include "llvm/Transforms/Utils/BasicBlockUtils.h"
>  #include "llvm/Transforms/Utils/Local.h"
>  #include "llvm/Transforms/Utils/LoopUtils.h"
> @@ -562,15 +564,36 @@ static bool iterativelyRotateLoop(Loop *
>    return MadeChange;
>  }
>
> +LoopRotatePass::LoopRotatePass() :
> MaxHeaderSize(DefaultRotationThreshold) {}
> +
> +PreservedAnalyses LoopRotatePass::run(Loop &L, AnalysisManager<Loop> &AM)
> {
> +  auto &FAM =
> AM.getResult<FunctionAnalysisManagerLoopProxy>(L).getManager();
> +  Function *F = L.getHeader()->getParent();
> +
> +  auto *LI = FAM.getCachedResult<LoopAnalysis>(*F);
> +  const auto *TTI = FAM.getCachedResult<TargetIRAnalysis>(*F);
> +  auto *AC = FAM.getCachedResult<AssumptionAnalysis>(*F);
> +  assert((LI && TTI && AC) && "Analyses for loop rotation not available");
> +
> +  // Optional analyses.
> +  auto *DT = FAM.getCachedResult<DominatorTreeAnalysis>(*F);
> +  auto *SE = FAM.getCachedResult<ScalarEvolutionAnalysis>(*F);
> +
> +  bool Changed = iterativelyRotateLoop(&L, MaxHeaderSize, LI, TTI, AC,
> DT, SE);
> +  if (!Changed)
> +    return PreservedAnalyses::all();
> +  return getLoopPassPreservedAnalyses();
> +}
> +
>  namespace {
>
> -class LoopRotate : public LoopPass {
> +class LoopRotateLegacyPass : public LoopPass {
>    unsigned MaxHeaderSize;
>
>  public:
>    static char ID; // Pass ID, replacement for typeid
> -  LoopRotate(int SpecifiedMaxHeaderSize = -1) : LoopPass(ID) {
> -    initializeLoopRotatePass(*PassRegistry::getPassRegistry());
> +  LoopRotateLegacyPass(int SpecifiedMaxHeaderSize = -1) : LoopPass(ID) {
> +    initializeLoopRotateLegacyPassPass(*PassRegistry::getPassRegistry());
>      if (SpecifiedMaxHeaderSize == -1)
>        MaxHeaderSize = DefaultRotationThreshold;
>      else
> @@ -602,13 +625,15 @@ public:
>  };
>  }
>
> -char LoopRotate::ID = 0;
> -INITIALIZE_PASS_BEGIN(LoopRotate, "loop-rotate", "Rotate Loops", false,
> false)
> +char LoopRotateLegacyPass::ID = 0;
> +INITIALIZE_PASS_BEGIN(LoopRotateLegacyPass, "loop-rotate", "Rotate Loops",
> +                      false, false)
>  INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker)
>  INITIALIZE_PASS_DEPENDENCY(LoopPass)
>  INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
> -INITIALIZE_PASS_END(LoopRotate, "loop-rotate", "Rotate Loops", false,
> false)
> +INITIALIZE_PASS_END(LoopRotateLegacyPass, "loop-rotate", "Rotate Loops",
> +                    false, false)
>
>  Pass *llvm::createLoopRotatePass(int MaxHeaderSize) {
> -  return new LoopRotate(MaxHeaderSize);
> +  return new LoopRotateLegacyPass(MaxHeaderSize);
>  }
>
> Modified: llvm/trunk/lib/Transforms/Scalar/Scalar.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/Scalar.cpp?rev=268452&r1=268451&r2=268452&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Scalar/Scalar.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/Scalar.cpp Tue May  3 17:02:31 2016
> @@ -53,7 +53,7 @@ void llvm::initializeScalarOpts(PassRegi
>    initializeLoopAccessAnalysisPass(Registry);
>    initializeLoopInstSimplifyPass(Registry);
>    initializeLoopInterchangePass(Registry);
> -  initializeLoopRotatePass(Registry);
> +  initializeLoopRotateLegacyPassPass(Registry);
>    initializeLoopStrengthReducePass(Registry);
>    initializeLoopRerollPass(Registry);
>    initializeLoopUnrollPass(Registry);
>
> Modified: llvm/trunk/test/Transforms/LoopRotate/basic.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopRotate/basic.ll?rev=268452&r1=268451&r2=268452&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/Transforms/LoopRotate/basic.ll (original)
> +++ llvm/trunk/test/Transforms/LoopRotate/basic.ll Tue May  3 17:02:31 2016
> @@ -1,4 +1,6 @@
>  ; RUN: opt -S -loop-rotate < %s | FileCheck %s
> +; RUN: opt -S
> -passes='require<loops>,require<targetir>,require<assumptions>,loop(rotate)'
> < %s | FileCheck %s
>

Sorry if this is a stupid question, but why do we need to explicitly
"require" the passes when the loop-rotate already declares the dependency?
(I feel like there's some part of the bigger picture that I'm missing here)

-- Sean Silva



> +
>  target datalayout =
> "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
>  target triple = "x86_64-apple-darwin10.0.0"
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160510/70f32e72/attachment-0001.html>


More information about the llvm-commits mailing list