aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp b/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
index e06e359fc592..9a6acd157a74 100644
--- a/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
+++ b/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
@@ -59,6 +59,24 @@ FunctionPass *llvm::createWebAssemblyDebugFixup() {
return new WebAssemblyDebugFixup();
}
+// At this very end of the compilation pipeline, if any DBG_VALUEs with
+// registers remain, it means they are dangling info which we failed to update
+// when their corresponding def instruction was transformed/moved/splitted etc.
+// 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) {
+ 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
+ << "\n");
+ MI.getDebugOperand(0).setReg(Register());
+ }
+ }
+}
+
bool WebAssemblyDebugFixup::runOnMachineFunction(MachineFunction &MF) {
LLVM_DEBUG(dbgs() << "********** Debug Fixup **********\n"
"********** Function: "
@@ -135,6 +153,8 @@ bool WebAssemblyDebugFixup::runOnMachineFunction(MachineFunction &MF) {
}
assert(Stack.empty() &&
"WebAssemblyDebugFixup: Stack not empty at end of basic block!");
+
+ nullifyDanglingDebugValues(MBB, TII);
}
return true;