[OpenMP][OpenMPIRBuilder] Implement loop unrolling.
authorMichael Kruse <llvm-project@meinersbur.de>
Thu, 2 Sep 2021 06:08:55 +0000 (01:08 -0500)
committerMichael Kruse <llvm-project@meinersbur.de>
Thu, 2 Sep 2021 07:37:25 +0000 (02:37 -0500)
commit707ce34b06190e275572c3c46843036db1bab6d1
tree8ee70867e18172fa726b524e9a665f3822bdc72b
parent3e60d216a4829a0e9a5045afa3e060f89ea18b04
[OpenMP][OpenMPIRBuilder] Implement loop unrolling.

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.

Reviewed By: jdoerfert, kiranchandramohan

Differential Revision: https://reviews.llvm.org/D107764
22 files changed:
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 [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_heuristic.c [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_partial_factor.c [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_partial_factor_for.c [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_partial_factor_for_collapse.c [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_partial_heuristic.c [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_partial_heuristic_constant_for.c [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_partial_heuristic_for_collapse.c [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_partial_heuristic_runtime_for.c [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_unroll_partial_factor.c [new file with mode: 0644]
clang/test/OpenMP/irbuilder_unroll_unroll_partial_heuristic.c [new file with mode: 0644]
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