LLVM  14.0.0git
WebAssemblyDebugValueManager.cpp
Go to the documentation of this file.
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 
15 #include "WebAssembly.h"
18 
19 using namespace llvm;
20 
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())
26  return;
27  CurrentReg = Instr->getOperand(0).getReg();
28 
29  MachineBasicBlock::iterator DI = *Instr;
30  ++DI;
31  for (MachineBasicBlock::iterator DE = Instr->getParent()->end(); DI != DE;
32  ++DI) {
33  if (DI->isDebugValue() &&
34  DI->hasDebugOperandForReg(Instr->getOperand(0).getReg()))
35  DbgValues.push_back(&*DI);
36  }
37 }
38 
40  MachineBasicBlock *MBB = Insert->getParent();
41  for (MachineInstr *DBI : reverse(DbgValues))
42  MBB->splice(Insert, DBI->getParent(), DBI);
43 }
44 
46  for (auto *DBI : DbgValues)
47  for (auto &MO : DBI->getDebugOperandsForReg(CurrentReg))
48  MO.setReg(Reg);
49  CurrentReg = Reg;
50 }
51 
53  unsigned NewReg) {
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))
59  MO.setReg(NewReg);
60  MBB->insert(Insert, Clone);
61  }
62 }
63 
65  for (auto *DBI : DbgValues) {
66  auto IndexType = DBI->isIndirectDebugValue()
69  for (auto &MO : DBI->getDebugOperandsForReg(CurrentReg))
70  MO.ChangeToTargetIndex(IndexType, LocalId);
71  }
72 }
llvm::WebAssemblyDebugValueManager::clone
void clone(MachineInstr *Insert, unsigned NewReg)
Definition: WebAssemblyDebugValueManager.cpp:52
MachineInstr.h
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
WebAssembly.h
Insert
Vector Rotate Left Mask Mask Insert
Definition: README_P9.txt:112
llvm::reverse
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
Definition: STLExtras.h:329
llvm::MachineInstr::getDebugOperandsForReg
static iterator_range< filter_iterator< Operand *, std::function< bool(Operand &Op)> > > getDebugOperandsForReg(Instruction *MI, Register Reg)
Returns a range of all of the operands that correspond to a debug use of Reg.
Definition: MachineInstr.h:539
llvm::MachineInstr::getOperand
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:499
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
WebAssemblyDebugValueManager.h
llvm::MachineOperand::isReg
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Definition: MachineOperand.h:321
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MachineFunction::CloneMachineInstr
MachineInstr * CloneMachineInstr(const MachineInstr *Orig)
Create a new MachineInstr which is a copy of Orig, identical in all ways except the instruction has n...
Definition: MachineFunction.cpp:358
llvm::MachineBasicBlock::getParent
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
Definition: MachineBasicBlock.h:225
llvm::MachineOperand::getReg
Register getReg() const
getReg - Returns the register number.
Definition: MachineOperand.h:360
llvm::WebAssemblyDebugValueManager::move
void move(MachineInstr *Insert)
Definition: WebAssemblyDebugValueManager.cpp:39
WebAssemblyMachineFunctionInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::MachineBasicBlock::splice
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
Definition: MachineBasicBlock.h:950
llvm::MachineInstr::getParent
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:286
llvm::WebAssemblyDebugValueManager::WebAssemblyDebugValueManager
WebAssemblyDebugValueManager(MachineInstr *Instr)
Definition: WebAssemblyDebugValueManager.cpp:21
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::WebAssembly::TI_LOCAL
@ TI_LOCAL
Definition: WebAssembly.h:93
llvm::MachineBasicBlock::insert
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
Definition: MachineBasicBlock.cpp:1312
llvm::WebAssembly::TI_LOCAL_INDIRECT
@ TI_LOCAL_INDIRECT
Definition: WebAssembly.h:103
llvm::WebAssemblyDebugValueManager::updateReg
void updateReg(unsigned Reg)
Definition: WebAssemblyDebugValueManager.cpp:45
llvm::WebAssemblyDebugValueManager::replaceWithLocal
void replaceWithLocal(unsigned LocalId)
Definition: WebAssemblyDebugValueManager.cpp:64
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::MachineBasicBlock::end
iterator end()
Definition: MachineBasicBlock.h:270