[OpenMP] Fix redefining stdint.h types#108607
Merged
Conversation
Member
|
@llvm/pr-subscribers-offload Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/108607.diff 5 Files Affected:
diff --git a/offload/DeviceRTL/CMakeLists.txt b/offload/DeviceRTL/CMakeLists.txt
index 6b86c4d1ce0cfa..bb8dc4e1d9a8c7 100644
--- a/offload/DeviceRTL/CMakeLists.txt
+++ b/offload/DeviceRTL/CMakeLists.txt
@@ -125,7 +125,7 @@ list(TRANSFORM LIBOMPTARGET_LLVM_INCLUDE_DIRS_DEVICERTL PREPEND "-I")
# Set flags for LLVM Bitcode compilation.
set(bc_flags -c -foffload-lto -std=c++17 -fvisibility=hidden
${clang_opt_flags} --offload-device-only
- -nocudalib -nogpulib -nostdinc
+ -nocudalib -nogpulib -nogpuinc -nostdlibinc
-fopenmp -fopenmp-cuda-mode
-Wno-unknown-cuda-version
-DOMPTARGET_DEVICE_RUNTIME
@@ -270,7 +270,7 @@ function(compileDeviceRTLLibrary target_cpu target_name target_triple)
-fopenmp --offload-arch=${target_cpu} -fopenmp-cuda-mode
-mllvm -openmp-opt-disable
-foffload-lto -fvisibility=hidden --offload-device-only
- -nocudalib -nogpulib -nostdinc -Wno-unknown-cuda-version
+ -nocudalib -nogpulib -nogpuinc -nostdlibinc -Wno-unknown-cuda-version
)
target_compile_definitions(${ide_target_name} PRIVATE SHARED_SCRATCHPAD_SIZE=512)
target_include_directories(${ide_target_name} PRIVATE
diff --git a/offload/DeviceRTL/include/DeviceTypes.h b/offload/DeviceRTL/include/DeviceTypes.h
index c7132be345e0e4..8b8921bb4ca7d4 100644
--- a/offload/DeviceRTL/include/DeviceTypes.h
+++ b/offload/DeviceRTL/include/DeviceTypes.h
@@ -12,6 +12,9 @@
#ifndef OMPTARGET_TYPES_H
#define OMPTARGET_TYPES_H
+#include <stdint.h>
+#include <stddef.h>
+
// Tell the compiler that we do not have any "call-like" inline assembly in the
// device rutime. That means we cannot have inline assembly which will call
// another function but only inline assembly that performs some operation or
@@ -21,32 +24,6 @@
// TODO: Find a good place for this
#pragma omp assumes ext_no_call_asm
-/// Base type declarations for freestanding mode
-///
-///{
-using int8_t = char;
-using uint8_t = unsigned char;
-using int16_t = short;
-using uint16_t = unsigned short;
-using int32_t = int;
-using uint32_t = unsigned int;
-using int64_t = long;
-using uint64_t = unsigned long;
-using size_t = decltype(sizeof(char));
-// TODO: Properly implement this
-using intptr_t = int64_t;
-using uintptr_t = uint64_t;
-
-static_assert(sizeof(int8_t) == 1, "type size mismatch");
-static_assert(sizeof(uint8_t) == 1, "type size mismatch");
-static_assert(sizeof(int16_t) == 2, "type size mismatch");
-static_assert(sizeof(uint16_t) == 2, "type size mismatch");
-static_assert(sizeof(int32_t) == 4, "type size mismatch");
-static_assert(sizeof(uint32_t) == 4, "type size mismatch");
-static_assert(sizeof(int64_t) == 8, "type size mismatch");
-static_assert(sizeof(uint64_t) == 8, "type size mismatch");
-///}
-
enum omp_proc_bind_t {
omp_proc_bind_false = 0,
omp_proc_bind_true = 1,
diff --git a/offload/include/Shared/Environment.h b/offload/include/Shared/Environment.h
index d141146b6bd5a1..147583c209fc3e 100644
--- a/offload/include/Shared/Environment.h
+++ b/offload/include/Shared/Environment.h
@@ -13,13 +13,13 @@
#ifndef OMPTARGET_SHARED_ENVIRONMENT_H
#define OMPTARGET_SHARED_ENVIRONMENT_H
+#include <stdint.h>
+
#ifdef OMPTARGET_DEVICE_RUNTIME
-#include "Types.h"
+#include "DeviceTypes.h"
#else
#include "SourceInfo.h"
-#include <cstdint>
-
using IdentTy = ident_t;
#endif
diff --git a/offload/include/Shared/Types.h b/offload/include/Shared/Types.h
deleted file mode 100644
index 15e3cfefa37ed9..00000000000000
--- a/offload/include/Shared/Types.h
+++ /dev/null
@@ -1,22 +0,0 @@
-//===-- Shared/Types.h - Type defs shared between host and device - C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Environments shared between host and device.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef OMPTARGET_SHARED_TYPES_H
-#define OMPTARGET_SHARED_TYPES_H
-
-#ifndef OMPTARGET_DEVICE_RUNTIME
-#include <cstdint>
-#else
-#include "DeviceTypes.h"
-#endif
-
-#endif // OMPTARGET_SHARED_TYPES_H
diff --git a/offload/include/Shared/Utils.h b/offload/include/Shared/Utils.h
index da83551fffd543..83a82678312c13 100644
--- a/offload/include/Shared/Utils.h
+++ b/offload/include/Shared/Utils.h
@@ -14,7 +14,7 @@
#ifndef OMPTARGET_SHARED_UTILS_H
#define OMPTARGET_SHARED_UTILS_H
-#include "Types.h"
+#include <stdint.h>
namespace utils {
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
shiltian
reviewed
Sep 13, 2024
offload/include/Shared/Types.h
Outdated
Contributor
There was a problem hiding this comment.
Can this OMPTARGET_DEVICE_RUNTIME definition go as well?
Contributor
Author
There was a problem hiding this comment.
The whole file is deleted, but we still use it for the definition of the IdentTy thing.
Contributor
There was a problem hiding this comment.
Yeah, that's what I wanted to ask.
shiltian
approved these changes
Sep 13, 2024
Summary: We can include `stdint.h` just find as long as we don't allow it to find system headers, passing `-nostdlibinc` and `-nogpuinc` suppresses these extra paths so we will just use the clang resource headers for `stdint.h` and `stddef.h`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
We can include
stdint.hjust fine as long as we don't allow it to findsystem headers, passing
-nostdlibincand-nogpuincsuppresses theseextra paths so we will just use the clang resource headers for
stdint.handstddef.h.