[Openmp-commits] [openmp] af4599b - [OpenMP][DeviceRTL] Add the support for printf in a freestanding way

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Thu Oct 7 19:15:41 PDT 2021


Author: Shilei Tian
Date: 2021-10-07T22:15:37-04:00
New Revision: af4599b8abcaff02450449a22a7206dbb694b952

URL: https://github.com/llvm/llvm-project/commit/af4599b8abcaff02450449a22a7206dbb694b952
DIFF: https://github.com/llvm/llvm-project/commit/af4599b8abcaff02450449a22a7206dbb694b952.diff

LOG: [OpenMP][DeviceRTL] Add the support for printf in a freestanding way

For NVPTX, `printf` can be used just with a function declaration. For AMDGCN, an
function definition is added, but it simply returns.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D109728

Added: 
    

Modified: 
    openmp/libomptarget/DeviceRTL/include/Debug.h

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/DeviceRTL/include/Debug.h b/openmp/libomptarget/DeviceRTL/include/Debug.h
index 48ee3e9ef03a0..e8e9078ee495c 100644
--- a/openmp/libomptarget/DeviceRTL/include/Debug.h
+++ b/openmp/libomptarget/DeviceRTL/include/Debug.h
@@ -25,9 +25,24 @@ void __assert_fail(const char *assertion, const char *file, unsigned line,
 
 ///}
 
-// TODO: We need to allow actual printf.
-#define PRINTF(fmt, ...) (void)fmt;
+/// Print
+/// TODO: For now we have to use macros to guard the code because Clang lowers
+/// `printf` to 
diff erent function calls on NVPTX and AMDGCN platforms, and it
+/// doesn't work for AMDGCN. After it can work on AMDGCN, we will remove the
+/// macro.
+/// {
+
+#ifndef __AMDGCN__
+extern "C" {
+int printf(const char *format, ...);
+}
+
+#define PRINTF(fmt, ...) (void)printf(fmt, __VA_ARGS__);
 #define PRINT(str) PRINTF("%s", str)
+#else
+#define PRINTF(fmt, ...)
+#define PRINT(str)
+#endif
 
 ///}
 


        


More information about the Openmp-commits mailing list