Skip to content

Commit 48ea0a1

Browse files
authored
[SYCL] Pass --spirv-preserve-auxdata to llvm-spirv for SPIR-V fat objects (#9089)
This option preserves function metadata and attributes we need in sycl-post-link. These were previously lost during forward translation to SPIR-V. --------- Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
1 parent 5bd42eb commit 48ea0a1

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9529,6 +9529,13 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
95299529
// operations which don't have mapping to OpenCL.DebugInfo.100 spec.
95309530
TranslatorArgs.push_back("-spirv-allow-extra-diexpressions");
95319531
TranslatorArgs.push_back("-spirv-allow-unknown-intrinsics=llvm.genx.");
9532+
bool CreatingSyclSPIRVFatObj =
9533+
C.getDriver().getFinalPhase(C.getArgs()) != phases::Link &&
9534+
TCArgs.getLastArgValue(options::OPT_fsycl_device_obj_EQ)
9535+
.equals_insensitive("spirv") &&
9536+
!TCArgs.hasArg(options::OPT_fsycl_device_only);
9537+
if (CreatingSyclSPIRVFatObj)
9538+
TranslatorArgs.push_back("--spirv-preserve-auxdata");
95329539

95339540
// Disable all the extensions by default
95349541
std::string ExtArg("-spirv-ext=-all");
@@ -9571,6 +9578,9 @@ void SPIRVTranslator::ConstructJob(Compilation &C, const JobAction &JA,
95719578
",+SPV_KHR_uniform_group_instructions"
95729579
",+SPV_INTEL_masked_gather_scatter"
95739580
",+SPV_INTEL_tensor_float32_conversion";
9581+
if (CreatingSyclSPIRVFatObj)
9582+
ExtArg += ",+SPV_KHR_non_semantic_info";
9583+
95749584
TranslatorArgs.push_back(TCArgs.MakeArgString(ExtArg));
95759585
}
95769586
for (auto I : Inputs) {
@@ -9947,6 +9957,10 @@ void SpirvToIrWrapper::ConstructJob(Compilation &C, const JobAction &JA,
99479957
// Output File
99489958
addArgs(CmdArgs, TCArgs, {"-o", Output.getFilename()});
99499959

9960+
// Make sure we preserve any auxiliary data which may be present in the
9961+
// SPIR-V object, which we need for SPIR-V-based fat objects.
9962+
addArgs(CmdArgs, TCArgs, {"-llvm-spirv-opts", "--spirv-preserve-auxdata"});
9963+
99509964
auto Cmd = std::make_unique<Command>(
99519965
JA, *this, ResponseFileSupport::None(),
99529966
TCArgs.MakeArgString(getToolChain().GetProgramPath(getShortName())),

clang/test/Driver/sycl-spirv-obj.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// SPIRV_DEVICE_OBJ-SAME: "-fsycl-is-device"
1111
// SPIRV_DEVICE_OBJ-SAME: "-o" "[[DEVICE_BC:.+\.bc]]"
1212
// SPIRV_DEVICE_OBJ: llvm-spirv{{.*}} "-o" "[[DEVICE_SPV:.+\.spv]]"
13+
// SPIRV_DEVICE_OBJ-SAME: "--spirv-preserve-auxdata"
14+
// SPIRV_DEVICE_OBJ-SAME: "-spirv-ext=-all,{{.*}},+SPV_KHR_non_semantic_info"
1315
// SPIRV_DEVICE_OBJ-SAME: "[[DEVICE_BC]]"
1416
// SPIRV_DEVICE_OBJ: clang{{.*}} "-cc1" "-triple" "x86_64-unknown-linux-gnu"
1517
// SPIRV_DEVICE_OBJ-SAME: "-fsycl-is-host"
@@ -38,5 +40,5 @@
3840
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fsycl-device-obj=spirv -### %t.o 2>&1 | \
3941
// RUN: FileCheck %s -check-prefixes=OPT_WARNING,LLVM_SPIRV_R
4042
// OPT_WARNING: warning: argument unused during compilation: '-fsycl-device-obj=spirv'
41-
// LLVM_SPIRV_R: spirv-to-ir-wrapper{{.*}}
43+
// LLVM_SPIRV_R: spirv-to-ir-wrapper{{.*}} "-llvm-spirv-opts" "--spirv-preserve-auxdata"
4244
// LLVM_SPIRV_R-NOT: llvm-spirv{{.*}} "-r"

0 commit comments

Comments
 (0)