Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 flang/lib/Parser/unparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2871,6 +2871,10 @@ class UnparseVisitor {
Put("\n");
EndOpenMP();
}
// Clause unparsers are usually generated by tablegen in the form
// CLAUSE(VALUE). Here we only want to print VALUE so a custom unparser is
// needed.
void Unparse(const OmpClause::CancellationConstructType &x) { Walk(x.v); }
void Unparse(const OpenMPCancellationPointConstruct &x) {
BeginOpenMP();
Word("!$OMP ");
Expand Down
53 changes: 53 additions & 0 deletions flang/test/Parser/OpenMP/cancel.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
!RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck %s

! CHECK: SUBROUTINE parallel
subroutine parallel
! CHECK: !$OMP PARALLEL
!$omp parallel
! CHECK: !$OMP CANCEL PARALLEL
!$omp cancel parallel
! CHECK: !$OMP END PARALLEL
!$omp end parallel
! CHECK: END SUBROUTINE
end subroutine

! CHECK: SUBROUTINE sections
subroutine sections
! CHECK: !$OMP PARALLEL SECTIONS
!$omp parallel sections
! CHECK: !$OMP CANCEL SECTIONS
!$omp cancel sections
! CHECK: !$OMP END PARALLEL SECTIONS
!$omp end parallel sections
! CHECK: END SUBROUTINE
end subroutine

! CHECK: SUBROUTINE loop
subroutine loop
! CHECK: !$OMP PARALLEL DO
!$omp parallel do
! CHECK: DO i=1_4,10_4
do i=1,10
! CHECK: !$OMP CANCEL DO
!$omp cancel do
! CHECK: END DO
enddo
! CHECK: !$OMP END PARALLEL DO
!$omp end parallel do
! CHECK: END SUBROUTINE
end subroutine

! CHECK: SUBROUTINE taskgroup
subroutine taskgroup
! CHECK: !$OMP TASKGROUP
!$omp taskgroup
! CHECK: !$OMP TASK
!$omp task
! CHECK: !$OMP CANCEL TASKGROUP
!$omp cancel taskgroup
! CHECK: !$OMP END TASK
!$omp end task
! CHECK: !$OMP END TASKGROUP
!$omp end taskgroup
! CHECK: END SUBROUTINE
end subroutine
3 changes: 3 additions & 0 deletions llvm/include/llvm/Frontend/Directive/DirectiveBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class Clause<string c> {
// Optional class holding value of the clause in flang AST.
string flangClass = "";

// If set to true, don't emit flang Unparser.
bit skipFlangUnparser = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename this to isArtificial? There may be more future cases for this, and more places to check this flag.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can easily tell what skipFlangUnparser means, but that it would be a consequence of isArtificial seems less obvious.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, what's more significant is the property of the clause object. skipFlangParser tells you what the consequence is, but not why it's there. There may be more consequences to follow that we haven't yet discovered, or that may appear in the future.


// If set to true, value is optional. Not optional by default.
bit isValueOptional = false;

Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Frontend/OpenMP/OMP.td
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def OMPC_CancellationConstructType : Clause<"cancellation_construct_type"> {
OMP_CANCELLATION_CONSTRUCT_None
];
let flangClass = "OmpCancellationConstructTypeClause";
let skipFlangUnparser = true;
}
def OMPC_Contains : Clause<"contains"> {
let clangClass = "OMPContainsClause";
Expand Down
4 changes: 4 additions & 0 deletions llvm/include/llvm/TableGen/DirectiveEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ class Clause : public BaseRecord {
return Def->getValueAsListOfDefs("allowedClauseValues");
}

bool skipFlangUnparser() const {
return Def->getValueAsBit("skipFlangUnparser");
}

bool isValueOptional() const { return Def->getValueAsBit("isValueOptional"); }

bool isValueList() const { return Def->getValueAsBit("isValueList"); }
Expand Down
2 changes: 2 additions & 0 deletions llvm/utils/TableGen/Basic/DirectiveEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,8 @@ static void generateFlangClauseUnparse(const DirectiveLanguage &DirLang,
OS << "\n";

for (const Clause Clause : DirLang.getClauses()) {
if (Clause.skipFlangUnparser())
continue;
if (!Clause.getFlangClass().empty()) {
if (Clause.isValueOptional() && Clause.getDefaultValue().empty()) {
OS << "void Unparse(const " << DirLang.getFlangClauseBaseClass()
Expand Down
Loading