Currently, local allocatables and contiguous/scalar pointers (and some
other conditions) are lowered to a set of independent variables in FIR
(one for the address, one for each bound and one for character length).
The intention was to help LLVM get rids of descriptors. But LLVM knows
how to do that anyway in those cases:
```
subroutine foo(x)
real, target :: x(100)
real, pointer, contiguous :: p(:)
p => x
call bar(p(50))
end subroutine
```
The output fir the option on or off is the same after llvm opt -O1,
there is no descriptor anymore, the indirection is removed.
```
define void @foo_(ptr %0) local_unnamed_addr {
%2 = getelementptr [100 x float], ptr %0, i64 0, i64 49
tail call void @bar_(ptr %2)
ret void
}
```
So the benefit of not using a descriptor in lowering is questionable,
and although it is abstracted as much as possible in the so called
MutableBoxValue class that represent allocatable/pointer in lowering
it is still causing bugs from time to time, and will also be a bit
problematic when emitting debug info for the pointer/allocatable.
In HLFIR lowering, the simplification to always use a descriptor in
lowering was already made. This patch allows decorrelating the impact
from this change from the bigger impact HLFIR will have so that it
is easier to get feedback if this causes performance issues.
The lowering tests relying on the previous behavior are only updated
to set back this option to true. The reason is that I think we should
preserve coverage of the code dealing with the "non descriptor" approach
in lowering until we actually get rid of it. The other reason is that
the test will have to be or are already covered by equivalent HLFIR
tests, which use descriptors.
Differential Revision: https://reviews.llvm.org/D148910
66 lines
2.7 KiB
Fortran
66 lines
2.7 KiB
Fortran
! RUN: bbc --use-desc-for-alloc=false -fopenmp -emit-fir %s -o - | FileCheck %s
|
|
|
|
! This test checks the lowering of atomic write
|
|
|
|
!CHECK: func @_QQmain() attributes {fir.bindc_name = "ompatomicwrite"} {
|
|
!CHECK: %[[VAR_X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"}
|
|
!CHECK: %[[VAR_Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"}
|
|
!CHECK: %[[VAR_Z:.*]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFEz"}
|
|
!CHECK: %[[CONST_44:.*]] = arith.constant 44 : i32
|
|
!CHECK: omp.atomic.write %[[VAR_X]] = %[[CONST_44]] hint(uncontended) memory_order(seq_cst) : !fir.ref<i32>, i32
|
|
!CHECK: %[[CONST_7:.*]] = arith.constant 7 : i32
|
|
!CHECK: {{.*}} = fir.load %[[VAR_Y]] : !fir.ref<i32>
|
|
!CHECK: %[[VAR_7y:.*]] = arith.muli %[[CONST_7]], {{.*}} : i32
|
|
!CHECK: omp.atomic.write %[[VAR_X]] = %[[VAR_7y]] memory_order(relaxed) : !fir.ref<i32>, i32
|
|
!CHECK: %[[CONST_10:.*]] = arith.constant 10 : i32
|
|
!CHECK: {{.*}} = fir.load %[[VAR_X]] : !fir.ref<i32>
|
|
!CHECK: {{.*}} = arith.muli %[[CONST_10]], {{.*}} : i32
|
|
!CHECK: {{.*}} = fir.load %[[VAR_Z]] : !fir.ref<i32>
|
|
!CHECK: %[[CONST_2:.*]] = arith.constant 2 : i32
|
|
!CHECK: {{.*}} = arith.divsi {{.*}}, %[[CONST_2]] : i32
|
|
!CHECK: {{.*}} = arith.addi {{.*}}, {{.*}} : i32
|
|
!CHECK: omp.atomic.write %[[VAR_Y]] = {{.*}} hint(speculative) memory_order(release) : !fir.ref<i32>, i32
|
|
!CHECK: return
|
|
!CHECK: }
|
|
|
|
program OmpAtomicWrite
|
|
use omp_lib
|
|
integer :: x, y, z
|
|
!$omp atomic seq_cst write hint(omp_sync_hint_uncontended)
|
|
x = 8*4 + 12
|
|
|
|
!$omp atomic write relaxed
|
|
x = 7 * y
|
|
|
|
!$omp atomic write release hint(omp_sync_hint_speculative)
|
|
y = 10*x + z/2
|
|
end program OmpAtomicWrite
|
|
|
|
! Test lowering atomic read for pointer variables.
|
|
! Please notice to use %[[VAL_1]] for operands of atomic operation, instead
|
|
! of %[[VAL_0]].
|
|
|
|
!CHECK-LABEL: func.func @_QPatomic_write_pointer() {
|
|
!CHECK: %[[VAL_0:.*]] = fir.alloca !fir.box<!fir.ptr<i32>> {bindc_name = "x", uniq_name = "_QFatomic_write_pointerEx"}
|
|
!CHECK: %[[VAL_1:.*]] = fir.alloca !fir.ptr<i32> {uniq_name = "_QFatomic_write_pointerEx.addr"}
|
|
!CHECK: %[[VAL_2:.*]] = fir.zero_bits !fir.ptr<i32>
|
|
!CHECK: fir.store %[[VAL_2]] to %[[VAL_1]] : !fir.ref<!fir.ptr<i32>>
|
|
!CHECK: %[[VAL_3:.*]] = arith.constant 1 : i32
|
|
!CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.ptr<i32>>
|
|
!CHECK: omp.atomic.write %[[VAL_4]] = %[[VAL_3]] : !fir.ptr<i32>, i32
|
|
!CHECK: %[[VAL_5:.*]] = arith.constant 2 : i32
|
|
!CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.ptr<i32>>
|
|
!CHECK: fir.store %[[VAL_5]] to %[[VAL_6]] : !fir.ptr<i32>
|
|
!CHECK: return
|
|
!CHECK: }
|
|
|
|
subroutine atomic_write_pointer()
|
|
integer, pointer :: x
|
|
|
|
!$omp atomic write
|
|
x = 1
|
|
|
|
x = 2
|
|
end
|
|
|