[flang-commits] [flang] 84bf4b7 - [flang][OpenMP] Parser support for the unroll construct (5.1)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Tue Jan 17 04:38:40 PST 2023


Author: Abid Malik
Date: 2023-01-17T12:38:00Z
New Revision: 84bf4b7cdf8ff9dac7abbff3a85f6091a57d9366

URL: https://github.com/llvm/llvm-project/commit/84bf4b7cdf8ff9dac7abbff3a85f6091a57d9366
DIFF: https://github.com/llvm/llvm-project/commit/84bf4b7cdf8ff9dac7abbff3a85f6091a57d9366.diff

LOG: [flang][OpenMP] Parser support for the unroll construct (5.1)

added parser support for the unroll construct

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D138229

Added: 
    flang/test/Parser/omp-unroll-full.f90
    flang/test/Parser/omp-unroll.f90

Modified: 
    flang/lib/Parser/openmp-parsers.cpp
    flang/lib/Parser/unparse.cpp
    flang/lib/Semantics/resolve-directives.cpp
    llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 
    


################################################################################
diff  --git a/flang/lib/Parser/openmp-parsers.cpp b/flang/lib/Parser/openmp-parsers.cpp
index 49d6ef000f13..cbcc6bfef651 100644
--- a/flang/lib/Parser/openmp-parsers.cpp
+++ b/flang/lib/Parser/openmp-parsers.cpp
@@ -215,6 +215,7 @@ TYPE_PARSER(
         construct<OmpClause>(construct<OmpClause::DynamicAllocators>()) ||
     "FINAL" >> construct<OmpClause>(construct<OmpClause::Final>(
                    parenthesized(scalarLogicalExpr))) ||
+    "FULL" >> construct<OmpClause>(construct<OmpClause::Full>()) ||
     "FIRSTPRIVATE" >> construct<OmpClause>(construct<OmpClause::Firstprivate>(
                           parenthesized(Parser<OmpObjectList>{}))) ||
     "FROM" >> construct<OmpClause>(construct<OmpClause::From>(
@@ -251,6 +252,8 @@ TYPE_PARSER(
                          parenthesized(scalarIntExpr))) ||
     "ORDERED" >> construct<OmpClause>(construct<OmpClause::Ordered>(
                      maybe(parenthesized(scalarIntConstantExpr)))) ||
+    "PARTIAL" >> construct<OmpClause>(construct<OmpClause::Partial>(
+                     maybe(parenthesized(scalarIntConstantExpr)))) ||
     "PRIORITY" >> construct<OmpClause>(construct<OmpClause::Priority>(
                       parenthesized(scalarIntExpr))) ||
     "PRIVATE" >> construct<OmpClause>(construct<OmpClause::Private>(
@@ -337,7 +340,8 @@ TYPE_PARSER(sourced(construct<OmpLoopDirective>(first(
     "TEAMS DISTRIBUTE SIMD" >>
         pure(llvm::omp::Directive::OMPD_teams_distribute_simd),
     "TEAMS DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_teams_distribute),
-    "TILE" >> pure(llvm::omp::Directive::OMPD_tile)))))
+    "TILE" >> pure(llvm::omp::Directive::OMPD_tile),
+    "UNROLL" >> pure(llvm::omp::Directive::OMPD_unroll)))))
 
 TYPE_PARSER(sourced(construct<OmpBeginLoopDirective>(
     sourced(Parser<OmpLoopDirective>{}), Parser<OmpClauseList>{})))

diff  --git a/flang/lib/Parser/unparse.cpp b/flang/lib/Parser/unparse.cpp
index 892d34b146df..3c31a0fcad72 100644
--- a/flang/lib/Parser/unparse.cpp
+++ b/flang/lib/Parser/unparse.cpp
@@ -2153,6 +2153,9 @@ class UnparseVisitor {
     case llvm::omp::Directive::OMPD_tile:
       Word("TILE ");
       break;
+    case llvm::omp::Directive::OMPD_unroll:
+      Word("UNROLL ");
+      break;
     default:
       break;
     }

