[flang][OpenMP] Parser support for the unroll construct (5.1)
authorAbid Malik <abidmuslim@gmail.com>
Tue, 17 Jan 2023 11:54:23 +0000 (11:54 +0000)
committerKiran Chandramohan <kiran.chandramohan@arm.com>
Tue, 17 Jan 2023 12:38:00 +0000 (12:38 +0000)
added parser support for the unroll construct

Reviewed By: kiranchandramohan

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

flang/lib/Parser/openmp-parsers.cpp
flang/lib/Parser/unparse.cpp
flang/lib/Semantics/resolve-directives.cpp
flang/test/Parser/omp-unroll-full.f90 [new file with mode: 0644]
flang/test/Parser/omp-unroll.f90 [new file with mode: 0644]
llvm/include/llvm/Frontend/OpenMP/OMP.td

index 49d6ef0..cbcc6bf 100644 (file)
@@ -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>{})))
index 892d34b..3c31a0f 100644 (file)
@@ -2153,6 +2153,9 @@ public:
     case llvm::omp::Directive::OMPD_tile:
       Word("TILE ");
       break;
+    case llvm::omp::Directive::OMPD_unroll:
+      Word("UNROLL ");
+      break;
     default:
       break;
     }
index ec66f7d..98821c0 100644 (file)
@@ -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 (file)
index 0000000..3f26f61
--- /dev/null
@@ -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 (file)
index 0000000..93163a3
--- /dev/null
@@ -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
index 9c55f0f..3713761 100644 (file)
@@ -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";