Skip to content

Commit 621a271

Browse files
authored
[flang][openacc] Warn for num_gangs, num_workers and vector_length on acc serial (#69622)
For portability with other compilers, just issue a portability warning instead of a hard error when `num_gangs`, `num_workers` or `vector_length` are present on an `!$acc serial` directive
1 parent afdad4f commit 621a271

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,12 @@ CHECK_SIMPLE_CLAUSE(IfPresent, ACCC_if_present)
380380
CHECK_SIMPLE_CLAUSE(Independent, ACCC_independent)
381381
CHECK_SIMPLE_CLAUSE(NoCreate, ACCC_no_create)
382382
CHECK_SIMPLE_CLAUSE(Nohost, ACCC_nohost)
383-
CHECK_SIMPLE_CLAUSE(NumWorkers, ACCC_num_workers)
384383
CHECK_SIMPLE_CLAUSE(Private, ACCC_private)
385384
CHECK_SIMPLE_CLAUSE(Read, ACCC_read)
386385
CHECK_SIMPLE_CLAUSE(Seq, ACCC_seq)
387386
CHECK_SIMPLE_CLAUSE(Tile, ACCC_tile)
388387
CHECK_SIMPLE_CLAUSE(UseDevice, ACCC_use_device)
389388
CHECK_SIMPLE_CLAUSE(Vector, ACCC_vector)
390-
CHECK_SIMPLE_CLAUSE(VectorLength, ACCC_vector_length)
391389
CHECK_SIMPLE_CLAUSE(Wait, ACCC_wait)
392390
CHECK_SIMPLE_CLAUSE(Worker, ACCC_worker)
393391
CHECK_SIMPLE_CLAUSE(Write, ACCC_write)
@@ -541,13 +539,30 @@ void AccStructureChecker::Enter(const parser::AccClause::Gang &g) {
541539
}
542540

543541
void AccStructureChecker::Enter(const parser::AccClause::NumGangs &n) {
544-
CheckAllowed(llvm::acc::Clause::ACCC_num_gangs);
542+
CheckAllowed(llvm::acc::Clause::ACCC_num_gangs,
543+
/*warnInsteadOfError=*/GetContext().directive ==
544+
llvm::acc::Directive::ACCD_serial ||
545+
GetContext().directive == llvm::acc::Directive::ACCD_serial_loop);
545546

546547
if (n.v.size() > 3)
547548
context_.Say(GetContext().clauseSource,
548549
"NUM_GANGS clause accepts a maximum of 3 arguments"_err_en_US);
549550
}
550551

552+
void AccStructureChecker::Enter(const parser::AccClause::NumWorkers &n) {
553+
CheckAllowed(llvm::acc::Clause::ACCC_num_workers,
554+
/*warnInsteadOfError=*/GetContext().directive ==
555+
llvm::acc::Directive::ACCD_serial ||
556+
GetContext().directive == llvm::acc::Directive::ACCD_serial_loop);
557+
}
558+
559+
void AccStructureChecker::Enter(const parser::AccClause::VectorLength &n) {
560+
CheckAllowed(llvm::acc::Clause::ACCC_vector_length,
561+
/*warnInsteadOfError=*/GetContext().directive ==
562+
llvm::acc::Directive::ACCD_serial ||
563+
GetContext().directive == llvm::acc::Directive::ACCD_serial_loop);
564+
}
565+
551566
void AccStructureChecker::Enter(const parser::AccClause::Reduction &reduction) {
552567
CheckAllowed(llvm::acc::Clause::ACCC_reduction);
553568

flang/lib/Semantics/check-directive-structure.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class DirectiveStructureChecker : public virtual BaseChecker {
333333

334334
void CheckRequireAtLeastOneOf(bool warnInsteadOfError = false);
335335

336-
void CheckAllowed(C clause);
336+
void CheckAllowed(C clause, bool warnInsteadOfError = false);
337337

338338
void CheckAtLeastOneClause();
339339

@@ -452,15 +452,21 @@ std::string DirectiveStructureChecker<D, C, PC,
452452
// Check that clauses present on the directive are allowed clauses.
453453
template <typename D, typename C, typename PC, std::size_t ClauseEnumSize>
454454
void DirectiveStructureChecker<D, C, PC, ClauseEnumSize>::CheckAllowed(
455-
C clause) {
455+
C clause, bool warnInsteadOfError) {
456456
if (!GetContext().allowedClauses.test(clause) &&
457457
!GetContext().allowedOnceClauses.test(clause) &&
458458
!GetContext().allowedExclusiveClauses.test(clause) &&
459459
!GetContext().requiredClauses.test(clause)) {
460-
context_.Say(GetContext().clauseSource,
461-
"%s clause is not allowed on the %s directive"_err_en_US,
462-
parser::ToUpperCaseLetters(getClauseName(clause).str()),
463-
parser::ToUpperCaseLetters(GetContext().directiveSource.ToString()));
460+
if (warnInsteadOfError)
461+
context_.Say(GetContext().clauseSource,
462+
"%s clause is not allowed on the %s directive and will be ignored"_port_en_US,
463+
parser::ToUpperCaseLetters(getClauseName(clause).str()),
464+
parser::ToUpperCaseLetters(GetContext().directiveSource.ToString()));
465+
else
466+
context_.Say(GetContext().clauseSource,
467+
"%s clause is not allowed on the %s directive"_err_en_US,
468+
parser::ToUpperCaseLetters(getClauseName(clause).str()),
469+
parser::ToUpperCaseLetters(GetContext().directiveSource.ToString()));
464470
return;
465471
}
466472
if ((GetContext().allowedOnceClauses.test(clause) ||

flang/test/Semantics/OpenACC/acc-serial.f90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ program openacc_serial_validity
7777
!$acc serial wait(wait1) wait(wait2)
7878
!$acc end serial
7979

80-
!ERROR: NUM_GANGS clause is not allowed on the SERIAL directive
80+
!PORTABILITY: NUM_GANGS clause is not allowed on the SERIAL directive and will be ignored
8181
!$acc serial num_gangs(8)
8282
!$acc end serial
8383

84-
!ERROR: NUM_WORKERS clause is not allowed on the SERIAL directive
84+
!PORTABILITY: NUM_WORKERS clause is not allowed on the SERIAL directive and will be ignored
8585
!$acc serial num_workers(8)
8686
!$acc end serial
8787

88-
!ERROR: VECTOR_LENGTH clause is not allowed on the SERIAL directive
88+
!PORTABILITY: VECTOR_LENGTH clause is not allowed on the SERIAL directive and will be ignored
8989
!$acc serial vector_length(128)
9090
!$acc end serial
9191

0 commit comments

Comments
 (0)