LLVM  14.0.0git
WebAssemblyNullifyDebugValueLists.cpp
Go to the documentation of this file.
1 //=== WebAssemblyNullifyDebugValueLists.cpp - Nullify DBG_VALUE_LISTs ---===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
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
14 ///
15 //===----------------------------------------------------------------------===//
16 
17 #include "WebAssembly.h"
18 #include "WebAssemblySubtarget.h"
19 using namespace llvm;
20 
21 #define DEBUG_TYPE "wasm-nullify-dbg-value-lists"
22 
23 namespace {
24 class WebAssemblyNullifyDebugValueLists final : public MachineFunctionPass {
25  StringRef getPassName() const override {
26  return "WebAssembly Nullify DBG_VALUE_LISTs";
27  }
28 
29  bool runOnMachineFunction(MachineFunction &MF) override;
30 
31 public:
32  static char ID; // Pass identification, replacement for typeid
33  WebAssemblyNullifyDebugValueLists() : MachineFunctionPass(ID) {}
34 };
35 } // end anonymous namespace
36 
38 INITIALIZE_PASS(WebAssemblyNullifyDebugValueLists, DEBUG_TYPE,
39  "WebAssembly Nullify DBG_VALUE_LISTs", false, false)
40 
42  return new WebAssemblyNullifyDebugValueLists();
43 }
44 
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;
52  for (auto &MBB : MF)
53  for (auto &MI : MBB)
54  if (MI.getOpcode() == TargetOpcode::DBG_VALUE_LIST)
55  DbgValueLists.push_back(&MI);
56 
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();
65  }
66 
67  return !DbgValueLists.empty();
68 }
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
WebAssembly.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
TII
const HexagonInstrInfo * TII
Definition: HexagonCopyToCombine.cpp:129
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:630
llvm::createWebAssemblyNullifyDebugValueLists
FunctionPass * createWebAssemblyNullifyDebugValueLists()
llvm::MachineFunction::getName
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Definition: MachineFunction.cpp:542
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::WebAssemblySubtarget
Definition: WebAssemblySubtarget.h:35
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
WebAssemblySubtarget.h
DEBUG_TYPE
#define DEBUG_TYPE
Definition: WebAssemblyNullifyDebugValueLists.cpp:21
llvm::BuildMI
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Definition: MachineInstrBuilder.h:328
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
INITIALIZE_PASS
INITIALIZE_PASS(WebAssemblyNullifyDebugValueLists, DEBUG_TYPE, "WebAssembly Nullify DBG_VALUE_LISTs", false, false) FunctionPass *llvm
Definition: WebAssemblyNullifyDebugValueLists.cpp:38
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37