[PATCH] D107764: [OpenMP][OpenMPIRBuilder] Implement loop unrolling.

Michael Kruse via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 9 06:22:45 PDT 2021


Meinersbur created this revision.
Meinersbur added reviewers: jdoerfert, AMDChirag, anchu-rajendran, kiranchandramohan, SouraVX, kiranktp, fghanim.
Meinersbur added a project: clang.
Herald added subscribers: zzheng, guansong, hiraditya, yaxunl, mgorny.
Meinersbur requested review of this revision.
Herald added a subscriber: sstefan1.
Herald added a project: LLVM.

Add methods for loop unrolling to the OpenMPIRBuilder class and use them in Clang if `-fopenmp-enable-irbuilder` is enabled. The unrolling methods are:

- `unrollLoopFull`
- `unrollLoopPartial`
- `unrollLoopHeuristic`

`unrollLoopPartial` and `unrollLoopHeuristic` can use compiler heuristics to automatically determine the unroll factor. If possible, that is if no CanonicalLoopInfo is required to pass to another method, metadata for LLVM's LoopUnrollPass is added. Otherwise the unroll factor is determined using the same heurstics as user by LoopUnrollPass. Not requiring a CanonicalLoopInfo, especially with `unrollLoopHeuristic` allows greater flexibility.

With full unrolling and partial unrolling with known unroll factor, instead of duplicating instructions by the OpenMPIRBuilder, the full unroll is still delegated to the LoopUnrollPass. In case of partial unrolling the loop is first tiled using the existing `tileLoops` methods, then the inner loop fully unrolled using the same mechanism.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107764

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/irbuilder_unroll_full.c
  clang/test/OpenMP/irbuilder_unroll_heuristic.c
  clang/test/OpenMP/irbuilder_unroll_partial_factor.c
  clang/test/OpenMP/irbuilder_unroll_partial_factor_for.c
  clang/test/OpenMP/irbuilder_unroll_partial_factor_for_collapse.c
  clang/test/OpenMP/irbuilder_unroll_partial_heuristic.c
  clang/test/OpenMP/irbuilder_unroll_partial_heuristic_constant_for.c
  clang/test/OpenMP/irbuilder_unroll_partial_heuristic_for_collapse.c
  clang/test/OpenMP/irbuilder_unroll_partial_heuristic_runtime_for.c
  clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c
  clang/test/OpenMP/irbuilder_unroll_unroll_partial_heuristic.c
  llvm/include/llvm/Analysis/LoopInfo.h
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Analysis/LoopInfo.cpp
  llvm/lib/Frontend/OpenMP/CMakeLists.txt
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107764.365173.patch
Type: text/x-patch
Size: 150418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210809/69107bea/attachment-0001.bin>


More information about the cfe-commits mailing list