mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-05-19 21:46:12 +00:00

This patch adds a new instruction that can represent variadic debug values, DBG_VALUE_VAR. This patch alone covers the addition of the instruction and a set of basic code changes in MachineInstr and a few adjacent areas, but does not correctly handle variadic debug values outside of these areas, nor does it generate them at any point. The new instruction is similar to the existing DBG_VALUE instruction, with the following differences: the operands are in a different order, any number of values may be used in the instruction following the Variable and Expression operands (these are referred to in code as “debug operands”) and are indexed from 0 so that getDebugOperand(X) == getOperand(X+2), and the Expression in a DBG_VALUE_VAR must use the DW_OP_LLVM_arg operator to pass arguments into the expression. The new DW_OP_LLVM_arg operator is only valid in expressions appearing in a DBG_VALUE_VAR; it takes a single argument and pushes the debug operand at the index given by the argument onto the Expression stack. For example the sub-expression `DW_OP_LLVM_arg, 0` has the meaning “Push the debug operand at index 0 onto the expression stack.” Differential Revision: https://reviews.llvm.org/D82363
70 lines
2.4 KiB
C++
70 lines
2.4 KiB
C++
//===-- WebAssemblyDebugValueManager.cpp - WebAssembly DebugValue Manager -===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// This file implements the manager for MachineInstr DebugValues.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "WebAssemblyDebugValueManager.h"
|
|
#include "WebAssembly.h"
|
|
#include "WebAssemblyMachineFunctionInfo.h"
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
using namespace llvm;
|
|
|
|
WebAssemblyDebugValueManager::WebAssemblyDebugValueManager(
|
|
MachineInstr *Instr) {
|
|
// This code differs from MachineInstr::collectDebugValues in that it scans
|
|
// the whole BB, not just contiguous DBG_VALUEs.
|
|
if (!Instr->getOperand(0).isReg())
|
|
return;
|
|
|
|
MachineBasicBlock::iterator DI = *Instr;
|
|
++DI;
|
|
for (MachineBasicBlock::iterator DE = Instr->getParent()->end(); DI != DE;
|
|
++DI) {
|
|
if (DI->isDebugValue() &&
|
|
DI->hasDebugOperandForReg(Instr->getOperand(0).getReg()))
|
|
DbgValues.push_back(&*DI);
|
|
}
|
|
}
|
|
|
|
void WebAssemblyDebugValueManager::move(MachineInstr *Insert) {
|
|
MachineBasicBlock *MBB = Insert->getParent();
|
|
for (MachineInstr *DBI : reverse(DbgValues))
|
|
MBB->splice(Insert, DBI->getParent(), DBI);
|
|
}
|
|
|
|
void WebAssemblyDebugValueManager::updateReg(unsigned Reg) {
|
|
for (auto *DBI : DbgValues)
|
|
DBI->getDebugOperand(0).setReg(Reg);
|
|
}
|
|
|
|
void WebAssemblyDebugValueManager::clone(MachineInstr *Insert,
|
|
unsigned NewReg) {
|
|
MachineBasicBlock *MBB = Insert->getParent();
|
|
MachineFunction *MF = MBB->getParent();
|
|
for (MachineInstr *DBI : reverse(DbgValues)) {
|
|
MachineInstr *Clone = MF->CloneMachineInstr(DBI);
|
|
Clone->getDebugOperand(0).setReg(NewReg);
|
|
MBB->insert(Insert, Clone);
|
|
}
|
|
}
|
|
|
|
void WebAssemblyDebugValueManager::replaceWithLocal(unsigned LocalId) {
|
|
for (auto *DBI : DbgValues) {
|
|
MachineOperand &Op0 = DBI->getDebugOperand(0);
|
|
MachineOperand &Op1 = DBI->getOperand(1);
|
|
bool Indirect = Op1.isImm() && Op1.getImm() == 0;
|
|
Op0.ChangeToTargetIndex(Indirect ? llvm::WebAssembly::TI_LOCAL_INDIRECT
|
|
: llvm::WebAssembly::TI_LOCAL,
|
|
LocalId);
|
|
}
|
|
}
|