[PATCH] D126277: [Debug] [Coroutines] Add deref operator for non complex expression

Chuanqi Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 23 23:34:41 PDT 2022


ChuanqiXu created this revision.
ChuanqiXu added reviewers: aprantl, dblaikie, jmorse.
Herald added a subscriber: hiraditya.
Herald added a project: All.
ChuanqiXu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Background:

When we construct coroutine frame, we would insert a dbg.declare intrinsic for it:

  %hdl = call void @llvm.coro.begin() ; would return coroutine handle
  call void @llvm.dbg.declare(metadata ptr %hdl, metadata ![[DEBUG_VARIABLE: __coro_frame]], metadata !DIExpression())

And in the splitted coroutine, it looks like:

  define void @coro_func.resume(ptr *hdl) {
  entry.resume:
      call void @llvm.dbg.declare(metadata ptr %hdl, metadata ![[DEBUG_VARIABLE: __coro_frame]], metadata !DIExpression())
  }

And we would salvage the debug info by inserting a new alloca here:

  define void @coro_func.resume(ptr %hdl) {
  entry.resume:
      %frame.debug = alloca ptr
      call void @llvm.dbg.declare(metadata ptr %frame.debug, metadata ![[DEBUG_VARIABLE: __coro_frame]], metadata !DIExpression())
      store ptr %hdl, %frame.debug
  }

But now, the problem comes since the `dbg.declare` refers to the address of that alloca instead of actual coroutine handle. I saw there are codes to solve the problem but it only applies to complex expression only. I feel if it is OK to relax the condition to make it work for `__coro_frame`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126277

Files:
  llvm/lib/Transforms/Coroutines/CoroFrame.cpp
  llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll


Index: llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll
===================================================================
--- llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll
+++ llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll
@@ -10,7 +10,7 @@
 ;
 ; CHECK:       define internal fastcc void @f.resume(
 ; CHECK:       entry.resume:
-; CHECK:            call void @llvm.dbg.declare(metadata %f.Frame** %[[FramePtr_RESUME:.*]], metadata ![[CORO_FRAME_IN_RESUME:[0-9]+]], metadata !DIExpression()
+; CHECK:            call void @llvm.dbg.declare(metadata %f.Frame** %[[FramePtr_RESUME:.*]], metadata ![[CORO_FRAME_IN_RESUME:[0-9]+]], metadata !DIExpression(DW_OP_deref)
 ;
 ; CHECK-DAG: ![[FILE:[0-9]+]] = !DIFile(filename: "coro-debug.cpp"
 ; CHECK-DAG: ![[RAMP:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov",
Index: llvm/lib/Transforms/Coroutines/CoroFrame.cpp
===================================================================
--- llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -2521,6 +2521,7 @@
   bool SkipOutermostLoad = !isa<DbgValueInst>(DVI);
   Value *Storage = DVI->getVariableLocationOp(0);
   Value *OriginalStorage = Storage;
+
   while (auto *Inst = dyn_cast_or_null<Instruction>(Storage)) {
     if (auto *LdInst = dyn_cast<LoadInst>(Inst)) {
       Storage = LdInst->getOperand(0);
@@ -2576,7 +2577,7 @@
       // expression, we need to add a DW_OP_deref at the *start* of the
       // expression to first load the contents of the alloca before
       // adjusting it with the expression.
-      if (Expr && Expr->isComplex())
+      if (Expr)
         Expr = DIExpression::prepend(Expr, DIExpression::DerefBefore);
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126277.431594.patch
Type: text/x-patch
Size: 1743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220524/75bbca37/attachment.bin>


More information about the llvm-commits mailing list