| 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://github.com/llvm/llvm-project/issues/49705. |
| 13 | /// TODO Correctly handle DBG_VALUE_LISTs |
| 14 | /// |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "WebAssembly.h" |
| 18 | #include "llvm/CodeGen/MachineFunctionAnalysisManager.h" |
| 19 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 20 | #include "llvm/CodeGen/MachinePassManager.h" |
| 21 | #include "llvm/IR/Analysis.h" |
| 22 | using namespace llvm; |
| 23 | |
| 24 | #define DEBUG_TYPE "wasm-nullify-dbg-value-lists" |
| 25 | |
| 26 | namespace { |
| 27 | class WebAssemblyNullifyDebugValueListsLegacy final |
| 28 | : public MachineFunctionPass { |
| 29 | StringRef getPassName() const override { |
| 30 | return "WebAssembly Nullify DBG_VALUE_LISTs" ; |
| 31 | } |
| 32 | |
| 33 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 34 | |
| 35 | public: |
| 36 | static char ID; // Pass identification, replacement for typeid |
| 37 | WebAssemblyNullifyDebugValueListsLegacy() : MachineFunctionPass(ID) {} |
| 38 | }; |
| 39 | } // end anonymous namespace |
| 40 | |
| 41 | char WebAssemblyNullifyDebugValueListsLegacy::ID = 0; |
| 42 | INITIALIZE_PASS(WebAssemblyNullifyDebugValueListsLegacy, DEBUG_TYPE, |
| 43 | "WebAssembly Nullify DBG_VALUE_LISTs" , false, false) |
| 44 | |
| 45 | FunctionPass *llvm::createWebAssemblyNullifyDebugValueListsLegacyPass() { |
| 46 | return new WebAssemblyNullifyDebugValueListsLegacy(); |
| 47 | } |
| 48 | |
| 49 | static bool nullifyDebugValueLists(MachineFunction &MF) { |
| 50 | LLVM_DEBUG(dbgs() << "********** Nullify DBG_VALUE_LISTs **********\n" |
| 51 | "********** Function: " |
| 52 | << MF.getName() << '\n'); |
| 53 | bool Changed = false; |
| 54 | // Our backend, including WebAssemblyDebugValueManager, currently cannot |
| 55 | // handle DBG_VALUE_LISTs correctly. So this makes them undefined, which will |
| 56 | // appear as "optimized out". |
| 57 | for (auto &MBB : MF) { |
| 58 | for (auto &MI : MBB) { |
| 59 | if (MI.getOpcode() == TargetOpcode::DBG_VALUE_LIST) { |
| 60 | MI.setDebugValueUndef(); |
| 61 | Changed = true; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | return Changed; |
| 66 | } |
| 67 | |
| 68 | bool WebAssemblyNullifyDebugValueListsLegacy::runOnMachineFunction( |
| 69 | MachineFunction &MF) { |
| 70 | return nullifyDebugValueLists(MF); |
| 71 | } |
| 72 | |
| 73 | PreservedAnalyses WebAssemblyNullifyDebugValueListsPass::run( |
| 74 | MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) { |
| 75 | return nullifyDebugValueLists(MF) ? getMachineFunctionPassPreservedAnalyses() |
| 76 | .preserveSet<CFGAnalyses>() |
| 77 | : PreservedAnalyses::all(); |
| 78 | } |
| 79 | |