diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp +++ b/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; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp +++ b/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().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 --- a/llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll +++ b/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