From d9b3bb0c30cbc6be598a1aef6a3371f3d6e65a15 Mon Sep 17 00:00:00 2001 From: Dmitry Sidorov Date: Wed, 26 Apr 2023 12:20:30 +0200 Subject: [PATCH] [PATCH 39/79] [DebugInfo] Add Flag parameter to DebugTypeBasic (#1965) It can only be FlagUnknownPhysicalLayout. There is no way we can generate it LLVM environment and get use of it, hence the patch just ignores it if it come from another SPIR-V generator. In general, there are following possible debug flags for DIBasicType: BigEndian, LittleEndian and Artificial. There is not way that clang will ever generate them, but that can be produced by manually writing assembly and transforming it to LLVM IR. While it can be potential improvement for the future - I don't see it useful to add to the spec and implementation right now. Signed-off-by: Sidorov, Dmitry Gbp-Pq: Name 0039-DebugInfo-Add-Flag-parameter-to-DebugTypeBasic-1965.patch --- lib/SPIRV/LLVMToSPIRVDbgTran.cpp | 2 +- lib/SPIRV/SPIRVToLLVMDbgTran.cpp | 4 +- lib/SPIRV/libSPIRV/SPIRV.debug.h | 50 +++++----- .../NonSemantic/basic-type-with-flag.spt | 96 +++++++++++++++++++ 4 files changed, 127 insertions(+), 25 deletions(-) create mode 100644 test/DebugInfo/NonSemantic/basic-type-with-flag.spt diff --git a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp index ee6b668..e849b43 100644 --- a/lib/SPIRV/LLVMToSPIRVDbgTran.cpp +++ b/lib/SPIRV/LLVMToSPIRVDbgTran.cpp @@ -574,7 +574,7 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgCompileUnit(const DICompileUnit *CU) { SPIRVEntry *LLVMToSPIRVDbgTran::transDbgBaseType(const DIBasicType *BT) { using namespace SPIRVDebug::Operand::TypeBasic; - SPIRVWordVec Ops(OperandCount); + SPIRVWordVec Ops(OperandCountOCL); Ops[NameIdx] = BM->getString(BT->getName().str())->getId(); ConstantInt *Size = getUInt(M, BT->getSizeInBits()); Ops[SizeIdx] = SPIRVWriter->transValue(Size, nullptr)->getId(); diff --git a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp index 0e00f7b..5917fc0 100644 --- a/lib/SPIRV/SPIRVToLLVMDbgTran.cpp +++ b/lib/SPIRV/SPIRVToLLVMDbgTran.cpp @@ -201,7 +201,9 @@ SPIRVToLLVMDbgTran::transCompilationUnit(const SPIRVExtInst *DebugInst) { DIBasicType *SPIRVToLLVMDbgTran::transTypeBasic(const SPIRVExtInst *DebugInst) { using namespace SPIRVDebug::Operand::TypeBasic; const SPIRVWordVec &Ops = DebugInst->getArguments(); - assert(Ops.size() == OperandCount && "Invalid number of operands"); + assert((Ops.size() == OperandCountOCL || + Ops.size() == OperandCountNonSemantic) && + "Invalid number of operands"); StringRef Name = getString(Ops[NameIdx]); auto Tag = static_cast( getConstantValueOrLiteral(Ops, EncodingIdx, DebugInst->getExtSetKind())); diff --git a/lib/SPIRV/libSPIRV/SPIRV.debug.h b/lib/SPIRV/libSPIRV/SPIRV.debug.h index 06c5af0..86e347e 100644 --- a/lib/SPIRV/libSPIRV/SPIRV.debug.h +++ b/lib/SPIRV/libSPIRV/SPIRV.debug.h @@ -62,25 +62,26 @@ enum Instruction { }; enum Flag { - FlagIsProtected = 1 << 0, - FlagIsPrivate = 1 << 1, - FlagIsPublic = FlagIsPrivate | FlagIsProtected, - FlagAccess = FlagIsPublic, - FlagIsLocal = 1 << 2, - FlagIsDefinition = 1 << 3, - FlagIsFwdDecl = 1 << 4, - FlagIsArtificial = 1 << 5, - FlagIsExplicit = 1 << 6, - FlagIsPrototyped = 1 << 7, - FlagIsObjectPointer = 1 << 8, - FlagIsStaticMember = 1 << 9, - FlagIsIndirectVariable = 1 << 10, - FlagIsLValueReference = 1 << 11, - FlagIsRValueReference = 1 << 12, - FlagIsOptimized = 1 << 13, - FlagIsEnumClass = 1 << 14, - FlagTypePassByValue = 1 << 15, - FlagTypePassByReference = 1 << 16, + FlagIsProtected = 1 << 0, + FlagIsPrivate = 1 << 1, + FlagIsPublic = FlagIsPrivate | FlagIsProtected, + FlagAccess = FlagIsPublic, + FlagIsLocal = 1 << 2, + FlagIsDefinition = 1 << 3, + FlagIsFwdDecl = 1 << 4, + FlagIsArtificial = 1 << 5, + FlagIsExplicit = 1 << 6, + FlagIsPrototyped = 1 << 7, + FlagIsObjectPointer = 1 << 8, + FlagIsStaticMember = 1 << 9, + FlagIsIndirectVariable = 1 << 10, + FlagIsLValueReference = 1 << 11, + FlagIsRValueReference = 1 << 12, + FlagIsOptimized = 1 << 13, + FlagIsEnumClass = 1 << 14, + FlagTypePassByValue = 1 << 15, + FlagTypePassByReference = 1 << 16, + FlagUnknownPhysicalLayout = 1 << 17, }; enum EncodingTag { @@ -306,10 +307,13 @@ enum { namespace TypeBasic { enum { - NameIdx = 0, - SizeIdx = 1, - EncodingIdx = 2, - OperandCount = 3 + NameIdx = 0, + SizeIdx = 1, + EncodingIdx = 2, + // For NonSemantic Specs + FlagsIdx = 3, + OperandCountOCL = 3, + OperandCountNonSemantic = 4 }; } diff --git a/test/DebugInfo/NonSemantic/basic-type-with-flag.spt b/test/DebugInfo/NonSemantic/basic-type-with-flag.spt new file mode 100644 index 0000000..ebad020 --- /dev/null +++ b/test/DebugInfo/NonSemantic/basic-type-with-flag.spt @@ -0,0 +1,96 @@ +;; This test checks, that SPIR-V module generated by another SPIR-V producer +;; containing FlagUnknownPhysicalLayout flag of DebugTypeBasic can be +;; consumed without issues + +; RUN: llvm-spirv %s -to-binary -o %t.spv +; RUN: llvm-spirv -r %t.spv +; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-LLVM + +; CHECK-LLVM: DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) + +119734787 65792 393230 56 0 +2 Capability Addresses +2 Capability Linkage +2 Capability Kernel +2 Capability Int8 +8 Extension "SPV_KHR_non_semantic_info" +5 ExtInstImport 1 "OpenCL.std" +11 ExtInstImport 2 "NonSemantic.Shader.DebugInfo.100" +3 MemoryModel 2 2 +8 String 25 "foo.cpp" +4 String 30 "int" +3 String 35 "A" +3 String 36 "b" +3 String 44 "foo" +5 String 45 "_Z3fooP1A" +3 String 51 "a" +3 Source 0 0 +5 Name 7 "_Z3fooP1A" +3 Name 8 "a" +4 Name 9 "entry" +4 Name 11 "a.addr" +5 Name 16 "struct.A" +3 Name 23 "b" + +15 ModuleProcessed "Debug info producer: clang version 3.1 (trunk 150996)" +7 Decorate 7 LinkageAttributes "_Z3fooP1A" Export +4 Decorate 11 Alignment 8 +4 TypeInt 3 32 0 +4 TypeInt 4 8 0 +4 Constant 3 21 0 +4 Constant 3 27 65536 +4 Constant 3 28 6 +4 Constant 3 31 32 +4 Constant 3 32 4 +4 Constant 3 37 1 +4 Constant 3 38 2 +4 Constant 3 41 4294967295 +4 Constant 3 46 3 +4 Constant 3 47 136 +4 Constant 3 49 16 +4 Constant 3 56 131072 ;; FlagUnknownPhysicalLayout +4 TypePointer 5 7 4 +4 TypeFunction 6 3 5 +4 TypePointer 10 7 5 +2 TypeVoid 13 +3 TypeStruct 16 3 + +4 TypePointer 17 7 16 +4 TypePointer 18 7 17 +4 TypePointer 22 7 3 + + +5 ExtInst 13 14 2 DebugInfoNone +7 ExtInst 13 26 2 DebugSource 25 14 +9 ExtInst 13 29 2 DebugCompilationUnit 27 21 26 28 +9 ExtInst 13 33 2 DebugTypeBasic 30 31 32 56 +14 ExtInst 13 39 2 DebugTypeMember 36 33 26 37 21 34 21 31 38 +15 ExtInst 13 34 2 DebugTypeComposite 35 21 26 37 21 29 14 31 21 39 +8 ExtInst 13 42 2 DebugTypePointer 34 41 21 +8 ExtInst 13 43 2 DebugTypeFunction 21 33 42 +15 ExtInst 13 48 2 DebugFunction 44 43 26 46 21 29 45 47 46 14 +9 ExtInst 13 50 2 DebugLexicalBlock 26 46 49 48 +13 ExtInst 13 52 2 DebugLocalVariable 51 42 26 46 21 48 21 1 +5 ExtInst 13 53 2 DebugExpression + +5 Function 3 7 0 6 +3 FunctionParameter 5 8 + +2 Label 9 +7 ExtInst 13 57 2 DebugFunctionDefinition 48 7 +4 Variable 10 11 7 +4 Bitcast 10 12 11 +5 Store 12 8 2 8 +6 ExtInst 13 54 2 DebugScope 48 +4 Line 25 3 13 +8 ExtInst 13 15 2 DebugDeclare 52 11 53 +6 ExtInst 13 55 2 DebugScope 50 +4 Line 25 4 3 +4 Bitcast 18 19 11 +6 Load 17 20 19 2 8 +6 InBoundsPtrAccessChain 22 23 20 21 21 +6 Load 3 24 23 2 4 +2 ReturnValue 24 + +1 FunctionEnd + -- 2.30.2