From 733d7cf9649968c05f41480747ed91c7b0c3a82f Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Tue, 24 May 2022 14:09:18 +0800 Subject: [PATCH] [Debug] [Coroutines] Add deref operator for non complex expression 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`. Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D126277 --- llvm/lib/Transforms/Coroutines/CoroFrame.cpp | 4 ++-- llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index f1caa5e98a3d..dea190901aa9 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -2564,6 +2564,7 @@ void coro::salvageDebugInfo( bool SkipOutermostLoad = !isa(DVI); Value *Storage = DVI->getVariableLocationOp(0); Value *OriginalStorage = Storage; + while (auto *Inst = dyn_cast_or_null(Storage)) { if (auto *LdInst = dyn_cast(Inst)) { Storage = LdInst->getOperand(0); @@ -2619,8 +2620,7 @@ void coro::salvageDebugInfo( // 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()) - Expr = DIExpression::prepend(Expr, DIExpression::DerefBefore); + Expr = DIExpression::prepend(Expr, DIExpression::DerefBefore); } DVI->replaceVariableLocationOp(OriginalStorage, Storage); diff --git a/llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll b/llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll index 8e262c657508..f275e50cfb28 100644 --- a/llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll +++ b/llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll @@ -10,7 +10,8 @@ ; ; 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: %[[FramePtr_RESUME:.*]] = alloca %f.Frame* +; 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",