Skip to content

Commit a353edb

Browse files
committed
Simplify coro::salvageDebugInfo() (NFC-ish)
This patch removes the hand-rolled implementation of salvageDebugInfo for cast and GEPs and replaces it with a call into llvm::salvageDebugInfoImpl(). A side-effect of this is that additional redundant convert operations are introduced, but those don't have any negative effect on the resulting DWARF expression. rdar://80227769 Differential Revision: https://reviews.llvm.org/D107384
1 parent d6b6880 commit a353edb

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2514,8 +2514,8 @@ void coro::salvageDebugInfo(
25142514
bool OutermostLoad = true;
25152515
Value *Storage = DVI->getVariableLocationOp(0);
25162516
Value *OriginalStorage = Storage;
2517-
while (Storage) {
2518-
if (auto *LdInst = dyn_cast<LoadInst>(Storage)) {
2517+
while (auto *Inst = dyn_cast<Instruction>(Storage)) {
2518+
if (auto *LdInst = dyn_cast<LoadInst>(Inst)) {
25192519
Storage = LdInst->getOperand(0);
25202520
// FIXME: This is a heuristic that works around the fact that
25212521
// LLVM IR debug intrinsics cannot yet distinguish between
@@ -2526,28 +2526,23 @@ void coro::salvageDebugInfo(
25262526
if (!OutermostLoad)
25272527
Expr = DIExpression::prepend(Expr, DIExpression::DerefBefore);
25282528
OutermostLoad = false;
2529-
} else if (auto *StInst = dyn_cast<StoreInst>(Storage)) {
2529+
} else if (auto *StInst = dyn_cast<StoreInst>(Inst)) {
25302530
Storage = StInst->getOperand(0);
2531-
} else if (auto *GEPInst = dyn_cast<GetElementPtrInst>(Storage)) {
2531+
} else {
25322532
SmallVector<uint64_t, 16> Ops;
25332533
SmallVector<Value *, 0> AdditionalValues;
2534-
Storage = llvm::salvageDebugInfoImpl(
2535-
*GEPInst, Expr ? Expr->getNumLocationOperands() : 0, Ops,
2534+
Value *Op = llvm::salvageDebugInfoImpl(
2535+
*Inst, Expr ? Expr->getNumLocationOperands() : 0, Ops,
25362536
AdditionalValues);
2537-
if (!Storage)
2538-
break;
2539-
// Debug declares cannot currently handle additional location
2540-
// operands.
2541-
if (!AdditionalValues.empty())
2537+
if (!Op || !AdditionalValues.empty()) {
2538+
// If salvaging failed or salvaging produced more than one location
2539+
// operand, give up.
25422540
break;
2541+
}
2542+
Storage = Op;
25432543
Expr = DIExpression::appendOpsToArg(Expr, Ops, 0, /*StackValue*/ false);
2544-
} else if (auto *BCInst = dyn_cast<llvm::BitCastInst>(Storage))
2545-
Storage = BCInst->getOperand(0);
2546-
else
2547-
break;
2544+
}
25482545
}
2549-
if (!Storage)
2550-
return;
25512546

25522547
// Store a pointer to the coroutine frame object in an alloca so it
25532548
// is available throughout the function when producing unoptimized

llvm/test/Transforms/Coroutines/coro-debug.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ attributes #7 = { noduplicate }
154154
; CHECK: call void @llvm.dbg.declare(metadata %f.Frame** %[[DBG_PTR]], metadata ![[RESUME_DIRECT:[0-9]+]], metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[EXPR_TAIL]])
155155
; CHECK: store %f.Frame* {{.*}}, %f.Frame** %[[DBG_PTR]]
156156
; CHECK-NOT: alloca %struct.test*
157-
; CHECK: call void @llvm.dbg.declare(metadata i32 0, metadata ![[RESUME_CONST:[0-9]+]], metadata !DIExpression())
157+
; CHECK: call void @llvm.dbg.declare(metadata i8 0, metadata ![[RESUME_CONST:[0-9]+]], metadata !DIExpression(DW_OP_LLVM_convert, 8, DW_ATE_signed, DW_OP_LLVM_convert, 32, DW_ATE_signed))
158158
; Note that keeping the undef value here could be acceptable, too.
159159
; CHECK-NOT: call void @llvm.dbg.declare(metadata i32* undef, metadata !{{[0-9]+}}, metadata !DIExpression())
160160
; CHECK: call void @coro.devirt.trigger(i8* null)

0 commit comments

Comments
 (0)