[llvm] 14193f4 - [SPIR-V] SPIR-V Backend must generate a valid OCL version if working in OpenCL environment (#89199)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 19 01:08:39 PDT 2024
Author: Vyacheslav Levytskyy
Date: 2024-04-19T10:08:35+02:00
New Revision: 14193f4320e26b75dc592abf952af1c63760665c
URL: https://github.com/llvm/llvm-project/commit/14193f4320e26b75dc592abf952af1c63760665c
DIFF: https://github.com/llvm/llvm-project/commit/14193f4320e26b75dc592abf952af1c63760665c.diff
LOG: [SPIR-V] SPIR-V Backend must generate a valid OCL version if working in OpenCL environment (#89199)
If there is no information about OpenCL version we are forced to
generate OpenCL 1.0 by default for the OpenCL environment to avoid
puzzling run-times with Unknown/0.0 version output. For a reference,
LLVM-SPIRV Translator avoids potential issues with run-times in a
similar manner.
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
llvm/test/CodeGen/SPIRV/empty-module.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 40c3e5f9c6bdab..8395d4b2bf66b5 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -167,10 +167,21 @@ void SPIRVModuleAnalysis::setBaseInfo(const Module &M) {
unsigned MajorNum = getMetadataUInt(VersionMD, 0, 2);
unsigned MinorNum = getMetadataUInt(VersionMD, 1);
unsigned RevNum = getMetadataUInt(VersionMD, 2);
- MAI.SrcLangVersion = (MajorNum * 100 + MinorNum) * 1000 + RevNum;
+ // Prevent Major part of OpenCL version to be 0
+ MAI.SrcLangVersion =
+ (std::max(1U, MajorNum) * 100 + MinorNum) * 1000 + RevNum;
} else {
- MAI.SrcLang = SPIRV::SourceLanguage::Unknown;
- MAI.SrcLangVersion = 0;
+ // If there is no information about OpenCL version we are forced to generate
+ // OpenCL 1.0 by default for the OpenCL environment to avoid puzzling
+ // run-times with Unknown/0.0 version output. For a reference, LLVM-SPIRV
+ // Translator avoids potential issues with run-times in a similar manner.
+ if (ST->isOpenCLEnv()) {
+ MAI.SrcLang = SPIRV::SourceLanguage::OpenCL_CPP;
+ MAI.SrcLangVersion = 100000;
+ } else {
+ MAI.SrcLang = SPIRV::SourceLanguage::Unknown;
+ MAI.SrcLangVersion = 0;
+ }
}
if (auto ExtNode = M.getNamedMetadata("opencl.used.extensions")) {
diff --git a/llvm/test/CodeGen/SPIRV/empty-module.ll b/llvm/test/CodeGen/SPIRV/empty-module.ll
index b56e58ccaf8f1b..b7cea042ee5ddc 100644
--- a/llvm/test/CodeGen/SPIRV/empty-module.ll
+++ b/llvm/test/CodeGen/SPIRV/empty-module.ll
@@ -1,9 +1,15 @@
-; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-OCL
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
-; CHECK-DAG: OpCapability Addresses
-; CHECK-DAG: OpCapability Linkage
-; CHECK-DAG: OpCapability Kernel
-; CHECK: %1 = OpExtInstImport "OpenCL.std"
-; CHECK: OpMemoryModel Physical64 OpenCL
-; CHECK: OpSource Unknown 0
+; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NOOCL
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK-DAG: OpCapability Linkage
+; CHECK-NOOCL-DAG: OpCapability Shader
+; CHECK-OCL-DAG: OpCapability Addresses
+; CHECK-OCL-DAG: OpCapability Kernel
+; CHECK-OCL: %1 = OpExtInstImport "OpenCL.std"
+; CHECK-NOOCL: OpMemoryModel Logical GLSL450
+; CHECK-OCL: OpMemoryModel Physical64 OpenCL
+; CHECK-NOOCL: OpSource Unknown 0
+; CHECK-OCL: OpSource OpenCL_CPP 100000
More information about the llvm-commits
mailing list