xref: /freebsd/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp (revision c66ec88fed842fbaad62c30d510644ceb7bd2d71)
1 //===-- WebAssemblyDebugValueManager.cpp - WebAssembly DebugValue Manager -===//
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 /// This file implements the manager for MachineInstr DebugValues.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #include "WebAssemblyDebugValueManager.h"
15 #include "WebAssembly.h"
16 #include "WebAssemblyMachineFunctionInfo.h"
17 #include "llvm/CodeGen/MachineInstr.h"
18 
19 using namespace llvm;
20 
21 WebAssemblyDebugValueManager::WebAssemblyDebugValueManager(
22     MachineInstr *Instr) {
23   Instr->collectDebugValues(DbgValues);
24 }
25 
26 void WebAssemblyDebugValueManager::move(MachineInstr *Insert) {
27   MachineBasicBlock *MBB = Insert->getParent();
28   for (MachineInstr *DBI : reverse(DbgValues))
29     MBB->splice(Insert, DBI->getParent(), DBI);
30 }
31 
32 void WebAssemblyDebugValueManager::updateReg(unsigned Reg) {
33   for (auto *DBI : DbgValues)
34     DBI->getDebugOperand(0).setReg(Reg);
35 }
36 
37 void WebAssemblyDebugValueManager::clone(MachineInstr *Insert,
38                                          unsigned NewReg) {
39   MachineBasicBlock *MBB = Insert->getParent();
40   MachineFunction *MF = MBB->getParent();
41   for (MachineInstr *DBI : reverse(DbgValues)) {
42     MachineInstr *Clone = MF->CloneMachineInstr(DBI);
43     Clone->getDebugOperand(0).setReg(NewReg);
44     MBB->insert(Insert, Clone);
45   }
46 }
47 
48 void WebAssemblyDebugValueManager::replaceWithLocal(unsigned LocalId) {
49   for (auto *DBI : DbgValues) {
50     MachineOperand &Op = DBI->getDebugOperand(0);
51     Op.ChangeToTargetIndex(llvm::WebAssembly::TI_LOCAL, LocalId);
52   }
53 }
54