From 4f2401f4f9074548b6de3952a6858aeac2f6950f Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Mon, 13 Mar 2023 02:44:47 -0700 Subject: [PATCH] [WebAssembly] Use MachineInstr::setDebugValueUndef When making `DBG_VALUE`/`DBG_VALUE_LIST` 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_LIST`s 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. Reviewed By: dschuff Differential Revision: https://reviews.llvm.org/D145998 --- .../Target/WebAssembly/WebAssemblyDebugFixup.cpp | 10 ++++---- .../WebAssemblyNullifyDebugValueLists.cpp | 27 +++++++++------------- llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll | 7 +++--- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp index 9a6acd1..f3f54a5 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp @@ -65,14 +65,14 @@ FunctionPass *llvm::createWebAssemblyDebugFixup() { // 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 @@ bool WebAssemblyDebugFixup::runOnMachineFunction(MachineFunction &MF) { assert(Stack.empty() && "WebAssemblyDebugFixup: Stack not empty at end of basic block!"); - nullifyDanglingDebugValues(MBB, TII); + setDanglingDebugValuesUndef(MBB, TII); } return true; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp index 9b94ee1..b58f7a0 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp @@ -48,22 +48,17 @@ bool WebAssemblyNullifyDebugValueLists::runOnMachineFunction( LLVM_DEBUG(dbgs() << "********** Nullify DBG_VALUE_LISTs **********\n" "********** Function: " << MF.getName() << '\n'); - const auto &TII = *MF.getSubtarget().getInstrInfo(); - SmallVector 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; } diff --git a/llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll b/llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll index c331136..dfd4fbb 100644 --- a/llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll +++ b/llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll @@ -5,12 +5,11 @@ target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" 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 -- 2.7.4