From af4599b8abcaff02450449a22a7206dbb694b952 Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Thu, 7 Oct 2021 22:15:23 -0400 Subject: [PATCH] [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 --- openmp/libomptarget/DeviceRTL/include/Debug.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/openmp/libomptarget/DeviceRTL/include/Debug.h b/openmp/libomptarget/DeviceRTL/include/Debug.h index 48ee3e9..e8e9078 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 different 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 ///} -- 2.7.4