[Openmp-commits] [PATCH] D107315: [libomptarget][nvptx] Drop printf to enable ffreestanding

Jon Chesterfield via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Aug 2 15:48:48 PDT 2021


JonChesterfield created this revision.
Herald added a subscriber: mgorny.
JonChesterfield requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

The nvptx devicertl compiles on more platforms if separated from
glibc. This patch disables printf from the devicertl as the lowering in
clang does not trigger with ffreestanding enabled.

Without ffreestanding, stdint et al include the ones from glibc.

This does not solve the general problem of compiling openmp on systems where
glibc causes compilation failure. It does allow running tests that don't use
libc headers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107315

Files:
  openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
  openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h


Index: openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
===================================================================
--- openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
+++ openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.h
@@ -12,12 +12,15 @@
 #ifndef _TARGET_IMPL_H_
 #define _TARGET_IMPL_H_
 
-#include <inttypes.h>
-#include <stdio.h>
-#include <stdlib.h>
-
 #include "nvptx_interface.h"
 
+#include <stddef.h>
+#include <stdint.h>
+
+// subset of inttypes.h
+#define PRId64 "ld"
+#define PRIu64 "lu"
+
 #define INLINE inline __attribute__((always_inline))
 #define NOINLINE __attribute__((noinline))
 #define ALIGN(N) __attribute__((aligned(N)))
@@ -77,4 +80,7 @@
   __kmpc_impl_all_lanes = ~(__kmpc_impl_lanemask_t)0
 };
 
+// Disable the printf calls as ffreestanding blocks the lowering in clang
+#define printf(...)
+
 #endif
Index: openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
===================================================================
--- openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
+++ openmp/libomptarget/deviceRTLs/nvptx/src/target_impl.cu
@@ -181,6 +181,9 @@
   return __kmpc_atomic_add(lock, 0u);
 }
 
+void *malloc(size_t size);
+void free(void *ptr);
+
 EXTERN void *__kmpc_impl_malloc(size_t x) { return malloc(x); }
 EXTERN void __kmpc_impl_free(void *x) { free(x); }
 
Index: openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
===================================================================
--- openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
+++ openmp/libomptarget/deviceRTLs/nvptx/CMakeLists.txt
@@ -153,6 +153,7 @@
 
 # Set flags for LLVM Bitcode compilation.
 set(bc_flags -S -x c++ -O1 -std=c++14
+             -ffreestanding
              -mllvm -openmp-opt-disable
              -target nvptx64
              -Xclang -emit-llvm-bc


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107315.363594.patch
Type: text/x-patch
Size: 1825 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210802/f95ab3a8/attachment.bin>


More information about the Openmp-commits mailing list