[Openmp-commits] [PATCH] D109728: [OpenMP][DeviceRTL] Add the support for printf in a freestanding way

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Sep 13 15:55:30 PDT 2021


tianshilei1992 created this revision.
tianshilei1992 added reviewers: JonChesterfield, jdoerfert.
Herald added subscribers: guansong, yaxunl.
tianshilei1992 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D109728

Files:
  openmp/libomptarget/DeviceRTL/include/Debug.h
  openmp/libomptarget/DeviceRTL/src/Debug.cpp


Index: openmp/libomptarget/DeviceRTL/src/Debug.cpp
===================================================================
--- openmp/libomptarget/DeviceRTL/src/Debug.cpp
+++ openmp/libomptarget/DeviceRTL/src/Debug.cpp
@@ -28,4 +28,18 @@
 }
 }
 
+/// AMDGCN implementations of the printf.
+///
+///{
+#pragma omp begin declare variant match(device = {arch(amdgcn)})
+
+extern "C" {
+inline __attribute__((always_inline)) int printf(const char *format, ...) {
+  return 0;
+}
+}
+
+#pragma omp end declare variant
+///}
+
 #pragma omp end declare target
Index: openmp/libomptarget/DeviceRTL/include/Debug.h
===================================================================
--- openmp/libomptarget/DeviceRTL/include/Debug.h
+++ openmp/libomptarget/DeviceRTL/include/Debug.h
@@ -23,8 +23,15 @@
 
 ///}
 
-// TODO: We need to allow actual printf.
-#define PRINTF(fmt, ...) (void)fmt;
+/// Print
+/// {
+extern "C" {
+int printf(const char *format, ...);
+}
+
+#define PRINTF(fmt, ...) (void)printf(fmt, __VA_ARGS__);
 #define PRINT(str) PRINTF("%s", str)
 
+///}
+
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109728.372358.patch
Type: text/x-patch
Size: 1067 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210913/effa6ce3/attachment.bin>


More information about the Openmp-commits mailing list