Skip to content

Commit d43a4e8

Browse files
authored
[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 <[email protected]>
1 parent 408713f commit d43a4e8

File tree

4 files changed

+127
-25
lines changed

4 files changed

+127
-25
lines changed

lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgCompileUnit(const DICompileUnit *CU) {
574574

575575
SPIRVEntry *LLVMToSPIRVDbgTran::transDbgBaseType(const DIBasicType *BT) {
576576
using namespace SPIRVDebug::Operand::TypeBasic;
577-
SPIRVWordVec Ops(OperandCount);
577+
SPIRVWordVec Ops(OperandCountOCL);
578578
Ops[NameIdx] = BM->getString(BT->getName().str())->getId();
579579
ConstantInt *Size = getUInt(M, BT->getSizeInBits());
580580
Ops[SizeIdx] = SPIRVWriter->transValue(Size, nullptr)->getId();

lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ SPIRVToLLVMDbgTran::transCompilationUnit(const SPIRVExtInst *DebugInst) {
194194
DIBasicType *SPIRVToLLVMDbgTran::transTypeBasic(const SPIRVExtInst *DebugInst) {
195195
using namespace SPIRVDebug::Operand::TypeBasic;
196196
const SPIRVWordVec &Ops = DebugInst->getArguments();
197-
assert(Ops.size() == OperandCount && "Invalid number of operands");
197+
assert((Ops.size() == OperandCountOCL ||
198+
Ops.size() == OperandCountNonSemantic) &&
199+
"Invalid number of operands");
198200
StringRef Name = getString(Ops[NameIdx]);
199201
auto Tag = static_cast<SPIRVDebug::EncodingTag>(
200202
getConstantValueOrLiteral(Ops, EncodingIdx, DebugInst->getExtSetKind()));

lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,26 @@ enum Instruction {
6262
};
6363

6464
enum Flag {
65-
FlagIsProtected = 1 << 0,
66-
FlagIsPrivate = 1 << 1,
67-
FlagIsPublic = FlagIsPrivate | FlagIsProtected,
68-
FlagAccess = FlagIsPublic,
69-
FlagIsLocal = 1 << 2,
70-
FlagIsDefinition = 1 << 3,
71-
FlagIsFwdDecl = 1 << 4,
72-
FlagIsArtificial = 1 << 5,
73-
FlagIsExplicit = 1 << 6,
74-
FlagIsPrototyped = 1 << 7,
75-
FlagIsObjectPointer = 1 << 8,
76-
FlagIsStaticMember = 1 << 9,
77-
FlagIsIndirectVariable = 1 << 10,
78-
FlagIsLValueReference = 1 << 11,
79-
FlagIsRValueReference = 1 << 12,
80-
FlagIsOptimized = 1 << 13,
81-
FlagIsEnumClass = 1 << 14,
82-
FlagTypePassByValue = 1 << 15,
83-
FlagTypePassByReference = 1 << 16,
65+
FlagIsProtected = 1 << 0,
66+
FlagIsPrivate = 1 << 1,
67+
FlagIsPublic = FlagIsPrivate | FlagIsProtected,
68+
FlagAccess = FlagIsPublic,
69+
FlagIsLocal = 1 << 2,
70+
FlagIsDefinition = 1 << 3,
71+
FlagIsFwdDecl = 1 << 4,
72+
FlagIsArtificial = 1 << 5,
73+
FlagIsExplicit = 1 << 6,
74+
FlagIsPrototyped = 1 << 7,
75+
FlagIsObjectPointer = 1 << 8,
76+
FlagIsStaticMember = 1 << 9,
77+
FlagIsIndirectVariable = 1 << 10,
78+
FlagIsLValueReference = 1 << 11,
79+
FlagIsRValueReference = 1 << 12,
80+
FlagIsOptimized = 1 << 13,
81+
FlagIsEnumClass = 1 << 14,
82+
FlagTypePassByValue = 1 << 15,
83+
FlagTypePassByReference = 1 << 16,
84+
FlagUnknownPhysicalLayout = 1 << 17,
8485
};
8586

8687
enum EncodingTag {
@@ -306,10 +307,13 @@ enum {
306307

307308
namespace TypeBasic {
308309
enum {
309-
NameIdx = 0,
310-
SizeIdx = 1,
311-
EncodingIdx = 2,
312-
OperandCount = 3
310+
NameIdx = 0,
311+
SizeIdx = 1,
312+
EncodingIdx = 2,
313+
// For NonSemantic Specs
314+
FlagsIdx = 3,
315+
OperandCountOCL = 3,
316+
OperandCountNonSemantic = 4
313317
};
314318
}
315319

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
;; This test checks, that SPIR-V module generated by another SPIR-V producer
2+
;; containing FlagUnknownPhysicalLayout flag of DebugTypeBasic can be
3+
;; consumed without issues
4+
5+
; RUN: llvm-spirv %s -to-binary -o %t.spv
6+
; RUN: llvm-spirv -r %t.spv
7+
; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-LLVM
8+
9+
; CHECK-LLVM: DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
10+
11+
119734787 65792 393230 56 0
12+
2 Capability Addresses
13+
2 Capability Linkage
14+
2 Capability Kernel
15+
2 Capability Int8
16+
8 Extension "SPV_KHR_non_semantic_info"
17+
5 ExtInstImport 1 "OpenCL.std"
18+
11 ExtInstImport 2 "NonSemantic.Shader.DebugInfo.100"
19+
3 MemoryModel 2 2
20+
8 String 25 "foo.cpp"
21+
4 String 30 "int"
22+
3 String 35 "A"
23+
3 String 36 "b"
24+
3 String 44 "foo"
25+
5 String 45 "_Z3fooP1A"
26+
3 String 51 "a"
27+
3 Source 0 0
28+
5 Name 7 "_Z3fooP1A"
29+
3 Name 8 "a"
30+
4 Name 9 "entry"
31+
4 Name 11 "a.addr"
32+
5 Name 16 "struct.A"
33+
3 Name 23 "b"
34+
35+
15 ModuleProcessed "Debug info producer: clang version 3.1 (trunk 150996)"
36+
7 Decorate 7 LinkageAttributes "_Z3fooP1A" Export
37+
4 Decorate 11 Alignment 8
38+
4 TypeInt 3 32 0
39+
4 TypeInt 4 8 0
40+
4 Constant 3 21 0
41+
4 Constant 3 27 65536
42+
4 Constant 3 28 6
43+
4 Constant 3 31 32
44+
4 Constant 3 32 4
45+
4 Constant 3 37 1
46+
4 Constant 3 38 2
47+
4 Constant 3 41 4294967295
48+
4 Constant 3 46 3
49+
4 Constant 3 47 136
50+
4 Constant 3 49 16
51+
4 Constant 3 56 131072 ;; FlagUnknownPhysicalLayout
52+
4 TypePointer 5 7 4
53+
4 TypeFunction 6 3 5
54+
4 TypePointer 10 7 5
55+
2 TypeVoid 13
56+
3 TypeStruct 16 3
57+
58+
4 TypePointer 17 7 16
59+
4 TypePointer 18 7 17
60+
4 TypePointer 22 7 3
61+
62+
63+
5 ExtInst 13 14 2 DebugInfoNone
64+
7 ExtInst 13 26 2 DebugSource 25 14
65+
9 ExtInst 13 29 2 DebugCompilationUnit 27 21 26 28
66+
9 ExtInst 13 33 2 DebugTypeBasic 30 31 32 56
67+
14 ExtInst 13 39 2 DebugTypeMember 36 33 26 37 21 34 21 31 38
68+
15 ExtInst 13 34 2 DebugTypeComposite 35 21 26 37 21 29 14 31 21 39
69+
8 ExtInst 13 42 2 DebugTypePointer 34 41 21
70+
8 ExtInst 13 43 2 DebugTypeFunction 21 33 42
71+
15 ExtInst 13 48 2 DebugFunction 44 43 26 46 21 29 45 47 46 14
72+
9 ExtInst 13 50 2 DebugLexicalBlock 26 46 49 48
73+
13 ExtInst 13 52 2 DebugLocalVariable 51 42 26 46 21 48 21 1
74+
5 ExtInst 13 53 2 DebugExpression
75+
76+
5 Function 3 7 0 6
77+
3 FunctionParameter 5 8
78+
79+
2 Label 9
80+
7 ExtInst 13 57 2 DebugFunctionDefinition 48 7
81+
4 Variable 10 11 7
82+
4 Bitcast 10 12 11
83+
5 Store 12 8 2 8
84+
6 ExtInst 13 54 2 DebugScope 48
85+
4 Line 25 3 13
86+
8 ExtInst 13 15 2 DebugDeclare 52 11 53
87+
6 ExtInst 13 55 2 DebugScope 50
88+
4 Line 25 4 3
89+
4 Bitcast 18 19 11
90+
6 Load 17 20 19 2 8
91+
6 InBoundsPtrAccessChain 22 23 20 21 21
92+
6 Load 3 24 23 2 4
93+
2 ReturnValue 24
94+
95+
1 FunctionEnd
96+

0 commit comments

Comments
 (0)