[libc-commits] [clang] [libc] [llvm] [OFFLOAD] Add support to build libc for SPIRV backend (PR #181049)
via libc-commits
libc-commits at lists.llvm.org
Wed Feb 11 15:50:21 PST 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp -- libc/src/math/spirv64/ceil.cpp libc/src/math/spirv64/ceilf.cpp libc/src/math/spirv64/copysign.cpp libc/src/math/spirv64/copysignf.cpp libc/src/math/spirv64/fabs.cpp libc/src/math/spirv64/fabsf.cpp libc/src/math/spirv64/floor.cpp libc/src/math/spirv64/floorf.cpp libc/src/math/spirv64/fma.cpp libc/src/math/spirv64/fmaf.cpp libc/src/math/spirv64/fmax.cpp libc/src/math/spirv64/fmaxf.cpp libc/src/math/spirv64/fmin.cpp libc/src/math/spirv64/fminf.cpp libc/src/math/spirv64/fmod.cpp libc/src/math/spirv64/fmodf.cpp libc/src/math/spirv64/frexp.cpp libc/src/math/spirv64/frexpf.cpp libc/src/math/spirv64/ldexp.cpp libc/src/math/spirv64/ldexpf.cpp libc/src/math/spirv64/lgamma.cpp libc/src/math/spirv64/lgamma_r.cpp libc/src/math/spirv64/llrint.cpp libc/src/math/spirv64/llrintf.cpp libc/src/math/spirv64/lrint.cpp libc/src/math/spirv64/lrintf.cpp libc/src/math/spirv64/nearbyint.cpp libc/src/math/spirv64/nearbyintf.cpp libc/src/math/spirv64/remainder.cpp libc/src/math/spirv64/remainderf.cpp libc/src/math/spirv64/rint.cpp libc/src/math/spirv64/rintf.cpp libc/src/math/spirv64/round.cpp libc/src/math/spirv64/roundf.cpp libc/src/math/spirv64/scalbn.cpp libc/src/math/spirv64/scalbnf.cpp libc/src/math/spirv64/sqrt.cpp libc/src/math/spirv64/sqrtf.cpp libc/src/math/spirv64/tgamma.cpp libc/src/math/spirv64/tgammaf.cpp libc/src/math/spirv64/trunc.cpp libc/src/math/spirv64/truncf.cpp libc/startup/gpu/spirv64/start.cpp clang/lib/Headers/llvm_libc_wrappers/assert.h clang/lib/Headers/llvm_libc_wrappers/ctype.h clang/lib/Headers/llvm_libc_wrappers/inttypes.h clang/lib/Headers/llvm_libc_wrappers/stdio.h clang/lib/Headers/llvm_libc_wrappers/stdlib.h clang/lib/Headers/llvm_libc_wrappers/string.h clang/lib/Headers/llvm_libc_wrappers/time.h libc/include/llvm-libc-macros/math-macros.h libc/include/llvm-libc-macros/signal-macros.h libc/include/llvm-libc-macros/time-macros.h libc/include/llvm-libc-types/fenv_t.h libc/shared/rpc_util.h libc/src/__support/macros/properties/architectures.h libc/src/__support/macros/properties/cpu_features.h libc/src/__support/time/gpu/time_utils.cpp libc/src/__support/time/gpu/time_utils.h --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Headers/llvm_libc_wrappers/assert.h b/clang/lib/Headers/llvm_libc_wrappers/assert.h
index 3d61d5db5..1b3ea6b4a 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/assert.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/assert.h
@@ -9,7 +9,8 @@
#ifndef __CLANG_LLVM_LIBC_WRAPPERS_ASSERT_H__
#define __CLANG_LLVM_LIBC_WRAPPERS_ASSERT_H__
-#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && !defined(__SPIRV__)
+#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && \
+ !defined(__SPIRV__)
#error "This file is for GPU offloading compilation only"
#endif
diff --git a/clang/lib/Headers/llvm_libc_wrappers/ctype.h b/clang/lib/Headers/llvm_libc_wrappers/ctype.h
index 7879e2fb5..8d7bb608d 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/ctype.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/ctype.h
@@ -9,7 +9,8 @@
#ifndef __CLANG_LLVM_LIBC_WRAPPERS_CTYPE_H__
#define __CLANG_LLVM_LIBC_WRAPPERS_CTYPE_H__
-#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && !defined(__SPIRV__)
+#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && \
+ !defined(__SPIRV__)
#error "This file is for GPU offloading compilation only"
#endif
diff --git a/clang/lib/Headers/llvm_libc_wrappers/inttypes.h b/clang/lib/Headers/llvm_libc_wrappers/inttypes.h
index e99d3f556..154b6cc21 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/inttypes.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/inttypes.h
@@ -9,7 +9,8 @@
#ifndef __CLANG_LLVM_LIBC_WRAPPERS_INTTYPES_H__
#define __CLANG_LLVM_LIBC_WRAPPERS_INTTYPES_H__
-#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && !defined(__SPIRV__)
+#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && \
+ !defined(__SPIRV__)
#error "This file is for GPU offloading compilation only"
#endif
diff --git a/clang/lib/Headers/llvm_libc_wrappers/stdio.h b/clang/lib/Headers/llvm_libc_wrappers/stdio.h
index b914c92dd..4044bb840 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/stdio.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/stdio.h
@@ -9,7 +9,8 @@
#ifndef __CLANG_LLVM_LIBC_WRAPPERS_STDIO_H__
#define __CLANG_LLVM_LIBC_WRAPPERS_STDIO_H__
-#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) &&!defined(__SPIRV__)
+#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && \
+ !defined(__SPIRV__)
#error "This file is for GPU offloading compilation only"
#endif
diff --git a/clang/lib/Headers/llvm_libc_wrappers/stdlib.h b/clang/lib/Headers/llvm_libc_wrappers/stdlib.h
index 24145c646..6d4987936 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/stdlib.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/stdlib.h
@@ -9,7 +9,8 @@
#ifndef __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__
#define __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__
-#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && !defined(__SPIRV__)
+#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && \
+ !defined(__SPIRV__)
#error "This file is for GPU offloading compilation only"
#endif
diff --git a/clang/lib/Headers/llvm_libc_wrappers/string.h b/clang/lib/Headers/llvm_libc_wrappers/string.h
index 78abe2eac..5edb86ac9 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/string.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/string.h
@@ -9,7 +9,8 @@
#ifndef __CLANG_LLVM_LIBC_WRAPPERS_STRING_H__
#define __CLANG_LLVM_LIBC_WRAPPERS_STRING_H__
-#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && !defined(__SPIRV__)
+#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && \
+ !defined(__SPIRV__)
#error "This file is for GPU offloading compilation only"
#endif
diff --git a/clang/lib/Headers/llvm_libc_wrappers/time.h b/clang/lib/Headers/llvm_libc_wrappers/time.h
index 9ed8ccc39..b798d462a 100644
--- a/clang/lib/Headers/llvm_libc_wrappers/time.h
+++ b/clang/lib/Headers/llvm_libc_wrappers/time.h
@@ -9,7 +9,8 @@
#ifndef __CLANG_LLVM_LIBC_WRAPPERS_TIME_H__
#define __CLANG_LLVM_LIBC_WRAPPERS_TIME_H__
-#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && !defined(__SPIRV__)
+#if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) && \
+ !defined(__SPIRV__)
#error "This file is for GPU offloading compilation only"
#endif
diff --git a/libc/include/llvm-libc-macros/math-macros.h b/libc/include/llvm-libc-macros/math-macros.h
index 2051e36f7..10d15b7e0 100644
--- a/libc/include/llvm-libc-macros/math-macros.h
+++ b/libc/include/llvm-libc-macros/math-macros.h
@@ -44,8 +44,8 @@
// Math error handling. Target support is assumed to be existent unless
// explicitly disabled.
-#if defined(__NVPTX__) || defined(__AMDGPU__) || defined(__SPIRV__) || defined(__FAST_MATH__) || \
- defined(__NO_MATH_ERRNO__)
+#if defined(__NVPTX__) || defined(__AMDGPU__) || defined(__SPIRV__) || \
+ defined(__FAST_MATH__) || defined(__NO_MATH_ERRNO__)
#define __LIBC_SUPPORTS_MATH_ERRNO 0
#else
#define __LIBC_SUPPORTS_MATH_ERRNO 1
diff --git a/libc/src/__support/macros/properties/architectures.h b/libc/src/__support/macros/properties/architectures.h
index f05fe9e18..f73fa7a76 100644
--- a/libc/src/__support/macros/properties/architectures.h
+++ b/libc/src/__support/macros/properties/architectures.h
@@ -21,7 +21,8 @@
#define LIBC_TARGET_ARCH_IS_NVPTX
#endif
-#if defined(LIBC_TARGET_ARCH_IS_NVPTX) || defined(LIBC_TARGET_ARCH_IS_AMDGPU) || defined(LIBC_TARGET_ARCH_IS_SPIRV)
+#if defined(LIBC_TARGET_ARCH_IS_NVPTX) || \
+ defined(LIBC_TARGET_ARCH_IS_AMDGPU) || defined(LIBC_TARGET_ARCH_IS_SPIRV)
#define LIBC_TARGET_ARCH_IS_GPU
#endif
diff --git a/libc/src/__support/macros/properties/cpu_features.h b/libc/src/__support/macros/properties/cpu_features.h
index 001299272..ce676d015 100644
--- a/libc/src/__support/macros/properties/cpu_features.h
+++ b/libc/src/__support/macros/properties/cpu_features.h
@@ -97,7 +97,8 @@
#endif
#if defined(__ARM_FEATURE_FMA) || (defined(__AVX2__) && defined(__FMA__)) || \
- defined(__NVPTX__) || defined(__AMDGPU__) || defined(__riscv_flen) || defined(__SPIRV__)
+ defined(__NVPTX__) || defined(__AMDGPU__) || defined(__riscv_flen) || \
+ defined(__SPIRV__)
#define LIBC_TARGET_CPU_HAS_FMA
// Provide a more fine-grained control of FMA instruction for ARM targets.
#if defined(LIBC_TARGET_CPU_HAS_FPU_HALF)
diff --git a/libc/src/math/spirv64/lgamma_r.cpp b/libc/src/math/spirv64/lgamma_r.cpp
index 2b01988d2..efb388e52 100644
--- a/libc/src/math/spirv64/lgamma_r.cpp
+++ b/libc/src/math/spirv64/lgamma_r.cpp
@@ -13,7 +13,8 @@
namespace LIBC_NAMESPACE_DECL {
-extern "C" double __attribute__((overloadable)) __spirv_ocl_lgamma_r(double, int*);
+extern "C" double __attribute__((overloadable)) __spirv_ocl_lgamma_r(double,
+ int *);
LLVM_LIBC_FUNCTION(double, lgamma_r, (double x, int *signp)) {
return __spirv_ocl_lgamma_r(x, signp);
}
diff --git a/libc/src/math/spirv64/tgamma.cpp b/libc/src/math/spirv64/tgamma.cpp
index 49691a29b..2395e56ac 100644
--- a/libc/src/math/spirv64/tgamma.cpp
+++ b/libc/src/math/spirv64/tgamma.cpp
@@ -14,8 +14,6 @@
namespace LIBC_NAMESPACE_DECL {
extern "C" double __attribute__((overloadable)) __spirv_ocl_tgamma(double);
-LLVM_LIBC_FUNCTION(double, tgamma, (double x)) {
- return __spirv_ocl_tgamma(x);
-}
+LLVM_LIBC_FUNCTION(double, tgamma, (double x)) { return __spirv_ocl_tgamma(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/math/spirv64/tgammaf.cpp b/libc/src/math/spirv64/tgammaf.cpp
index 1c9aa95a7..ae9af5e74 100644
--- a/libc/src/math/spirv64/tgammaf.cpp
+++ b/libc/src/math/spirv64/tgammaf.cpp
@@ -14,8 +14,6 @@
namespace LIBC_NAMESPACE_DECL {
extern "C" float __attribute__((overloadable)) __spirv_ocl_tgamma(float);
-LLVM_LIBC_FUNCTION(float, tgammaf, (float x)) {
- return __spirv_ocl_tgamma(x);
-}
+LLVM_LIBC_FUNCTION(float, tgammaf, (float x)) { return __spirv_ocl_tgamma(x); }
} // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/startup/gpu/spirv64/start.cpp b/libc/startup/gpu/spirv64/start.cpp
index 780ec68c2..702f76647 100644
--- a/libc/startup/gpu/spirv64/start.cpp
+++ b/libc/startup/gpu/spirv64/start.cpp
@@ -64,8 +64,7 @@ _start(int argc, char **argv, char **envp, int *ret) {
__atomic_fetch_or(ret, main(argc, argv, envp), __ATOMIC_RELAXED);
}
-extern "C" [[gnu::visibility("protected"), clang::device_kernel]] void
-_end() {
+extern "C" [[gnu::visibility("protected"), clang::device_kernel]] void _end() {
// Only a single thread should call the destructors registred with 'atexit'.
// The loader utility will handle the actual exit and return code cleanly.
__cxa_finalize(nullptr);
``````````
</details>
https://github.com/llvm/llvm-project/pull/181049
More information about the libc-commits
mailing list