diff --git a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp index 8fba6417a7..3f141f315f 100644 --- a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp +++ b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp @@ -53,6 +53,13 @@ void LLVMToSPIRVDbgTran::transDebugMetadata() { if (DIF.compile_unit_count() == 0) return; + if (isNonSemanticDebugInfo()) { + if (!BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_6)) + BM->addExtension(SPIRV::ExtensionID::SPV_KHR_non_semantic_info); + else + BM->setMinSPIRVVersion(static_cast(VersionNumber::SPIRV_1_6)); + } + for (DICompileUnit *CU : DIF.compile_units()) { transDbgEntry(CU); for (DIImportedEntity *IE : CU->getImportedEntities()) @@ -284,8 +291,6 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgEntryImpl(const MDNode *MDN) { if (!MDN) return BM->addDebugInfo(SPIRVDebug::DebugInfoNone, getVoidTy(), SPIRVWordVec()); - if (isNonSemanticDebugInfo()) - BM->addExtension(SPIRV::ExtensionID::SPV_KHR_non_semantic_info); if (const DINode *DIEntry = dyn_cast(MDN)) { switch (DIEntry->getTag()) { // Types diff --git a/lib/SPIRV/SPIRVWriter.cpp b/lib/SPIRV/SPIRVWriter.cpp index 1111ccd156..6225c26a9c 100644 --- a/lib/SPIRV/SPIRVWriter.cpp +++ b/lib/SPIRV/SPIRVWriter.cpp @@ -1088,7 +1088,10 @@ void LLVMToSPIRVBase::transAuxDataInst(SPIRVFunction *BF, Function *F) { auto *BM = BF->getModule(); if (!BM->preserveAuxData()) return; - BM->addExtension(SPIRV::ExtensionID::SPV_KHR_non_semantic_info); + if (!BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_6)) + BM->addExtension(SPIRV::ExtensionID::SPV_KHR_non_semantic_info); + else + BM->setMinSPIRVVersion(static_cast(VersionNumber::SPIRV_1_6)); const auto &FnAttrs = F->getAttributes().getFnAttrs(); for (const auto &Attr : FnAttrs) { std::vector Ops; diff --git a/lib/SPIRV/libSPIRV/SPIRVInstruction.h b/lib/SPIRV/libSPIRV/SPIRVInstruction.h index 279edc67af..8b97891a30 100644 --- a/lib/SPIRV/libSPIRV/SPIRVInstruction.h +++ b/lib/SPIRV/libSPIRV/SPIRVInstruction.h @@ -1917,7 +1917,8 @@ class SPIRVExtInst : public SPIRVFunctionCallGeneric { } llvm::Optional getRequiredExtension() const override { - if (SPIRVBuiltinSetNameMap::map(ExtSetKind).find("NonSemantic.") == 0) + if (SPIRVBuiltinSetNameMap::map(ExtSetKind).find("NonSemantic.") == 0 && + !Module->isAllowedToUseVersion(VersionNumber::SPIRV_1_6)) return ExtensionID::SPV_KHR_non_semantic_info; return {}; } diff --git a/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-attributes-attrkind.ll b/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-attributes-attrkind.ll index 143c86f16e..31a2f9da5e 100644 --- a/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-attributes-attrkind.ll +++ b/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-attributes-attrkind.ll @@ -1,10 +1,19 @@ ; RUN: llvm-as < %s -o %t.bc -; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata -o - | FileCheck %s --check-prefix=CHECK-SPIRV +; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata --spirv-max-version=1.5 -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-EXT ; RUN: llvm-spirv %t.bc -o %t.spv --spirv-preserve-auxdata ; RUN: llvm-spirv -r --spirv-preserve-auxdata %t.spv -o %t.rev.bc ; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM -; CHECK-SPIRV: Extension "SPV_KHR_non_semantic_info" +; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-NOEXT +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-preserve-auxdata +; RUN: llvm-spirv -r --spirv-preserve-auxdata %t.spv -o %t.rev.bc +; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM + +; Check SPIR-V versions in a format magic number + version +; CHECK-SPIRV-EXT: 119734787 65536 +; CHECK-SPIRV-EXT: Extension "SPV_KHR_non_semantic_info" +; CHECK-SPIRV-NOEXT: 119734787 67072 + ; CHECK-SPIRV: ExtInstImport [[#Import:]] "NonSemantic.AuxData" ; CHECK-SPIRV: String [[#Attr0:]] "nounwind" diff --git a/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-attributes.ll b/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-attributes.ll index 193af4b4d0..c64de4f5a7 100644 --- a/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-attributes.ll +++ b/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-attributes.ll @@ -1,13 +1,25 @@ ; RUN: llvm-as < %s -o %t.bc -; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata -o - | FileCheck %s --check-prefix=CHECK-SPIRV -; RUN: not llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata --spirv-ext=-SPV_KHR_non_semantic_info -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SPIRV-EXT-DISABLED +; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata --spirv-max-version=1.5 -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-EXT +; RUN: not llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata --spirv-max-version=1.5 --spirv-ext=-SPV_KHR_non_semantic_info -o - 2>&1 | FileCheck %s --check-prefix=CHECK-SPIRV-EXT-DISABLED +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-preserve-auxdata --spirv-max-version=1.5 +; RUN: llvm-spirv -r --spirv-preserve-auxdata %t.spv -o %t.rev.bc +; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM +; RUN: llvm-spirv -r %t.spv -o %t.rev.without.bc +; RUN: llvm-dis %t.rev.without.bc -o - | FileCheck %s --implicit-check-not="{{foo|bar|baz}}" + +; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-NOEXT +; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata --spirv-ext=+SPV_KHR_non_semantic_info -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-NOEXT ; RUN: llvm-spirv %t.bc -o %t.spv --spirv-preserve-auxdata ; RUN: llvm-spirv -r --spirv-preserve-auxdata %t.spv -o %t.rev.bc ; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM ; RUN: llvm-spirv -r %t.spv -o %t.rev.without.bc ; RUN: llvm-dis %t.rev.without.bc -o - | FileCheck %s --implicit-check-not="{{foo|bar|baz}}" -; CHECK-SPIRV: Extension "SPV_KHR_non_semantic_info" +; Check SPIR-V versions in a format magic number + version +; CHECK-SPIRV-EXT: 119734787 65536 +; CHECK-SPIRV-EXT: Extension "SPV_KHR_non_semantic_info" +; CHECK-SPIRV-NOEXT: 119734787 67072 + ; CHECK-SPIRV: ExtInstImport [[#Import:]] "NonSemantic.AuxData" ; CHECK-SPIRV: String [[#Attr0:]] "foo" diff --git a/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-metadata.ll b/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-metadata.ll index abc0a042ac..13f41f366e 100644 --- a/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-metadata.ll +++ b/test/extensions/KHR/SPV_KHR_non_semantic_info/preserve-all-function-metadata.ll @@ -1,12 +1,23 @@ ; RUN: llvm-as < %s -o %t.bc -; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata -o - | FileCheck %s --check-prefix=CHECK-SPIRV +; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata --spirv-max-version=1.5 -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-EXT +; RUN: llvm-spirv %t.bc -o %t.spv --spirv-preserve-auxdata --spirv-max-version=1.5 +; RUN: llvm-spirv -r --spirv-preserve-auxdata %t.spv -o %t.rev.bc +; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM +; RUN: llvm-spirv -r %t.spv -o %t.rev.without.bc +; RUN: llvm-dis %t.rev.without.bc -o - | FileCheck %s --implicit-check-not="{{foo|bar|baz}}" + +; RUN: llvm-spirv %t.bc -spirv-text --spirv-preserve-auxdata -o - | FileCheck %s --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-NOEXT ; RUN: llvm-spirv %t.bc -o %t.spv --spirv-preserve-auxdata ; RUN: llvm-spirv -r --spirv-preserve-auxdata %t.spv -o %t.rev.bc ; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM ; RUN: llvm-spirv -r %t.spv -o %t.rev.without.bc ; RUN: llvm-dis %t.rev.without.bc -o - | FileCheck %s --implicit-check-not="{{foo|bar|baz}}" -; CHECK-SPIRV: Extension "SPV_KHR_non_semantic_info" +; Check SPIR-V versions in a format magic number + version +; CHECK-SPIRV-EXT: 119734787 65536 +; CHECK-SPIRV-EXT: Extension "SPV_KHR_non_semantic_info" +; CHECK-SPIRV-NOEXT: 119734787 67072 + ; CHECK-SPIRV: ExtInstImport [[#Import:]] "NonSemantic.AuxData" ; CHECK-SPIRV: String [[#MD0Name:]] "foo"