Skip to content

Commit b8fc4ea

Browse files
Merge pull request #2765 from adrian-prantl/75904857
Add debug info support for swiftasync arguments to GlobalISel
2 parents c864f20 + 38f6f36 commit b8fc4ea

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,6 +1882,19 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
18821882
MF->setVariableDbgInfo(DI.getVariable(), DI.getExpression(),
18831883
getOrCreateFrameIndex(*AI), DI.getDebugLoc());
18841884
} else {
1885+
// Special handling for swift_async arguments. They need to
1886+
// describe the incoming register specified by the ABI so they
1887+
// can be described as entry values.
1888+
if (auto *Arg = dyn_cast<Argument>(Address))
1889+
if (MF->getFunction().hasParamAttribute(Arg->getArgNo(),
1890+
Attribute::SwiftAsync)) {
1891+
Register Reg =
1892+
std::next(MF->getRegInfo().livein_begin(), Arg->getArgNo())
1893+
->first;
1894+
MIRBuilder.buildIndirectDbgValue(Reg, DI.getVariable(),
1895+
DI.getExpression());
1896+
return true;
1897+
}
18851898
// A dbg.declare describes the address of a source variable, so lower it
18861899
// into an indirect DBG_VALUE.
18871900
MIRBuilder.buildIndirectDbgValue(getOrCreateVReg(*Address),
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
; RUN: llc -O0 -filetype=obj < %s | llvm-dwarfdump --name n - | FileCheck %s
2+
;
3+
; CHECK: DW_TAG_formal_parameter
4+
; CHECK-NEXT: DW_AT_location (DW_OP_entry_value(DW_OP_reg22 W22), DW_OP_deref, DW_OP_plus_uconst 0x18, DW_OP_plus_uconst 0x8)
5+
; CHECK-NEXT: DW_AT_name ("n")
6+
7+
; ModuleID = '/tmp/t.ll'
8+
source_filename = "/tmp/fib.s"
9+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
10+
target triple = "arm64-apple-macosx11.0.0"
11+
12+
%"$s3fib9FibonacciC9fibonacciyS2iYF.Frame" = type { %swift.context*, i64, %T3fib9FibonacciC*, i64, i64, i64, i64, %T3fib9FibonacciC*, i8*, i64, i8*, i64 }
13+
%swift.context = type {}
14+
%T3fib9FibonacciC = type <{ %swift.refcounted, %swift.defaultactor, %TSa }>
15+
%swift.refcounted = type { %swift.type*, i64 }
16+
%swift.type = type { i64 }
17+
%swift.defaultactor = type { [10 x i8*] }
18+
%TSa = type <{ %Ts12_ArrayBufferV }>
19+
%Ts12_ArrayBufferV = type <{ %Ts14_BridgeStorageV }>
20+
%Ts14_BridgeStorageV = type <{ %swift.bridge* }>
21+
%swift.bridge = type opaque
22+
%TSi = type <{ i64 }>
23+
%swift.executor = type {}
24+
25+
; Function Attrs: argmemonly nofree nosync nounwind willreturn
26+
declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #0
27+
28+
define hidden swifttailcc void @"$s3fib9FibonacciC9fibonacciyS2iYFTQ3_"(i8* swiftasync %0, i64 %1) #1 !dbg !59 {
29+
call void @llvm.dbg.declare(metadata i8* %0, metadata !65, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 24, DW_OP_plus_uconst, 40)), !dbg !67
30+
call void @llvm.dbg.declare(metadata i8* %0, metadata !68, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 24, DW_OP_plus_uconst, 32)), !dbg !69
31+
call void @llvm.dbg.declare(metadata i8* %0, metadata !70, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 24, DW_OP_plus_uconst, 24)), !dbg !71
32+
call void @llvm.dbg.declare(metadata i8* %0, metadata !72, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 24, DW_OP_plus_uconst, 16)), !dbg !74
33+
call void @llvm.dbg.declare(metadata i8* %0, metadata !75, metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 24, DW_OP_plus_uconst, 8)), !dbg !76
34+
%3 = bitcast i8* %0 to i8**, !dbg !77
35+
%4 = load i8*, i8** %3, align 8, !dbg !77
36+
%5 = call i8** @llvm.swift.async.context.addr() #3, !dbg !77
37+
store i8* %4, i8** %5, align 8, !dbg !77
38+
%6 = getelementptr inbounds i8, i8* %4, i32 24
39+
%7 = bitcast i8* %6 to %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"*
40+
%8 = bitcast %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7 to i8*
41+
%9 = alloca %TSi, align 8
42+
%10 = alloca [32 x i8], align 8
43+
%11 = alloca %TSi, align 8
44+
%12 = getelementptr inbounds %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame", %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7, i32 0, i32 0
45+
%13 = getelementptr inbounds %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame", %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7, i32 0, i32 1
46+
%14 = getelementptr inbounds %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame", %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7, i32 0, i32 2
47+
%15 = getelementptr inbounds %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame", %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7, i32 0, i32 3
48+
%16 = getelementptr inbounds %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame", %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7, i32 0, i32 4
49+
%17 = getelementptr inbounds %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame", %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7, i32 0, i32 5
50+
%18 = getelementptr inbounds %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame", %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7, i32 0, i32 10, !dbg !82
51+
%19 = load i8*, i8** %18, align 8, !dbg !82
52+
%20 = getelementptr inbounds %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame", %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7, i32 0, i32 7, !dbg !82
53+
%21 = load %T3fib9FibonacciC*, %T3fib9FibonacciC** %20, align 8, !dbg !82
54+
%22 = bitcast i8* %0 to i8**, !dbg !83
55+
%23 = load i8*, i8** %22, align 8, !dbg !83
56+
%24 = call i8** @llvm.swift.async.context.addr() #3, !dbg !83
57+
store i8* %23, i8** %24, align 8, !dbg !83
58+
%25 = bitcast i8* %23 to %swift.context*, !dbg !82
59+
store %swift.context* %25, %swift.context** %12, align 8, !dbg !82
60+
%26 = getelementptr inbounds %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame", %"$s3fib9FibonacciC9fibonacciyS2iYF.Frame"* %7, i32 0, i32 11, !dbg !82
61+
store i64 %1, i64* %26, align 8, !dbg !82
62+
call swiftcc void @swift_task_dealloc(i8* %19) #3, !dbg !82
63+
call void @llvm.lifetime.end.p0i8(i64 -1, i8* %19), !dbg !82
64+
%27 = bitcast %T3fib9FibonacciC* %21 to %swift.executor*, !dbg !82
65+
%28 = load %swift.context*, %swift.context** %12, align 8, !dbg !82
66+
musttail call swifttailcc void @swift_task_switch(%swift.context* swiftasync %28, i8* bitcast (void (i8*)* @"$s3fib9FibonacciC9fibonacciyS2iYFTY4_" to i8*), %swift.executor* %27) #3, !dbg !85
67+
ret void, !dbg !85
68+
}
69+
70+
declare hidden swifttailcc void @"$s3fib9FibonacciC9fibonacciyS2iYFTY4_"(i8* swiftasync) #1
71+
72+
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
73+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
74+
75+
; Function Attrs: nounwind
76+
declare extern_weak swifttailcc void @swift_task_switch(%swift.context*, i8*, %swift.executor*) #3
77+
78+
; Function Attrs: nounwind readnone
79+
declare i8** @llvm.swift.async.context.addr() #4
80+
81+
; Function Attrs: argmemonly nounwind
82+
declare extern_weak swiftcc void @swift_task_dealloc(i8*) #5
83+
84+
attributes #0 = { argmemonly nofree nosync nounwind willreturn }
85+
attributes #1 = { "frame-pointer"="non-leaf" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-a12" "target-features"="+aes,+crc,+crypto,+fp-armv8,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+v8.3a,+zcm,+zcz" "unsafe-fp-math"="false" "use-soft-float"="false" }
86+
attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }
87+
attributes #3 = { nounwind }
88+
attributes #4 = { nounwind readnone }
89+
attributes #5 = { argmemonly nounwind }
90+
91+
!llvm.dbg.cu = !{!0}
92+
!swift.module.flags = !{!12}
93+
!llvm.asan.globals = !{!13, !14, !15, !16, !17, !18, !19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34, !35, !36, !37}
94+
!llvm.module.flags = !{!38, !39, !40, !41, !42, !43, !44, !45, !46, !47, !48, !49, !50, !51, !52, !53, !54}
95+
!llvm.linker.options = !{!55, !56, !57, !58}
96+
97+
!0 = distinct !DICompileUnit(language: DW_LANG_Swift, file: !1, producer: "Swift version 5.5-dev (LLVM 6cafa2dc0b8de57, Swift 9c8f32517768a78)", isOptimized: false, runtimeVersion: 5, emissionKind: FullDebug, enums: !2, imports: !3)
98+
!1 = !DIFile(filename: "/Volumes/Data/swift/llvm-project/../llvm-project/lldb/test/API/lang/swift/async/unwind/backtrace_locals/main.swift", directory: "/Volumes/Data/swift/llvm-project")
99+
!2 = !{}
100+
!3 = !{!4, !6, !8, !10}
101+
!4 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !1, entity: !5, file: !1)
102+
!5 = !DIModule(scope: null, name: "fib", includePath: "/Volumes/Data/swift/llvm-project/../llvm-project/lldb/test/API/lang/swift/async/unwind/backtrace_locals")
103+
!6 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !1, entity: !7, file: !1)
104+
!7 = !DIModule(scope: null, name: "Swift", includePath: "/Volumes/Data/swift/_build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx/Swift.swiftmodule/arm64-apple-macos.swiftmodule")
105+
!8 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !1, entity: !9, file: !1)
106+
!9 = !DIModule(scope: null, name: "_Concurrency", includePath: "/Volumes/Data/swift/_build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx/_Concurrency.swiftmodule/arm64-apple-macos.swiftmodule")
107+
!10 = !DIImportedEntity(tag: DW_TAG_imported_module, scope: !1, entity: !11, file: !1)
108+
!11 = !DIModule(scope: null, name: "SwiftOnoneSupport", includePath: "/Volumes/Data/swift/_build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx/SwiftOnoneSupport.swiftmodule/arm64-apple-macos.swiftmodule")
109+
!12 = !{!"standard-library", i1 false}
110+
!13 = distinct !{null, null, null, i1 false, i1 true}
111+
!14 = distinct !{null, null, null, i1 false, i1 true}
112+
!15 = distinct !{null, null, null, i1 false, i1 true}
113+
!16 = distinct !{null, null, null, i1 false, i1 true}
114+
!17 = distinct !{null, null, null, i1 false, i1 true}
115+
!18 = distinct !{null, null, null, i1 false, i1 true}
116+
!19 = distinct !{null, null, null, i1 false, i1 true}
117+
!20 = distinct !{null, null, null, i1 false, i1 true}
118+
!21 = distinct !{null, null, null, i1 false, i1 true}
119+
!22 = distinct !{null, null, null, i1 false, i1 true}
120+
!23 = distinct !{null, null, null, i1 false, i1 true}
121+
!24 = distinct !{null, null, null, i1 false, i1 true}
122+
!25 = distinct !{null, null, null, i1 false, i1 true}
123+
!26 = distinct !{null, null, null, i1 false, i1 true}
124+
!27 = distinct !{null, null, null, i1 false, i1 true}
125+
!28 = distinct !{null, null, null, i1 false, i1 true}
126+
!29 = distinct !{null, null, null, i1 false, i1 true}
127+
!30 = distinct !{null, null, null, i1 false, i1 true}
128+
!31 = distinct !{null, null, null, i1 false, i1 true}
129+
!32 = distinct !{null, null, null, i1 false, i1 true}
130+
!33 = distinct !{null, null, null, i1 false, i1 true}
131+
!34 = distinct !{null, null, null, i1 false, i1 true}
132+
!35 = distinct !{null, null, null, i1 false, i1 true}
133+
!36 = distinct !{null, null, null, i1 false, i1 true}
134+
!37 = distinct !{null, null, null, i1 false, i1 true}
135+
!38 = !{i32 1, !"Objective-C Version", i32 2}
136+
!39 = !{i32 1, !"Objective-C Image Info Version", i32 0}
137+
!40 = !{i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"}
138+
!41 = !{i32 1, !"Objective-C Garbage Collection", i8 0}
139+
!42 = !{i32 1, !"Objective-C Class Properties", i32 64}
140+
!43 = !{i32 7, !"Dwarf Version", i32 4}
141+
!44 = !{i32 2, !"Debug Info Version", i32 3}
142+
!45 = !{i32 1, !"wchar_size", i32 4}
143+
!46 = !{i32 1, !"branch-target-enforcement", i32 0}
144+
!47 = !{i32 1, !"sign-return-address", i32 0}
145+
!48 = !{i32 1, !"sign-return-address-all", i32 0}
146+
!49 = !{i32 1, !"sign-return-address-with-bkey", i32 0}
147+
!50 = !{i32 7, !"PIC Level", i32 2}
148+
!51 = !{i32 1, !"Swift Version", i32 7}
149+
!52 = !{i32 1, !"Swift ABI Version", i32 7}
150+
!53 = !{i32 1, !"Swift Major Version", i8 5}
151+
!54 = !{i32 1, !"Swift Minor Version", i8 5}
152+
!55 = !{!"-lswiftSwiftOnoneSupport"}
153+
!56 = !{!"-lswiftCore"}
154+
!57 = !{!"-lswift_Concurrency"}
155+
!58 = !{!"-lobjc"}
156+
!59 = distinct !DISubprogram(name: "fibonacci", linkageName: "$s3fib9FibonacciC9fibonacciyS2iYF", scope: !60, file: !1, line: 4, type: !61, scopeLine: 9, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
157+
!60 = !DICompositeType(tag: DW_TAG_structure_type, name: "Fibonacci", scope: !5, file: !1, size: 64, elements: !2, runtimeLang: DW_LANG_Swift, identifier: "$s3fib9FibonacciCD")
158+
!61 = !DISubroutineType(types: !62)
159+
!62 = !{!63, !63, !60}
160+
!63 = !DICompositeType(tag: DW_TAG_structure_type, name: "Int", scope: !7, file: !64, size: 64, elements: !2, runtimeLang: DW_LANG_Swift, identifier: "$sSiD")
161+
!64 = !DIFile(filename: "_build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/lib/swift/macosx/Swift.swiftmodule/arm64-apple-macos.swiftmodule", directory: "/Volumes/Data/swift")
162+
!65 = !DILocalVariable(name: "res", scope: !59, file: !1, line: 11, type: !66)
163+
!66 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !63)
164+
!67 = !DILocation(line: 11, column: 14, scope: !59)
165+
!68 = !DILocalVariable(name: "n_2", scope: !59, file: !1, line: 9, type: !66)
166+
!69 = !DILocation(line: 9, column: 14, scope: !59)
167+
!70 = !DILocalVariable(name: "n_1", scope: !59, file: !1, line: 8, type: !66)
168+
!71 = !DILocation(line: 8, column: 14, scope: !59)
169+
!72 = !DILocalVariable(name: "self", arg: 2, scope: !59, file: !1, line: 4, type: !73, flags: DIFlagArtificial)
170+
!73 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !60)
171+
!74 = !DILocation(line: 4, column: 10, scope: !59)
172+
!75 = !DILocalVariable(name: "n", arg: 1, scope: !59, file: !1, line: 4, type: !66)
173+
!76 = !DILocation(line: 4, column: 20, scope: !59)
174+
!77 = !DILocation(line: 0, scope: !78, inlinedAt: !81)
175+
!78 = distinct !DISubprogram(linkageName: "__swift_async_resume_project_context", scope: !5, file: !79, type: !80, flags: DIFlagArtificial, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
176+
!79 = !DIFile(filename: "<compiler-generated>", directory: "")
177+
!80 = !DISubroutineType(types: null)
178+
!81 = distinct !DILocation(line: 9, column: 26, scope: !59)
179+
!82 = !DILocation(line: 9, column: 26, scope: !59)
180+
!83 = !DILocation(line: 0, scope: !78, inlinedAt: !84)
181+
!84 = distinct !DILocation(line: 9, column: 26, scope: !59)
182+
!85 = !DILocation(line: 0, scope: !86, inlinedAt: !87)
183+
!86 = distinct !DISubprogram(linkageName: "__swift_suspend_point", scope: !5, file: !79, type: !80, flags: DIFlagArtificial, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2)
184+
!87 = distinct !DILocation(line: 9, column: 26, scope: !59)

0 commit comments

Comments
 (0)