[PATCH] D144793: [DebugInfo] Upgrade `dbg.addr` to `dbg.value` r=Orlando,StephenTozer,probinson,rnk
J. Ryan Stinnett via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 25 16:13:21 PST 2023
jryans created this revision.
jryans added reviewers: Orlando, StephenTozer, probinson, rnk.
Herald added a subscriber: hiraditya.
Herald added a project: All.
jryans requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
As part of removing `dbg.addr`, this upgrades any calls to `dbg.value` with
`DW_OP_deref` prepended onto the value expression.
Part of `dbg.addr` removal
Discussed in https://discourse.llvm.org/t/what-is-the-status-of-dbg-addr/62898
Depends on D144792 <https://reviews.llvm.org/D144792>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D144793
Files:
llvm/lib/IR/AutoUpgrade.cpp
llvm/test/Bitcode/upgrade-dbg-addr.ll
llvm/test/Bitcode/upgrade-dbg-addr.ll.bc
llvm/test/Bitcode/upgrade-dbg-value.ll
Index: llvm/test/Bitcode/upgrade-dbg-value.ll
===================================================================
--- llvm/test/Bitcode/upgrade-dbg-value.ll
+++ llvm/test/Bitcode/upgrade-dbg-value.ll
@@ -1,4 +1,4 @@
-; Test upgrade of dbg.dvalue intrinsics with offsets.
+; Test upgrade of dbg.value intrinsics with offsets.
;
; RUN: llvm-dis < %s.bc | FileCheck %s
; RUN: verify-uselistorder < %s.bc
Index: llvm/test/Bitcode/upgrade-dbg-addr.ll
===================================================================
--- /dev/null
+++ llvm/test/Bitcode/upgrade-dbg-addr.ll
@@ -0,0 +1,18 @@
+; Test upgrade of dbg.addr intrinsics into dbg.value with DW_OP_deref
+;
+; RUN: llvm-dis < %s.bc | FileCheck %s
+; RUN: verify-uselistorder < %s.bc
+
+define i32 @example(i32 %num) !dbg !10 {
+entry:
+ %num.addr = alloca i32
+ store i32 %num, ptr %num.addr
+ ; CHECK-NOT: call void @llvm.dbg.addr
+ ; CHECK: call void @llvm.dbg.value(metadata ptr %num.addr, metadata !16, metadata !DIExpression(DW_OP_deref))
+ call void @llvm.dbg.addr(metadata ptr %num.addr, metadata !16, metadata !DIExpression())
+ %0 = load i32, ptr %num.addr
+ ret i32 %0
+}
+
+; CHECK: declare void @llvm.dbg.value(metadata, metadata, metadata)
+declare void @llvm.dbg.addr(metadata, metadata, metadata)
Index: llvm/lib/IR/AutoUpgrade.cpp
===================================================================
--- llvm/lib/IR/AutoUpgrade.cpp
+++ llvm/lib/IR/AutoUpgrade.cpp
@@ -16,6 +16,7 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
@@ -27,6 +28,7 @@
#include "llvm/IR/IntrinsicsARM.h"
#include "llvm/IR/IntrinsicsX86.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/ErrorHandling.h"
@@ -844,6 +846,11 @@
break;
}
case 'd': {
+ if (Name == "dbg.addr") {
+ rename(F);
+ NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::dbg_value);
+ return true;
+ }
if (Name == "dbg.value" && F->arg_size() == 4) {
rename(F);
NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::dbg_value);
@@ -4128,7 +4135,20 @@
NewCall = Builder.CreateCall(NewFn, {CI->getArgOperand(0)});
break;
- case Intrinsic::dbg_value:
+ case Intrinsic::dbg_value: {
+ StringRef Name = F->getName();
+ Name = Name.substr(5); // Strip llvm
+ // Upgrade `dbg.addr` to `dbg.value` with `DW_OP_deref`
+ if (Name.startswith("dbg.addr")) {
+ DIExpression *Expr = cast<DIExpression>(
+ cast<MetadataAsValue>(CI->getArgOperand(2))->getMetadata());
+ Expr = DIExpression::prepend(Expr, DIExpression::DerefBefore, 0);
+ NewCall =
+ Builder.CreateCall(NewFn, {CI->getArgOperand(0), CI->getArgOperand(1),
+ MetadataAsValue::get(C, Expr)});
+ break;
+ }
+
// Upgrade from the old version that had an extra offset argument.
assert(CI->arg_size() == 4);
// Drop nonzero offsets instead of attempting to upgrade them.
@@ -4141,6 +4161,7 @@
}
CI->eraseFromParent();
return;
+ }
case Intrinsic::ptr_annotation:
// Upgrade from versions that lacked the annotation attribute argument.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144793.500460.patch
Type: text/x-patch
Size: 3413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230226/678f2fcd/attachment.bin>
More information about the llvm-commits
mailing list