From 3365e24ee74e1506a4a09d917289d74701e36797 Mon Sep 17 00:00:00 2001 From: "Levytskyy, Vyacheslav" Date: Mon, 13 Jan 2025 02:35:26 -0800 Subject: [PATCH] Introduce SPIR-V Backend support in Clang/Driver --- clang/lib/Driver/ToolChains/Clang.cpp | 39 +++++++----------------- clang/test/Driver/sycl-spirv-backend.cpp | 2 +- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index a25659459a5b4..10e3a4920fda7 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -10706,38 +10706,21 @@ static void getSPIRVBackendOpts(const llvm::opt::ArgList &TCArgs, ArgStringList &BackendArgs) { BackendArgs.push_back(TCArgs.MakeArgString("-filetype=obj")); BackendArgs.push_back( - TCArgs.MakeArgString("-mtriple=spirv64-unknown-unknown")); - // TODO: Optimization level is currently forced to -O0 due to some testing - // issues. Update optimization level after testing issues are resolved. - BackendArgs.push_back(TCArgs.MakeArgString("-O0")); + TCArgs.MakeArgString("-mtriple=spirv64v1.6-unknown-unknown")); BackendArgs.push_back( TCArgs.MakeArgString("--avoid-spirv-capabilities=Shader")); BackendArgs.push_back( TCArgs.MakeArgString("--translator-compatibility-mode")); - - // TODO: There is some overlap between the lists of extensions in SPIR-V - // backend and SPIR-V Trnaslator). We will try to combine them when SPIR-V - // backdn is ready. - std::string ExtArg("--spirv-ext="); - std::string DefaultExtArg = - "+SPV_EXT_shader_atomic_float_add,+SPV_EXT_shader_atomic_float_min_max" - ",+SPV_KHR_no_integer_wrap_decoration,+SPV_KHR_float_controls" - ",+SPV_KHR_expect_assume,+SPV_KHR_linkonce_odr"; - std::string INTELExtArg = ",+SPV_INTEL_subgroups,+SPV_INTEL_function_pointers" - ",+SPV_INTEL_arbitrary_precision_integers" - ",+SPV_INTEL_variable_length_array"; - ExtArg = ExtArg + DefaultExtArg + INTELExtArg; - - // Other args - ExtArg += ",+SPV_INTEL_bfloat16_conversion" - ",+SPV_KHR_uniform_group_instructions" - ",+SPV_INTEL_optnone" - ",+SPV_KHR_subgroup_rotate" - ",+SPV_INTEL_usm_storage_classes" - ",+SPV_EXT_shader_atomic_float16_add" - ",+SPV_KHR_bit_instructions"; - - BackendArgs.push_back(TCArgs.MakeArgString(ExtArg)); + // TODO: A list of SPIR-V extensions that are supported by the SPIR-V backend + // is growing. Let's postpone the decision on which extensions to enable until + // - the list is stable, and + // - we decide on a mapping of user requested extensions into backend's ones. + // Meanwhile we enable all the SPIR-V backend extensions. + BackendArgs.push_back(TCArgs.MakeArgString("--spirv-ext=all")); + // TODO: + // - handle -Xspirv-translator option to avoid "argument unused during + // compilation" error + // - handle --spirv-ext=+ and --spirv-ext=- options } // Utility function to gather all llvm-spirv options. diff --git a/clang/test/Driver/sycl-spirv-backend.cpp b/clang/test/Driver/sycl-spirv-backend.cpp index db159f6deafb5..7697c1055b3d2 100644 --- a/clang/test/Driver/sycl-spirv-backend.cpp +++ b/clang/test/Driver/sycl-spirv-backend.cpp @@ -3,4 +3,4 @@ /// // RUN: %clangxx -fsycl -fsycl-use-spirv-backend-for-spirv-gen -### %s 2>&1 | FileCheck %s -// CHECK: llc{{.*}} "-filetype=obj" "-mtriple=spirv64-unknown-unknown" "-O0" "--avoid-spirv-capabilities=Shader" "--translator-compatibility-mode" "--spirv-ext= +// CHECK: llc{{.*}} "-filetype=obj" "-mtriple=spirv64{{[^-]*}}-unknown-unknown" "--avoid-spirv-capabilities=Shader" "--translator-compatibility-mode" "--spirv-ext=