Skip to content

Commit 26baf62

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 (cherry picked from commit a353edb) Conflicts: llvm/lib/Transforms/Coroutines/CoroFrame.cpp
1 parent 3058548 commit 26baf62

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 21 additions & 26 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,41 +2526,36 @@ 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)) {
2532-
SmallVector<uint64_t, 16> Ops;
2533-
SmallVector<Value *, 0> AdditionalValues;
2534-
Storage = llvm::salvageDebugInfoImpl(
2535-
*GEPInst, Expr ? Expr->getNumLocationOperands() : 0, Ops,
2536-
AdditionalValues);
2537-
if (!Storage)
2538-
break;
2539-
// Debug declares cannot currently handle additional location
2540-
// operands.
2541-
if (!AdditionalValues.empty())
2542-
break;
2543-
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 if (auto *I2PInst = dyn_cast<llvm::IntToPtrInst>(Storage)) {
2531+
} else if (auto *I2PInst = dyn_cast<llvm::IntToPtrInst>(Inst)) {
25472532
Storage = I2PInst->getOperand(0);
2548-
} else if (auto *P2IInst = dyn_cast<llvm::PtrToIntInst>(Storage)) {
2533+
} else if (auto *P2IInst = dyn_cast<llvm::PtrToIntInst>(Inst)) {
25492534
Storage = P2IInst->getOperand(0);
2550-
} else if (auto *IInst = dyn_cast<llvm::IntrinsicInst>(Storage)) {
2535+
} else if (auto *IInst = dyn_cast<llvm::IntrinsicInst>(Inst)) {
25512536
if (IInst->getIntrinsicID() == Intrinsic::ptrauth_auth)
25522537
Storage = IInst->getArgOperand(0);
25532538
else
25542539
break;
2555-
} else if (auto *Phi = dyn_cast<PHINode>(Storage)) {
2540+
} else if (auto *Phi = dyn_cast<PHINode>(Inst)) {
25562541
if (Phi->getNumIncomingValues() != 1)
25572542
return;
25582543
Storage = Phi->getIncomingValue(0);
2559-
} else
2560-
break;
2544+
} else {
2545+
SmallVector<uint64_t, 16> Ops;
2546+
SmallVector<Value *, 0> AdditionalValues;
2547+
Value *Op = llvm::salvageDebugInfoImpl(
2548+
*Inst, Expr ? Expr->getNumLocationOperands() : 0, Ops,
2549+
AdditionalValues);
2550+
if (!Op || !AdditionalValues.empty()) {
2551+
// If salvaging failed or salvaging produced more than one location
2552+
// operand, give up.
2553+
break;
2554+
}
2555+
Storage = Op;
2556+
Expr = DIExpression::appendOpsToArg(Expr, Ops, 0, /*StackValue*/ false);
2557+
}
25612558
}
2562-
if (!Storage)
2563-
return;
25642559

25652560
// Store a pointer to the coroutine frame object in an alloca so it
25662561
// 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)