[PATCH] D121324: [debug-info] Debug salvage llvm.dbg.addr in original function that point into the coroutine frame when splitting coros.

Michael Gottesman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 9 11:59:29 PST 2022


gottesmm created this revision.
Herald added subscribers: ChuanqiXu, hiraditya.
Herald added a project: All.
gottesmm requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

We are already doing this in the split functions while we clone. This just
handles the original function.

I also updated the coroutine split test to validate that we are always referring
to the msg in the context object instead of in a shadow copy.

rdar://83957028


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121324

Files:
  llvm/lib/Transforms/Coroutines/CoroSplit.cpp
  llvm/test/Transforms/Coroutines/coro-debug-dbg.addr-swift.ll


Index: llvm/test/Transforms/Coroutines/coro-debug-dbg.addr-swift.ll
===================================================================
--- llvm/test/Transforms/Coroutines/coro-debug-dbg.addr-swift.ll
+++ llvm/test/Transforms/Coroutines/coro-debug-dbg.addr-swift.ll
@@ -8,8 +8,8 @@
 ; RUN: opt %s -passes='function(coro-early),cgscc(coro-split,simplifycfg)' -S | FileCheck %s
 
 ; CHECK-LABEL: define swifttailcc void @"$s10async_args14withGenericArgyyxnYalF"(%swift.context* swiftasync %0, %swift.opaque* noalias %1, %swift.type* %T){{.*}} {
-; CHECK: call void @llvm.dbg.declare(
-; CHECK: call void @llvm.dbg.addr(
+; CHECK: call void @llvm.dbg.declare(metadata %swift.context** [[CORO_CTX:%[a-z0-9\.]+]],
+; CHECK: call void @llvm.dbg.addr(metadata %swift.context** [[CORO_CTX]],
 ; CHECK-NOT: llvm.dbg.value
 ; CHECK-NOT: llvm.dbg.addr
 ; CHECK-NOT: llvm.dbg.declare
@@ -19,15 +19,15 @@
 
 ; CHECK-LABEL: define internal swifttailcc void @"$s10async_args14withGenericArgyyxnYalFTY0_"(i8* swiftasync %0)
 ; CHECK: entryresume.0
-; CHECK: call void @llvm.dbg.declare(
-; CHECK: call void @llvm.dbg.addr(
+; CHECK: call void @llvm.dbg.declare(metadata i8** [[CORO_CTX:%[a-z0-9\.]+]],
+; CHECK: call void @llvm.dbg.addr(metadata i8** [[CORO_CTX]],
 ; CHECK: musttail call swifttailcc void @"$s10async_args10forceSplityyYaF"(%swift.context* swiftasync
 ; CHECK-NEXT: ret void
 ; CHECK-NEXT: }
 
 ; CHECK: define internal swifttailcc void @"$s10async_args14withGenericArgyyxnYalFTQ1_"(i8* swiftasync %0)
-; CHECK: call void @llvm.dbg.declare
-; CHECK: call void @llvm.dbg.addr
+; CHECK: call void @llvm.dbg.declare(metadata i8** [[CORO_CTX:%[a-z0-9\.]+]],
+; CHECK: call void @llvm.dbg.addr(metadata i8** [[CORO_CTX]],
 ; CHECK: call void @llvm.dbg.value(metadata %swift.opaque** undef,
 ; CHECK: ret void
 ; CHECK-NEXT: }
Index: llvm/lib/Transforms/Coroutines/CoroSplit.cpp
===================================================================
--- llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -1920,6 +1920,26 @@
   // This invalidates SwiftErrorOps in the Shape.
   replaceSwiftErrorOps(F, Shape, nullptr);
 
+  // Finally, salvage the llvm.dbg.{declare,addr} in our original function that
+  // point into the coroutine frame. We only do this for the current function
+  // since the Cloner salvaged debug info for us in the new coroutine funclets.
+  SmallVector<DbgVariableIntrinsic *, 8> Worklist;
+  SmallDenseMap<llvm::Value *, llvm::AllocaInst *, 4> DbgPtrAllocaCache;
+  for (auto &BB : F) {
+    for (auto &I : BB) {
+      if (auto *DDI = dyn_cast<DbgDeclareInst>(&I)) {
+        Worklist.push_back(DDI);
+        continue;
+      }
+      if (auto *DDI = dyn_cast<DbgAddrIntrinsic>(&I)) {
+        Worklist.push_back(DDI);
+        continue;
+      }
+    }
+  }
+  for (auto *DDI : Worklist)
+    coro::salvageDebugInfo(DbgPtrAllocaCache, DDI, Shape.OptimizeFrame);
+
   return Shape;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121324.414182.patch
Type: text/x-patch
Size: 2953 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220309/cd6b1afd/attachment.bin>


More information about the llvm-commits mailing list