Skip to content

Commit

Permalink
[OpenMP][DeviceRTL] Add the support for printf in a freestanding way
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shiltian committed Oct 8, 2021
1 parent faa0e2a commit af4599b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions openmp/libomptarget/DeviceRTL/include/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

///}

Expand Down

0 comments on commit af4599b

Please sign in to comment.