WebAssemblyNullifyDebugValueLists.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include "WebAssembly.h"
  17. #include "WebAssemblySubtarget.h"
  18. #include "llvm/CodeGen/MachineFunctionPass.h"
  19. using namespace llvm;
  20. #define DEBUG_TYPE "wasm-nullify-dbg-value-lists"
  21. namespace {
  22. class WebAssemblyNullifyDebugValueLists final : public MachineFunctionPass {
  23. StringRef getPassName() const override {
  24. return "WebAssembly Nullify DBG_VALUE_LISTs";
  25. }
  26. bool runOnMachineFunction(MachineFunction &MF) override;
  27. public:
  28. static char ID; // Pass identification, replacement for typeid
  29. WebAssemblyNullifyDebugValueLists() : MachineFunctionPass(ID) {}
  30. };
  31. } // end anonymous namespace
  32. char WebAssemblyNullifyDebugValueLists::ID = 0;
  33. INITIALIZE_PASS(WebAssemblyNullifyDebugValueLists, DEBUG_TYPE,
  34. "WebAssembly Nullify DBG_VALUE_LISTs", false, false)
  35. FunctionPass *llvm::createWebAssemblyNullifyDebugValueLists() {
  36. return new WebAssemblyNullifyDebugValueLists();
  37. }
  38. bool WebAssemblyNullifyDebugValueLists::runOnMachineFunction(
  39. MachineFunction &MF) {
  40. LLVM_DEBUG(dbgs() << "********** Nullify DBG_VALUE_LISTs **********\n"
  41. "********** Function: "
  42. << MF.getName() << '\n');
  43. const auto &TII = *MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
  44. SmallVector<MachineInstr *, 2> DbgValueLists;
  45. for (auto &MBB : MF)
  46. for (auto &MI : MBB)
  47. if (MI.getOpcode() == TargetOpcode::DBG_VALUE_LIST)
  48. DbgValueLists.push_back(&MI);
  49. // Our backend, including WebAssemblyDebugValueManager, currently cannot
  50. // handle DBG_VALUE_LISTs correctly. So this converts DBG_VALUE_LISTs to
  51. // "DBG_VALUE $noreg", which will appear as "optimized out".
  52. for (auto *DVL : DbgValueLists) {
  53. BuildMI(*DVL->getParent(), DVL, DVL->getDebugLoc(),
  54. TII.get(TargetOpcode::DBG_VALUE), false, Register(),
  55. DVL->getOperand(0).getMetadata(), DVL->getOperand(1).getMetadata());
  56. DVL->eraseFromParent();
  57. }
  58. return !DbgValueLists.empty();
  59. }