forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Frontend][OpenMP] Refactor getLeafConstructs, add getCompoundConstru…
…ct (llvm#87247) Emit a special leaf construct table in DirectiveEmitter.cpp, which will allow both decomposition of a construct into leafs, and composition of constituent constructs into a single compound construct (if possible). The function `getLeafConstructs` is no longer auto-generated, but implemented in OMP.cpp. The table contains a row for each directive, and each row has the following format `dir_id, num_leafs, leaf1, leaf2, ..., leafN, -1, ...` The rows are sorted lexicographically with respect to the leaf constructs. This allows a binary search for the row corresponding to the given list of leafs. There is an auxiliary table that for each directive contains the index of the row corresponding to that directive. Looking up leaf constructs for a directive `dir_id` is of constant time, and and consists of two lookups: `LeafTable[Auxiliary[dir_id]]`. Finding a compound directive given the set of leafs is of time O(logn), and is roughly represented by `row = binary_search(LeafTable); return row[0]`. The functions `getLeafConstructs` and `getCompoundConstruct` use these lookup methods internally.
- Loading branch information
Showing
7 changed files
with
301 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//===- llvm/unittests/Frontend/OpenMPComposeTest.cpp ----------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm/ADT/ArrayRef.h" | ||
#include "llvm/Frontend/OpenMP/OMP.h" | ||
#include "gtest/gtest.h" | ||
|
||
using namespace llvm; | ||
using namespace llvm::omp; | ||
|
||
TEST(Composition, GetLeafConstructs) { | ||
ArrayRef<Directive> L1 = getLeafConstructs(OMPD_loop); | ||
ASSERT_EQ(L1, (ArrayRef<Directive>{})); | ||
ArrayRef<Directive> L2 = getLeafConstructs(OMPD_parallel_for); | ||
ASSERT_EQ(L2, (ArrayRef<Directive>{OMPD_parallel, OMPD_for})); | ||
ArrayRef<Directive> L3 = getLeafConstructs(OMPD_parallel_for_simd); | ||
ASSERT_EQ(L3, (ArrayRef<Directive>{OMPD_parallel, OMPD_for, OMPD_simd})); | ||
} | ||
|
||
TEST(Composition, GetCompoundConstruct) { | ||
Directive C1 = | ||
getCompoundConstruct({OMPD_target, OMPD_teams, OMPD_distribute}); | ||
ASSERT_EQ(C1, OMPD_target_teams_distribute); | ||
Directive C2 = getCompoundConstruct({OMPD_target}); | ||
ASSERT_EQ(C2, OMPD_target); | ||
Directive C3 = getCompoundConstruct({OMPD_target, OMPD_masked}); | ||
ASSERT_EQ(C3, OMPD_unknown); | ||
Directive C4 = getCompoundConstruct({OMPD_target, OMPD_teams_distribute}); | ||
ASSERT_EQ(C4, OMPD_target_teams_distribute); | ||
Directive C5 = getCompoundConstruct({}); | ||
ASSERT_EQ(C5, OMPD_unknown); | ||
Directive C6 = getCompoundConstruct({OMPD_parallel_for, OMPD_simd}); | ||
ASSERT_EQ(C6, OMPD_parallel_for_simd); | ||
Directive C7 = getCompoundConstruct({OMPD_do, OMPD_simd}); | ||
ASSERT_EQ(C7, OMPD_do_simd); // Make sure it's not OMPD_end_do_simd | ||
} |
Oops, something went wrong.