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 // The GNU headers like to define 'toupper' and 'tolower' redundantly. This is 17 // necessary to prevent it from doing that and remapping our implementation. 18 #if (defined(__NVPTX__) || defined(__AMDGPU__)) && defined(__GLIBC__) 19 #pragma push_macro("__USE_EXTERN_INLINES") 20 #undef __USE_EXTERN_INLINES 21 #endif 22 23 #include_next <ctype.h> 24 25 #if (defined(__NVPTX__) || defined(__AMDGPU__)) && defined(__GLIBC__) 26 #pragma pop_macro("__USE_EXTERN_INLINES") 27 #endif 28 29 #if __has_include(<llvm-libc-decls/ctype.h>) 30 31 #if defined(__HIP__) || defined(__CUDA__) 32 #define __LIBC_ATTRS __attribute__((device)) 33 #endif 34 35 // The GNU headers like to provide these as macros, we need to undefine them so 36 // they do not conflict with the following definitions for the GPU. 37 38 #pragma push_macro("isalnum") 39 #pragma push_macro("isalpha") 40 #pragma push_macro("isascii") 41 #pragma push_macro("isblank") 42 #pragma push_macro("iscntrl") 43 #pragma push_macro("isdigit") 44 #pragma push_macro("isgraph") 45 #pragma push_macro("islower") 46 #pragma push_macro("isprint") 47 #pragma push_macro("ispunct") 48 #pragma push_macro("isspace") 49 #pragma push_macro("isupper") 50 #pragma push_macro("isxdigit") 51 #pragma push_macro("toascii") 52 #pragma push_macro("tolower") 53 #pragma push_macro("toupper") 54 #pragma push_macro("isalnum_l") 55 #pragma push_macro("isalpha_l") 56 #pragma push_macro("isascii_l") 57 #pragma push_macro("isblank_l") 58 #pragma push_macro("iscntrl_l") 59 #pragma push_macro("isdigit_l") 60 #pragma push_macro("isgraph_l") 61 #pragma push_macro("islower_l") 62 #pragma push_macro("isprint_l") 63 #pragma push_macro("ispunct_l") 64 #pragma push_macro("isspace_l") 65 #pragma push_macro("isupper_l") 66 #pragma push_macro("isxdigit_l") 67 68 #undef isalnum 69 #undef isalpha 70 #undef isascii 71 #undef iscntrl 72 #undef isdigit 73 #undef islower 74 #undef isgraph 75 #undef isprint 76 #undef ispunct 77 #undef isspace 78 #undef isupper 79 #undef isblank 80 #undef isxdigit 81 #undef toascii 82 #undef tolower 83 #undef toupper 84 #undef isalnum_l 85 #undef isalpha_l 86 #undef iscntrl_l 87 #undef isdigit_l 88 #undef islower_l 89 #undef isgraph_l 90 #undef isprint_l 91 #undef ispunct_l 92 #undef isspace_l 93 #undef isupper_l 94 #undef isblank_l 95 #undef isxdigit_l 96 97 #pragma omp begin declare target 98 99 #include <llvm-libc-decls/ctype.h> 100 101 #pragma omp end declare target 102 103 // Restore the original macros when compiling on the host. 104 #if !defined(__NVPTX__) && !defined(__AMDGPU__) 105 #pragma pop_macro("isalnum") 106 #pragma pop_macro("isalpha") 107 #pragma pop_macro("isascii") 108 #pragma pop_macro("isblank") 109 #pragma pop_macro("iscntrl") 110 #pragma pop_macro("isdigit") 111 #pragma pop_macro("isgraph") 112 #pragma pop_macro("islower") 113 #pragma pop_macro("isprint") 114 #pragma pop_macro("ispunct") 115 #pragma pop_macro("isspace") 116 #pragma pop_macro("isupper") 117 #pragma pop_macro("isxdigit") 118 #pragma pop_macro("toascii") 119 #pragma pop_macro("tolower") 120 #pragma pop_macro("toupper") 121 #pragma pop_macro("isalnum_l") 122 #pragma pop_macro("isalpha_l") 123 #pragma pop_macro("isascii_l") 124 #pragma pop_macro("isblank_l") 125 #pragma pop_macro("iscntrl_l") 126 #pragma pop_macro("isdigit_l") 127 #pragma pop_macro("isgraph_l") 128 #pragma pop_macro("islower_l") 129 #pragma pop_macro("isprint_l") 130 #pragma pop_macro("ispunct_l") 131 #pragma pop_macro("isspace_l") 132 #pragma pop_macro("isupper_l") 133 #pragma pop_macro("isxdigit_l") 134 #endif 135 136 #undef __LIBC_ATTRS 137 138 #endif 139 140 #endif // __CLANG_LLVM_LIBC_WRAPPERS_CTYPE_H__ 141