[llvm] a353edb - Simplify coro::salvageDebugInfo() (NFC-ish)
Adrian Prantl via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 10 15:21:29 PDT 2021
Author: Adrian Prantl
Date: 2021-08-10T15:21:18-07:00
New Revision: a353edb8d6d142c00404eb588944a231d8cd989d
URL: https://github.com/llvm/llvm-project/commit/a353edb8d6d142c00404eb588944a231d8cd989d
DIFF: https://github.com/llvm/llvm-project/commit/a353edb8d6d142c00404eb588944a231d8cd989d.diff
LOG: 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
Added:
Modified:
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/test/Transforms/Coroutines/coro-debug.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
index 921b83ba715ea..e4ef23c0094bd 100644
--- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
+++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp
@@ -2514,8 +2514,8 @@ void coro::salvageDebugInfo(
bool OutermostLoad = true;
Value *Storage = DVI->getVariableLocationOp(0);
Value *OriginalStorage = Storage;
- while (Storage) {
- if (auto *LdInst = dyn_cast<LoadInst>(Storage)) {
+ while (auto *Inst = dyn_cast<Instruction>(Storage)) {
+ if (auto *LdInst = dyn_cast<LoadInst>(Inst)) {
Storage = LdInst->getOperand(0);
// FIXME: This is a heuristic that works around the fact that
// LLVM IR debug intrinsics cannot yet distinguish between
@@ -2526,28 +2526,23 @@ void coro::salvageDebugInfo(
if (!OutermostLoad)
Expr = DIExpression::prepend(Expr, DIExpression::DerefBefore);
OutermostLoad = false;
- } else if (auto *StInst = dyn_cast<StoreInst>(Storage)) {
+ } else if (auto *StInst = dyn_cast<StoreInst>(Inst)) {
Storage = StInst->getOperand(0);
- } else if (auto *GEPInst = dyn_cast<GetElementPtrInst>(Storage)) {
+ } else {
SmallVector<uint64_t, 16> Ops;
SmallVector<Value *, 0> AdditionalValues;
- Storage = llvm::salvageDebugInfoImpl(
- *GEPInst, Expr ? Expr->getNumLocationOperands() : 0, Ops,
+ Value *Op = llvm::salvageDebugInfoImpl(
+ *Inst, Expr ? Expr->getNumLocationOperands() : 0, Ops,
AdditionalValues);
- if (!Storage)
- break;
- // Debug declares cannot currently handle additional location
- // operands.
- if (!AdditionalValues.empty())
+ if (!Op || !AdditionalValues.empty()) {
+ // If salvaging failed or salvaging produced more than one location
+ // operand, give up.
break;
+ }
+ Storage = Op;
Expr = DIExpression::appendOpsToArg(Expr, Ops, 0, /*StackValue*/ false);
- } else if (auto *BCInst = dyn_cast<llvm::BitCastInst>(Storage))
- Storage = BCInst->getOperand(0);
- else
- break;
+ }
}
- if (!Storage)
- return;
// Store a pointer to the coroutine frame object in an alloca so it
// is available throughout the function when producing unoptimized
diff --git a/llvm/test/Transforms/Coroutines/coro-debug.ll b/llvm/test/Transforms/Coroutines/coro-debug.ll
index b766794ffab70..1e86b656d62ea 100644
--- a/llvm/test/Transforms/Coroutines/coro-debug.ll
+++ b/llvm/test/Transforms/Coroutines/coro-debug.ll
@@ -154,7 +154,7 @@ attributes #7 = { noduplicate }
; 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]])
; CHECK: store %f.Frame* {{.*}}, %f.Frame** %[[DBG_PTR]]
; CHECK-NOT: alloca %struct.test*
-; CHECK: call void @llvm.dbg.declare(metadata i32 0, metadata ![[RESUME_CONST:[0-9]+]], metadata !DIExpression())
+; 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))
; Note that keeping the undef value here could be acceptable, too.
; CHECK-NOT: call void @llvm.dbg.declare(metadata i32* undef, metadata !{{[0-9]+}}, metadata !DIExpression())
; CHECK: call void @coro.devirt.trigger(i8* null)
More information about the llvm-commits
mailing list