Skip to content

Commit d965d9a

Browse files
MrSidimsagainull
authored andcommitted
Add DW_ATE_complex_float translation (#1946)
It's mapped on new Encoding value for DebugBasicType in NonSemantic.Shader.DebugInfo.200 spec. If another DebugInfo instruction set is specified - it's mapped to DW_TAG_unspecified_type Spec: KhronosGroup/SPIRV-Registry#186 Signed-off-by: Sidorov, Dmitry <[email protected]> Original commit: KhronosGroup/SPIRV-LLVM-Translator@66b7618
1 parent 677cd0e commit d965d9a

File tree

5 files changed

+118
-2
lines changed

5 files changed

+118
-2
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ SPIRVEntry *LLVMToSPIRVDbgTran::transDbgBaseType(const DIBasicType *BT) {
572572
auto Encoding = static_cast<dwarf::TypeKind>(BT->getEncoding());
573573
SPIRVDebug::EncodingTag EncTag = SPIRVDebug::Unspecified;
574574
SPIRV::DbgEncodingMap::find(Encoding, &EncTag);
575+
// Unset encoding if it's complex and NonSemantic.Shader.DebugInfo.200 is not
576+
// enabled
577+
if (EncTag == SPIRVDebug::Complex &&
578+
BM->getDebugInfoEIS() != SPIRVEIS_NonSemantic_Shader_DebugInfo_200)
579+
EncTag = SPIRVDebug::Unspecified;
575580
Ops[EncodingIdx] = EncTag;
576581
if (isNonSemanticDebugInfo())
577582
transformToConstant(Ops, {EncodingIdx});

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
23662366
return mapValue(BV, transOCLBuiltinFromExtInst(ExtInst, BB));
23672367
case SPIRVEIS_Debug:
23682368
case SPIRVEIS_OpenCL_DebugInfo_100:
2369+
case SPIRVEIS_NonSemantic_Shader_DebugInfo_100:
23692370
case SPIRVEIS_NonSemantic_Shader_DebugInfo_200:
23702371
return mapValue(BV, DbgTran->transDebugIntrinsic(ExtInst, BB));
23712372
default:

llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ enum EncodingTag {
8888
Signed = 4,
8989
SignedChar = 5,
9090
Unsigned = 6,
91-
UnsignedChar = 7
91+
UnsignedChar = 7,
92+
Complex = 8
9293
};
9394

9495
enum CompositeTypeTag {
@@ -1000,6 +1001,7 @@ inline void DbgEncodingMap::init() {
10001001
add(dwarf::DW_ATE_signed_char, SPIRVDebug::SignedChar);
10011002
add(dwarf::DW_ATE_unsigned, SPIRVDebug::Unsigned);
10021003
add(dwarf::DW_ATE_unsigned_char, SPIRVDebug::UnsignedChar);
1004+
add(dwarf::DW_ATE_complex_float, SPIRVDebug::Complex);
10031005
}
10041006

10051007
typedef SPIRVMap<dwarf::Tag, SPIRVDebug::TypeQualifierTag> DbgTypeQulifierMap;
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
;; Tests for Fortran's complex type encoding in debug info
2+
;; Compiled from the following Fortran source
3+
;;
4+
;; program complex_numbers
5+
;; implicit none
6+
;; complex :: a, b, c
7+
;;
8+
;; a = (1.0, 2.0)
9+
;; b = (2.0, -1.0)
10+
;;
11+
;; c = a + b
12+
;;
13+
;; end program complex_numbers
14+
15+
; RUN: llvm-as %s -o %t.bc
16+
; RUN: llvm-spirv %t.bc -spirv-text --spirv-debug-info-version=nonsemantic-shader-200 -o - | FileCheck %s --check-prefix=CHECK-SPIRV-200
17+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-debug-info-version=nonsemantic-shader-200
18+
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc
19+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM-200
20+
21+
; RUN: llvm-spirv %t.bc -spirv-text --spirv-debug-info-version=nonsemantic-shader-100 -o - | FileCheck %s --check-prefix=CHECK-SPIRV-100
22+
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-debug-info-version=nonsemantic-shader-100
23+
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc
24+
; RUN: llvm-dis %t.rev.bc -o - | FileCheck %s --check-prefix=CHECK-LLVM-100
25+
26+
; CHECK-SPIRV-200-DAG: ExtInstImport [[#Import:]] "NonSemantic.Shader.DebugInfo.200
27+
; CHECK-SPIRV-200-DAG: String [[#Name:]] "COMPLEX*8"
28+
; CHECK-SPIRV-200-DAG: Constant [[#]] [[#Size:]] 64
29+
; CHECK-SPIRV-200-DAG: Constant [[#]] [[#Encoding:]] 8
30+
; CHECK-SPIRV-200-DAG: ExtInst [[#]] [[#Type:]] [[#Import]] DebugTypeBasic [[#Name]] [[#Size]] [[#Encoding]]
31+
; CHECK-SPIRV-200-DAG: ExtInst [[#]] [[#]] [[#Import]] DebugLocalVariable [[#]] [[#Type]]
32+
; CHECK-SPIRV-200-DAG: ExtInst [[#]] [[#]] [[#Import]] DebugLocalVariable [[#]] [[#Type]]
33+
; CHECK-SPIRV-200-DAG: ExtInst [[#]] [[#]] [[#Import]] DebugLocalVariable [[#]] [[#Type]]
34+
35+
; CHECK-LLVM-200: ![[#]] = !DILocalVariable(name: "a", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#Type:]])
36+
; CHECK-LLVM-200: ![[#Type]] = !DIBasicType(name: "COMPLEX*8", size: 64, encoding: DW_ATE_complex_float)
37+
; CHECK-LLVM-200: ![[#]] = !DILocalVariable(name: "b", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#Type]])
38+
; CHECK-LLVM-200: ![[#]] = !DILocalVariable(name: "c", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#Type]])
39+
40+
; CHECK-SPIRV-100-DAG: ExtInstImport [[#Import:]] "NonSemantic.Shader.DebugInfo.100
41+
; CHECK-SPIRV-100-DAG: String [[#Name:]] "COMPLEX*8"
42+
; CHECK-SPIRV-100-DAG: Constant [[#]] [[#Size:]] 64
43+
; CHECK-SPIRV-100-DAG: Constant [[#]] [[#Encoding:]] 0
44+
; CHECK-SPIRV-100-DAG: ExtInst [[#]] [[#Type:]] [[#Import]] DebugTypeBasic [[#Name]] [[#Size]] [[#Encoding]]
45+
; CHECK-SPIRV-100-DAG: ExtInst [[#]] [[#]] [[#Import]] DebugLocalVariable [[#]] [[#Type]]
46+
; CHECK-SPIRV-100-DAG: ExtInst [[#]] [[#]] [[#Import]] DebugLocalVariable [[#]] [[#Type]]
47+
; CHECK-SPIRV-100-DAG: ExtInst [[#]] [[#]] [[#Import]] DebugLocalVariable [[#]] [[#Type]]
48+
49+
; CHECK-LLVM-100: ![[#]] = !DILocalVariable(name: "a", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#Type:]])
50+
; CHECK-LLVM-100: ![[#Type]] = !DIBasicType(tag: DW_TAG_unspecified_type, name: "COMPLEX*8")
51+
; CHECK-LLVM-100: ![[#]] = !DILocalVariable(name: "b", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#Type]])
52+
; CHECK-LLVM-100: ![[#]] = !DILocalVariable(name: "c", scope: ![[#]], file: ![[#]], line: [[#]], type: ![[#Type]])
53+
54+
; ModuleID = 'test.f90'
55+
source_filename = "test.f90"
56+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
57+
target triple = "spir64-unknown-unknown"
58+
59+
@0 = internal unnamed_addr constant i32 65536, align 4
60+
@1 = internal unnamed_addr constant i32 2, align 4
61+
62+
; Function Attrs: nounwind uwtable
63+
define void @MAIN__() local_unnamed_addr !dbg !4 !llfort.type_idx !12 {
64+
alloca_0:
65+
%func_result = tail call i32 @for_set_fpe_(ptr nonnull @0), !dbg !13, !llfort.type_idx !14
66+
%func_result2 = tail call i32 @for_set_reentrancy(ptr nonnull @1), !dbg !13, !llfort.type_idx !14
67+
call void @llvm.dbg.value(metadata float 1.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !15
68+
call void @llvm.dbg.value(metadata float 2.000000e+00, metadata !11, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32)), !dbg !15
69+
call void @llvm.dbg.value(metadata float 2.000000e+00, metadata !10, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !15
70+
call void @llvm.dbg.value(metadata float -1.000000e+00, metadata !10, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32)), !dbg !15
71+
call void @llvm.dbg.value(metadata float poison, metadata !8, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !15
72+
call void @llvm.dbg.value(metadata float poison, metadata !8, metadata !DIExpression(DW_OP_LLVM_fragment, 32, 32)), !dbg !15
73+
ret void, !dbg !16
74+
}
75+
76+
declare !llfort.intrin_id !17 !llfort.type_idx !18 i32 @for_set_fpe_(ptr nocapture readonly) local_unnamed_addr
77+
78+
; Function Attrs: nofree
79+
declare !llfort.intrin_id !19 !llfort.type_idx !20 i32 @for_set_reentrancy(ptr nocapture readonly) local_unnamed_addr
80+
81+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
82+
declare void @llvm.dbg.value(metadata, metadata, metadata)
83+
84+
!llvm.module.flags = !{!0, !1}
85+
!llvm.dbg.cu = !{!2}
86+
!omp_offload.info = !{}
87+
88+
!0 = !{i32 2, !"Debug Info Version", i32 3}
89+
!1 = !{i32 2, !"Dwarf Version", i32 4}
90+
!2 = distinct !DICompileUnit(language: DW_LANG_Fortran95, file: !3, producer: "Intel(R) Fortran", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
91+
!3 = !DIFile(filename: "test.f90", directory: "complex")
92+
!4 = distinct !DISubprogram(name: "complex_numbers", linkageName: "MAIN__", scope: !3, file: !3, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagMainSubprogram, unit: !2, retainedNodes: !7)
93+
!5 = !DISubroutineType(types: !6)
94+
!6 = !{null}
95+
!7 = !{!8, !10, !11}
96+
!8 = !DILocalVariable(name: "c", scope: !4, file: !3, line: 3, type: !9)
97+
!9 = !DIBasicType(name: "COMPLEX*8", size: 64, encoding: DW_ATE_complex_float)
98+
!10 = !DILocalVariable(name: "b", scope: !4, file: !3, line: 3, type: !9)
99+
!11 = !DILocalVariable(name: "a", scope: !4, file: !3, line: 3, type: !9)
100+
!12 = !{i64 23}
101+
!13 = !DILocation(line: 1, column: 9, scope: !4)
102+
!14 = !{i64 2}
103+
!15 = !DILocation(line: 0, scope: !4)
104+
!16 = !DILocation(line: 9, column: 1, scope: !4)
105+
!17 = !{i32 97}
106+
!18 = !{i64 27}
107+
!19 = !{i32 98}
108+
!20 = !{i64 29}

llvm-spirv/tools/llvm-spirv/llvm-spirv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ int main(int Ac, char **Av) {
766766
SPIRV::DebugInfoEIS::NonSemantic_Shader_DebugInfo_200)
767767
Opts.setAllowExtraDIExpressionsEnabled(true);
768768
if (DebugEIS.getValue() ==
769-
SPIRV::DebugInfoEIS::NonSemantic_Shader_DebugInfo_200 ||
769+
SPIRV::DebugInfoEIS::NonSemantic_Shader_DebugInfo_100 ||
770770
DebugEIS.getValue() ==
771771
SPIRV::DebugInfoEIS::NonSemantic_Shader_DebugInfo_200)
772772
Opts.setAllowedToUseExtension(

0 commit comments

Comments
 (0)