https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/87258
>From a889f3074fc8c4ae5c6d9480308be0501217b9ff Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek <krzysztof.parzys...@amd.com> Date: Mon, 11 Mar 2024 12:55:38 -0500 Subject: [PATCH 1/3] [Frontend][OpenMP] Add functions for checking construct type Implement helper functions to identify leaf, composite, and combined constructs. --- llvm/include/llvm/Frontend/OpenMP/OMP.h | 4 +++ llvm/lib/Frontend/OpenMP/OMP.cpp | 25 ++++++++++++++++++ llvm/unittests/Frontend/OpenMPComposeTest.cpp | 26 +++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/llvm/include/llvm/Frontend/OpenMP/OMP.h b/llvm/include/llvm/Frontend/OpenMP/OMP.h index 4ed47f15dfe59e..ec8ae68f1c2ca0 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMP.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMP.h @@ -20,6 +20,10 @@ namespace llvm::omp { ArrayRef<Directive> getLeafConstructs(Directive D); Directive getCompoundConstruct(ArrayRef<Directive> Parts); + +bool isLeafConstruct(Directive D); +bool isCompositeConstruct(Directive D); +bool isCombinedConstruct(Directive D); } // namespace llvm::omp #endif // LLVM_FRONTEND_OPENMP_OMP_H diff --git a/llvm/lib/Frontend/OpenMP/OMP.cpp b/llvm/lib/Frontend/OpenMP/OMP.cpp index dd99d3d074fd1e..98d7c63bb8537e 100644 --- a/llvm/lib/Frontend/OpenMP/OMP.cpp +++ b/llvm/lib/Frontend/OpenMP/OMP.cpp @@ -78,4 +78,29 @@ Directive getCompoundConstruct(ArrayRef<Directive> Parts) { return Found; return OMPD_unknown; } + +bool isLeafConstruct(Directive D) { return getLeafConstructs(D).empty(); } + +bool isCompositeConstruct(Directive D) { + // OpenMP Spec 5.2: [17.3, 8-9] + // If directive-name-A and directive-name-B both correspond to loop- + // associated constructs then directive-name is a composite construct + llvm::ArrayRef<Directive> Leafs{getLeafConstructs(D)}; + if (Leafs.empty()) + return false; + if (getDirectiveAssociation(Leafs.front()) != Association::Loop) + return false; + + size_t numLoopConstructs = + llvm::count_if(Leafs.drop_front(), [](Directive L) { + return getDirectiveAssociation(L) == Association::Loop; + }); + return numLoopConstructs != 0; +} + +bool isCombinedConstruct(Directive D) { + // OpenMP Spec 5.2: [17.3, 9-10] + // Otherwise directive-name is a combined construct. + return !getLeafConstructs(D).empty() && !isCompositeConstruct(D); +} } // namespace llvm::omp diff --git a/llvm/unittests/Frontend/OpenMPComposeTest.cpp b/llvm/unittests/Frontend/OpenMPComposeTest.cpp index 29b1be4eb3432c..cc02af8bf67c26 100644 --- a/llvm/unittests/Frontend/OpenMPComposeTest.cpp +++ b/llvm/unittests/Frontend/OpenMPComposeTest.cpp @@ -39,3 +39,29 @@ TEST(Composition, GetCompoundConstruct) { Directive C7 = getCompoundConstruct({OMPD_parallel_for, OMPD_simd}); ASSERT_EQ(C7, OMPD_parallel_for_simd); } + +TEST(Composition, IsLeafConstruct) { + ASSERT_TRUE(isLeafConstruct(OMPD_loop)); + ASSERT_TRUE(isLeafConstruct(OMPD_teams)); + ASSERT_FALSE(isLeafConstruct(OMPD_for_simd)); + ASSERT_FALSE(isLeafConstruct(OMPD_distribute_simd)); +} + +TEST(Composition, IsCompositeConstruct) { + ASSERT_TRUE(isCompositeConstruct(OMPD_distribute_simd)); + ASSERT_FALSE(isCompositeConstruct(OMPD_for)); + ASSERT_TRUE(isCompositeConstruct(OMPD_for_simd)); + // directive-name-A = "parallel", directive-name-B = "for simd", + // only directive-name-A is loop-associated, so this is not a + // composite construct, even though "for simd" is. + ASSERT_FALSE(isCompositeConstruct(OMPD_parallel_for_simd)); +} + +TEST(Composition, IsCombinedConstruct) { + // "parallel for simd" is a combined construct, see comment in + // IsCompositeConstruct. + ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for_simd)); + ASSERT_FALSE(isCombinedConstruct(OMPD_for_simd)); + ASSERT_TRUE(isCombinedConstruct(OMPD_parallel_for)); + ASSERT_FALSE(isCombinedConstruct(OMPD_parallel)); +} >From cb7c0f8c1d929939bccbd2565cd11132c18a9687 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek <krzysztof.parzys...@amd.com> Date: Wed, 17 Apr 2024 11:42:32 -0500 Subject: [PATCH 2/3] Rename test --- .../Frontend/{OpenMPComposeTest.cpp => OpenMPCompositionTest.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename llvm/unittests/Frontend/{OpenMPComposeTest.cpp => OpenMPCompositionTest.cpp} (100%) diff --git a/llvm/unittests/Frontend/OpenMPComposeTest.cpp b/llvm/unittests/Frontend/OpenMPCompositionTest.cpp similarity index 100% rename from llvm/unittests/Frontend/OpenMPComposeTest.cpp rename to llvm/unittests/Frontend/OpenMPCompositionTest.cpp >From 8f935fbcd7ee8a572e0a5242d1b6ad5c5a70975d Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek <krzysztof.parzys...@amd.com> Date: Wed, 17 Apr 2024 11:46:48 -0500 Subject: [PATCH 3/3] Finish the renaming --- llvm/unittests/Frontend/CMakeLists.txt | 2 +- llvm/unittests/Frontend/OpenMPCompositionTest.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm/unittests/Frontend/CMakeLists.txt b/llvm/unittests/Frontend/CMakeLists.txt index ddb6a16cbb984e..3f290b63ba6479 100644 --- a/llvm/unittests/Frontend/CMakeLists.txt +++ b/llvm/unittests/Frontend/CMakeLists.txt @@ -14,7 +14,7 @@ add_llvm_unittest(LLVMFrontendTests OpenMPContextTest.cpp OpenMPIRBuilderTest.cpp OpenMPParsingTest.cpp - OpenMPComposeTest.cpp + OpenMPCompositionTest.cpp DEPENDS acc_gen diff --git a/llvm/unittests/Frontend/OpenMPCompositionTest.cpp b/llvm/unittests/Frontend/OpenMPCompositionTest.cpp index 5e9b2c2df174a3..0b32e0d96dc84c 100644 --- a/llvm/unittests/Frontend/OpenMPCompositionTest.cpp +++ b/llvm/unittests/Frontend/OpenMPCompositionTest.cpp @@ -1,4 +1,4 @@ -//===- llvm/unittests/Frontend/OpenMPComposeTest.cpp ----------------------===// +//===- llvm/unittests/Frontend/OpenMPCompositionTest.cpp ------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits