Skip to content

Commit ebd0d60

Browse files
authored
merge main into amd-staging (llvm#1403)
2 parents cff6501 + 022c58a commit ebd0d60

File tree

21 files changed

+721
-200
lines changed

21 files changed

+721
-200
lines changed

flang/lib/Lower/ConvertExprToHLFIR.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ class HlfirDesignatorBuilder {
279279
gen(const Fortran::evaluate::SymbolRef &symbolRef) {
280280
if (std::optional<fir::FortranVariableOpInterface> varDef =
281281
getSymMap().lookupVariableDefinition(symbolRef)) {
282-
if (symbolRef.get().GetUltimate().test(Fortran::semantics::Symbol::Flag::CrayPointee)) {
282+
if (symbolRef.get().GetUltimate().test(
283+
Fortran::semantics::Symbol::Flag::CrayPointee)) {
283284
// The pointee is represented with a descriptor inheriting
284285
// the shape and type parameters of the pointee.
285286
// We have to update the base_addr to point to the current

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2306,7 +2306,7 @@ void OmpAttributeVisitor::Post(const parser::Name &name) {
23062306
// the scope of the parallel region, and not in this scope.
23072307
// TODO: check whether this should be caught in IsObjectWithDSA
23082308
!symbol->test(Symbol::Flag::OmpPrivate)) {
2309-
if (symbol->test(Symbol::Flag::CrayPointee)) {
2309+
if (symbol->GetUltimate().test(Symbol::Flag::CrayPointee)) {
23102310
std::string crayPtrName{
23112311
semantics::GetCrayPointer(*symbol).name().ToString()};
23122312
if (!IsObjectWithDSA(*currScope().FindSymbol(crayPtrName)))
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
! Test lowering of Cray pointee references.
2+
! RUN: flang-new -fc1 -emit-hlfir -fopenmp %s -o - 2>&1 | FileCheck %s
3+
4+
module test_host_assoc_cray_pointer
5+
! CHECK-LABEL: fir.global @_QMtest_host_assoc_cray_pointerEivar : i64
6+
real*8 var(*)
7+
! CHECK-LABEL: fir.global @_QMtest_host_assoc_cray_pointerEvar : !fir.array<?xf64>
8+
pointer(ivar,var)
9+
10+
contains
11+
12+
! CHECK-LABEL: func.func @_QMtest_host_assoc_cray_pointerPset_cray_pointer()
13+
subroutine set_cray_pointer
14+
! CHECK: %[[ALLOCA:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf64>>>
15+
! CHECK: %[[IVAR_ADDR:.*]] = fir.address_of(@_QMtest_host_assoc_cray_pointerEivar) : !fir.ref<i64>
16+
! CHECK: %[[IVAR_DECL:.*]]:2 = hlfir.declare %[[IVAR_ADDR]] {uniq_name = "_QMtest_host_assoc_cray_pointerEivar"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
17+
! CHECK: %[[VAR_DECL:.*]]:2 = hlfir.declare %[[ALLOCA]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMtest_host_assoc_cray_pointerEvar"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>)
18+
real*8 pointee(2)
19+
pointee(1) = 42.0
20+
21+
ivar = loc(pointee)
22+
23+
!$omp parallel default(none) shared(ivar)
24+
! CHECK: omp.parallel
25+
! CHECK: %[[I_01:.*]] = fir.convert %[[IVAR_DECL]]#0 : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i64>>
26+
! CHECK: %[[I_02:.*]] = fir.load %[[I_01]] : !fir.ref<!fir.ptr<i64>>
27+
! CHECK: %[[I_03:.*]] = fir.convert %[[VAR_DECL]]#0 : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>) -> !fir.ref<!fir.box<none>>
28+
! CHECK: %[[I_04:.*]] = fir.convert %[[I_02]] : (!fir.ptr<i64>) -> !fir.llvm_ptr<i8>
29+
! CHECK: fir.call @_FortranAPointerAssociateScalar(%[[I_03]], %[[I_04]]) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
30+
print *, var(1)
31+
!$omp end parallel
32+
end subroutine
33+
end module
34+
35+
program test_cray_pointers_01
36+
real*8, save :: var(*)
37+
! CHECK: %[[BOX_ALLOCA:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xf64>>>
38+
! CHECK: %[[IVAR_ALLOCA:.*]] = fir.alloca i64 {bindc_name = "ivar", uniq_name = "_QFEivar"}
39+
! CHECK: %[[IVAR_DECL_01:.*]]:2 = hlfir.declare %[[IVAR_ALLOCA]] {uniq_name = "_QFEivar"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
40+
pointer(ivar,var)
41+
! CHECK: %[[VAR_DECL_02:.*]]:2 = hlfir.declare %[[BOX_ALLOCA]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFEvar"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf64>>>>)
42+
43+
real*8 pointee(2)
44+
pointee(1) = 42.0
45+
46+
!$omp parallel default(none) private(ivar) shared(pointee)
47+
! CHECK: omp.parallel private({{.*}} %[[IVAR_DECL_01]]#0 -> %[[ARG0:.*]] : !fir.ref<i64>) {
48+
! CHECK: %[[IVAR_DECL_02:.*]]:2 = hlfir.declare %[[ARG0]] {uniq_name = "_QFEivar"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
49+
! CHECK: hlfir.assign %{{.*}} to %[[IVAR_DECL_02]]#0 : i64, !fir.ref<i64>
50+
ivar = loc(pointee)
51+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
52+
! CHECK: %[[CONST_2:.*]] = arith.constant 2 : i32
53+
! CHECK: {{.*}} = math.fpowi {{.*}}, %[[CONST_2]] fastmath<contract> : f64, i32
54+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
55+
var(1) = var(1) ** 2
56+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
57+
print *, var(1)
58+
! CHECK: omp.terminator
59+
! CHECK: }
60+
!$omp end parallel
61+
end program test_cray_pointers_01
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
! Test lowering of Cray pointee references.
2+
! RUN: flang-new -fc1 -emit-hlfir -fopenmp %s -o - 2>&1 | FileCheck %s
3+
4+
! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "test_cray_pointers_02"}
5+
program test_cray_pointers_02
6+
implicit none
7+
8+
! CHECK: fir.call @_QPnone_shared() fastmath<contract> : () -> ()
9+
! CHECK: fir.call @_QPnone_private() fastmath<contract> : () -> ()
10+
! CHECK: fir.call @_QPnone_firstprivate() fastmath<contract> : () -> ()
11+
! CHECK: fir.call @_QPprivate_shared() fastmath<contract> : () -> ()
12+
! CHECK: fir.call @_QPprivate_firstprivate() fastmath<contract> : () -> ()
13+
! CHECK: fir.call @_QPfirstprivate_shared() fastmath<contract> : () -> ()
14+
! CHECK: fir.call @_QPfirstprivate_private() fastmath<contract> : () -> ()
15+
call none_shared()
16+
call none_private()
17+
call none_firstprivate()
18+
call private_shared()
19+
call private_firstprivate()
20+
call firstprivate_shared()
21+
call firstprivate_private()
22+
! CHECK: return
23+
! CHECK: }
24+
end program test_cray_pointers_02
25+
26+
! CHECK-LABEL: func.func @_QPnone_shared()
27+
subroutine none_shared()
28+
implicit none
29+
integer var(*)
30+
pointer(ivar,var)
31+
integer pointee(8)
32+
33+
pointee(1) = 42
34+
ivar = loc(pointee)
35+
36+
!$omp parallel num_threads(1) default(none) shared(ivar)
37+
! CHECK: omp.parallel
38+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
39+
! CHECK: {{.*}} = arith.divsi
40+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
41+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
42+
var(1) = var(1) / 2
43+
print '(A24,I6)', 'none_shared', var(1)
44+
!$omp end parallel
45+
! CHECK: return
46+
end subroutine
47+
48+
! CHECK-LABEL: func.func @_QPnone_private()
49+
subroutine none_private()
50+
implicit none
51+
integer var(*)
52+
pointer(ivar,var)
53+
integer pointee(8)
54+
55+
pointee(1) = 42
56+
ivar = loc(pointee)
57+
58+
!$omp parallel num_threads(1) default(none) private(ivar) shared(pointee)
59+
! CHECK: omp.parallel
60+
ivar = loc(pointee)
61+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
62+
! CHECK: {{.*}} = arith.addi
63+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
64+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
65+
var(1) = var(1) + 2
66+
print '(A24,I6)', 'none_private', var(1)
67+
!$omp end parallel
68+
! CHECK: return
69+
end subroutine
70+
71+
! CHECK-LABEL: func.func @_QPnone_firstprivate()
72+
subroutine none_firstprivate()
73+
implicit none
74+
integer var(*)
75+
pointer(ivar,var)
76+
integer pointee(8)
77+
78+
pointee(1) = 42
79+
ivar = loc(pointee)
80+
81+
!$omp parallel num_threads(1) default(none) firstprivate(ivar)
82+
! CHECK: omp.parallel
83+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
84+
! CHECK: {{.*}} = arith.muli
85+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
86+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
87+
var(1) = var(1) * 2
88+
print '(A24,I6)', 'none_firstprivate', var(1)
89+
!$omp end parallel
90+
! CHECK: return
91+
end subroutine
92+
93+
! CHECK-LABEL: func.func @_QPprivate_shared()
94+
subroutine private_shared()
95+
implicit none
96+
integer var(*)
97+
pointer(ivar,var)
98+
integer pointee(8)
99+
100+
pointee(1) = 42
101+
ivar = loc(pointee)
102+
103+
!$omp parallel num_threads(1) default(private) shared(ivar)
104+
! CHECK: omp.parallel
105+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
106+
! CHECK: {{.*}} = math.ipowi
107+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
108+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
109+
var(1) = var(1) ** 2
110+
print '(A24,I6)', 'private_shared', var(1)
111+
!$omp end parallel
112+
! CHECK: return
113+
end subroutine
114+
115+
! CHECK-LABEL: func.func @_QPprivate_firstprivate()
116+
subroutine private_firstprivate()
117+
implicit none
118+
integer var(*)
119+
pointer(ivar,var)
120+
integer pointee(8)
121+
122+
pointee(1) = 42
123+
ivar = loc(pointee)
124+
125+
!$omp parallel num_threads(1) default(private) firstprivate(ivar)
126+
! CHECK: omp.parallel
127+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
128+
! CHECK: {{.*}} = arith.subi
129+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
130+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
131+
var(1) = var(1) - 2
132+
print '(A24,I6)', 'private_firstprivate', var(1)
133+
!$omp end parallel
134+
! CHECK: return
135+
end subroutine
136+
137+
! CHECK-LABEL: func.func @_QPfirstprivate_shared()
138+
subroutine firstprivate_shared()
139+
implicit none
140+
integer var(*)
141+
pointer(ivar,var)
142+
integer pointee(8)
143+
144+
pointee(1) = 42
145+
ivar = loc(pointee)
146+
147+
!$omp parallel num_threads(1) default(firstprivate) shared(ivar)
148+
! CHECK: omp.parallel
149+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
150+
! CHECK: {{.*}} = arith.divsi
151+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
152+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
153+
var(1) = var(1) / 2
154+
print '(A24,I6)', 'firstprivate_shared', var(1)
155+
!$omp end parallel
156+
! CHECK: return
157+
end subroutine
158+
159+
! CHECK-LABEL: func.func @_QPfirstprivate_private()
160+
subroutine firstprivate_private()
161+
implicit none
162+
integer var(*)
163+
pointer(ivar,var)
164+
integer pointee(8)
165+
166+
pointee(1) = 42
167+
ivar = loc(pointee)
168+
169+
!$omp parallel num_threads(1) default(firstprivate) private(ivar) shared(pointee)
170+
! CHECK: omp.parallel
171+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
172+
! CHECK: {{.*}} = math.ipowi
173+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
174+
! CHECK: fir.call @_FortranAPointerAssociateScalar({{.*}}) fastmath<contract> : (!fir.ref<!fir.box<none>>, !fir.llvm_ptr<i8>) -> ()
175+
ivar = loc(pointee)
176+
var(1) = var(1) ** 2
177+
print '(A24,I6)', 'firstprivate_private', var(1)
178+
!$omp end parallel
179+
! CHECK: return
180+
end subroutine

libc/config/linux/x86_64/entrypoints.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,10 @@ endif()
653653
if(LIBC_TYPES_HAS_FLOAT16)
654654
list(APPEND TARGET_LIBM_ENTRYPOINTS
655655
# math.h C23 _Float16 entrypoints
656-
libc.src.math.asinf16
657656
libc.src.math.acosf16
658657
libc.src.math.acoshf16
658+
libc.src.math.asinf16
659+
libc.src.math.asinhf16
659660
libc.src.math.canonicalizef16
660661
libc.src.math.ceilf16
661662
libc.src.math.copysignf16

libc/docs/headers/math/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ Higher Math Functions
257257
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
258258
| asin | |check| | | | |check| | | 7.12.4.2 | F.10.1.2 |
259259
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
260-
| asinh | |check| | | | | | 7.12.5.2 | F.10.2.2 |
260+
| asinh | |check| | | | |check| | | 7.12.5.2 | F.10.2.2 |
261261
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+
262262
| asinpi | | | | | | 7.12.4.9 | F.10.1.9 |
263263
+-----------+------------------+-----------------+------------------------+----------------------+------------------------+------------------------+----------------------------+

libc/include/math.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ functions:
5959
return_type: float
6060
arguments:
6161
- type: float
62+
- name: asinhf16
63+
standards:
64+
- stdc
65+
return_type: _Float16
66+
arguments:
67+
- type: _Float16
68+
guard: LIBC_TYPES_HAS_FLOAT16
6269
- name: atan
6370
standards:
6471
- stdc

libc/src/math/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ add_math_entrypoint_object(asinf16)
5454

5555
add_math_entrypoint_object(asinh)
5656
add_math_entrypoint_object(asinhf)
57+
add_math_entrypoint_object(asinhf16)
5758

5859
add_math_entrypoint_object(atan)
5960
add_math_entrypoint_object(atanf)

libc/src/math/asinhf16.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//===-- Implementation header for asinhf16 ----------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception.
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SRC_MATH_ASINHF16_H
10+
#define LLVM_LIBC_SRC_MATH_ASINHF16_H
11+
12+
#include "src/__support/macros/config.h"
13+
#include "src/__support/macros/properties/types.h"
14+
15+
namespace LIBC_NAMESPACE_DECL {
16+
17+
float16 asinhf16(float16 x);
18+
19+
} // namespace LIBC_NAMESPACE_DECL
20+
21+
#endif // LLVM_LIBC_SRC_MATH_ASINHF16_H

libc/src/math/generic/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3980,6 +3980,27 @@ add_entrypoint_object(
39803980
libc.src.__support.macros.optimization
39813981
)
39823982

3983+
add_entrypoint_object(
3984+
asinhf16
3985+
SRCS
3986+
asinhf16.cpp
3987+
HDRS
3988+
../asinhf16.h
3989+
DEPENDS
3990+
.explogxf
3991+
libc.hdr.fenv_macros
3992+
libc.src.__support.FPUtil.cast
3993+
libc.src.__support.FPUtil.except_value_utils
3994+
libc.src.__support.FPUtil.fenv_impl
3995+
libc.src.__support.FPUtil.fp_bits
3996+
libc.src.__support.FPUtil.multiply_add
3997+
libc.src.__support.FPUtil.polyeval
3998+
libc.src.__support.FPUtil.rounding_mode
3999+
libc.src.__support.FPUtil.sqrt
4000+
libc.src.__support.macros.optimization
4001+
libc.src.__support.macros.properties.types
4002+
)
4003+
39834004
add_entrypoint_object(
39844005
atanhf
39854006
SRCS

0 commit comments

Comments
 (0)