[flang-commits] [flang] d1653c8 - [Flang][OpenMP] NFC: Versions of critical, master tests with HLFIR flow

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Tue Sep 26 23:50:28 PDT 2023


Author: Kiran Chandramohan
Date: 2023-09-27T06:29:12Z
New Revision: d1653c8e9ba9fa23add726e1c772419cb968d0fa

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

LOG: [Flang][OpenMP] NFC: Versions of critical, master tests with HLFIR flow

The conversion to LLVM dialect test is moved and the translation to LLVM
IR is removed from these tests. These are covered separately in
convert-to-llvm-openmp-and-fir.fir (for critical, master is already
tested in this file) and MLIR to LLVM IR tests.

Added: 
    flang/test/Lower/OpenMP/critical.f90
    flang/test/Lower/OpenMP/master.f90

Modified: 
    flang/test/Fir/convert-to-llvm-openmp-and-fir.fir

Removed: 
    


################################################################################
diff  --git a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
index 21334e4aacd613b..ba1a15bf773d2ef 100644
--- a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
+++ b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir
@@ -864,3 +864,30 @@ func.func @sub_() {
     }
     return
   }
+
+// -----
+
+// CHECK:  omp.critical.declare @help   hint(contended)
+omp.critical.declare @help hint(contended)
+
+// CHECK: llvm.func @omp_critical_() {
+func.func @omp_critical_() {
+// CHECK: %[[X_REF:.*]] = llvm.alloca %{{.*}} x i32 {bindc_name = "x", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_criticalEx"} : (i64) -> !llvm.ptr<i32>
+  %0 = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFomp_criticalEx"}
+// CHECK: %[[Y_REF:.*]] = llvm.alloca %{{.*}} x i32 {bindc_name = "y", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_criticalEy"} : (i64) -> !llvm.ptr<i32>
+  %1 = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFomp_criticalEy"}
+// CHECK: omp.critical(@help)
+  omp.critical(@help) {
+// CHECK: %[[X_VAL:.*]] = llvm.load %[[X_REF]] : !llvm.ptr<i32>
+    %2 = fir.load %0 : !fir.ref<i32>
+// CHECK: %[[Y_VAL:.*]] = llvm.load %[[Y_REF]] : !llvm.ptr<i32>
+    %3 = fir.load %1 : !fir.ref<i32>
+// CHECK: %[[RESULT:.*]] = llvm.add %[[X_VAL]], %[[Y_VAL]]  : i32
+    %4 = arith.addi %2, %3 : i32
+// CHECK: llvm.store %[[RESULT]], %[[X_REF]] : !llvm.ptr<i32>
+    fir.store %4 to %0 : !fir.ref<i32>
+// CHECK: omp.terminator
+    omp.terminator
+  }
+  return
+}

diff  --git a/flang/test/Lower/OpenMP/critical.f90 b/flang/test/Lower/OpenMP/critical.f90
new file mode 100644
index 000000000000000..9fbd172df96421c
--- /dev/null
+++ b/flang/test/Lower/OpenMP/critical.f90
@@ -0,0 +1,28 @@
+!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
+
+!CHECK: omp.critical.declare @help2 hint(none)
+!CHECK: omp.critical.declare @help1 hint(contended)
+
+subroutine omp_critical()
+  use omp_lib
+  integer :: x, y
+!CHECK: omp.critical(@help1)
+!$OMP CRITICAL(help1) HINT(omp_lock_hint_contended)
+  x = x + y
+!CHECK: omp.terminator
+!$OMP END CRITICAL(help1)
+
+! Test that the same name can be used again
+! Also test with the zero hint expression
+!CHECK: omp.critical(@help2)
+!$OMP CRITICAL(help2) HINT(omp_lock_hint_none)
+  x = x - y
+!CHECK: omp.terminator
+!$OMP END CRITICAL(help2)
+
+!CHECK: omp.critical
+!$OMP CRITICAL
+  y = x + y
+!CHECK: omp.terminator
+!$OMP END CRITICAL
+end subroutine omp_critical

diff  --git a/flang/test/Lower/OpenMP/master.f90 b/flang/test/Lower/OpenMP/master.f90
new file mode 100644
index 000000000000000..7db1be4f005b571
--- /dev/null
+++ b/flang/test/Lower/OpenMP/master.f90
@@ -0,0 +1,99 @@
+!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
+
+!===============================================================================
+! parallel construct with function call which has master construct internally
+!===============================================================================
+!CHECK-LABEL: func @_QPomp_master
+subroutine omp_master()
+
+!CHECK: omp.master  {
+!$omp master
+
+    !CHECK: fir.call @_QPmaster() {{.*}}: () -> ()
+    call master()
+
+!CHECK: omp.terminator
+!$omp end master
+
+end subroutine omp_master
+
+!CHECK-LABEL: func @_QPparallel_function_master
+subroutine parallel_function_master()
+
+!CHECK: omp.parallel {
+!$omp parallel
+
+    !CHECK: fir.call @_QPfoo() {{.*}}: () -> ()
+    call foo()
+
+!CHECK: omp.terminator
+!$omp end parallel
+
+end subroutine parallel_function_master
+
+!===============================================================================
+! master construct nested inside parallel construct
+!===============================================================================
+
+!CHECK-LABEL: func @_QPomp_parallel_master
+subroutine omp_parallel_master()
+
+!CHECK: omp.parallel {
+!$omp parallel
+    !CHECK: fir.call @_QPparallel() {{.*}}: () -> ()
+    call parallel()
+
+!CHECK: omp.master {
+!$omp master
+
+    !CHECK: fir.call @_QPparallel_master() {{.*}}: () -> ()
+    call parallel_master()
+
+!CHECK: omp.terminator
+!$omp end master
+
+!CHECK: omp.terminator
+!$omp end parallel
+
+end subroutine omp_parallel_master
+
+!===============================================================================
+! master construct nested inside parallel construct with conditional flow
+!===============================================================================
+
+!CHECK-LABEL: func @_QPomp_master_parallel
+subroutine omp_master_parallel()
+    integer :: alpha, beta, gama
+    alpha = 4
+    beta = 5
+    gama = 6
+
+!CHECK: omp.master {
+!$omp master
+
+    !CHECK: %{{.*}} = fir.load %{{.*}}
+    !CHECK: %{{.*}} = fir.load %{{.*}}
+    !CHECK: %[[RESULT:.*]] = arith.cmpi sge, %{{.*}}, %{{.*}}
+    !CHECK: fir.if %[[RESULT]] {
+    if (alpha .ge. gama) then
+
+!CHECK: omp.parallel {
+!$omp parallel
+        !CHECK: fir.call @_QPinside_if_parallel() {{.*}}: () -> ()
+        call inside_if_parallel()
+
+!CHECK: omp.terminator
+!$omp end parallel
+
+        !CHECK: %{{.*}} = fir.load %{{.*}}
+        !CHECK: %{{.*}} = fir.load %{{.*}}
+        !CHECK: %{{.*}} = arith.addi %{{.*}}, %{{.*}}
+        !CHECK: hlfir.assign %{{.*}} to %{{.*}}#0 : i32, !fir.ref<i32>
+        beta = alpha + gama
+    end if
+    !CHECK: else
+
+!CHECK: omp.terminator
+!$omp end master
+
+end subroutine omp_master_parallel


        


More information about the flang-commits mailing list