diff --git a/buildbot/configure.py b/buildbot/configure.py index d7c073c63ad5f..03945344e37f5 100644 --- a/buildbot/configure.py +++ b/buildbot/configure.py @@ -208,6 +208,24 @@ def do_configure(args, passthrough_args): "-DBUG_REPORT_URL=https://github.com/intel/llvm/issues", ] + if args.ci_defaults: + llvm_builtin_targets = "default;spirv64-unknown-unknown" + cmake_cmd.extend( + [ + "-DLLVM_BUILTIN_TARGETS={}".format(llvm_builtin_targets), + ] + ) + else: + llvm_runtime_targets = "spirv64-unknown-unknown" + llvm_spirv64_runtimes = "compiler-rt" + cmake_cmd.extend( + [ + "-DRUNTIMES_spirv64-unknown-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 990e78271237d..e1fba9b85328e 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -5839,6 +5839,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-unknown-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 05320a2d51cc3..c073cdf4b1aa0 100644 --- a/clang/lib/Driver/ToolChains/SYCL.cpp +++ b/clang/lib/Driver/ToolChains/SYCL.cpp @@ -597,6 +597,7 @@ SYCLToolChain::getDeviceLibNames(const Driver &D, "libsycl-fallback-complex-fp64", "libsycl-fallback-cmath", "libsycl-fallback-cmath-fp64", + "libclang_rt.builtins", "libsycl-fallback-imf", "libsycl-fallback-imf-fp64", "libsycl-fallback-imf-bf16"}; @@ -833,6 +834,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 +1923,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-unknown-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/clang/test/Driver/sycl-no-rdc-fat-archive-old-model.cpp b/clang/test/Driver/sycl-no-rdc-fat-archive-old-model.cpp index fe871ebf916dc..34180c469aba3 100644 --- a/clang/test/Driver/sycl-no-rdc-fat-archive-old-model.cpp +++ b/clang/test/Driver/sycl-no-rdc-fat-archive-old-model.cpp @@ -13,18 +13,18 @@ // CHECK: 2: clang-offload-unbundler, {1}, tempfilelist // CHECK: 3: spirv-to-ir-wrapper, {2}, tempfilelist, (device-sycl) // CHECK: 4: input, "{{.*}}libsycl-crt.bc", ir, (device-sycl) -// CHECK: 23: linker, {4, {{.*}}}, ir, (device-sycl) -// CHECK: 24: linker, {3, 23}, ir, (device-sycl) -// CHECK: 25: foreach, {3, 24}, ir, (device-sycl) -// CHECK: 26: file-table-tform, {3, 25}, tempfilelist, (device-sycl) -// CHECK: 27: sycl-post-link, {26}, tempfiletable, (device-sycl) -// CHECK: 28: foreach, {26, 27}, tempfiletable, (device-sycl) -// CHECK: 29: file-table-tform, {28}, tempfilelist, (device-sycl) -// CHECK: 30: file-table-tform, {28}, tempfilelist, (device-sycl) -// CHECK: 31: foreach, {26, 30}, tempfilelist, (device-sycl) -// CHECK: 32: file-table-tform, {31}, tempfilelist, (device-sycl) -// CHECK: 33: llvm-spirv, {32}, tempfilelist, (device-sycl) -// CHECK: 34: file-table-tform, {29, 33}, tempfiletable, (device-sycl) -// CHECK: 35: clang-offload-wrapper, {34}, object, (device-sycl) -// CHECK: 36: offload, "device-sycl (spir64-unknown-unknown)" {35}, object -// CHECK: 37: linker, {0, 36}, image, (host-sycl) +// CHECK: 24: linker, {4, {{.*}}}, ir, (device-sycl) +// CHECK: 25: linker, {3, 24}, ir, (device-sycl) +// CHECK: 26: foreach, {3, 25}, ir, (device-sycl) +// CHECK: 27: file-table-tform, {3, 26}, tempfilelist, (device-sycl) +// CHECK: 28: sycl-post-link, {27}, tempfiletable, (device-sycl) +// CHECK: 29: foreach, {27, 28}, tempfiletable, (device-sycl) +// CHECK: 30: file-table-tform, {29}, tempfilelist, (device-sycl) +// CHECK: 31: file-table-tform, {29}, tempfilelist, (device-sycl) +// CHECK: 32: foreach, {27, 31}, tempfilelist, (device-sycl) +// CHECK: 33: file-table-tform, {32}, tempfilelist, (device-sycl) +// CHECK: 34: llvm-spirv, {33}, tempfilelist, (device-sycl) +// CHECK: 35: file-table-tform, {30, 34}, tempfiletable, (device-sycl) +// CHECK: 36: clang-offload-wrapper, {35}, object, (device-sycl) +// CHECK: 37: offload, "device-sycl (spir64-unknown-unknown)" {36}, object +// CHECK: 38: linker, {0, 37}, image, (host-sycl) diff --git a/clang/test/Driver/sycl-no-rdc-fat-archive-win.cpp b/clang/test/Driver/sycl-no-rdc-fat-archive-win.cpp index bc0e5c3f63566..fc50fa7fed855 100644 --- a/clang/test/Driver/sycl-no-rdc-fat-archive-win.cpp +++ b/clang/test/Driver/sycl-no-rdc-fat-archive-win.cpp @@ -18,18 +18,18 @@ // CHECK: 2: clang-offload-unbundler, {1}, tempfilelist // CHECK: 3: spirv-to-ir-wrapper, {2}, tempfilelist, (device-sycl) // CHECK: 4: input, "{{.*}}libsycl-crt{{.*}}", ir, (device-sycl) -// CHECK: 24: linker, {4, {{.*}}}, ir, (device-sycl) -// CHECK: 25: linker, {3, 24}, ir, (device-sycl) -// CHECK: 26: foreach, {3, 25}, ir, (device-sycl) -// CHECK: 27: file-table-tform, {3, 26}, tempfilelist, (device-sycl) -// CHECK: 28: sycl-post-link, {27}, tempfiletable, (device-sycl) -// CHECK: 29: foreach, {27, 28}, tempfiletable, (device-sycl) -// CHECK: 30: file-table-tform, {29}, tempfilelist, (device-sycl) -// CHECK: 31: file-table-tform, {29}, tempfilelist, (device-sycl) -// CHECK: 32: foreach, {27, 31}, tempfilelist, (device-sycl) -// CHECK: 33: file-table-tform, {32}, tempfilelist, (device-sycl) -// CHECK: 34: llvm-spirv, {33}, tempfilelist, (device-sycl) -// CHECK: 35: file-table-tform, {30, 34}, tempfiletable, (device-sycl) -// CHECK: 36: clang-offload-wrapper, {35}, object, (device-sycl) -// CHECK: 37: offload, "device-sycl (spir64-unknown-unknown)" {36}, object -// CHECK: 38: linker, {0, 37}, image, (host-sycl) +// CHECK: 25: linker, {4, {{.*}}}, ir, (device-sycl) +// CHECK: 26: linker, {3, 25}, ir, (device-sycl) +// CHECK: 27: foreach, {3, 26}, ir, (device-sycl) +// CHECK: 28: file-table-tform, {3, 27}, tempfilelist, (device-sycl) +// CHECK: 29: sycl-post-link, {28}, tempfiletable, (device-sycl) +// CHECK: 30: foreach, {28, 29}, tempfiletable, (device-sycl) +// CHECK: 31: file-table-tform, {30}, tempfilelist, (device-sycl) +// CHECK: 32: file-table-tform, {30}, tempfilelist, (device-sycl) +// CHECK: 33: foreach, {28, 32}, tempfilelist, (device-sycl) +// CHECK: 34: file-table-tform, {33}, tempfilelist, (device-sycl) +// CHECK: 35: llvm-spirv, {34}, tempfilelist, (device-sycl) +// CHECK: 36: file-table-tform, {31, 35}, tempfiletable, (device-sycl) +// CHECK: 37: clang-offload-wrapper, {36}, object, (device-sycl) +// CHECK: 38: offload, "device-sycl (spir64-unknown-unknown)" {37}, object +// CHECK: 39: linker, {0, 38}, image, (host-sycl) diff --git a/clang/test/Driver/sycl-no-rdc-old-model.cpp b/clang/test/Driver/sycl-no-rdc-old-model.cpp index 6bb6fec807614..814779a581136 100644 --- a/clang/test/Driver/sycl-no-rdc-old-model.cpp +++ b/clang/test/Driver/sycl-no-rdc-old-model.cpp @@ -12,19 +12,19 @@ // CHECK: 12: preprocessor, {11}, c++-cpp-output, (device-sycl) // CHECK: 13: compiler, {12}, ir, (device-sycl) // CHECK: 18: input, "{{.*}}libsycl-crt.bc", ir, (device-sycl) -// CHECK: 37: linker, {18, {{.*}}}, ir, (device-sycl) -// CHECK: 38: linker, {4, 37}, ir, (device-sycl) -// CHECK: 39: sycl-post-link, {38}, tempfiletable, (device-sycl) -// CHECK: 40: file-table-tform, {39}, tempfilelist, (device-sycl) -// CHECK: 41: llvm-spirv, {40}, tempfilelist, (device-sycl) -// CHECK: 42: file-table-tform, {39, 41}, tempfiletable, (device-sycl) -// CHECK: 43: clang-offload-wrapper, {42}, object, (device-sycl) -// CHECK: 44: offload, "device-sycl (spir64-unknown-unknown)" {43}, object -// CHECK: 45: linker, {13, 37}, ir, (device-sycl) -// CHECK: 46: sycl-post-link, {45}, tempfiletable, (device-sycl) -// CHECK: 47: file-table-tform, {46}, tempfilelist, (device-sycl) -// CHECK: 48: llvm-spirv, {47}, tempfilelist, (device-sycl) -// CHECK: 49: file-table-tform, {46, 48}, tempfiletable, (device-sycl) -// CHECK: 50: clang-offload-wrapper, {49}, object, (device-sycl) -// CHECK: 51: offload, "device-sycl (spir64-unknown-unknown)" {50}, object -// CHECK: 52: linker, {8, 17, 44, 51}, image, (host-sycl) +// CHECK: 38: linker, {18, {{.*}}}, ir, (device-sycl) +// CHECK: 39: linker, {4, 38}, ir, (device-sycl) +// CHECK: 40: sycl-post-link, {39}, tempfiletable, (device-sycl) +// CHECK: 41: file-table-tform, {40}, tempfilelist, (device-sycl) +// CHECK: 42: llvm-spirv, {41}, tempfilelist, (device-sycl) +// CHECK: 43: file-table-tform, {40, 42}, tempfiletable, (device-sycl) +// CHECK: 44: clang-offload-wrapper, {43}, object, (device-sycl) +// CHECK: 45: offload, "device-sycl (spir64-unknown-unknown)" {44}, object +// CHECK: 46: linker, {13, 38}, ir, (device-sycl) +// CHECK: 47: sycl-post-link, {46}, tempfiletable, (device-sycl) +// CHECK: 48: file-table-tform, {47}, tempfilelist, (device-sycl) +// CHECK: 49: llvm-spirv, {48}, tempfilelist, (device-sycl) +// CHECK: 50: file-table-tform, {47, 49}, tempfiletable, (device-sycl) +// CHECK: 51: clang-offload-wrapper, {50}, object, (device-sycl) +// CHECK: 52: offload, "device-sycl (spir64-unknown-unknown)" {51}, object +// CHECK: 53: linker, {8, 17, 45, 52}, image, (host-sycl) diff --git a/clang/test/Driver/sycl-no-rdc-win.cpp b/clang/test/Driver/sycl-no-rdc-win.cpp index 61b39a642d1c5..715d54d3eed5c 100644 --- a/clang/test/Driver/sycl-no-rdc-win.cpp +++ b/clang/test/Driver/sycl-no-rdc-win.cpp @@ -15,22 +15,22 @@ // CHECK: 13: compiler, {12}, ir, (device-sycl) // CHECK: 14: offload, "host-sycl (x86_64-pc-windows-msvc)" {10}, "device-sycl (spir64-unknown-unknown)" {13}, c++-cpp-output // CHECK: 18: input, "{{.*}}libsycl-crt{{.*}}", ir, (device-sycl) -// CHECK: 38: linker, {18, {{.*}}}, ir, (device-sycl) -// CHECK: 39: linker, {4, 38}, ir, (device-sycl) -// CHECK: 40: sycl-post-link, {39}, tempfiletable, (device-sycl) -// CHECK: 41: file-table-tform, {40}, tempfilelist, (device-sycl) -// CHECK: 42: llvm-spirv, {41}, tempfilelist, (device-sycl) -// CHECK: 43: file-table-tform, {40, 42}, tempfiletable, (device-sycl) -// CHECK: 44: clang-offload-wrapper, {43}, object, (device-sycl) -// CHECK: 45: offload, "device-sycl (spir64-unknown-unknown)" {44}, object -// CHECK: 46: linker, {13, 38}, ir, (device-sycl) -// CHECK: 47: sycl-post-link, {46}, tempfiletable, (device-sycl) -// CHECK: 48: file-table-tform, {47}, tempfilelist, (device-sycl) -// CHECK: 49: llvm-spirv, {48}, tempfilelist, (device-sycl) -// CHECK: 50: file-table-tform, {47, 49}, tempfiletable, (device-sycl) -// CHECK: 51: clang-offload-wrapper, {50}, object, (device-sycl) -// CHECK: 52: offload, "device-sycl (spir64-unknown-unknown)" {51}, object -// CHECK: 53: linker, {8, 17, 45, 52}, image, (host-sycl) +// CHECK: 39: linker, {18, {{.*}}}, ir, (device-sycl) +// CHECK: 40: linker, {4, 39}, ir, (device-sycl) +// CHECK: 41: sycl-post-link, {40}, tempfiletable, (device-sycl) +// CHECK: 42: file-table-tform, {41}, tempfilelist, (device-sycl) +// CHECK: 43: llvm-spirv, {42}, tempfilelist, (device-sycl) +// CHECK: 44: file-table-tform, {41, 43}, tempfiletable, (device-sycl) +// CHECK: 45: clang-offload-wrapper, {44}, object, (device-sycl) +// CHECK: 46: offload, "device-sycl (spir64-unknown-unknown)" {45}, object +// CHECK: 47: linker, {13, 39}, ir, (device-sycl) +// CHECK: 48: sycl-post-link, {47}, tempfiletable, (device-sycl) +// CHECK: 49: file-table-tform, {48}, tempfilelist, (device-sycl) +// CHECK: 50: llvm-spirv, {49}, tempfilelist, (device-sycl) +// CHECK: 51: file-table-tform, {48, 50}, tempfiletable, (device-sycl) +// CHECK: 52: clang-offload-wrapper, {51}, object, (device-sycl) +// CHECK: 53: offload, "device-sycl (spir64-unknown-unknown)" {52}, object +// CHECK: 54: linker, {8, 17, 46, 53}, image, (host-sycl) // RUN: %clang -### -fsycl -fno-sycl-rdc -c -fsycl-targets=spir64_gen --sysroot=%S/Inputs/SYCL %t1.cpp 2>&1 | FileCheck -check-prefix=CHECK-EARLY %s // RUN: %clang_cl -### -fsycl -fno-sycl-rdc -c -fsycl-targets=spir64_gen /clang:--sysroot=%S/Inputs/SYCL %t1.cpp 2>&1 | FileCheck -check-prefix=CHECK-EARLY %s diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake index d658b7009e859..5cf3968c4d359 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_SPIRV_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 331183c235b27..0227c0e15bccd 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(__SPIRV64__ "" __SPIRV64) 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(__SPIRV64) + add_default_target_arch(spirv64) elseif(__WEBASSEMBLY32) add_default_target_arch(wasm32) elseif(__WEBASSEMBLY64) @@ -425,6 +428,10 @@ 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 "spirv64") + set(COMPILER_RT_GPU_BUILD ON) + set(COMPILER_RT_SPIRV_BUILD ON) + set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -flto -c") endif() endif() @@ -526,6 +533,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-unknown-unknown") else() set(target "${arch}${triple_suffix}") endif() diff --git a/compiler-rt/cmake/builtin-config-ix.cmake b/compiler-rt/cmake/builtin-config-ix.cmake index abaaeadf3bd06..78353c60cd403 100644 --- a/compiler-rt/cmake/builtin-config-ix.cmake +++ b/compiler-rt/cmake/builtin-config-ix.cmake @@ -78,6 +78,7 @@ else() endif() set(AMDGPU amdgcn) +set(SPIRV64 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) @@ -109,7 +110,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} ${SPIRV64} ${WASM32} ${WASM64} ${VE} ${LOONGARCH64} ${M68K}) include(CompilerRTUtils) diff --git a/compiler-rt/lib/builtins/CMakeLists.txt b/compiler-rt/lib/builtins/CMakeLists.txt index c83488bd3ed57..44ff3511a8641 100644 --- a/compiler-rt/lib/builtins/CMakeLists.txt +++ b/compiler-rt/lib/builtins/CMakeLists.txt @@ -757,6 +757,7 @@ if (APPLE) endif() set(amdgcn_SOURCES ${GENERIC_SOURCES}) +set(spirv64_SOURCES ${GENERIC_SOURCES}) set(armv4t_SOURCES ${arm_min_SOURCES}) set(armv5te_SOURCES ${arm_min_SOURCES}) @@ -967,7 +968,7 @@ else () endif() # Directly targeting the GPU requires a few extra flags. - if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx") + if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "amdgcn|nvptx|spirv64") append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding BUILTIN_CFLAGS) append_list_if(COMPILER_RT_HAS_NOGPULIB_FLAG -nogpulib BUILTIN_CFLAGS) append_list_if(COMPILER_RT_HAS_FLTO_FLAG -flto BUILTIN_CFLAGS) diff --git a/compiler-rt/lib/builtins/int_lib.h b/compiler-rt/lib/builtins/int_lib.h index 943430de259d8..0eb47212a1a41 100644 --- a/compiler-rt/lib/builtins/int_lib.h +++ b/compiler-rt/lib/builtins/int_lib.h @@ -64,7 +64,7 @@ COMPILER_RT_ALIAS_VISIBILITY(aliasname) \ __asm__(SYMBOL_NAME(aliasname) " = " SYMBOL_NAME(name)); \ COMPILER_RT_ABI __typeof(name) aliasname; -#elif defined(_WIN32) || defined(__UEFI__) +#elif defined(_WIN32) || defined(__UEFI__) || (__SPIRV__) #define COMPILER_RT_ALIAS(name, aliasname) #else #error Unsupported target diff --git a/compiler-rt/lib/builtins/int_types.h b/compiler-rt/lib/builtins/int_types.h index 7c7f8cb64aa9a..0be6852ccc03d 100644 --- a/compiler-rt/lib/builtins/int_types.h +++ b/compiler-rt/lib/builtins/int_types.h @@ -75,6 +75,10 @@ typedef union { #undef CRT_HAS_128BIT #endif +#if defined(__SPIRV__) +#undef CRT_HAS_128BIT +#endif + #ifdef CRT_HAS_128BIT typedef int ti_int __attribute__((mode(TI))); typedef unsigned tu_int __attribute__((mode(TI))); 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..4f63a0d0a0589 100644 --- a/libdevice/device_complex.h +++ b/libdevice/device_complex.h @@ -22,6 +22,20 @@ #define CMPLXF(r, i) ((float __complex__){(float)(r), (float)(i)}) #endif +#if defined(_WIN32) +DEVICE_EXTERN_C +float __complex__ __mulsc3(float a, float b, float c, float d); + +DEVICE_EXTERN_C +double __complex__ __muldc3(double a, double b, double c, double d); + +DEVICE_EXTERN_C +float __complex__ __divsc3(float a, float b, float c, float d); + +DEVICE_EXTERN_C +double __complex__ __divdc3(double a, double b, double c, double d); +#endif + DEVICE_EXTERN_C double __devicelib_cimag(double __complex__ z); @@ -153,17 +167,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 f22b551b89aca..5ab8c66e2a20c 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 f39639641c316..b9deb42521646 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-unknown-unknown_LLVM_ENABLE_RUNTIMES OR + ("compiler-rt" IN_LIST LLVM_ENABLE_RUNTIMES AND + "spirv64-unknown-unknown" IN_LIST LLVM_BUILTIN_TARGETS)) + add_dependencies(sycl-toolchain builtins-spirv64-unknown-unknown) + list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS builtins-spirv64-unknown-unknown) +endif() + if("libclc" IN_LIST LLVM_ENABLE_RUNTIMES) add_dependencies(sycl-toolchain libclc) list(APPEND SYCL_TOOLCHAIN_DEPLOY_COMPONENTS libspirv-builtins)