[OpenMP] Provide math functions in OpenMP device code via OpenMP variants
authorJohannes Doerfert <johannes@jdoerfert.de>
Sat, 28 Mar 2020 01:36:30 +0000 (20:36 -0500)
committerJohannes Doerfert <johannes@jdoerfert.de>
Wed, 8 Apr 2020 04:33:24 +0000 (23:33 -0500)
commitf85ae058f580e9d74c4a8f2f0de168c18da6150f
tree6729136b5b9cfeb454159575f882e65f2d6f20a9
parenteb5a16efbf59150af31bd4e3d37b8ea5976d780b
[OpenMP] Provide math functions in OpenMP device code via OpenMP variants

For OpenMP target regions to piggy back on the CUDA/AMDGPU/... implementation of math functions,
we include the appropriate definitions inside of an `omp begin/end declare variant match(device={arch(nvptx)})` scope.
This way, the vendor specific math functions will become specialized versions of the system math functions.
When a system math function is called and specialized version is available the selection logic introduced in D75779
instead call the specialized version. In contrast to the code path we used so far, the system header is actually included.
This means functions without specialized versions are available and so are macro definitions.

This should address PR42061, PR42798, and PR42799.

Reviewed By: ye-luo

Differential Revision: https://reviews.llvm.org/D75788
29 files changed:
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Headers/CMakeLists.txt
clang/lib/Headers/__clang_cuda_cmath.h
clang/lib/Headers/__clang_cuda_device_functions.h
clang/lib/Headers/__clang_cuda_math.h
clang/lib/Headers/__clang_cuda_math_forward_declares.h
clang/lib/Headers/openmp_wrappers/__clang_openmp_device_functions.h [moved from clang/lib/Headers/openmp_wrappers/__clang_openmp_math_declares.h with 58% similarity]
clang/lib/Headers/openmp_wrappers/__clang_openmp_math.h [deleted file]
clang/lib/Headers/openmp_wrappers/cmath
clang/lib/Headers/openmp_wrappers/math.h
clang/lib/Headers/openmp_wrappers/time.h [new file with mode: 0644]
clang/test/Headers/Inputs/include/climits [new file with mode: 0644]
clang/test/Headers/Inputs/include/cmath
clang/test/Headers/Inputs/include/cstdlib
clang/test/Headers/Inputs/include/math.h
clang/test/Headers/Inputs/include/stdlib.h
clang/test/Headers/nvptx_device_cmath_functions.c
clang/test/Headers/nvptx_device_cmath_functions.cpp
clang/test/Headers/nvptx_device_cmath_functions_cxx17.cpp
clang/test/Headers/nvptx_device_math_complex.c [new file with mode: 0644]
clang/test/Headers/nvptx_device_math_functions.c
clang/test/Headers/nvptx_device_math_functions.cpp
clang/test/Headers/nvptx_device_math_functions_cxx17.cpp
clang/test/Headers/nvptx_device_math_macro.cpp [new file with mode: 0644]
clang/test/Headers/nvptx_device_math_modf.cpp [new file with mode: 0644]
clang/test/Headers/nvptx_device_math_sin.c [new file with mode: 0644]
clang/test/Headers/nvptx_device_math_sin.cpp [new file with mode: 0644]
clang/test/Headers/nvptx_device_math_sin_cos.cpp [new file with mode: 0644]
clang/test/Headers/nvptx_device_math_sincos.cpp [new file with mode: 0644]