1 //=== WebAssemblyNullifyDebugValueLists.cpp - Nullify DBG_VALUE_LISTs ---===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// Nullify DBG_VALUE_LISTs instructions as a temporary measure before we
11 /// implement DBG_VALUE_LIST handling in WebAssemblyDebugValueManager.
12 /// See https://bugs.llvm.org/show_bug.cgi?id=50361.
13 /// TODO Correctly handle DBG_VALUE_LISTs
15 //===----------------------------------------------------------------------===//
17 #include "WebAssembly.h"
18 #include "WebAssemblySubtarget.h"
21 #define DEBUG_TYPE "wasm-nullify-dbg-value-lists"
24 class WebAssemblyNullifyDebugValueLists final
: public MachineFunctionPass
{
25 StringRef
getPassName() const override
{
26 return "WebAssembly Nullify DBG_VALUE_LISTs";
29 bool runOnMachineFunction(MachineFunction
&MF
) override
;
32 static char ID
; // Pass identification, replacement for typeid
33 WebAssemblyNullifyDebugValueLists() : MachineFunctionPass(ID
) {}
35 } // end anonymous namespace
37 char WebAssemblyNullifyDebugValueLists::ID
= 0;
38 INITIALIZE_PASS(WebAssemblyNullifyDebugValueLists
, DEBUG_TYPE
,
39 "WebAssembly Nullify DBG_VALUE_LISTs", false, false)
41 FunctionPass
*llvm::createWebAssemblyNullifyDebugValueLists() {
42 return new WebAssemblyNullifyDebugValueLists();
45 bool WebAssemblyNullifyDebugValueLists::runOnMachineFunction(
46 MachineFunction
&MF
) {
47 LLVM_DEBUG(dbgs() << "********** Nullify DBG_VALUE_LISTs **********\n"
48 "********** Function: "
49 << MF
.getName() << '\n');
50 const auto &TII
= *MF
.getSubtarget
<WebAssemblySubtarget
>().getInstrInfo();
51 SmallVector
<MachineInstr
*, 2> DbgValueLists
;
54 if (MI
.getOpcode() == TargetOpcode::DBG_VALUE_LIST
)
55 DbgValueLists
.push_back(&MI
);
57 // Our backend, including WebAssemblyDebugValueManager, currently cannot
58 // handle DBG_VALUE_LISTs correctly. So this converts DBG_VALUE_LISTs to
59 // "DBG_VALUE $noreg", which will appear as "optimized out".
60 for (auto *DVL
: DbgValueLists
) {
61 BuildMI(*DVL
->getParent(), DVL
, DVL
->getDebugLoc(),
62 TII
.get(TargetOpcode::DBG_VALUE
), false, Register(),
63 DVL
->getOperand(0).getMetadata(), DVL
->getOperand(1).getMetadata());
64 DVL
->eraseFromParent();
67 return !DbgValueLists
.empty();