1 //===-- WebAssemblyDebugValueManager.cpp - WebAssembly DebugValue Manager -===//
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 /// This file implements the manager for MachineInstr DebugValues.
12 //===----------------------------------------------------------------------===//
14 #include "WebAssemblyDebugValueManager.h"
15 #include "WebAssembly.h"
16 #include "WebAssemblyMachineFunctionInfo.h"
17 #include "llvm/CodeGen/MachineInstr.h"
21 WebAssemblyDebugValueManager::WebAssemblyDebugValueManager(
22 MachineInstr
*Instr
) {
23 // This code differs from MachineInstr::collectDebugValues in that it scans
24 // the whole BB, not just contiguous DBG_VALUEs.
25 if (!Instr
->getOperand(0).isReg())
27 CurrentReg
= Instr
->getOperand(0).getReg();
29 MachineBasicBlock::iterator DI
= *Instr
;
31 for (MachineBasicBlock::iterator DE
= Instr
->getParent()->end(); DI
!= DE
;
33 if (DI
->isDebugValue() &&
34 DI
->hasDebugOperandForReg(Instr
->getOperand(0).getReg()))
35 DbgValues
.push_back(&*DI
);
39 void WebAssemblyDebugValueManager::move(MachineInstr
*Insert
) {
40 MachineBasicBlock
*MBB
= Insert
->getParent();
41 for (MachineInstr
*DBI
: reverse(DbgValues
))
42 MBB
->splice(Insert
, DBI
->getParent(), DBI
);
45 void WebAssemblyDebugValueManager::updateReg(unsigned Reg
) {
46 for (auto *DBI
: DbgValues
)
47 for (auto &MO
: DBI
->getDebugOperandsForReg(CurrentReg
))
52 void WebAssemblyDebugValueManager::clone(MachineInstr
*Insert
,
54 MachineBasicBlock
*MBB
= Insert
->getParent();
55 MachineFunction
*MF
= MBB
->getParent();
56 for (MachineInstr
*DBI
: reverse(DbgValues
)) {
57 MachineInstr
*Clone
= MF
->CloneMachineInstr(DBI
);
58 for (auto &MO
: Clone
->getDebugOperandsForReg(CurrentReg
))
60 MBB
->insert(Insert
, Clone
);
64 void WebAssemblyDebugValueManager::replaceWithLocal(unsigned LocalId
) {
65 for (auto *DBI
: DbgValues
) {
66 auto IndexType
= DBI
->isIndirectDebugValue()
67 ? llvm::WebAssembly::TI_LOCAL_INDIRECT
68 : llvm::WebAssembly::TI_LOCAL
;
69 for (auto &MO
: DBI
->getDebugOperandsForReg(CurrentReg
))
70 MO
.ChangeToTargetIndex(IndexType
, LocalId
);