[PATCH] D145998: [WebAssembly] Use MachineInstr::setDebugValueUndef
Heejin Ahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 13 15:53:14 PDT 2023
aheejin created this revision.
aheejin added a reviewer: dschuff.
Herald added subscribers: pmatos, asb, wingo, ecnelises, sunfish, hiraditya, jgravelle-google, sbc100.
Herald added a project: All.
aheejin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When making `DBG_VALUE`/`DBG_VALUE_INST` instructions undefined, there
is a method that takes care of it so we don't need to do it manually.
This changes the test because previously we are converting
`DBG_VALUE_LISTS` into `DBG_VALUE $noreg` but now we leave
`DBG_VALUE_LIST` but set it to undef by turning all its register
operands `$noreg`. The effect is the same.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D145998
Files:
llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp
llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll
Index: llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll
===================================================================
--- llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll
+++ llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll
@@ -5,12 +5,11 @@
target triple = "wasm32-unknown-unknown"
; WebAssembly backend does not currently handle DBG_VALUE_LIST instructions
-; correctly. In the meantime, they are converted to 'DBG_VALUE $noreg's in
+; correctly. In the meantime, they are converted to undefs in
; WebAssemblyNullifyDebugValueLists pass.
-; BEFORE: DBG_VALUE_LIST
-; AFTER-NOT: DBG_VALUE_LIST
-; AFTER: DBG_VALUE $noreg, $noreg
+; BEFORE: DBG_VALUE_LIST !{{[0-9]+}}, !DIExpression(), %{{[0-9]+}}, %{{[0-9]+}}
+; AFTER: DBG_VALUE_LIST !{{[0-9]+}}, !DIExpression(), $noreg, $noreg
define i32 @dbg_value_list_test() !dbg !6 {
entry:
%0 = call i32 @foo(), !dbg !9
Index: llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp
@@ -48,22 +48,17 @@
LLVM_DEBUG(dbgs() << "********** Nullify DBG_VALUE_LISTs **********\n"
"********** Function: "
<< MF.getName() << '\n');
- const auto &TII = *MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
- SmallVector<MachineInstr *, 2> DbgValueLists;
- for (auto &MBB : MF)
- for (auto &MI : MBB)
- if (MI.getOpcode() == TargetOpcode::DBG_VALUE_LIST)
- DbgValueLists.push_back(&MI);
-
+ bool Changed = false;
// Our backend, including WebAssemblyDebugValueManager, currently cannot
- // handle DBG_VALUE_LISTs correctly. So this converts DBG_VALUE_LISTs to
- // "DBG_VALUE $noreg", which will appear as "optimized out".
- for (auto *DVL : DbgValueLists) {
- BuildMI(*DVL->getParent(), DVL, DVL->getDebugLoc(),
- TII.get(TargetOpcode::DBG_VALUE), false, Register(),
- DVL->getOperand(0).getMetadata(), DVL->getOperand(1).getMetadata());
- DVL->eraseFromParent();
+ // handle DBG_VALUE_LISTs correctly. So this makes them undefined, which will
+ // appear as "optimized out".
+ for (auto &MBB : MF) {
+ for (auto &MI : MBB) {
+ if (MI.getOpcode() == TargetOpcode::DBG_VALUE_LIST) {
+ MI.setDebugValueUndef();
+ Changed = true;
+ }
+ }
}
-
- return !DbgValueLists.empty();
+ return Changed;
}
Index: llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
@@ -65,14 +65,14 @@
// Because Wasm cannot access values in LLVM virtual registers in the debugger,
// these dangling DBG_VALUEs in effect kill the effect of any previous DBG_VALUE
// associated with the variable, which will appear as "optimized out".
-static void nullifyDanglingDebugValues(MachineBasicBlock &MBB,
- const TargetInstrInfo *TII) {
+static void setDanglingDebugValuesUndef(MachineBasicBlock &MBB,
+ const TargetInstrInfo *TII) {
for (auto &MI : llvm::make_early_inc_range(MBB)) {
if (MI.isDebugValue() && MI.getDebugOperand(0).isReg() &&
!MI.isUndefDebugValue()) {
- LLVM_DEBUG(dbgs() << "Warning: dangling DBG_VALUE nullified: " << MI
+ LLVM_DEBUG(dbgs() << "Warning: dangling DBG_VALUE set to undef: " << MI
<< "\n");
- MI.getDebugOperand(0).setReg(Register());
+ MI.setDebugValueUndef();
}
}
}
@@ -154,7 +154,7 @@
assert(Stack.empty() &&
"WebAssemblyDebugFixup: Stack not empty at end of basic block!");
- nullifyDanglingDebugValues(MBB, TII);
+ setDanglingDebugValuesUndef(MBB, TII);
}
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145998.504879.patch
Type: text/x-patch
Size: 3957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230313/767e6498/attachment.bin>
More information about the llvm-commits
mailing list