[flang-commits] [flang] Single to hlfir (PR #69877)
via flang-commits
flang-commits at lists.llvm.org
Sun Oct 22 05:30:09 PDT 2023
https://github.com/harishch4 created https://github.com/llvm/llvm-project/pull/69877
None
>From 858686de8a67014c99b0a2b412e811b513381610 Mon Sep 17 00:00:00 2001
From: Harish Chambeti <hchambet at amd.com>
Date: Mon, 16 Oct 2023 10:56:07 +0530
Subject: [PATCH 1/2] [Flang] Move openmp single construct test to hlfir
---
flang/test/Lower/OpenMP/single.f90 | 121 +++++++++++++++++++++++++++++
1 file changed, 121 insertions(+)
create mode 100644 flang/test/Lower/OpenMP/single.f90
diff --git a/flang/test/Lower/OpenMP/single.f90 b/flang/test/Lower/OpenMP/single.f90
new file mode 100644
index 000000000000000..22d9bb1d5d70ed8
--- /dev/null
+++ b/flang/test/Lower/OpenMP/single.f90
@@ -0,0 +1,121 @@
+!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+!RUN: bbc -emit-fir -fopenmp %s -o - | FileCheck %s
+
+!===============================================================================
+! Single construct
+!===============================================================================
+
+!CHECK-LABEL: func @_QPomp_single
+!CHECK-SAME: (%[[x:.*]]: !fir.ref<i32> {fir.bindc_name = "x"})
+subroutine omp_single(x)
+ integer, intent(inout) :: x
+ !CHECK: omp.parallel
+ !$omp parallel
+ !CHECK: omp.single
+ !$omp single
+ !CHECK: %[[xval:.*]] = fir.load %[[x]] : !fir.ref<i32>
+ !CHECK: %[[res:.*]] = arith.addi %[[xval]], %{{.*}} : i32
+ !CHECK: fir.store %[[res]] to %[[x]] : !fir.ref<i32>
+ x = x + 12
+ !CHECK: omp.terminator
+ !$omp end single
+ !CHECK: omp.terminator
+ !$omp end parallel
+end subroutine omp_single
+
+!===============================================================================
+! Single construct with nowait
+!===============================================================================
+
+!CHECK-LABEL: func @_QPomp_single_nowait
+!CHECK-SAME: (%[[x:.*]]: !fir.ref<i32> {fir.bindc_name = "x"})
+subroutine omp_single_nowait(x)
+ integer, intent(inout) :: x
+ !CHECK: omp.parallel
+ !$omp parallel
+ !CHECK: omp.single nowait
+ !$omp single
+ !CHECK: %[[xval:.*]] = fir.load %[[x]] : !fir.ref<i32>
+ !CHECK: %[[res:.*]] = arith.addi %[[xval]], %{{.*}} : i32
+ !CHECK: fir.store %[[res]] to %[[x]] : !fir.ref<i32>
+ x = x + 12
+ !CHECK: omp.terminator
+ !$omp end single nowait
+ !CHECK: omp.terminator
+ !$omp end parallel
+end subroutine omp_single_nowait
+
+!===============================================================================
+! Single construct with allocate
+!===============================================================================
+
+!CHECK-LABEL: func @_QPsingle_allocate
+subroutine single_allocate()
+ use omp_lib
+ integer :: x
+ !CHECK: omp.parallel {
+ !$omp parallel
+ !CHECK: omp.single allocate(%{{.+}} : i32 -> %{{.+}} : !fir.ref<i32>) {
+ !$omp single allocate(omp_high_bw_mem_alloc: x) private(x)
+ !CHECK: arith.addi
+ x = x + 12
+ !CHECK: omp.terminator
+ !$omp end single
+ !CHECK: omp.terminator
+ !$omp end parallel
+end subroutine single_allocate
+
+!===============================================================================
+! Single construct with private/firstprivate
+!===============================================================================
+
+! CHECK-LABEL: func.func @_QPsingle_privatization(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
+! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f64> {fir.bindc_name = "y"}) {
+! CHECK: omp.single {
+! CHECK: %[[VAL_2:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFsingle_privatizationEx"}
+! CHECK: %[[VAL_3:.*]] = fir.alloca f64 {bindc_name = "y", pinned, uniq_name = "_QFsingle_privatizationEy"}
+! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_1]] : !fir.ref<f64>
+! CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ref<f64>
+! CHECK: fir.call @_QPbar(%[[VAL_2]], %[[VAL_3]]) {{.*}}: (!fir.ref<f32>, !fir.ref<f64>) -> ()
+! CHECK: omp.terminator
+! CHECK: }
+! CHECK: return
+! CHECK: }
+
+subroutine single_privatization(x, y)
+ real :: x
+ real(8) :: y
+
+ !$omp single private(x) firstprivate(y)
+ call bar(x, y)
+ !$omp end single
+end subroutine
+
+! CHECK-LABEL: func.func @_QPsingle_privatization2(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
+! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f64> {fir.bindc_name = "y"}) {
+! CHECK: omp.parallel {
+! CHECK: omp.single {
+! CHECK: %[[VAL_2:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFsingle_privatization2Ex"}
+! CHECK: %[[VAL_3:.*]] = fir.alloca f64 {bindc_name = "y", pinned, uniq_name = "_QFsingle_privatization2Ey"}
+! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_1]] : !fir.ref<f64>
+! CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ref<f64>
+! CHECK: fir.call @_QPbar(%[[VAL_2]], %[[VAL_3]]) {{.*}}: (!fir.ref<f32>, !fir.ref<f64>) -> ()
+! CHECK: omp.terminator
+! CHECK: }
+! CHECK: omp.terminator
+! CHECK: }
+! CHECK: return
+! CHECK: }
+
+subroutine single_privatization2(x, y)
+ real :: x
+ real(8) :: y
+
+ !$omp parallel
+ !$omp single private(x) firstprivate(y)
+ call bar(x, y)
+ !$omp end single
+ !$omp end parallel
+end subroutine
>From 09f5914c388209edb11ff5fd2ba8fb3a9734ad28 Mon Sep 17 00:00:00 2001
From: Harish Chambeti <hchambet at amd.com>
Date: Mon, 16 Oct 2023 11:03:26 +0530
Subject: [PATCH 2/2] Changes for HLFIR Lowering
---
flang/test/Lower/OpenMP/single.f90 | 46 ++++++++++++++++++------------
1 file changed, 28 insertions(+), 18 deletions(-)
diff --git a/flang/test/Lower/OpenMP/single.f90 b/flang/test/Lower/OpenMP/single.f90
index 22d9bb1d5d70ed8..a97ec27e1cd0624 100644
--- a/flang/test/Lower/OpenMP/single.f90
+++ b/flang/test/Lower/OpenMP/single.f90
@@ -1,5 +1,5 @@
-!RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
-!RUN: bbc -emit-fir -fopenmp %s -o - | FileCheck %s
+!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
+!RUN: bbc -emit-hlfir -fopenmp %s -o - | FileCheck %s
!===============================================================================
! Single construct
@@ -9,13 +9,14 @@
!CHECK-SAME: (%[[x:.*]]: !fir.ref<i32> {fir.bindc_name = "x"})
subroutine omp_single(x)
integer, intent(inout) :: x
+ !CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[x]] {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFomp_singleEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
!CHECK: omp.parallel
!$omp parallel
!CHECK: omp.single
!$omp single
- !CHECK: %[[xval:.*]] = fir.load %[[x]] : !fir.ref<i32>
+ !CHECK: %[[xval:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>
!CHECK: %[[res:.*]] = arith.addi %[[xval]], %{{.*}} : i32
- !CHECK: fir.store %[[res]] to %[[x]] : !fir.ref<i32>
+ !CHECK: hlfir.assign %[[res]] to %[[X_DECL]]#0 : i32, !fir.ref<i32>
x = x + 12
!CHECK: omp.terminator
!$omp end single
@@ -31,13 +32,14 @@ end subroutine omp_single
!CHECK-SAME: (%[[x:.*]]: !fir.ref<i32> {fir.bindc_name = "x"})
subroutine omp_single_nowait(x)
integer, intent(inout) :: x
+ !CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[x]] {fortran_attrs = #fir.var_attrs<intent_inout>, uniq_name = "_QFomp_single_nowaitEx"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
!CHECK: omp.parallel
!$omp parallel
!CHECK: omp.single nowait
!$omp single
- !CHECK: %[[xval:.*]] = fir.load %[[x]] : !fir.ref<i32>
+ !CHECK: %[[xval:.*]] = fir.load %[[X_DECL]]#0 : !fir.ref<i32>
!CHECK: %[[res:.*]] = arith.addi %[[xval]], %{{.*}} : i32
- !CHECK: fir.store %[[res]] to %[[x]] : !fir.ref<i32>
+ !CHECK: hlfir.assign %[[res]] to %[[X_DECL]]#0 : i32, !fir.ref<i32>
x = x + 12
!CHECK: omp.terminator
!$omp end single nowait
@@ -70,14 +72,18 @@ end subroutine single_allocate
!===============================================================================
! CHECK-LABEL: func.func @_QPsingle_privatization(
-! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f64> {fir.bindc_name = "y"}) {
-! CHECK: omp.single {
-! CHECK: %[[VAL_2:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFsingle_privatizationEx"}
-! CHECK: %[[VAL_3:.*]] = fir.alloca f64 {bindc_name = "y", pinned, uniq_name = "_QFsingle_privatizationEy"}
-! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_1]] : !fir.ref<f64>
-! CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ref<f64>
-! CHECK: fir.call @_QPbar(%[[VAL_2]], %[[VAL_3]]) {{.*}}: (!fir.ref<f32>, !fir.ref<f64>) -> ()
+! CHECK: %[[VAL_0_DECL:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFsingle_privatizationEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! CHECK: %[[VAL_1_DECL:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFsingle_privatizationEy"} : (!fir.ref<f64>) -> (!fir.ref<f64>, !fir.ref<f64>)
+! CHECK: omp.single {
+! CHECK: %[[X:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFsingle_privatizationEx"}
+! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {uniq_name = "_QFsingle_privatizationEx"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! CHECK: %[[Y:.*]] = fir.alloca f64 {bindc_name = "y", pinned, uniq_name = "_QFsingle_privatizationEy"}
+! CHECK: %[[Y_DECL:.*]]:2 = hlfir.declare %[[Y]] {uniq_name = "_QFsingle_privatizationEy"} : (!fir.ref<f64>) -> (!fir.ref<f64>, !fir.ref<f64>)
+! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_1_DECL]]#1 : !fir.ref<f64>
+! CHECK: fir.store %[[VAL_6]] to %[[Y_DECL]]#1 : !fir.ref<f64>
+! CHECK: fir.call @_QPbar(%[[X_DECL]]#1, %[[Y_DECL]]#1) fastmath<contract> : (!fir.ref<f32>, !fir.ref<f64>) -> ()
! CHECK: omp.terminator
! CHECK: }
! CHECK: return
@@ -95,13 +101,17 @@ subroutine single_privatization(x, y)
! CHECK-LABEL: func.func @_QPsingle_privatization2(
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<f32> {fir.bindc_name = "x"},
! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref<f64> {fir.bindc_name = "y"}) {
+! CHECK: %[[VAL_0_DECL:.*]]:2 = hlfir.declare %[[VAL_0]] {uniq_name = "_QFsingle_privatization2Ex"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! CHECK: %[[VAL_1_DECL:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = "_QFsingle_privatization2Ey"} : (!fir.ref<f64>) -> (!fir.ref<f64>, !fir.ref<f64>)
! CHECK: omp.parallel {
! CHECK: omp.single {
-! CHECK: %[[VAL_2:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFsingle_privatization2Ex"}
-! CHECK: %[[VAL_3:.*]] = fir.alloca f64 {bindc_name = "y", pinned, uniq_name = "_QFsingle_privatization2Ey"}
-! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_1]] : !fir.ref<f64>
-! CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ref<f64>
-! CHECK: fir.call @_QPbar(%[[VAL_2]], %[[VAL_3]]) {{.*}}: (!fir.ref<f32>, !fir.ref<f64>) -> ()
+! CHECK: %[[X:.*]] = fir.alloca f32 {bindc_name = "x", pinned, uniq_name = "_QFsingle_privatization2Ex"}
+! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {uniq_name = "_QFsingle_privatization2Ex"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+! CHECK: %[[Y:.*]] = fir.alloca f64 {bindc_name = "y", pinned, uniq_name = "_QFsingle_privatization2Ey"}
+! CHECK: %[[Y_DECL:.*]]:2 = hlfir.declare %[[Y]] {uniq_name = "_QFsingle_privatization2Ey"} : (!fir.ref<f64>) -> (!fir.ref<f64>, !fir.ref<f64>)
+! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_1_DECL]]#1 : !fir.ref<f64>
+! CHECK: fir.store %[[VAL_6]] to %[[Y_DECL]]#1 : !fir.ref<f64>
+! CHECK: fir.call @_QPbar(%[[X_DECL]]#1, %[[Y_DECL]]#1) fastmath<contract> : (!fir.ref<f32>, !fir.ref<f64>) -> ()
! CHECK: omp.terminator
! CHECK: }
! CHECK: omp.terminator
More information about the flang-commits
mailing list