[PATCH] D84886: Create LoopNestPass

Ta-Wei Tu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 29 12:39:18 PDT 2020


TaWeiTu created this revision.
TaWeiTu added reviewers: Whitney, etiotto, fedor.sergeev, chandlerc.
Herald added subscribers: llvm-commits, cfe-commits, asbirlea, dexonsmith, steven_wu, hiraditya, mgorny.
Herald added projects: clang, LLVM.
TaWeiTu requested review of this revision.

Per http://llvm.org/OpenProjects.html#llvm_loopnest <http://llvm.org/OpenProjects.html#llvm_loopnest>, the goal of this patch is to create facilities that allow implementing loop nest passes that run on top-level loop nests for the New Pass Manager.

Under the design, the loop nest passes will have a `run` method with the following signature:

  PreservedAnalyses run(LoopNest &LN, LoopNestAnalysisManager &AM, LoopStandardAnalysisResults &AR, LNPMUpdater &U);

`LNPMUpdater` (short for loop nest pass manager updater) supports invalidating loop nests (`markLoopNestAsDeleted`), re-visiting the current loop nest (`revisitCurrentLoopNest`) and adding new top-level loop nests to the function (`addNewLoopNests`).

The loop nest passes can be grouped together by `LoopNestPassManager`, and then embedded into an `FPM` via `FunctionToLoopNestPassAdaptor`. Since both `FunctionToLoopNestPassAdaptor` and `FunctionToLoopPassAdaptor` require loop canonicalization passes to be run first, the `LoopNestToLoopPassAdaptor` is also introduced in the patch.
The intended usage of the adaptor is to group the loop passes together into an `LPM` first, and then embed the `LPM` into `LoopNestPassManager`. With this, the loop canonicalization phase will be run only once for both loop and loop nest passes.

Currently, the `LoopNestAnalysisManager` is nothing but a wrapper around `LoopAnalysisManager` that provides the APIs on `LoopNest` and forwards the requests to the internal LPM. That is, the loop nest analyses should still be implemented as loop analyses.
The reason behind the design is that we do not support updating the `LoopNest` object dynamically yet. That means the `LoopNest` object will be constantly invalidated by the loop nest passes and loop passes, and invalidating a `LoopNest` structure means that we have to invalidate all analyses associated with it. This is quite inefficient since the analyses might have the ability to be maintained online.

Other facilities like parsing the pipeline, the proxies between analysis managers, are also implemented in this patch. The `PassBuilderCallbacksTest` has also been applied to loop-nest-related infrastructures. The actual functionalities of the components, however, are not tested yet. Still, embedding loop passes into LNPM seems to be working as I've modified some existing loop-pass related tests to verify the results. Also, all the existing unit-tests and regression-tests work, so at least this is not breaking anything now.

Though we definitely need more testing on the functionalities, I would like the submit the diff earlier to see what you think about the patch and the design. Fine-grained tests will be added later.

Please kindly provide feedbacks and comments on the patch. Thank you very much!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84886

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Analysis/LoopNestAnalysis.h
  llvm/include/llvm/Analysis/LoopNestAnalysisManager.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Transforms/Scalar/LoopNestPassManager.h
  llvm/include/llvm/Transforms/Scalar/LoopPassManager.h
  llvm/include/llvm/Transforms/Utils/LoopUtils.h
  llvm/lib/Analysis/CMakeLists.txt
  llvm/lib/Analysis/LoopNestAnalysis.cpp
  llvm/lib/Analysis/LoopNestAnalysisManager.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Scalar/CMakeLists.txt
  llvm/lib/Transforms/Scalar/LoopNestPassManager.cpp
  llvm/lib/Transforms/Utils/LoopUtils.cpp
  llvm/test/Transforms/LICM/assume.ll
  llvm/test/Transforms/LoopDeletion/invalidation.ll
  llvm/test/Transforms/LoopDeletion/multiple-exit-conditions.ll
  llvm/test/Transforms/LoopNest/print.ll
  llvm/test/Transforms/LoopRotate/basic.ll
  llvm/test/Transforms/LoopRotate/freeze-crash.ll
  llvm/test/Transforms/LoopRotate/multiple-deopt-exits.ll
  llvm/test/Transforms/LoopRotate/pr35210.ll
  llvm/tools/llvm-opt-fuzzer/llvm-opt-fuzzer.cpp
  llvm/tools/opt/NewPMDriver.cpp
  llvm/unittests/IR/PassBuilderCallbacksTest.cpp
  llvm/unittests/Transforms/Scalar/LICMTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84886.281697.patch
Type: text/x-patch
Size: 77494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200729/fcdb5fa4/attachment-0001.bin>


More information about the llvm-commits mailing list