diff  --git a/flang/lib/Semantics/resolve-directives.cpp b/flang/lib/Semantics/resolve-directives.cpp
index ec66f7d2795f..98821c0ebdd2 100644
--- a/flang/lib/Semantics/resolve-directives.cpp
+++ b/flang/lib/Semantics/resolve-directives.cpp
@@ -1222,6 +1222,7 @@ bool OmpAttributeVisitor::Pre(const parser::OpenMPLoopConstruct &x) {
   case llvm::omp::Directive::OMPD_teams_distribute_parallel_do_simd:
   case llvm::omp::Directive::OMPD_teams_distribute_simd:
   case llvm::omp::Directive::OMPD_tile:
+  case llvm::omp::Directive::OMPD_unroll:
     PushContext(beginDir.source, beginDir.v);
     break;
   default:

diff  --git a/flang/test/Parser/omp-unroll-full.f90 b/flang/test/Parser/omp-unroll-full.f90
new file mode 100644
index 000000000000..3f26f61fc9aa
--- /dev/null
+++ b/flang/test/Parser/omp-unroll-full.f90
@@ -0,0 +1,22 @@
+! RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck --ignore-case %s
+! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s
+
+subroutine openmp_parse_unroll(x)
+
+  integer, intent(inout)::x
+
+!CHECK: !$omp unroll full
+!$omp  unroll full
+!CHECK: do
+  do x = 1, 100
+  	call F1()
+!CHECK: end do
+  end do
+!CHECK: !$omp end unroll
+!$omp end unroll
+
+!PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct
+!PARSE-TREE: OmpBeginLoopDirective
+!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = unroll
+!PARSE-TREE: OmpClauseList -> OmpClause -> Full
+END subroutine openmp_parse_unroll

diff  --git a/flang/test/Parser/omp-unroll.f90 b/flang/test/Parser/omp-unroll.f90
new file mode 100644
index 000000000000..93163a3390db
--- /dev/null
+++ b/flang/test/Parser/omp-unroll.f90
@@ -0,0 +1,24 @@
+! RUN: %flang_fc1 -fdebug-unparse-no-sema -fopenmp %s | FileCheck --ignore-case %s
+! RUN: %flang_fc1 -fdebug-dump-parse-tree -fopenmp %s | FileCheck --check-prefix="PARSE-TREE" %s
+
+subroutine openmp_parse_unroll(x)
+
+  integer, intent(inout)::x
+
+!CHECK: !$omp unroll partial(3)
+!$omp  unroll partial(3)
+!CHECK: do
+  do x = 1, 100
+  	call F1()
+!CHECK: end do
+  end do
+!CHECK: !$omp end unroll
+!$omp end unroll
+
+!PARSE-TREE: OpenMPConstruct -> OpenMPLoopConstruct
+!PARSE-TREE: OmpBeginLoopDirective
+!PARSE-TREE: OmpLoopDirective -> llvm::omp::Directive = unroll
+!PARSE-TREE: OmpClauseList -> OmpClause -> Partial -> Scalar -> Integer -> Constant -> Expr = '3_4'
+!PARSE-TREE: LiteralConstant -> IntLiteralConstant = '3'
+
+END subroutine openmp_parse_unroll

diff  --git a/llvm/include/llvm/Frontend/OpenMP/OMP.td b/llvm/include/llvm/Frontend/OpenMP/OMP.td
index 9c55f0f6e7b9..371376177051 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMP.td
+++ b/llvm/include/llvm/Frontend/OpenMP/OMP.td
@@ -72,8 +72,14 @@ def OMPC_Sizes: Clause<"sizes"> {
   let flangClass = "ScalarIntExpr";
   let isValueList = true;
   }
-def OMPC_Full: Clause<"full"> { let clangClass = "OMPFullClause"; }
-def OMPC_Partial: Clause<"partial"> { let clangClass = "OMPPartialClause"; }
+def OMPC_Full: Clause<"full"> { 
+  let clangClass = "OMPFullClause"; 
+}
+def OMPC_Partial: Clause<"partial"> { 
+  let clangClass = "OMPPartialClause";
+  let flangClass = "ScalarIntConstantExpr"; 
+  let isValueOptional = true;
+ }
 def OMPC_FirstPrivate : Clause<"firstprivate"> {
   let clangClass = "OMPFirstprivateClause";
   let flangClass = "OmpObjectList";


        


More information about the flang-commits mailing list