diff --git a/flang/include/flang/Semantics/riscv-ext-with-intrinsics.def b/flang/include/flang/Semantics/riscv-ext-with-intrinsics.def --- a/flang/include/flang/Semantics/riscv-ext-with-intrinsics.def +++ b/flang/include/flang/Semantics/riscv-ext-with-intrinsics.def @@ -15,3 +15,8 @@ RISCV_EXTENSION(Zbkb) RISCV_EXTENSION(Zbkc) RISCV_EXTENSION(Zbkx) + +RISCV_EXTENSION(Zknd) +RISCV_EXTENSION(Zkne) +RISCV_EXTENSION(Zknh) +RISCV_EXTENSION(Zksh) diff --git a/flang/lib/Optimizer/Builder/RISCVIntrinsicCall.cpp b/flang/lib/Optimizer/Builder/RISCVIntrinsicCall.cpp --- a/flang/lib/Optimizer/Builder/RISCVIntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/RISCVIntrinsicCall.cpp @@ -22,6 +22,20 @@ // RISC-V specific intrinsic handlers. static constexpr MathOperation riscvMathOperations[] = { + {"__riscv_aes64ds", "llvm.riscv.aes64ds.i64", + genFuncType, Ty::Integer<8>, Ty::Integer<8>>, genLibCall}, + {"__riscv_aes64dsm", "llvm.riscv.aes64dsm.i64", + genFuncType, Ty::Integer<8>, Ty::Integer<8>>, genLibCall}, + {"__riscv_aes64es", "llvm.riscv.aes64es.i64", + genFuncType, Ty::Integer<8>, Ty::Integer<8>>, genLibCall}, + {"__riscv_aes64esm", "llvm.riscv.aes64esm.i64", + genFuncType, Ty::Integer<8>, Ty::Integer<8>>, genLibCall}, + {"__riscv_aes64im", "llvm.riscv.aes64im.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_aes64ks1i", "llvm.riscv.aes64ks1i.i64", + genFuncType, Ty::Integer<8>, Ty::Integer<1>>, genLibCall}, + {"__riscv_aes64ks2", "llvm.riscv.aes64ks2.i64", + genFuncType, Ty::Integer<8>, Ty::Integer<8>>, genLibCall}, {"__riscv_brev8", "llvm.riscv.brev8.i32", genFuncType, Ty::Integer<4>>, genLibCall}, {"__riscv_brev8", "llvm.riscv.brev8.i64", @@ -42,6 +56,26 @@ genFuncType, Ty::Integer<4>>, genLibCall}, {"__riscv_orc_b", "llvm.riscv.orc.b.i64", genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sha256sig0", "llvm.riscv.sha256sig0.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sha256sig1", "llvm.riscv.sha256sig1.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sha256sum0", "llvm.riscv.sha256sum0.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sha256sum1", "llvm.riscv.sha256sum1.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sha512sig0", "llvm.riscv.sha512sig0.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sha512sig1", "llvm.riscv.sha512sig1.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sha512sum0", "llvm.riscv.sha512sum0.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sha512sum1", "llvm.riscv.sha512sum1.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sm3p0", "llvm.riscv.sm3p0.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, + {"__riscv_sm3p1", "llvm.riscv.sm3p1.i64", + genFuncType, Ty::Integer<8>>, genLibCall}, {"__riscv_unzip", "llvm.riscv.unzip.i32", genFuncType, Ty::Integer<4>>, genLibCall}, {"__riscv_xperm4", "llvm.riscv.xperm4.i32", diff --git a/flang/module/__riscv64_zknd_intrinsics.f90 b/flang/module/__riscv64_zknd_intrinsics.f90 new file mode 100644 --- /dev/null +++ b/flang/module/__riscv64_zknd_intrinsics.f90 @@ -0,0 +1,61 @@ +!===-- module/__riscv64_zknd_intrinsics.f90 --------------------------------===! +! +! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +! See https://llvm.org/LICENSE.txt for license information. +! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +! +!===------------------------------------------------------------------------===! + +module __RISCV64_Zknd_intrinsics + + private + + abstract interface + elemental integer(8) function func_i8i8(x) + integer(8), intent(in) :: x + end function func_i8i8 + elemental integer(8) function func_i8i8i1(x, y) + integer(8), intent(in) :: x + integer(1), intent(in) :: y + end function func_i8i8i1 + elemental integer(8) function func_i8i8i8(x, y) + integer(8), intent(in) :: x, y + end function func_i8i8i8 + end interface + + ! aes64ds + procedure(func_i8i8i8) :: __riscv_aes64ds_i8 + interface aes64ds + procedure :: __riscv_aes64ds_i8 + end interface aes64ds + public :: aes64ds + + ! aes64dsm + procedure(func_i8i8i8) :: __riscv_aes64dsm_i8 + interface aes64dsm + procedure :: __riscv_aes64dsm_i8 + end interface aes64dsm + public :: aes64dsm + + ! aes64im + procedure(func_i8i8) :: __riscv_aes64im_i8 + interface aes64im + procedure :: __riscv_aes64im_i8 + end interface aes64im + public :: aes64im + + ! aes64ks1i + procedure(func_i8i8i1) :: __riscv_aes64ks1i_i8 + interface aes64ks1i + procedure :: __riscv_aes64ks1i_i8 + end interface aes64ks1i + public :: aes64ks1i + + ! aes64ks2 + procedure(func_i8i8i8) :: __riscv_aes64ks2_i8 + interface aes64ks2 + procedure :: __riscv_aes64ks2_i8 + end interface aes64ks2 + public :: aes64ks2 + +end module __RISCV64_Zknd_intrinsics diff --git a/flang/module/__riscv64_zkne_intrinsics.f90 b/flang/module/__riscv64_zkne_intrinsics.f90 new file mode 100644 --- /dev/null +++ b/flang/module/__riscv64_zkne_intrinsics.f90 @@ -0,0 +1,51 @@ +!===-- module/__riscv64_zkne_intrinsics.f90 --------------------------------===! +! +! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +! See https://llvm.org/LICENSE.txt for license information. +! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +! +!===------------------------------------------------------------------------===! + +module __RISCV64_Zkne_intrinsics + + private + + abstract interface + elemental integer(8) function func_i8i8i1(x, y) + integer(8), intent(in) :: x + integer(1), intent(in) :: y + end function func_i8i8i1 + elemental integer(8) function func_i8i8i8(x, y) + integer(8), intent(in) :: x, y + end function func_i8i8i8 + end interface + + ! aes64es + procedure(func_i8i8i8) :: __riscv_aes64es_i8 + interface aes64es + procedure :: __riscv_aes64es_i8 + end interface aes64es + public :: aes64es + + ! aes64esm + procedure(func_i8i8i8) :: __riscv_aes64esm_i8 + interface aes64esm + procedure :: __riscv_aes64esm_i8 + end interface aes64esm + public :: aes64esm + + ! aes64ks1i + procedure(func_i8i8i1) :: __riscv_aes64ks1i_i8 + interface aes64ks1i + procedure :: __riscv_aes64ks1i_i8 + end interface aes64ks1i + public :: aes64ks1i + + ! aes64ks2 + procedure(func_i8i8i8) :: __riscv_aes64ks2_i8 + interface aes64ks2 + procedure :: __riscv_aes64ks2_i8 + end interface aes64ks2 + public :: aes64ks2 + +end module __RISCV64_Zkne_intrinsics diff --git a/flang/module/__riscv64_zknh_intrinsics.f90 b/flang/module/__riscv64_zknh_intrinsics.f90 new file mode 100644 --- /dev/null +++ b/flang/module/__riscv64_zknh_intrinsics.f90 @@ -0,0 +1,75 @@ +!===-- module/__riscv64_zknh_intrinsics.f90 --------------------------------===! +! +! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +! See https://llvm.org/LICENSE.txt for license information. +! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +! +!===------------------------------------------------------------------------===! + +module __RISCV64_Zknh_intrinsics + + private + + abstract interface + elemental integer(8) function func_i8i8(x) + integer(8), intent(in) :: x + end function func_i8i8 + end interface + + ! sha256sig0 + procedure(func_i8i8) :: __riscv_sha256sig0_i8 + interface sha256sig0 + procedure :: __riscv_sha256sig0_i8 + end interface sha256sig0 + public :: sha256sig0 + + ! sha256sig1 + procedure(func_i8i8) :: __riscv_sha256sig1_i8 + interface sha256sig1 + procedure :: __riscv_sha256sig1_i8 + end interface sha256sig1 + public :: sha256sig1 + + ! sha256sum0 + procedure(func_i8i8) :: __riscv_sha256sum0_i8 + interface sha256sum0 + procedure :: __riscv_sha256sum0_i8 + end interface sha256sum0 + public :: sha256sum0 + + ! sha256sum1 + procedure(func_i8i8) :: __riscv_sha256sum1_i8 + interface sha256sum1 + procedure :: __riscv_sha256sum1_i8 + end interface sha256sum1 + public :: sha256sum1 + + ! sha512sig0 + procedure(func_i8i8) :: __riscv_sha512sig0_i8 + interface sha512sig0 + procedure :: __riscv_sha512sig0_i8 + end interface sha512sig0 + public :: sha512sig0 + + ! sha512sig1 + procedure(func_i8i8) :: __riscv_sha512sig1_i8 + interface sha512sig1 + procedure :: __riscv_sha512sig1_i8 + end interface sha512sig1 + public :: sha512sig1 + + ! sha512sum0 + procedure(func_i8i8) :: __riscv_sha512sum0_i8 + interface sha512sum0 + procedure :: __riscv_sha512sum0_i8 + end interface sha512sum0 + public :: sha512sum0 + + ! sha512sum1 + procedure(func_i8i8) :: __riscv_sha512sum1_i8 + interface sha512sum1 + procedure :: __riscv_sha512sum1_i8 + end interface sha512sum1 + public :: sha512sum1 + +end module __RISCV64_Zknh_intrinsics diff --git a/flang/module/__riscv64_zksh_intrinsics.f90 b/flang/module/__riscv64_zksh_intrinsics.f90 new file mode 100644 --- /dev/null +++ b/flang/module/__riscv64_zksh_intrinsics.f90 @@ -0,0 +1,33 @@ +!===-- module/__riscv64_zksh_intrinsics.f90 --------------------------------===! +! +! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +! See https://llvm.org/LICENSE.txt for license information. +! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +! +!===------------------------------------------------------------------------===! + +module __RISCV64_Zksh_intrinsics + + private + + abstract interface + elemental integer(8) function func_i8i8(x) + integer(8), intent(in) :: x + end function func_i8i8 + end interface + + ! sm3p0 + procedure(func_i8i8) :: __riscv_sm3p0_i8 + interface sm3p0 + procedure :: __riscv_sm3p0_i8 + end interface sm3p0 + public :: sm3p0 + + ! sm3p1 + procedure(func_i8i8) :: __riscv_sm3p1_i8 + interface sm3p1 + procedure :: __riscv_sm3p1_i8 + end interface sm3p1 + public :: sm3p1 + +end module __RISCV64_Zksh_intrinsics diff --git a/flang/test/Lower/RISCV/riscv-zksh-intrinsics.f90 b/flang/test/Lower/RISCV/riscv-zksh-intrinsics.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/RISCV/riscv-zksh-intrinsics.f90 @@ -0,0 +1,16 @@ +! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu -target-feature +zksh \ +! RUN: -emit-llvm %s -o - | FileCheck --check-prefix="CHECK-LLVMIR" %s + +! CHECK-LABEL: sm3p0_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sm3p0.i64(i64 %{{[0-9]}}) +subroutine sm3p0_i64_test(x) + integer(8) :: x, r + r = sm3p0(x) +end + +! CHECK-LABEL: sm3p1_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sm3p1.i64(i64 %{{[0-9]}}) +subroutine sm3p1_i64_test(x) + integer(8) :: x, r + r = sm3p1(x) +end diff --git a/flang/test/Lower/RISCV/riscv64-zknd-intrinsics.f90 b/flang/test/Lower/RISCV/riscv64-zknd-intrinsics.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/RISCV/riscv64-zknd-intrinsics.f90 @@ -0,0 +1,38 @@ +! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu -target-feature +zknd \ +! RUN: -emit-llvm %s -o - | FileCheck --check-prefix="CHECK-LLVMIR" %s + +! CHECK-LABEL: aes64ds_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.aes64ds.i64(i64 %{{[0-9]}}, i64 %{{[0-9]}}) +subroutine aes64ds_i64_test(x, y) + integer(8) :: x, y, r + r = aes64ds(x, y) +end + +! CHECK-LABEL: aes64dsm_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.aes64dsm.i64(i64 %{{[0-9]}}, i64 %{{[0-9]}}) +subroutine aes64dsm_i64_test(x, y) + integer(8) :: x, y, r + r = aes64dsm(x, y) +end + +! CHECK-LABEL: aes64im_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.aes64im.i64(i64 %{{[0-9]}}) +subroutine aes64im_i64_test(x) + integer(8) :: x, r + r = aes64im(x) +end + +! CHECK-LABEL: aes64ks1i_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.aes64ks1i.i64(i64 %{{[0-9]}}, i8 %{{[0-9]}}) +subroutine aes64ks1i_i64_test(x, y) + integer(8) :: x, r + integer(1) :: y + r = aes64ks1i(x, y) +end + +! CHECK-LABEL: aes64ks2_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.aes64ks2.i64(i64 %{{[0-9]}}, i64 %{{[0-9]}}) +subroutine aes64ks2_i64_test(x, y) + integer(8) :: x, y, r + r = aes64ks2(x, y) +end diff --git a/flang/test/Lower/RISCV/riscv64-zkne-intrinsics.f90 b/flang/test/Lower/RISCV/riscv64-zkne-intrinsics.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/RISCV/riscv64-zkne-intrinsics.f90 @@ -0,0 +1,31 @@ +! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu -target-feature +zkne \ +! RUN: -emit-llvm %s -o - | FileCheck --check-prefix="CHECK-LLVMIR" %s + +! CHECK-LABEL: aes64ks1i_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.aes64ks1i.i64(i64 %{{[0-9]}}, i8 %{{[0-9]}}) +subroutine aes64ks1i_i64_test(x, y) + integer(8) :: x, r + integer(1) :: y + r = aes64ks1i(x, y) +end + +! CHECK-LABEL: aes64ks2_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.aes64ks2.i64(i64 %{{[0-9]}}, i64 %{{[0-9]}}) +subroutine aes64ks2_i64_test(x, y) + integer(8) :: x, y, r + r = aes64ks2(x, y) +end + +! CHECK-LABEL: aes64es_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.aes64es.i64(i64 %{{[0-9]}}, i64 %{{[0-9]}}) +subroutine aes64es_i64_test(x, y) + integer(8) :: x, y, r + r = aes64es(x, y) +end + +! CHECK-LABEL: aes64esm_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.aes64esm.i64(i64 %{{[0-9]}}, i64 %{{[0-9]}}) +subroutine aes64esm_i64_test(x, y) + integer(8) :: x, y, r + r = aes64esm(x, y) +end diff --git a/flang/test/Lower/RISCV/riscv64-zknh-intrinsics.f90 b/flang/test/Lower/RISCV/riscv64-zknh-intrinsics.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/RISCV/riscv64-zknh-intrinsics.f90 @@ -0,0 +1,58 @@ +! RUN: %flang_fc1 -triple riscv64-unknown-linux-gnu -target-feature +zknh \ +! RUN: -emit-llvm %s -o - | FileCheck --check-prefix="CHECK-LLVMIR" %s + +! CHECK-LABEL: sha256sig0_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sha256sig0.i64(i64 %{{[0-9]}}) +subroutine sha256sig0_i64_test(x) + integer(8) :: x, r + r = sha256sig0(x) +end + +! CHECK-LABEL: sha256sig1_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sha256sig1.i64(i64 %{{[0-9]}}) +subroutine sha256sig1_i64_test(x) + integer(8) :: x, r + r = sha256sig1(x) +end + +! CHECK-LABEL: sha256sum0_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sha256sum0.i64(i64 %{{[0-9]}}) +subroutine sha256sum0_i64_test(x) + integer(8) :: x, r + r = sha256sum0(x) +end + +! CHECK-LABEL: sha256sum1_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sha256sum1.i64(i64 %{{[0-9]}}) +subroutine sha256sum1_i64_test(x) + integer(8) :: x, r + r = sha256sum1(x) +end + +! CHECK-LABEL: sha512sig0_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sha512sig0.i64(i64 %{{[0-9]}}) +subroutine sha512sig0_i64_test(x) + integer(8) :: x, r + r = sha512sig0(x) +end + +! CHECK-LABEL: sha512sig1_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sha512sig1.i64(i64 %{{[0-9]}}) +subroutine sha512sig1_i64_test(x) + integer(8) :: x, r + r = sha512sig1(x) +end + +! CHECK-LABEL: sha512sum0_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sha512sum0.i64(i64 %{{[0-9]}}) +subroutine sha512sum0_i64_test(x) + integer(8) :: x, r + r = sha512sum0(x) +end + +! CHECK-LABEL: sha512sum1_i64_test +! CHECK-LLVMIR: call i64 @llvm.riscv.sha512sum1.i64(i64 %{{[0-9]}}) +subroutine sha512sum1_i64_test(x) + integer(8) :: x, r + r = sha512sum1(x) +end diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -15,6 +15,10 @@ "__riscv64_zbkb_intrinsics" "__riscv64_zbkc_intrinsics" "__riscv64_zbkx_intrinsics" + "__riscv64_zknd_intrinsics" + "__riscv64_zkne_intrinsics" + "__riscv64_zknh_intrinsics" + "__riscv64_zksh_intrinsics" "__cuda_builtins" "ieee_arithmetic" "ieee_exceptions"