[llvm] 4f2401f - [WebAssembly] Use MachineInstr::setDebugValueUndef

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


Author: Heejin Ahn
Date: 2023-03-17T20:15:01-07:00
New Revision: 4f2401f4f9074548b6de3952a6858aeac2f6950f

URL: https://github.com/llvm/llvm-project/commit/4f2401f4f9074548b6de3952a6858aeac2f6950f
DIFF: https://github.com/llvm/llvm-project/commit/4f2401f4f9074548b6de3952a6858aeac2f6950f.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
    llvm/lib/Target/WebAssembly/WebAssemblyNullifyDebugValueLists.cpp
    llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
index 9a6acd157a745..f3f54a5fb501a 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 9b94ee15253d4..b58f7a0152aeb 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<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;
 }

diff  --git a/llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll b/llvm/test/DebugInfo/WebAssembly/dbg-value-list.ll
index c33113673a2a5..dfd4fbbcf3e34 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


        


More information about the llvm-commits mailing list