From 20bf13f909321e70c828da5d3fd964bc91470f9c Mon Sep 17 00:00:00 2001 From: Michael D Toguchi Date: Tue, 7 May 2024 11:22:24 -0700 Subject: [PATCH] [Driver][SYCL][NewOffloadModel] Hook up -fsycl-device-obj support The -fsycl-device-obj option is available to allow the user to specify if they want a different output binary with -fsycl based compilations. Default is to create LLVM-IR based device binaries, but when using -fsycl-device-obj=spirv, we will generate SPIR-V based binaries. --- clang/lib/Driver/Driver.cpp | 9 +++++++++ clang/test/Driver/sycl-offload-new-driver.c | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3670054dc7ae0..cd8bd3d55e7e2 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -7914,6 +7914,15 @@ Action *Driver::BuildOffloadingActions(Compilation &C, ++TCAndArch; } } + // Use of -fsycl-device-obj=spirv converts the original LLVM-IR file to + // SPIR-V for later consumption. + for (Action *&A : DeviceActions) { + if (!Args.getLastArgValue(options::OPT_fsycl_device_obj_EQ) + .equals_insensitive("spirv") || + Kind != Action::OFK_SYCL || A->getType() != types::TY_LLVM_BC) + continue; + A = C.MakeAction(A, types::TY_SPIRV); + } // Compiling HIP in non-RDC mode requires linking each action individually. for (Action *&A : DeviceActions) { diff --git a/clang/test/Driver/sycl-offload-new-driver.c b/clang/test/Driver/sycl-offload-new-driver.c index fa9b8e4289872..0f42bb2cbe95f 100644 --- a/clang/test/Driver/sycl-offload-new-driver.c +++ b/clang/test/Driver/sycl-offload-new-driver.c @@ -36,6 +36,21 @@ // WRAPPER_OPTIONS-SAME: "-sycl-device-libraries=libsycl-crt.new.o,libsycl-complex.new.o,libsycl-complex-fp64.new.o,libsycl-cmath.new.o,libsycl-cmath-fp64.new.o,libsycl-imf.new.o,libsycl-imf-fp64.new.o,libsycl-imf-bf16.new.o,libsycl-itt-user-wrappers.new.o,libsycl-itt-compiler-wrappers.new.o,libsycl-itt-stubs.new.o" // WRAPPER_OPTIONS-SAME: "-sycl-device-library-location={{.*}}/lib" +/// Verify phases used to generate SPIR-V instead of LLVM-IR +// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \ +// RUN: -fsycl-device-obj=spirv -ccc-print-phases %s 2>&1 \ +// RUN: | FileCheck -check-prefix SPIRV_OBJ %s +// RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \ +// RUN: -fsycl-device-only -fsycl-device-obj=spirv \ +// RUN: -ccc-print-phases %s 2>&1 \ +// RUN: | FileCheck -check-prefix SPIRV_OBJ %s +// SPIRV_OBJ: [[#SPVOBJ:]]: input, "{{.*}}", c++, (device-sycl) +// SPIRV_OBJ: [[#SPVOBJ+1]]: preprocessor, {[[#SPVOBJ]]}, c++-cpp-output, (device-sycl) +// SPIRV_OBJ: [[#SPVOBJ+2]]: compiler, {[[#SPVOBJ+1]]}, ir, (device-sycl) +// SPIRV_OBJ: [[#SPVOBJ+3]]: backend, {[[#SPVOBJ+2]]}, ir, (device-sycl) +// SPIRV_OBJ: [[#SPVOBJ+4]]: llvm-spirv, {[[#SPVOBJ+3]]}, spirv, (device-sycl) +// SPIRV_OBJ: [[#SPVOBJ+5]]: offload, "device-sycl (spir64-unknown-unknown)" {[[#SPVOBJ+4]]}, {{.*}} + // RUN: %clangxx --target=x86_64-unknown-linux-gnu -fsycl --offload-new-driver \ // RUN: -Xspirv-translator -translator-opt -### %s 2>&1 \ // RUN: | FileCheck -check-prefix WRAPPER_OPTIONS_TRANSLATOR %s