106c3fb27SDimitry Andric //===-- Wrapper for C standard stdlib.h declarations on the GPU -----------===// 206c3fb27SDimitry Andric // 306c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 406c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 506c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 606c3fb27SDimitry Andric // 706c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 806c3fb27SDimitry Andric 906c3fb27SDimitry Andric #ifndef __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__ 1006c3fb27SDimitry Andric #define __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__ 1106c3fb27SDimitry Andric 1206c3fb27SDimitry Andric #if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) 1306c3fb27SDimitry Andric #error "This file is for GPU offloading compilation only" 1406c3fb27SDimitry Andric #endif 1506c3fb27SDimitry Andric 1606c3fb27SDimitry Andric #include_next <stdlib.h> 1706c3fb27SDimitry Andric 1806c3fb27SDimitry Andric #if __has_include(<llvm-libc-decls/stdlib.h>) 1906c3fb27SDimitry Andric 2006c3fb27SDimitry Andric #if defined(__HIP__) || defined(__CUDA__) 2106c3fb27SDimitry Andric #define __LIBC_ATTRS __attribute__((device)) 2206c3fb27SDimitry Andric #endif 2306c3fb27SDimitry Andric 2406c3fb27SDimitry Andric #pragma omp begin declare target 2506c3fb27SDimitry Andric 26*5f757f3fSDimitry Andric // The LLVM C library uses these named types so we forward declare them. 2706c3fb27SDimitry Andric typedef void (*__atexithandler_t)(void); 28*5f757f3fSDimitry Andric typedef int (*__bsearchcompare_t)(const void *, const void *); 29*5f757f3fSDimitry Andric typedef int (*__qsortcompare_t)(const void *, const void *); 30*5f757f3fSDimitry Andric typedef int (*__qsortrcompare_t)(const void *, const void *, void *); 3106c3fb27SDimitry Andric 3206c3fb27SDimitry Andric // Enforce ABI compatibility with the structs used by the LLVM C library. 3306c3fb27SDimitry Andric _Static_assert(__builtin_offsetof(div_t, quot) == 0, "ABI mismatch!"); 3406c3fb27SDimitry Andric _Static_assert(__builtin_offsetof(ldiv_t, quot) == 0, "ABI mismatch!"); 3506c3fb27SDimitry Andric _Static_assert(__builtin_offsetof(lldiv_t, quot) == 0, "ABI mismatch!"); 3606c3fb27SDimitry Andric 3706c3fb27SDimitry Andric #include <llvm-libc-decls/stdlib.h> 3806c3fb27SDimitry Andric 3906c3fb27SDimitry Andric #pragma omp end declare target 4006c3fb27SDimitry Andric 4106c3fb27SDimitry Andric #undef __LIBC_ATTRS 4206c3fb27SDimitry Andric 4306c3fb27SDimitry Andric #endif 4406c3fb27SDimitry Andric 4506c3fb27SDimitry Andric #endif // __CLANG_LLVM_LIBC_WRAPPERS_STDLIB_H__ 46