1 //===-- Wrapper for C standard ctype.h declarations on the GPU ------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef __CLANG_LLVM_LIBC_WRAPPERS_CTYPE_H__ 10 #define __CLANG_LLVM_LIBC_WRAPPERS_CTYPE_H__ 11 12 #if !defined(_OPENMP) && !defined(__HIP__) && !defined(__CUDA__) 13 #error "This file is for GPU offloading compilation only" 14 #endif 15 16 #include_next <ctype.h> 17 18 #if __has_include(<llvm-libc-decls/ctype.h>) 19 20 #if defined(__HIP__) || defined(__CUDA__) 21 #define __LIBC_ATTRS __attribute__((device)) 22 #endif 23 24 // The GNU headers like to provide these as macros, we need to undefine them so 25 // they do not conflict with the following definitions for the GPU. 26 27 #pragma push_macro("isalnum") 28 #pragma push_macro("isalpha") 29 #pragma push_macro("isblank") 30 #pragma push_macro("iscntrl") 31 #pragma push_macro("isdigit") 32 #pragma push_macro("isgraph") 33 #pragma push_macro("islower") 34 #pragma push_macro("isprint") 35 #pragma push_macro("ispunct") 36 #pragma push_macro("isspace") 37 #pragma push_macro("isupper") 38 #pragma push_macro("isxdigit") 39 #pragma push_macro("tolower") 40 #pragma push_macro("toupper") 41 42 #undef isalnum 43 #undef isalpha 44 #undef iscntrl 45 #undef isdigit 46 #undef islower 47 #undef isgraph 48 #undef isprint 49 #undef ispunct 50 #undef isspace 51 #undef isupper 52 #undef isblank 53 #undef isxdigit 54 #undef tolower 55 #undef toupper 56 57 #pragma omp begin declare target 58 59 #include <llvm-libc-decls/ctype.h> 60 61 #pragma omp end declare target 62 63 // Restore the original macros when compiling on the host. 64 #if !defined(__NVPTX__) && !defined(__AMDGPU__) 65 #pragma pop_macro("isalnum") 66 #pragma pop_macro("isalpha") 67 #pragma pop_macro("isblank") 68 #pragma pop_macro("iscntrl") 69 #pragma pop_macro("isdigit") 70 #pragma pop_macro("isgraph") 71 #pragma pop_macro("islower") 72 #pragma pop_macro("isprint") 73 #pragma pop_macro("ispunct") 74 #pragma pop_macro("isspace") 75 #pragma pop_macro("isupper") 76 #pragma pop_macro("isxdigit") 77 #pragma pop_macro("tolower") 78 #pragma pop_macro("toupper") 79 #endif 80 81 #undef __LIBC_ATTRS 82 83 #endif 84 85 #endif // __CLANG_LLVM_LIBC_WRAPPERS_CTYPE_H__ 86