[OpenMP][OpenMPIRBuilder] Implement loop unrolling.
authorMichael Kruse <llvm-project@meinersbur.de>
Sat, 4 Sep 2021 23:50:49 +0000 (18:50 -0500)
committerMichael Kruse <llvm-project@meinersbur.de>
Sun, 5 Sep 2021 00:18:58 +0000 (19:18 -0500)
commit650bbc56203c947bb85176c40ca9c7c7a91c3c57
treea3a0f5a20176355f7de8b8eced441b605f4c9ed9
parent37e6a27da754e1a613b0f657c9ae91221237d66a
[OpenMP][OpenMPIRBuilder] Implement loop unrolling.

Recommit of 707ce34b06190e275572c3c46843036db1bab6d1. Don't introduce a
dependency to the LLVMPasses component, instead register the required
passes individually.

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
23 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/lib/Transforms/IPO/CMakeLists.txt
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp