Skip to content

Commit 7c9404c

Browse files
authored
[flang][OpenMP] Add frontend support for ompx_bare clause (#111106)
1 parent 5fd385b commit 7c9404c

File tree

14 files changed

+122
-12
lines changed

14 files changed

+122
-12
lines changed

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3474,6 +3474,16 @@ OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
34743474
Clause = ParseOpenMPOMPXAttributesClause(WrongDirective);
34753475
break;
34763476
case OMPC_ompx_bare:
3477+
if (DKind == llvm::omp::Directive::OMPD_target) {
3478+
// Flang splits the combined directives which requires OMPD_target to be
3479+
// marked as accepting the `ompx_bare` clause in `OMP.td`. Thus, we need
3480+
// to explicitly check whether this clause is applied to an `omp target`
3481+
// without `teams` and emit an error.
3482+
Diag(Tok, diag::err_omp_unexpected_clause)
3483+
<< getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind);
3484+
ErrorFound = true;
3485+
WrongDirective = true;
3486+
}
34773487
if (WrongDirective)
34783488
Diag(Tok, diag::note_ompx_bare_clause)
34793489
<< getOpenMPClauseName(CKind) << "target teams";

flang/lib/Lower/OpenMP/ClauseProcessor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ static void convertLoopBounds(lower::AbstractConverter &converter,
220220
// ClauseProcessor unique clauses
221221
//===----------------------------------------------------------------------===//
222222

223+
bool ClauseProcessor::processBare(mlir::omp::BareClauseOps &result) const {
224+
return markClauseOccurrence<omp::clause::OmpxBare>(result.bare);
225+
}
226+
223227
bool ClauseProcessor::processBind(mlir::omp::BindClauseOps &result) const {
224228
if (auto *clause = findUniqueClause<omp::clause::Bind>()) {
225229
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();

flang/lib/Lower/OpenMP/ClauseProcessor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class ClauseProcessor {
5353
: converter(converter), semaCtx(semaCtx), clauses(clauses) {}
5454

5555
// 'Unique' clauses: They can appear at most once in the clause list.
56+
bool processBare(mlir::omp::BareClauseOps &result) const;
5657
bool processBind(mlir::omp::BindClauseOps &result) const;
5758
bool
5859
processCollapse(mlir::Location currentLocation, lower::pft::Evaluation &eval,

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,7 @@ static void genTargetClauses(
11841184
llvm::SmallVectorImpl<const semantics::Symbol *> &isDevicePtrSyms,
11851185
llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) {
11861186
ClauseProcessor cp(converter, semaCtx, clauses);
1187+
cp.processBare(clauseOps);
11871188
cp.processDepend(clauseOps);
11881189
cp.processDevice(stmtCtx, clauseOps);
11891190
cp.processHasDeviceAddr(clauseOps, hasDeviceAddrSyms);
@@ -2860,6 +2861,7 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
28602861
!std::holds_alternative<clause::Nowait>(clause.u) &&
28612862
!std::holds_alternative<clause::NumTeams>(clause.u) &&
28622863
!std::holds_alternative<clause::NumThreads>(clause.u) &&
2864+
!std::holds_alternative<clause::OmpxBare>(clause.u) &&
28632865
!std::holds_alternative<clause::Priority>(clause.u) &&
28642866
!std::holds_alternative<clause::Private>(clause.u) &&
28652867
!std::holds_alternative<clause::ProcBind>(clause.u) &&

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ TYPE_PARSER(
657657
parenthesized(scalarIntExpr))) ||
658658
"NUM_THREADS" >> construct<OmpClause>(construct<OmpClause::NumThreads>(
659659
parenthesized(scalarIntExpr))) ||
660+
"OMPX_BARE" >> construct<OmpClause>(construct<OmpClause::OmpxBare>()) ||
660661
"ORDER" >> construct<OmpClause>(construct<OmpClause::Order>(
661662
parenthesized(Parser<OmpOrderClause>{}))) ||
662663
"ORDERED" >> construct<OmpClause>(construct<OmpClause::Ordered>(

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,6 @@ CHECK_SIMPLE_CLAUSE(Align, OMPC_align)
28672867
CHECK_SIMPLE_CLAUSE(Compare, OMPC_compare)
28682868
CHECK_SIMPLE_CLAUSE(CancellationConstructType, OMPC_cancellation_construct_type)
28692869
CHECK_SIMPLE_CLAUSE(OmpxAttribute, OMPC_ompx_attribute)
2870-
CHECK_SIMPLE_CLAUSE(OmpxBare, OMPC_ompx_bare)
28712870
CHECK_SIMPLE_CLAUSE(Weak, OMPC_weak)
28722871

28732872
CHECK_REQ_SCALAR_INT_CLAUSE(NumTeams, OMPC_num_teams)
@@ -4395,6 +4394,17 @@ void OmpStructureChecker::Enter(const parser::OmpClause::To &x) {
43954394
}
43964395
}
43974396

4397+
void OmpStructureChecker::Enter(const parser::OmpClause::OmpxBare &x) {
4398+
// Don't call CheckAllowedClause, because it allows "ompx_bare" on
4399+
// a non-combined "target" directive (for reasons of splitting combined
4400+
// directives). In source code it's only allowed on "target teams".
4401+
if (GetContext().directive != llvm::omp::Directive::OMPD_target_teams) {
4402+
context_.Say(GetContext().clauseSource,
4403+
"%s clause is only allowed on combined TARGET TEAMS"_err_en_US,
4404+
parser::ToUpperCaseLetters(getClauseName(llvm::omp::OMPC_ompx_bare)));
4405+
}
4406+
}
4407+
43984408
llvm::StringRef OmpStructureChecker::getClauseName(llvm::omp::Clause clause) {
43994409
return llvm::omp::getOpenMPClauseName(clause);
44004410
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=51 %s -o - | FileCheck %s
2+
3+
program test
4+
integer :: tmp
5+
!$omp target teams ompx_bare num_teams(42) thread_limit(43)
6+
tmp = 1
7+
!$omp end target teams
8+
end program
9+
10+
! CHECK: omp.target ompx_bare
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
!RUN: %python %S/../test_errors.py %s %flang -fopenmp -fopenmp-version=51
2+
3+
subroutine test1
4+
!ERROR: OMPX_BARE clause is only allowed on combined TARGET TEAMS
5+
!$omp target ompx_bare
6+
!$omp end target
7+
end
8+
9+
subroutine test2
10+
!$omp target
11+
!ERROR: OMPX_BARE clause is only allowed on combined TARGET TEAMS
12+
!$omp teams ompx_bare
13+
!$omp end teams
14+
!$omp end target
15+
end
16+
17+
subroutine test3
18+
integer i
19+
!ERROR: OMPX_BARE clause is only allowed on combined TARGET TEAMS
20+
!$omp target teams distribute ompx_bare
21+
do i = 0, 10
22+
end do
23+
!$omp end target teams distribute
24+
end
25+
26+
subroutine test4
27+
!No errors
28+
!$omp target teams ompx_bare
29+
!$omp end target teams
30+
end

llvm/include/llvm/Frontend/OpenMP/ConstructDecompositionT.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ struct ConstructDecompositionT {
239239
bool
240240
applyClause(const tomp::clause::OmpxAttributeT<TypeTy, IdTy, ExprTy> &clause,
241241
const ClauseTy *);
242+
bool applyClause(const tomp::clause::OmpxBareT<TypeTy, IdTy, ExprTy> &clause,
243+
const ClauseTy *);
242244

243245
uint32_t version;
244246
llvm::omp::Directive construct;
@@ -1103,6 +1105,13 @@ bool ConstructDecompositionT<C, H>::applyClause(
11031105
return applyToOutermost(node);
11041106
}
11051107

1108+
template <typename C, typename H>
1109+
bool ConstructDecompositionT<C, H>::applyClause(
1110+
const tomp::clause::OmpxBareT<TypeTy, IdTy, ExprTy> &clause,
1111+
const ClauseTy *node) {
1112+
return applyToOutermost(node);
1113+
}
1114+
11061115
template <typename C, typename H>
11071116
bool ConstructDecompositionT<C, H>::applyClause(
11081117
const tomp::clause::OmpxAttributeT<TypeTy, IdTy, ExprTy> &clause,

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,7 @@ def OMP_Target : Directive<"target"> {
10181018
VersionedClause<OMPC_Device>,
10191019
VersionedClause<OMPC_If>,
10201020
VersionedClause<OMPC_NoWait>,
1021+
VersionedClause<OMPC_OMPX_Bare>,
10211022
VersionedClause<OMPC_OMPX_DynCGroupMem>,
10221023
VersionedClause<OMPC_ThreadLimit, 51>,
10231024
];

0 commit comments

Comments
 (0)