Skip to content

[Frontend][OpenMP] Add functions for checking construct type #87258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c9ee93f
[MLIR][OpenMP] Group clause operands into structures
skatrak Mar 26, 2024
7af7e9d
[Flang][OpenMP][Lower] Use clause operand structures
skatrak Mar 26, 2024
e291fad
[Flang][OpenMP][Lower] Split MLIR codegen for clauses and constructs
skatrak Mar 28, 2024
d56c859
Merge branch 'main' into users/skatrak/spr/clause-operands-01-mlir
skatrak Mar 28, 2024
3d9ec39
Merge branch 'users/skatrak/spr/clause-operands-01-mlir' into users/s…
skatrak Mar 28, 2024
0416ec4
Merge branch 'users/skatrak/spr/clause-operands-02-flang' into users/…
skatrak Mar 28, 2024
ec0ed50
[Flang][OpenMP][Lower] Refactor lowering of compound constructs
skatrak Mar 29, 2024
f725fac
[flang][OpenMP] Move clause/object conversion to happen early, in genOMP
kparzysz Mar 29, 2024
291dc48
[Frontend][OpenMP] Refactor getLeafConstructs, add getCompoundConstruct
kparzysz Apr 1, 2024
a889f30
[Frontend][OpenMP] Add functions for checking construct type
kparzysz Mar 11, 2024
0d92781
Address review comments
kparzysz Apr 2, 2024
46770f8
[flang][OpenMP] Move clause/object conversion to happen early, in genOMP
kparzysz Mar 29, 2024
de93771
Merge branch 'main' into users/kparzysz/spr/a05-makeclause
kparzysz Apr 17, 2024
065b54c
clang-format
kparzysz Apr 17, 2024
e799507
Merge branch 'users/kparzysz/spr/a05-makeclause' into users/kparzysz/…
kparzysz Apr 17, 2024
a803e4a
Merge branch 'users/kparzysz/spr/a06-leafsorcomposite' into users/kpa…
kparzysz Apr 17, 2024
cb7c0f8
Rename test
kparzysz Apr 17, 2024
8f935fb
Finish the renaming
kparzysz Apr 17, 2024
d5c06db
Merge branch 'main' into users/kparzysz/spr/a07-construct-type
kparzysz Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions llvm/include/llvm/Frontend/OpenMP/OMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
25 changes: 25 additions & 0 deletions llvm/lib/Frontend/OpenMP/OMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,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
2 changes: 1 addition & 1 deletion llvm/unittests/Frontend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ add_llvm_unittest(LLVMFrontendTests
OpenMPContextTest.cpp
OpenMPIRBuilderTest.cpp
OpenMPParsingTest.cpp
OpenMPComposeTest.cpp
OpenMPCompositionTest.cpp

DEPENDS
acc_gen
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -39,3 +39,30 @@ TEST(Composition, GetCompoundConstruct) {
Directive C7 = getCompoundConstruct({OMPD_do, OMPD_simd});
ASSERT_EQ(C7, OMPD_do_simd); // Make sure it's not OMPD_end_do_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));
ASSERT_FALSE(isLeafConstruct(OMPD_parallel_for));
}

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-B 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));
}
Loading