brintos

brintos / llvm-project-archived public Read only

0
0
Text · 11.2 KiB · 0ef24a6 Raw
247 lines · plain
1; RUN: opt < %s -passes='default<O0>' -S | FileCheck %s2 3; Define a function 'f' that resembles the Clang frontend's output for the4; following C++ coroutine:5;6;   void foo() {7;     int i = 0;8;     ++i;9;     int x = {};10;     print(i);  // Prints '1'11;12;     co_await suspend_always();13;14;     int j = 0;15;     x[0] = 1;16;     x[1] = 2;17;     ++i;18;     print(i);  // Prints '2'19;     ++j;20;     print(j);  // Prints '1'21;     print(x);  // Print '1'22;   }23;24; The CHECKs verify that dbg.declare intrinsics are created for the coroutine25; funclet 'f.resume', and that they reference the address of the variables on26; the coroutine frame. The debug locations for the original function 'foo' are27; static (!11 and !13), whereas the coroutine funclet will have its own new28; ones with identical line and column numbers.29;30; CHECK-LABEL: define void @_Z3foov() {{.*}} {31; CHECK:       entry:32; CHECK:         %j = alloca i32, align 433; CHECK:         #dbg_declare(ptr %j, ![[JVAR:[0-9]+]], !DIExpression(), ![[JDBGLOC:[0-9]+]]34; CHECK:         %[[MEMORY:.*]] = call ptr @new({{.+}}), !dbg ![[IDBGLOC:[0-9]+]]35; CHECK:         #dbg_declare(ptr %[[MEMORY]], ![[XVAR:[0-9]+]], !DIExpression(DW_OP_plus_uconst, 32), ![[IDBGLOC]]36; CHECK:         #dbg_declare(ptr %[[MEMORY]], ![[IVAR:[0-9]+]], !DIExpression(DW_OP_plus_uconst, 20), ![[IDBGLOC]]37; CHECK:       await.ready:38;39; CHECK-LABEL: define internal fastcc void @_Z3foov.resume({{.*}}) {{.*}} {40; CHECK:       entry.resume:41; CHECK-NEXT:    %[[DBG_PTR:.*]] = alloca ptr42; CHECK-NEXT:    #dbg_declare(ptr %[[DBG_PTR]], ![[XVAR_RESUME:[0-9]+]],   !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 32),43; CHECK-NEXT:    #dbg_declare(ptr %[[DBG_PTR]], ![[IVAR_RESUME:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 20), ![[IDBGLOC_RESUME:[0-9]+]]44; CHECK-NEXT:    #dbg_declare(ptr %[[DBG_PTR]], ![[FRAME_RESUME:[0-9]+]], !DIExpression(DW_OP_deref),45; CHECK-NEXT:    store ptr {{.*}}, ptr %[[DBG_PTR]]46; CHECK:         %[[J:.*]] = alloca i32, align 447; CHECK-NEXT:    #dbg_declare(ptr %[[J]], ![[JVAR_RESUME:[0-9]+]], !DIExpression(), ![[JDBGLOC_RESUME:[0-9]+]]48; CHECK:       init.ready:49; CHECK:       await.ready:50;51; CHECK-DAG: ![[FRAME_RESUME]] = !DILocalVariable(name: "__coro_frame"52; CHECK-DAG: ![[IVAR]] = !DILocalVariable(name: "i"53; CHECK-DAG: ![[PROG_SCOPE:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov"54; CHECK-DAG: ![[BLK_SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: ![[PROG_SCOPE]], file: !1, line: 23, column: 12)55; CHECK-DAG: ![[IDBGLOC]] = !DILocation(line: 23, column: 6, scope: ![[PROG_SCOPE]])56; CHECK-DAG: ![[XVAR]] = !DILocalVariable(name: "x"57; CHECK-DAG: ![[JVAR]] = !DILocalVariable(name: "j"58; CHECK-DAG: ![[JDBGLOC]] = !DILocation(line: 32, column: 7, scope: ![[BLK_SCOPE]])59 60; CHECK-DAG: ![[XVAR_RESUME]] = !DILocalVariable(name: "x"61; CHECK-DAG: ![[RESUME_PROG_SCOPE:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov.resume"62; CHECK-DAG: ![[IDBGLOC_RESUME]] = !DILocation(line: 24, column: 7, scope: ![[RESUME_BLK_SCOPE:[0-9]+]])63; CHECK-DAG: ![[RESUME_BLK_SCOPE]] = distinct !DILexicalBlock(scope: ![[RESUME_PROG_SCOPE]], file: !1, line: 23, column: 12)64; CHECK-DAG: ![[IVAR_RESUME]] = !DILocalVariable(name: "i"65; CHECK-DAG: ![[JVAR_RESUME]] = !DILocalVariable(name: "j"66; CHECK-DAG: ![[JDBGLOC_RESUME]] = !DILocation(line: 32, column: 7, scope: ![[RESUME_BLK_SCOPE]])67define void @_Z3foov() presplitcoroutine !dbg !8 {68entry:69  %__promise = alloca i8, align 870  %i = alloca i32, align 471  %j = alloca i32, align 472  %x = alloca [10 x i32], align 1673  %id = call token @llvm.coro.id(i32 16, ptr %__promise, ptr null, ptr null)74  %alloc = call i1 @llvm.coro.alloc(token %id)75  br i1 %alloc, label %coro.alloc, label %coro.init76 77coro.alloc:                                       ; preds = %entry78  %size = call i64 @llvm.coro.size.i64(), !dbg !2379  %memory = call ptr @new(i64 %size), !dbg !2380  br label %coro.init, !dbg !2381 82coro.init:                                        ; preds = %coro.alloc, %entry83  %phi.entry.alloc = phi ptr [ null, %entry ], [ %memory, %coro.alloc ], !dbg !2384  %begin = call ptr @llvm.coro.begin(token %id, ptr %phi.entry.alloc), !dbg !2385  %ready = call i1 @await_ready()86  br i1 %ready, label %init.ready, label %init.suspend87 88init.suspend:                                     ; preds = %coro.init89  %save = call token @llvm.coro.save(ptr null)90  call void @await_suspend()91  %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)92  switch i8 %suspend, label %coro.ret [93    i8 0, label %init.ready94    i8 1, label %init.cleanup95  ]96 97init.cleanup:                                     ; preds = %init.suspend98  br label %cleanup99 100init.ready:                                       ; preds = %init.suspend, %coro.init101  call void @await_resume()102  call void @llvm.dbg.declare(metadata ptr %i, metadata !6, metadata !DIExpression()), !dbg !11103  store i32 0, ptr %i, align 4104  %i.init.ready.load = load i32, ptr %i, align 4105  %i.init.ready.inc = add nsw i32 %i.init.ready.load, 1106  store i32 %i.init.ready.inc, ptr %i, align 4107  call void @llvm.dbg.declare(metadata ptr %x, metadata !14, metadata !DIExpression()), !dbg !11108  call void @llvm.memset.p0.i64(ptr align 16 %x, i8 0, i64 40, i1 false), !dbg !11109  %i.init.ready.reload = load i32, ptr %i, align 4110  call void @print(i32 %i.init.ready.reload)111  %ready.again = call zeroext i1 @await_ready()112  br i1 %ready.again, label %await.ready, label %await.suspend113 114await.suspend:                                    ; preds = %init.ready115  %save.again = call token @llvm.coro.save(ptr null)116  %from.address = call ptr @from_address(ptr %begin)117  call void @await_suspend()118  %suspend.again = call i8 @llvm.coro.suspend(token %save.again, i1 false)119  switch i8 %suspend.again, label %coro.ret [120    i8 0, label %await.ready121    i8 1, label %await.cleanup122  ]123 124await.cleanup:                                    ; preds = %await.suspend125  br label %cleanup126 127await.ready:                                      ; preds = %await.suspend, %init.ready128  call void @await_resume()129  call void @llvm.dbg.declare(metadata ptr %j, metadata !12, metadata !DIExpression()), !dbg !13130  store i32 0, ptr %j, align 4131  store i32 1, ptr %x, align 16, !dbg !19132  %arrayidx1 = getelementptr inbounds [10 x i32], ptr %x, i64 0, i64 1, !dbg !20133  store i32 2, ptr %arrayidx1, align 4, !dbg !21134  %i.await.ready.load = load i32, ptr %i, align 4135  %i.await.ready.inc = add nsw i32 %i.await.ready.load, 1136  store i32 %i.await.ready.inc, ptr %i, align 4137  %j.await.ready.load = load i32, ptr %j, align 4138  %j.await.ready.inc = add nsw i32 %j.await.ready.load, 1139  store i32 %j.await.ready.inc, ptr %j, align 4140  %i.await.ready.reload = load i32, ptr %i, align 4141  call void @print(i32 %i.await.ready.reload)142  %j.await.ready.reload = load i32, ptr %j, align 4143  call void @print(i32 %j.await.ready.reload)144  call void @return_void()145  br label %coro.final146 147coro.final:                                       ; preds = %await.ready148  call void @final_suspend()149  %coro.final.await_ready = call i1 @await_ready()150  br i1 %coro.final.await_ready, label %final.ready, label %final.suspend151 152final.suspend:                                    ; preds = %coro.final153  %final.suspend.coro.save = call token @llvm.coro.save(ptr null)154  %final.suspend.from_address = call ptr @from_address(ptr %begin)155  call void @await_suspend()156  %final.suspend.coro.suspend = call i8 @llvm.coro.suspend(token %final.suspend.coro.save, i1 true)157  switch i8 %final.suspend.coro.suspend, label %coro.ret [158    i8 0, label %final.ready159    i8 1, label %final.cleanup160  ]161 162final.cleanup:                                    ; preds = %final.suspend163  br label %cleanup164 165final.ready:                                      ; preds = %final.suspend, %coro.final166  call void @await_resume()167  br label %cleanup168 169cleanup:                                          ; preds = %final.ready, %final.cleanup, %await.cleanup, %init.cleanup170  %cleanup.dest.slot.0 = phi i32 [ 0, %final.ready ], [ 2, %final.cleanup ], [ 2, %await.cleanup ], [ 2, %init.cleanup ]171  %free.memory = call ptr @llvm.coro.free(token %id, ptr %begin)172  %free = icmp ne ptr %free.memory, null173  br i1 %free, label %coro.free, label %after.coro.free174 175coro.free:                                        ; preds = %cleanup176  call void @delete(ptr %free.memory)177  br label %after.coro.free178 179after.coro.free:                                  ; preds = %coro.free, %cleanup180  switch i32 %cleanup.dest.slot.0, label %unreachable [181    i32 0, label %cleanup.cont182    i32 2, label %coro.ret183  ]184 185cleanup.cont:                                     ; preds = %after.coro.free186  br label %coro.ret187 188coro.ret:                                         ; preds = %cleanup.cont, %after.coro.free, %final.suspend, %await.suspend, %init.suspend189  call void @llvm.coro.end(ptr null, i1 false, token none)190  ret void191 192unreachable:                                      ; preds = %after.coro.free193  unreachable194}195 196declare void @llvm.dbg.declare(metadata, metadata, metadata)197declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr)198declare i1 @llvm.coro.alloc(token)199declare i64 @llvm.coro.size.i64()200declare token @llvm.coro.save(ptr)201declare ptr @llvm.coro.begin(token, ptr writeonly)202declare i8 @llvm.coro.suspend(token, i1)203declare ptr @llvm.coro.free(token, ptr nocapture readonly)204declare void @llvm.coro.end(ptr, i1, token)205 206declare ptr @new(i64)207declare void @delete(ptr)208declare i1 @await_ready()209declare void @await_suspend()210declare void @await_resume()211declare void @print(i32)212declare ptr @from_address(ptr)213declare void @return_void()214declare void @final_suspend()215 216declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)217 218!llvm.dbg.cu = !{!0}219!llvm.linker.options = !{}220!llvm.module.flags = !{!3, !4}221!llvm.ident = !{!5}222 223!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, splitDebugInlining: false, nameTableKind: None)224!1 = !DIFile(filename: "repro.cpp", directory: ".")225!2 = !{}226!3 = !{i32 7, !"Dwarf Version", i32 4}227!4 = !{i32 2, !"Debug Info Version", i32 3}228!5 = !{!"clang version 11.0.0"}229!6 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 24, type: !10)230!7 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)231!8 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 23, type: !9, scopeLine: 23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)232!9 = !DISubroutineType(types: !2)233!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)234!11 = !DILocation(line: 24, column: 7, scope: !7)235!12 = !DILocalVariable(name: "j", scope: !7, file: !1, line: 32, type: !10)236!13 = !DILocation(line: 32, column: 7, scope: !7)237!14 = !DILocalVariable(name: "x", scope: !22, file: !1, line: 34, type: !15)238!15 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 320, elements: !16)239!16 = !{!17}240!17 = !DISubrange(count: 10)241!18 = !DILocation(line: 42, column: 3, scope: !7)242!19 = !DILocation(line: 42, column: 8, scope: !7)243!20 = !DILocation(line: 43, column: 3, scope: !7)244!21 = !DILocation(line: 43, column: 8, scope: !7)245!22 = distinct !DILexicalBlock(scope: !8, file: !1, line: 23, column: 12)246!23 = !DILocation(line: 23, column: 6, scope: !8)247