diff --git a/buildbot/configure.py b/buildbot/configure.py index 8477469031a99..8fccfb678c1e0 100644 --- a/buildbot/configure.py +++ b/buildbot/configure.py @@ -213,6 +213,25 @@ def do_configure(args, passthrough_args): "-DBUG_REPORT_URL=https://github.com/intel/llvm/issues", ] + if sys.platform == "linux": + if args.ci_defaults: + llvm_builtin_targets = "default;spirv64-intel-unknown" + cmake_cmd.extend( + [ + "-DLLVM_BUILTIN_TARGETS={}".format(llvm_builtin_targets), + ] + ) + else: + llvm_runtime_targets = "spirv64-intel-unknown" + llvm_spirv64_runtimes = "compiler-rt" + cmake_cmd.extend( + [ + "-DRUNTIMES_spirv64-intel-unknown_LLVM_ENABLE_RUNTIMES={}".format( + llvm_spirv64_runtimes + ), + "-DLLVM_RUNTIME_TARGETS={}".format(llvm_runtime_targets), + ] + ) if llvm_enable_runtimes: cmake_cmd.extend( [ diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 4a1a84115a8df..996238e3f8b8a 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5826,6 +5826,13 @@ class OffloadingActionBuilder final { int NumOfDeviceLibLinked = 0; SmallVector, 4> LibLocCandidates; SYCLInstallation.getSYCLDeviceLibPath(LibLocCandidates); + if (TC->getTriple().isSPIROrSPIRV()) { + std::string CompilerRTPath = TC->getCompilerRTPath(); + SmallString<128> SPIRVCompilerRTPath(CompilerRTPath); + llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-intel-unknown"); + if (llvm::sys::fs::exists(SPIRVCompilerRTPath)) + LibLocCandidates.emplace_back(SPIRVCompilerRTPath); + } const toolchains::SYCLToolChain &SYCLTC = static_cast(*TC); diff --git a/clang/lib/Driver/ToolChains/SYCL.cpp b/clang/lib/Driver/ToolChains/SYCL.cpp index 2a50df84e2850..80a1774d95394 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -597,6 +597,9 @@ SYCLToolChain::getDeviceLibNames(const Driver &D, "libsycl-fallback-complex-fp64", "libsycl-fallback-cmath", "libsycl-fallback-cmath-fp64", +#if !defined(_WIN32) + "libclang_rt.builtins", +#endif "libsycl-fallback-imf", "libsycl-fallback-imf-fp64", "libsycl-fallback-imf-bf16"}; @@ -833,6 +836,8 @@ const char *SYCL::Linker::constructLLVMLinkCommand( InputFilename.contains("libspirv") || InputFilename.contains("libdevice"))) return true; + if (InputFilename.starts_with("libclang_rt.builtins")) + return true; StringRef LibSyclPrefix("libsycl-"); if (!InputFilename.starts_with(LibSyclPrefix) || !InputFilename.ends_with(LibPostfix) || @@ -1920,7 +1925,13 @@ SYCLToolChain::getDeviceLibs( SmallVector, 4> LibraryPaths; SYCLInstallation.getSYCLDeviceLibPath(LibraryPaths); - + if (getTriple().isSPIROrSPIRV()) { + std::string CompilerRTPath = getCompilerRTPath(); + SmallString<128> SPIRVCompilerRTPath(CompilerRTPath); + llvm::sys::path::append(SPIRVCompilerRTPath, "spirv64-intel-unknown"); + if (llvm::sys::fs::exists(SPIRVCompilerRTPath)) + LibraryPaths.emplace_back(SPIRVCompilerRTPath); + } // Formulate all of the device libraries needed for this compilation. SmallVector DeviceLibs = getDeviceLibNames(getDriver(), DriverArgs, getTriple()); diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index d658b7009e859..b165c8ee61fb5 100644 --- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -368,6 +368,27 @@ function(add_compiler_rt_runtime name type) set_property(TARGET ${libname} PROPERTY CXX_STANDARD ${LIB_CXX_STANDARD}) endif() set_target_output_directories(${libname} ${output_dir_${libname}}) + if(COMPILER_RT_GPU_BUILD) + find_program(LLVM_LINK_EXE + NAMES llvm-link + PATHS ${LLVM_TOOLS_BINARY_DIR} + NO_DEFAULT_PATH) + file(GENERATE + OUTPUT ${CMAKE_BINARY_DIR}/${libname}.rsp + CONTENT "$,\n>") + if(LLVM_LINK_EXE) + set(compiler_rt_bc_file ${output_dir_${libname}}/lib${output_name_${libname}}.bc) + add_custom_target(${libname}_bc + COMMAND ${LLVM_LINK_EXE} -o ${compiler_rt_bc_file} @${CMAKE_BINARY_DIR}/${libname}.rsp) + add_dependencies(${libname}_bc ${libname}) + if(LIB_PARENT_TARGET) + add_dependencies(${LIB_PARENT_TARGET} ${libname}_bc) + endif() + install(FILES ${compiler_rt_bc_file} + DESTINATION ${install_dir_${libname}} + ${COMPONENT_OPTION}) + endif() + endif() install(TARGETS ${libname} ARCHIVE DESTINATION ${install_dir_${libname}} ${COMPONENT_OPTION} diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake index cbd18d26c0b93..abdff7fb2dc3a 100644 --- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake @@ -164,6 +164,7 @@ macro(detect_target_arch) check_symbol_exists(__s390x__ "" __S390X) check_symbol_exists(__sparc "" __SPARC) check_symbol_exists(__sparcv9 "" __SPARCV9) + check_symbol_exists(__SPIRV__ "" __SPIRV) check_symbol_exists(__wasm32__ "" __WEBASSEMBLY32) check_symbol_exists(__wasm64__ "" __WEBASSEMBLY64) check_symbol_exists(__ve__ "" __VE) @@ -221,6 +222,8 @@ macro(detect_target_arch) add_default_target_arch(sparcv9) elseif(__SPARC) add_default_target_arch(sparc) + elseif(__SPIRV) + add_default_target_arch(spirv64) elseif(__WEBASSEMBLY32) add_default_target_arch(wasm32) elseif(__WEBASSEMBLY64) @@ -421,6 +424,9 @@ macro(construct_compiler_rt_default_triple) elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "nvptx") set(COMPILER_RT_GPU_BUILD ON) set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c") + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "spirv") + set(COMPILER_RT_GPU_BUILD ON) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fsycl -fsycl-device-only -c -emit-llvm") endif() endif() @@ -506,6 +512,8 @@ function(get_compiler_rt_target arch variable) set(target "amdgcn-amd-amdhsa") elseif("${arch}" MATCHES "^nvptx") set(target "nvptx64-nvidia-cuda") + elseif("${arch}" MATCHES "^spirv64") + set(target "spirv64-intel-unknown") else() set(target "${arch}${triple_suffix}") endif() diff --git a/compiler-rt/cmake/base-config-ix.cmake b/compiler-rt/cmake/base-config-ix.cmake index 37dfa5534dfef..85bc6d4de7e0a 100644 --- a/compiler-rt/cmake/base-config-ix.cmake +++ b/compiler-rt/cmake/base-config-ix.cmake @@ -227,6 +227,9 @@ macro(test_targets) test_target_arch(amdgcn "" "--target=amdgcn-amd-amdhsa" "-nogpulib" "-flto" "-fconvergent-functions" "-Xclang -mcode-object-version=none") + + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "spirv") + test_target_arch(spirv64 "" "-fsycl" "-fsycl-device-only") elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "hexagon") test_target_arch(hexagon "" "") elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "loongarch64") diff --git a/compiler-rt/cmake/builtin-config-ix.cmake b/compiler-rt/cmake/builtin-config-ix.cmake index 569582a35e7ab..b1ef0d20efeb8 100644 --- a/compiler-rt/cmake/builtin-config-ix.cmake +++ b/compiler-rt/cmake/builtin-config-ix.cmake @@ -24,6 +24,8 @@ builtin_check_c_compiler_flag(-nogpulib COMPILER_RT_HAS_NOGPULIB_FLA builtin_check_c_compiler_flag(-flto COMPILER_RT_HAS_FLTO_FLAG) builtin_check_c_compiler_flag(-fconvergent-functions COMPILER_RT_HAS_FCONVERGENT_FUNCTIONS_FLAG) builtin_check_c_compiler_flag("-Xclang -mcode-object-version=none" COMPILER_RT_HAS_CODE_OBJECT_VERSION_FLAG) +builtin_check_c_compiler_flag(-fsycl COMPILER_RT_HAS_SYCL_FLAG) +builtin_check_c_compiler_flag(-fsycl-device-only COMPILER_RT_HAS_SYCL_DEVICE_ONLY_FLAG) builtin_check_c_compiler_flag(-Wbuiltin-declaration-mismatch COMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG) builtin_check_c_compiler_flag(/Zl COMPILER_RT_HAS_ZL_FLAG) builtin_check_c_compiler_flag(-fcf-protection=full COMPILER_RT_HAS_FCF_PROTECTION_FLAG) @@ -79,6 +81,7 @@ else() endif() set(AMDGPU amdgcn) +set(SPIRV spirv64) set(ARM64 aarch64 arm64ec aarch64_lfi) set(ARM32 arm armhf armv4t armv5te armv6 armv6m armv7m armv7em armv7 armv7s armv7k armv8m.base armv8m.main armv8.1m.main) set(AVR avr) @@ -110,7 +113,7 @@ endif() set(ALL_BUILTIN_SUPPORTED_ARCH ${X86} ${X86_64} ${AMDGPU} ${ARM32} ${ARM64} ${AVR} ${HEXAGON} ${MIPS32} ${MIPS64} ${NVPTX} ${PPC32} ${PPC64} - ${RISCV32} ${RISCV64} ${S390X} ${SPARC} ${SPARCV9} + ${RISCV32} ${RISCV64} ${S390X} ${SPARC} ${SPARCV9} ${SPIRV} ${WASM32} ${WASM64} ${VE} ${LOONGARCH64} ${M68K}) include(CompilerRTUtils) diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index 44548c191fbd2..f32e79a1dc327 100644 --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -192,6 +192,14 @@ set(GENERIC_SOURCES umodti3.c ) +set(SPIRV64_SOURCES + divdc3.c + divsc3.c + mulsc3.c + muldc3.c +) + + # We only build BF16 files when "__bf16" is available. set(BF16_SOURCES extendbfsf2.c @@ -739,6 +747,7 @@ if (APPLE) endif() set(amdgcn_SOURCES ${GENERIC_SOURCES}) +set(spirv64_SOURCES ${SPIRV64_SOURCES}) set(armv4t_SOURCES ${arm_min_SOURCES}) set(armv5te_SOURCES ${arm_min_SOURCES}) @@ -965,6 +974,12 @@ else () endif() endif() + if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "spirv64") + append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding BUILTIN_CFLAGS) + append_list_if(COMPILER_RT_HAS_SYCL_FLAG -fsycl BUILTIN_CFLAGS) + append_list_if(COMPILER_RT_HAS_SYCL_DEVICE_ONLY_FLAG -fsycl-device-only BUILTIN_CFLAGS) + endif() + set(BUILTIN_DEFS "") if(COMPILER_RT_BUILTINS_HIDE_SYMBOLS) @@ -1019,7 +1034,8 @@ else () int main(void) { return 0; }" COMPILER_RT_HAS_${arch}_BFLOAT16) # Build BF16 files only when "__bf16" is available. - if(COMPILER_RT_HAS_${arch}_BFLOAT16) + + if(COMPILER_RT_HAS_${arch}_BFLOAT16 AND NOT COMPILER_RT_HAS_SYCL_FLAG) list(APPEND ${arch}_SOURCES ${BF16_SOURCES}) endif() @@ -1039,16 +1055,28 @@ else () list(APPEND BUILTIN_CFLAGS_${arch} -fforce-enable-int128) endif() - add_compiler_rt_runtime(clang_rt.builtins - STATIC - ARCHS ${arch} - DEPS ${deps_${arch}} - SOURCES ${${arch}_SOURCES} - DEFS ${BUILTIN_DEFS} - CFLAGS ${BUILTIN_CFLAGS_${arch}} - C_STANDARD 11 - CXX_STANDARD 17 - PARENT_TARGET builtins) + if("${LLVM_BUILTINS_TARGET}" MATCHES "spirv64") + add_compiler_rt_runtime(clang_rt.builtins + STATIC + ARCHS ${arch} + DEPS ${deps_${arch}} + SOURCES ${${arch}_SOURCES} + DEFS ${BUILTIN_DEFS} + CFLAGS ${BUILTIN_CFLAGS_${arch}} + CXX_STANDARD 17 + PARENT_TARGET builtins) + else() + add_compiler_rt_runtime(clang_rt.builtins + STATIC + ARCHS ${arch} + DEPS ${deps_${arch}} + SOURCES ${${arch}_SOURCES} + DEFS ${BUILTIN_DEFS} + CFLAGS ${BUILTIN_CFLAGS_${arch}} + C_STANDARD 11 + CXX_STANDARD 17 + PARENT_TARGET builtins) + endif() # Write out the sources that were used to compile the builtins so that tests can be run in # an independent compiler-rt build (see: compiler-rt/test/builtins/CMakeLists.txt) diff --git a/compiler-rt/lib/builtins/fp_lib.h b/compiler-rt/lib/builtins/fp_lib.h index 95b24aac1ff1d..c252be4b19d6d 100644 --- a/compiler-rt/lib/builtins/fp_lib.h +++ b/compiler-rt/lib/builtins/fp_lib.h @@ -344,19 +344,35 @@ static __inline fp_t __compiler_rt_fmaxX(fp_t x, fp_t y) { #if defined(SINGLE_PRECISION) static __inline fp_t __compiler_rt_logbf(fp_t x) { +#ifdef __SPIRV__ + return __spirv_ocl_logb(x); +#else return __compiler_rt_logbX(x); +#endif } static __inline fp_t __compiler_rt_scalbnf(fp_t x, int y) { +#ifdef __SPIRV__ + return __spirv_ocl_ldexp(x, y); +#else return __compiler_rt_scalbnX(x, y); +#endif } #elif defined(DOUBLE_PRECISION) static __inline fp_t __compiler_rt_logb(fp_t x) { +#ifdef __SPIRV__ + return __spirv_ocl_logb(x); +#else return __compiler_rt_logbX(x); +#endif } static __inline fp_t __compiler_rt_scalbn(fp_t x, int y) { +#ifdef __SPIRV__ + return __spirv_ocl_ldexp(x, y); +#else return __compiler_rt_scalbnX(x, y); +#endif } static __inline fp_t __compiler_rt_fmax(fp_t x, fp_t y) { #if defined(__aarch64__) || defined(__arm64ec__) diff --git a/compiler-rt/lib/builtins/int_lib.h b/compiler-rt/lib/builtins/int_lib.h index 943430de259d8..5e9d200a1072d 100644 --- a/compiler-rt/lib/builtins/int_lib.h +++ b/compiler-rt/lib/builtins/int_lib.h @@ -26,6 +26,8 @@ #else #define COMPILER_RT_ABI __attribute__((__pcs__("aapcs"))) #endif +#elif defined(__SPIRV__) +#define COMPILER_RT_ABI SYCL_EXTERNAL extern "C" #else #define COMPILER_RT_ABI #endif diff --git a/compiler-rt/lib/builtins/int_math.h b/compiler-rt/lib/builtins/int_math.h index 08bfe922ffa13..7fe2710f86809 100644 --- a/compiler-rt/lib/builtins/int_math.h +++ b/compiler-rt/lib/builtins/int_math.h @@ -31,13 +31,21 @@ #if defined(_MSC_VER) && !defined(__clang__) #define CRT_INFINITY INFINITY #else +#if defined(DOUBLE_PRECISION) +#define CRT_INFINITY __builtin_huge_val() +#else #define CRT_INFINITY __builtin_huge_valf() #endif +#endif #if defined(_MSC_VER) && !defined(__clang__) #define crt_isfinite(x) _finite((x)) #define crt_isinf(x) !_finite((x)) #define crt_isnan(x) _isnan((x)) +#elif defined(__SPIRV__) +#define crt_isinf(x) __spirv_IsInf((x)) +#define crt_isnan(x) __spirv_IsNan((x)) +#define crt_isfinite(x) __spirv_IsFinite((x)) #else // Define crt_isfinite in terms of the builtin if available, otherwise provide // an alternate version in terms of our other functions. This supports some @@ -61,6 +69,9 @@ #define crt_copysign(x, y) copysign((x), (y)) #define crt_copysignf(x, y) copysignf((x), (y)) #define crt_copysignl(x, y) copysignl((x), (y)) +#elif defined(__SPIRV__) +#define crt_copysign(x, y) __spirv_ocl_copysign((x), (y)) +#define crt_copysignf(x, y) __spirv_ocl_copysign((x), (y)) #else #define crt_copysign(x, y) __builtin_copysign((x), (y)) #define crt_copysignf(x, y) __builtin_copysignf((x), (y)) diff --git a/compiler-rt/lib/builtins/muldc3.c b/compiler-rt/lib/builtins/muldc3.c index 0ea7041c37060..43dfcc7a580d5 100644 --- a/compiler-rt/lib/builtins/muldc3.c +++ b/compiler-rt/lib/builtins/muldc3.c @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +#define DOUBLE_PRECISION #include "int_lib.h" #include "int_math.h" diff --git a/libdevice/complex_wrapper.cpp b/libdevice/complex_wrapper.cpp index f01872fb6aee1..5be81e390761a 100644 --- a/libdevice/complex_wrapper.cpp +++ b/libdevice/complex_wrapper.cpp @@ -86,17 +86,4 @@ float __complex__ catanhf(float __complex__ z) { DEVICE_EXTERN_C_INLINE float __complex__ catanf(float __complex__ z) { return __devicelib_catanf(z); } -// __mulsc3 -// Returns: the product of a + ib and c + id -DEVICE_EXTERN_C_INLINE -float __complex__ __mulsc3(float __a, float __b, float __c, float __d) { - return __devicelib___mulsc3(__a, __b, __c, __d); -} - -// __divsc3 -// Returns: the quotient of (a + ib) / (c + id) -DEVICE_EXTERN_C_INLINE -float __complex__ __divsc3(float __a, float __b, float __c, float __d) { - return __devicelib___divsc3(__a, __b, __c, __d); -} #endif // __SPIR__ || __SPIRV__ diff --git a/libdevice/complex_wrapper_fp64.cpp b/libdevice/complex_wrapper_fp64.cpp index d3f42face5ec3..257fb11f24347 100644 --- a/libdevice/complex_wrapper_fp64.cpp +++ b/libdevice/complex_wrapper_fp64.cpp @@ -87,17 +87,4 @@ double __complex__ catanh(double __complex__ z) { DEVICE_EXTERN_C_INLINE double __complex__ catan(double __complex__ z) { return __devicelib_catan(z); } -// __muldc3 -// Returns: the product of a + ib and c + id -DEVICE_EXTERN_C_INLINE -double __complex__ __muldc3(double __a, double __b, double __c, double __d) { - return __devicelib___muldc3(__a, __b, __c, __d); -} - -// __divdc3 -// Returns: the quotient of (a + ib) / (c + id) -DEVICE_EXTERN_C_INLINE -double __complex__ __divdc3(double __a, double __b, double __c, double __d) { - return __devicelib___divdc3(__a, __b, __c, __d); -} #endif // __SPIR__ || __SPIRV__ diff --git a/libdevice/device_complex.h b/libdevice/device_complex.h index 6fa4254ff2025..88916715d0900 100644 --- a/libdevice/device_complex.h +++ b/libdevice/device_complex.h @@ -153,17 +153,5 @@ double __complex__ __devicelib_catan(double __complex__ z); DEVICE_EXTERN_C float __complex__ __devicelib_catanf(float __complex__ z); - -DEVICE_EXTERN_C -double __complex__ __devicelib___muldc3(double a, double b, double c, double d); - -DEVICE_EXTERN_C -float __complex__ __devicelib___mulsc3(float a, float b, float c, float d); - -DEVICE_EXTERN_C -double __complex__ __devicelib___divdc3(double a, double b, double c, double d); - -DEVICE_EXTERN_C -float __complex__ __devicelib___divsc3(float a, float b, float c, float d); #endif // __SPIR__ || __SPIRV__ #endif // __LIBDEVICE_DEVICE_COMPLEX_H_ diff --git a/libdevice/fallback-complex-fp64.cpp b/libdevice/fallback-complex-fp64.cpp index 28a5be8ab4a48..5b4c72089edbb 100644 --- a/libdevice/fallback-complex-fp64.cpp +++ b/libdevice/fallback-complex-fp64.cpp @@ -21,102 +21,6 @@ double __devicelib_creal(double __complex__ z) { return __real__(z); } DEVICE_EXTERN_C_INLINE double __devicelib_cimag(double __complex__ z) { return __imag__(z); } -// __muldc3 -// Returns: the product of a + ib and c + id -DEVICE_EXTERN_C_INLINE -double __complex__ __devicelib___muldc3(double __a, double __b, double __c, - double __d) { - double __ac = __a * __c; - double __bd = __b * __d; - double __ad = __a * __d; - double __bc = __b * __c; - double __complex__ z; - z = CMPLX((__ac - __bd), (__ad + __bc)); - if (__spirv_IsNan(__devicelib_creal(z)) && - __spirv_IsNan(__devicelib_cimag(z))) { - int __recalc = 0; - if (__spirv_IsInf(__a) || __spirv_IsInf(__b)) { - __a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0 : 0.0, __a); - __b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0 : 0.0, __b); - if (__spirv_IsNan(__c)) - __c = __spirv_ocl_copysign(0.0, __c); - if (__spirv_IsNan(__d)) - __d = __spirv_ocl_copysign(0.0, __d); - __recalc = 1; - } - if (__spirv_IsInf(__c) || __spirv_IsInf(__d)) { - __c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0 : 0.0, __c); - __d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0 : 0.0, __d); - if (__spirv_IsNan(__a)) - __a = __spirv_ocl_copysign(0.0, __a); - if (__spirv_IsNan(__b)) - __b = __spirv_ocl_copysign(0.0, __b); - __recalc = 1; - } - if (!__recalc && (__spirv_IsInf(__ac) || __spirv_IsInf(__bd) || - __spirv_IsInf(__ad) || __spirv_IsInf(__bc))) { - if (__spirv_IsNan(__a)) - __a = __spirv_ocl_copysign(0.0, __a); - if (__spirv_IsNan(__b)) - __b = __spirv_ocl_copysign(0.0, __b); - if (__spirv_IsNan(__c)) - __c = __spirv_ocl_copysign(0.0, __c); - if (__spirv_IsNan(__d)) - __d = __spirv_ocl_copysign(0.0, __d); - __recalc = 1.0; - } - if (__recalc) { - z = CMPLX((INFINITY * (__a * __c - __b * __d)), - (INFINITY * (__a * __d + __b * __c))); - } - } - return z; -} - -// __divdc3 -// Returns: the quotient of (a + ib) / (c + id) -DEVICE_EXTERN_C_INLINE -double __complex__ __devicelib___divdc3(double __a, double __b, double __c, - double __d) { - int __ilogbw = 0; - double __logbw = __spirv_ocl_logb( - __spirv_ocl_fmax(__spirv_ocl_fabs(__c), __spirv_ocl_fabs(__d))); - if (__spirv_IsFinite(__logbw)) { - __ilogbw = (int)__logbw; - __c = __spirv_ocl_ldexp(__c, -__ilogbw); - __d = __spirv_ocl_ldexp(__d, -__ilogbw); - } - double __denom = __c * __c + __d * __d; - double __complex__ z; - double z_real = - __spirv_ocl_ldexp((__a * __c + __b * __d) / __denom, -__ilogbw); - double z_imag = - __spirv_ocl_ldexp((__b * __c - __a * __d) / __denom, -__ilogbw); - z = CMPLX(z_real, z_imag); - if (__spirv_IsNan(z_real) && __spirv_IsNan(z_imag)) { - if ((__denom == 0.0) && (!__spirv_IsNan(__a) || !__spirv_IsNan(__b))) { - z_real = __spirv_ocl_copysign((double)INFINITY, __c) * __a; - z_imag = __spirv_ocl_copysign((double)INFINITY, __c) * __b; - z = CMPLX(z_real, z_imag); - } else if ((__spirv_IsInf(__a) || __spirv_IsInf(__b)) && - __spirv_IsFinite(__c) && __spirv_IsFinite(__d)) { - __a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0 : 0.0, __a); - __b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0 : 0.0, __b); - z_real = INFINITY * (__a * __c + __b * __d); - z_imag = INFINITY * (__b * __c - __a * __d); - z = CMPLX(z_real, z_imag); - } else if (__spirv_IsInf(__logbw) && __logbw > 0.0 && - __spirv_IsFinite(__a) && __spirv_IsFinite(__b)) { - __c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0 : 0.0, __c); - __d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0 : 0.0, __d); - z_real = 0.0 * (__a * __c + __b * __d); - z_imag = 0.0 * (__b * __c - __a * __d); - z = CMPLX(z_real, z_imag); - } - } - return z; -} - DEVICE_EXTERN_C_INLINE double __devicelib_cabs(double __complex__ z) { return __spirv_ocl_hypot(__devicelib_creal(z), __devicelib_cimag(z)); @@ -177,9 +81,8 @@ DEVICE_EXTERN_C_INLINE double __complex__ __devicelib_cpow(double __complex__ x, double __complex__ y) { double __complex__ t = __devicelib_clog(x); - double __complex__ w = - __devicelib___muldc3(__devicelib_creal(y), __devicelib_cimag(y), - __devicelib_creal(t), __devicelib_cimag(t)); + double __complex__ w = __muldc3(__devicelib_creal(y), __devicelib_cimag(y), + __devicelib_creal(t), __devicelib_cimag(t)); return __devicelib_cexp(w); } @@ -427,8 +330,8 @@ double __complex__ __devicelib_catanh(double __complex__ z) { double __complex__ t1 = 1.0 + z; double __complex__ t2 = 1.0 - z; double __complex__ t3 = - __devicelib___divdc3(__devicelib_creal(t1), __devicelib_cimag(t1), - __devicelib_creal(t2), __devicelib_cimag(t2)); + __divdc3(__devicelib_creal(t1), __devicelib_cimag(t1), + __devicelib_creal(t2), __devicelib_cimag(t2)); double __complex__ w = __devicelib_clog(t3) / 2.0; return CMPLX(__spirv_ocl_copysign(__devicelib_creal(w), z_real), __spirv_ocl_copysign(__devicelib_cimag(w), z_imag)); diff --git a/libdevice/fallback-complex.cpp b/libdevice/fallback-complex.cpp index 9f94195a3a407..fd6e22d45e8d7 100644 --- a/libdevice/fallback-complex.cpp +++ b/libdevice/fallback-complex.cpp @@ -20,104 +20,6 @@ float __devicelib_crealf(float __complex__ z) { return __real__(z); } DEVICE_EXTERN_C_INLINE float __devicelib_cimagf(float __complex__ z) { return __imag__(z); } -// __mulsc3 -// Returns: the product of a + ib and c + id -DEVICE_EXTERN_C_INLINE -float __complex__ __devicelib___mulsc3(float __a, float __b, float __c, - float __d) { - float __ac = __a * __c; - float __bd = __b * __d; - float __ad = __a * __d; - float __bc = __b * __c; - float __complex__ z; - z = CMPLXF((__ac - __bd), (__ad + __bc)); - if (__spirv_IsNan(__devicelib_crealf(z)) && - __spirv_IsNan(__devicelib_cimagf(z))) { - int __recalc = 0; - if (__spirv_IsInf(__a) || __spirv_IsInf(__b)) { - __a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0f : 0.0f, __a); - __b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0f : 0.0f, __b); - if (__spirv_IsNan(__c)) - __c = __spirv_ocl_copysign(0.0f, __c); - if (__spirv_IsNan(__d)) - __d = __spirv_ocl_copysign(0.0f, __d); - __recalc = 1; - } - if (__spirv_IsInf(__c) || __spirv_IsInf(__d)) { - __c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0f : 0.0f, __c); - __d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0f : 0.0f, __d); - if (__spirv_IsNan(__a)) - __a = __spirv_ocl_copysign(0.0f, __a); - if (__spirv_IsNan(__b)) - __b = __spirv_ocl_copysign(0.0f, __b); - __recalc = 1; - } - if (!__recalc && (__spirv_IsInf(__ac) || __spirv_IsInf(__bd) || - __spirv_IsInf(__ad) || __spirv_IsInf(__bc))) { - if (__spirv_IsNan(__a)) - __a = __spirv_ocl_copysign(0.0f, __a); - if (__spirv_IsNan(__b)) - __b = __spirv_ocl_copysign(0.0f, __b); - if (__spirv_IsNan(__c)) - __c = __spirv_ocl_copysign(0.0f, __c); - if (__spirv_IsNan(__d)) - __d = __spirv_ocl_copysign(0.0f, __d); - __recalc = 1.0f; - } - if (__recalc) { - z = CMPLXF((INFINITY * (__a * __c - __b * __d)), - (INFINITY * (__a * __d + __b * __c))); - } - } - return z; -} - -// __divsc3 -// Returns: the quotient of (a + ib) / (c + id) -// FIXME: divsc3/divdc3 have overflow issue when dealing with large number. -// And this overflow issue is from libc++/compiler-rt's implementation. -DEVICE_EXTERN_C_INLINE -float __complex__ __devicelib___divsc3(float __a, float __b, float __c, - float __d) { - int __ilogbw = 0; - float __logbw = __spirv_ocl_logb( - __spirv_ocl_fmax(__spirv_ocl_fabs(__c), __spirv_ocl_fabs(__d))); - if (__spirv_IsFinite(__logbw)) { - __ilogbw = (int)__logbw; - __c = __spirv_ocl_ldexp(__c, -__ilogbw); - __d = __spirv_ocl_ldexp(__d, -__ilogbw); - } - float __denom = __c * __c + __d * __d; - float __complex__ z; - float z_real = - __spirv_ocl_ldexp((__a * __c + __b * __d) / __denom, -__ilogbw); - float z_imag = - __spirv_ocl_ldexp((__b * __c - __a * __d) / __denom, -__ilogbw); - z = CMPLXF(z_real, z_imag); - if (__spirv_IsNan(z_real) && __spirv_IsNan(z_imag)) { - if ((__denom == 0.0f) && (!__spirv_IsNan(__a) || !__spirv_IsNan(__b))) { - z_real = __spirv_ocl_copysign(INFINITY, __c) * __a; - z_imag = __spirv_ocl_copysign(INFINITY, __c) * __b; - z = CMPLXF(z_real, z_imag); - } else if ((__spirv_IsInf(__a) || __spirv_IsInf(__b)) && - __spirv_IsFinite(__c) && __spirv_IsFinite(__d)) { - __a = __spirv_ocl_copysign(__spirv_IsInf(__a) ? 1.0f : 0.0f, __a); - __b = __spirv_ocl_copysign(__spirv_IsInf(__b) ? 1.0f : 0.0f, __b); - z_real = INFINITY * (__a * __c + __b * __d); - z_imag = INFINITY * (__b * __c - __a * __d); - z = CMPLXF(z_real, z_imag); - } else if (__spirv_IsInf(__logbw) && __logbw > 0.0f && - __spirv_IsFinite(__a) && __spirv_IsFinite(__b)) { - __c = __spirv_ocl_copysign(__spirv_IsInf(__c) ? 1.0f : 0.0f, __c); - __d = __spirv_ocl_copysign(__spirv_IsInf(__d) ? 1.0f : 0.0f, __d); - z_real = 0.0f * (__a * __c + __b * __d); - z_imag = 0.0f * (__b * __c - __a * __d); - z = CMPLXF(z_real, z_imag); - } - } - return z; -} - DEVICE_EXTERN_C_INLINE float __devicelib_cargf(float __complex__ z) { return __spirv_ocl_atan2(__devicelib_cimagf(z), __devicelib_crealf(z)); @@ -169,9 +71,8 @@ float __complex__ __devicelib_clogf(float __complex__ z) { DEVICE_EXTERN_C_INLINE float __complex__ __devicelib_cpowf(float __complex__ x, float __complex__ y) { float __complex__ t = __devicelib_clogf(x); - float __complex__ w = - __devicelib___mulsc3(__devicelib_crealf(y), __devicelib_cimagf(y), - __devicelib_crealf(t), __devicelib_cimagf(t)); + float __complex__ w = __mulsc3(__devicelib_crealf(y), __devicelib_cimagf(y), + __devicelib_crealf(t), __devicelib_cimagf(t)); return __devicelib_cexpf(w); } @@ -421,8 +322,8 @@ float __complex__ __devicelib_catanhf(float __complex__ z) { float __complex__ t1 = 1.0f + z; float __complex__ t2 = 1.0f - z; float __complex__ t3 = - __devicelib___divsc3(__devicelib_crealf(t1), __devicelib_cimagf(t1), - __devicelib_crealf(t2), __devicelib_cimagf(t2)); + __divsc3(__devicelib_crealf(t1), __devicelib_cimagf(t1), + __devicelib_crealf(t2), __devicelib_cimagf(t2)); float __complex__ w = __devicelib_clogf(t3) / 2.0f; return CMPLXF(__spirv_ocl_copysign(__devicelib_crealf(w), z_real), __spirv_ocl_copysign(__devicelib_cimagf(w), z_imag)); diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt index fba0c7a01f972..046d32a87235e 100644 --- a/llvm/runtimes/CMakeLists.txt +++ b/llvm/runtimes/CMakeLists.txt @@ -141,6 +141,7 @@ function(builtin_register_target compiler_rt_path name) -DLLVM_RUNTIME_OUTPUT_INTDIR=${LLVM_TOOLS_BINARY_DIR} -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON -DLLVM_CMAKE_DIR=${CMAKE_BINARY_DIR} + -DLLVM_BUILTINS_TARGET=${name} -DCMAKE_C_COMPILER_WORKS=ON -DCMAKE_CXX_COMPILER_WORKS=ON -DCMAKE_ASM_COMPILER_WORKS=ON diff --git a/sycl/CMakeLists.txt b/sycl/CMakeLists.txt index e55ae14ab6dd8..1d37fb7ef18a7 100644 --- a/sycl/CMakeLists.txt +++ b/sycl/CMakeLists.txt @@ -529,6 +529,13 @@ if("lld" IN_LIST LLVM_ENABLE_PROJECTS) list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS lld) endif() +if ("compiler-rt" IN_LIST RUNTIMES_spirv64-intel-sycl_LLVM_ENABLE_RUNTIMES OR + ("compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES AND + "spirv64-intel-unknown" IN_LIST LLVM_BUILTIN_TARGETS)) + add_dependencies(sycl-toolchain builtins-spirv64-intel-unknown) + list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS builtins-spirv64-intel-unknown) +endif() + if("libclc" IN_LIST LLVM_ENABLE_PROJECTS) add_dependencies(sycl-toolchain libspirv-builtins) list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins) diff --git a/sycl/include/sycl/stl_wrappers/cmath b/sycl/include/sycl/stl_wrappers/cmath index b411eb7e81e81..6b111e93fe44a 100644 --- a/sycl/include/sycl/stl_wrappers/cmath +++ b/sycl/include/sycl/stl_wrappers/cmath @@ -216,8 +216,8 @@ extern __DPCPP_SYCL_EXTERNAL_LIBC double __complex__ __muldc3(double a, double d); extern __DPCPP_SYCL_EXTERNAL_LIBC float __complex__ __divsc3(float a, float b, float c, float d); -extern __DPCPP_SYCL_EXTERNAL_LIBC double __complex__ __divdc3(float a, float b, - float c, float d); +extern __DPCPP_SYCL_EXTERNAL_LIBC double __complex__ __divdc3(double a, double b, + double c, double d); } #elif defined(_WIN32) extern "C" {