[flang-commits] [flang] [flang][cuda] Add bind name for __brev interface (PR #152806)

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Mon Aug 11 20:12:05 PDT 2025


https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/152806

>From 397d808fd1fb37af94a2fa080c087853a5061245 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 8 Aug 2025 14:40:51 -0700
Subject: [PATCH] [flang][cuda] Add bind name for __brev interface

---
 flang/module/cudadevice.f90                | 4 ++--
 flang/test/Lower/CUDA/cuda-device-proc.cuf | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90
index d0c312c09353f..79bea0c62f798 100644
--- a/flang/module/cudadevice.f90
+++ b/flang/module/cudadevice.f90
@@ -765,11 +765,11 @@ attributes(device) real(8) function sinpi(x) bind(c,name='__nv_sinpi')
   end interface
 
   interface __brev
-    attributes(device) integer function __brev(i) bind(c)
+    attributes(device) integer function __brev(i) bind(c, name='__nv_brev')
       !dir$ ignore_tkr (d) i
       integer, value :: i
     end function
-    attributes(device) integer(8) function __brevll(i) bind(c)
+    attributes(device) integer(8) function __brevll(i) bind(c, name ='__nv_brevll')
       !dir$ ignore_tkr (d) i
       integer(8), value :: i
     end function
diff --git a/flang/test/Lower/CUDA/cuda-device-proc.cuf b/flang/test/Lower/CUDA/cuda-device-proc.cuf
index d5e614a83b354..4583c644a6b2a 100644
--- a/flang/test/Lower/CUDA/cuda-device-proc.cuf
+++ b/flang/test/Lower/CUDA/cuda-device-proc.cuf
@@ -11,6 +11,8 @@ attributes(global) subroutine devsub()
   integer(8) :: al
   integer(8) :: time
   integer :: smalltime
+  integer(4) :: res
+  integer(8) :: resl
 
   call syncthreads()
   call syncwarp(1)
@@ -49,6 +51,9 @@ attributes(global) subroutine devsub()
   smalltime = clock()
   time = clock64()
   time = globalTimer()
+
+  res = __brev(ai)
+  resl = __brev(al)
 end
 
 ! CHECK-LABEL: func.func @_QPdevsub() attributes {cuf.proc_attr = #cuf.cuda_proc<global>}
@@ -89,6 +94,9 @@ end
 ! CHECK: %{{.*}} = nvvm.read.ptx.sreg.clock64 : i64
 ! CHECK: %{{.*}} = nvvm.read.ptx.sreg.globaltimer : i64
 
+! CHECK: %{{.*}} = fir.call @__nv_brev(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i32) -> i32
+! CHECK: %{{.*}} = fir.call @__nv_brevll(%{{.*}}) proc_attrs<bind_c> fastmath<contract> : (i64) -> i64
+
 subroutine host1()
   integer, device :: a(32)
   integer, device :: ret



More information about the flang-commits mailing list