[PATCH] D145998: [WebAssembly] Use MachineInstr::setDebugValueUndef

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 17 20:15:14 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG4f2401f4f907: [WebAssembly] Use MachineInstr::setDebugValueUndef (authored by aheejin).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145998/new/

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.506268.patch
Type: text/x-patch
Size: 3957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230318/5a5bd23a/attachment.bin>


More information about the llvm-commits mailing list