|
| 1 | +; Tests that we add DILabels for the suspend points. |
| 2 | +; |
| 3 | +; We check both the generated LLVM: |
| 4 | +; RUN: opt < %s -passes='cgscc(coro-split)' -S | FileCheck %s |
| 5 | +; |
| 6 | +; And the debug info: |
| 7 | +; RUN: opt < %s -passes='cgscc(coro-split),coro-cleanup' \ |
| 8 | +; RUN: | llc -O0 -filetype=obj -o - \ |
| 9 | +; RUN: | llvm-dwarfdump - \ |
| 10 | +; RUN: | FileCheck %s -check-prefix=DWARF |
| 11 | + |
| 12 | +source_filename = "coro.c" |
| 13 | +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 14 | +target triple = "x86_64-unknown-linux-gnu" |
| 15 | + |
| 16 | +declare void @bar(...) local_unnamed_addr #2 |
| 17 | +declare void @baz(...) local_unnamed_addr #2 |
| 18 | + |
| 19 | +; Roughly equivalent to: |
| 20 | +; |
| 21 | +; task f() { |
| 22 | +; while (true) { |
| 23 | +; bar(); |
| 24 | +; co_await std::suspend_always{}; |
| 25 | +; baz(); |
| 26 | +; co_await std::suspend_always{}; |
| 27 | +; } |
| 28 | +; } |
| 29 | + |
| 30 | +; Function Attrs: nounwind uwtable |
| 31 | +define ptr @f() #3 !dbg !16 { |
| 32 | +entry: |
| 33 | + %0 = tail call token @llvm.coro.id(i32 0, ptr null, ptr @f, ptr null), !dbg !26 |
| 34 | + %1 = tail call i64 @llvm.coro.size.i64(), !dbg !26 |
| 35 | + %frame = tail call ptr @malloc(i64 %1), !dbg !26 |
| 36 | + %2 = tail call ptr @llvm.coro.begin(token %0, ptr %frame) #4, !dbg !26 |
| 37 | + br label %loop1, !dbg !27 |
| 38 | + |
| 39 | +loop1: ; preds = %for.cond, %entry |
| 40 | + tail call void (...) @bar() #7, !dbg !33 |
| 41 | + %3 = tail call token @llvm.coro.save(ptr null), !dbg !34 |
| 42 | + %4 = tail call i8 @llvm.coro.suspend(token %3, i1 false), !dbg !34 |
| 43 | + switch i8 %4, label %coro_Suspend [ |
| 44 | + i8 0, label %loop2 |
| 45 | + i8 1, label %coro_Cleanup |
| 46 | + ], !dbg !34 |
| 47 | + |
| 48 | +loop2: ; preds = %for.cond, %entry |
| 49 | + tail call void (...) @baz() #7, !dbg !35 |
| 50 | + %5 = tail call token @llvm.coro.save(ptr null), !dbg !36 |
| 51 | + %6 = tail call i8 @llvm.coro.suspend(token %5, i1 false), !dbg !36 |
| 52 | + switch i8 %6, label %coro_Suspend [ |
| 53 | + i8 0, label %loop1 |
| 54 | + i8 1, label %coro_Cleanup |
| 55 | + ], !dbg !36 |
| 56 | + |
| 57 | +coro_Cleanup: ; preds = %for.cond |
| 58 | + %7 = tail call ptr @llvm.coro.free(token %0, ptr %2), !dbg !37 |
| 59 | + tail call void @free(ptr nonnull %7), !dbg !37 |
| 60 | + br label %coro_Suspend, !dbg !37 |
| 61 | + |
| 62 | +coro_Suspend: ; preds = %for.cond, %if.then, %coro_Cleanup |
| 63 | + tail call i1 @llvm.coro.end(ptr null, i1 false, token none) #4, !dbg !40 |
| 64 | + ret ptr %2, !dbg !41 |
| 65 | +} |
| 66 | + |
| 67 | +; Check that the resume function contains the `#dbg_label` instructions. |
| 68 | +; CHECK-LABEL: define ptr @f() #1 !dbg !6 { |
| 69 | +; CHECK: resume.0: ; preds = %resume.entry |
| 70 | +; CHECK-NEXT: #dbg_label(![[RESUME_0:[0-9]+]], !{{[0-9]+}}) |
| 71 | +; CHECK: resume.1: ; preds = %resume.entry |
| 72 | +; CHECK-NEXT: #dbg_label(![[RESUME_1:[0-9]+]], !{{[0-9]+}}) |
| 73 | + |
| 74 | +; Check that the destroy function contains the `#dbg_label` instructions. |
| 75 | +; CHECK-LABEL: define internal fastcc void @f.destroy({{.*}}) #1 !dbg !38 { |
| 76 | +; CHECK: resume.0: ; preds = %resume.entry |
| 77 | +; CHECK-NEXT: #dbg_label(![[DESTROY_0:[0-9]+]], !{{[0-9]+}}) |
| 78 | +; CHECK: resume.1: ; preds = %resume.entry |
| 79 | +; CHECK-NEXT: #dbg_label(![[DESTROY_1:[0-9]+]], !{{[0-9]+}}) |
| 80 | + |
| 81 | +; Check that the DILabels are correct. |
| 82 | +; CHECK: ![[RESUME_0]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_0", file: !{{[0-9]*}}, line: 12, column: 6, isArtificial: true, coroSuspendIdx: 0) |
| 83 | +; CHECK: ![[RESUME_1]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_1", file: !{{[0-9]*}}, line: 14, column: 6, isArtificial: true, coroSuspendIdx: 1) |
| 84 | +; CHECK: ![[DESTROY_0]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_0", file: !{{[0-9]*}}, line: 12, column: 6, isArtificial: true, coroSuspendIdx: 0) |
| 85 | +; CHECK: ![[DESTROY_1]] = !DILabel(scope: !{{[0-9]+}}, name: "__coro_resume_1", file: !{{[0-9]*}}, line: 14, column: 6, isArtificial: true, coroSuspendIdx: 1) |
| 86 | + |
| 87 | +; DWARF: {{.*}}DW_TAG_label |
| 88 | +; DWARF-LABEL: DW_AT_name ("__coro_resume_0") |
| 89 | +; DWARF-NEXT: DW_AT_decl_file |
| 90 | +; DWARF-NEXT: DW_AT_decl_line (12) |
| 91 | +; DWARF-NEXT: DW_AT_decl_column (6) |
| 92 | +; DWARF-NEXT: DW_AT_artificial (true) |
| 93 | +; DWARF-NEXT: DW_AT_LLVM_coro_suspend_idx (0x00) |
| 94 | +; DWARF-NEXT: DW_AT_low_pc |
| 95 | + |
| 96 | + |
| 97 | +; Function Attrs: argmemonly nounwind readonly |
| 98 | +declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #5 |
| 99 | + |
| 100 | +; Function Attrs: nounwind |
| 101 | +declare noalias ptr @malloc(i64) local_unnamed_addr #6 |
| 102 | +declare i64 @llvm.coro.size.i64() #1 |
| 103 | +declare ptr @llvm.coro.begin(token, ptr writeonly) #7 |
| 104 | +declare token @llvm.coro.save(ptr) #7 |
| 105 | +declare i8 @llvm.coro.suspend(token, i1) #7 |
| 106 | +declare ptr @llvm.coro.free(token, ptr nocapture readonly) #5 |
| 107 | +declare void @free(ptr nocapture) local_unnamed_addr #6 |
| 108 | +declare i1 @llvm.coro.end(ptr, i1, token) #7 |
| 109 | + |
| 110 | +attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 111 | +attributes #1 = { nounwind readnone } |
| 112 | +attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 113 | +attributes #3 = { nounwind uwtable presplitcoroutine "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 114 | +attributes #4 = { noduplicate } |
| 115 | +attributes #5 = { argmemonly nounwind readonly } |
| 116 | +attributes #6 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } |
| 117 | +attributes #7 = { nounwind } |
| 118 | +attributes #8 = { alwaysinline nounwind } |
| 119 | + |
| 120 | +!llvm.dbg.cu = !{!0} |
| 121 | +!llvm.module.flags = !{!3, !4} |
| 122 | +!llvm.ident = !{!5} |
| 123 | + |
| 124 | +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 - manually edited", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) |
| 125 | +!1 = !DIFile(filename: "coro.c", directory: "/home/gor/build/bin") |
| 126 | +!2 = !{} |
| 127 | +!3 = !{i32 2, !"Dwarf Version", i32 4} |
| 128 | +!4 = !{i32 2, !"Debug Info Version", i32 3} |
| 129 | +!5 = !{!"clang version 4.0.0 - manually edited"} |
| 130 | +!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) |
| 131 | +!16 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 8, type: !17, isLocal: false, isDefinition: true, scopeLine: 8, isOptimized: true, unit: !0, retainedNodes: !20) |
| 132 | +!17 = !DISubroutineType(types: !18) |
| 133 | +!18 = !{!19} |
| 134 | +!19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64, align: 64) |
| 135 | +!20 = !{!21, !22, !24} |
| 136 | +!21 = !DILocalVariable(name: "coro_hdl", scope: !16, file: !1, line: 9, type: !19) |
| 137 | +!22 = !DILocalVariable(name: "i", scope: !23, file: !1, line: 11, type: !9) |
| 138 | +!23 = distinct !DILexicalBlock(scope: !16, file: !1, line: 11, column: 3) |
| 139 | +!24 = !DILocalVariable(name: "coro_mem", scope: !16, file: !1, line: 16, type: !19) |
| 140 | +!26 = !DILocation(line: 9, column: 3, scope: !16) |
| 141 | +!27 = !DILocation(line: 10, column: 8, scope: !23) |
| 142 | +!33 = !DILocation(line: 11, column: 6, scope: !23) |
| 143 | +!34 = !DILocation(line: 12, column: 6, scope: !23) |
| 144 | +!35 = !DILocation(line: 13, column: 6, scope: !23) |
| 145 | +!36 = !DILocation(line: 14, column: 6, scope: !23) |
| 146 | +!37 = !DILocation(line: 16, column: 3, scope: !16) |
| 147 | +!40 = !DILocation(line: 16, column: 3, scope: !16) |
| 148 | +!41 = !DILocation(line: 17, column: 1, scope: !16) |
0 commit comments