Detailed debug-info (DWARF) support in new backends (initially x64).
This PR propagates "value labels" all the way from CLIF to DWARF metadata on the emitted machine code. The key idea is as follows: - Translate value-label metadata on the input into "value_label" pseudo-instructions when lowering into VCode. These pseudo-instructions take a register as input, denote a value label, and semantically are like a "move into value label" -- i.e., they update the current value (as seen by debugging tools) of the given local. These pseudo-instructions emit no machine code. - Perform a dataflow analysis *at the machine-code level*, tracking value-labels that propagate into registers and into [SP+constant] stack storage. This is a forward dataflow fixpoint analysis where each storage location can contain a *set* of value labels, and each value label can reside in a *set* of storage locations. (Meet function is pairwise intersection by storage location.) This analysis traces value labels symbolically through loads and stores and reg-to-reg moves, so it will naturally handle spills and reloads without knowing anything special about them. - When this analysis converges, we have, at each machine-code offset, a mapping from value labels to some number of storage locations; for each offset for each label, we choose the best location (prefer registers). Note that we can choose any location, as the symbolic dataflow analysis is sound and guarantees that the value at the value_label instruction propagates to all of the named locations. - Then we can convert this mapping into a format that the DWARF generation code (wasmtime's debug crate) can use. This PR also adds the new-backend variant to the gdb tests on CI.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
//! This module defines x86_64-specific machine instruction types.
|
||||
|
||||
use crate::binemit::{CodeOffset, StackMap};
|
||||
use crate::ir::{types, ExternalName, Opcode, SourceLoc, TrapCode, Type};
|
||||
use crate::ir::{types, ExternalName, Opcode, SourceLoc, TrapCode, Type, ValueLabel};
|
||||
use crate::isa::x64::abi::X64ABIMachineSpec;
|
||||
use crate::isa::x64::settings as x64_settings;
|
||||
use crate::isa::CallConv;
|
||||
@@ -484,6 +484,9 @@ pub enum Inst {
|
||||
/// A Mach-O TLS symbol access. Returns address of the TLS
|
||||
/// symbol in rax.
|
||||
MachOTlsGetAddr { symbol: ExternalName },
|
||||
|
||||
/// A definition of a value label.
|
||||
ValueLabelMarker { reg: Reg, label: ValueLabel },
|
||||
}
|
||||
|
||||
pub(crate) fn low32_will_sign_extend_to_64(x: u64) -> bool {
|
||||
@@ -544,7 +547,8 @@ impl Inst {
|
||||
| Inst::XmmMinMaxSeq { .. }
|
||||
| Inst::XmmUninitializedValue { .. }
|
||||
| Inst::ElfTlsGetAddr { .. }
|
||||
| Inst::MachOTlsGetAddr { .. } => None,
|
||||
| Inst::MachOTlsGetAddr { .. }
|
||||
| Inst::ValueLabelMarker { .. } => None,
|
||||
|
||||
// These use dynamic SSE opcodes.
|
||||
Inst::GprToXmm { op, .. }
|
||||
@@ -1800,6 +1804,10 @@ impl PrettyPrint for Inst {
|
||||
Inst::MachOTlsGetAddr { ref symbol } => {
|
||||
format!("macho_tls_get_addr {:?}", symbol)
|
||||
}
|
||||
|
||||
Inst::ValueLabelMarker { label, reg } => {
|
||||
format!("value_label {:?}, {}", label, reg.show_rru(mb_rru))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2071,6 +2079,10 @@ fn x64_get_regs(inst: &Inst, collector: &mut RegUsageCollector) {
|
||||
collector.add_def(reg);
|
||||
}
|
||||
}
|
||||
|
||||
Inst::ValueLabelMarker { reg, .. } => {
|
||||
collector.add_use(*reg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2446,6 +2458,8 @@ fn x64_map_regs<RUM: RegUsageMapper>(inst: &mut Inst, mapper: &RUM) {
|
||||
dst.map_uses(mapper);
|
||||
}
|
||||
|
||||
Inst::ValueLabelMarker { ref mut reg, .. } => map_use(mapper, reg),
|
||||
|
||||
Inst::Ret
|
||||
| Inst::EpiloguePlaceholder
|
||||
| Inst::JmpKnown { .. }
|
||||
@@ -2536,6 +2550,25 @@ impl MachInst for Inst {
|
||||
}
|
||||
}
|
||||
|
||||
fn stack_op_info(&self) -> Option<MachInstStackOpInfo> {
|
||||
match self {
|
||||
Self::VirtualSPOffsetAdj { offset } => Some(MachInstStackOpInfo::NomSPAdj(*offset)),
|
||||
Self::MovRM {
|
||||
size: 8,
|
||||
src,
|
||||
dst: SyntheticAmode::NominalSPOffset { simm32 },
|
||||
} => Some(MachInstStackOpInfo::StoreNomSPOff(*src, *simm32 as i64)),
|
||||
Self::Mov64MR {
|
||||
src: SyntheticAmode::NominalSPOffset { simm32 },
|
||||
dst,
|
||||
} => Some(MachInstStackOpInfo::LoadNomSPOff(
|
||||
dst.to_reg(),
|
||||
*simm32 as i64,
|
||||
)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_move(dst_reg: Writable<Reg>, src_reg: Reg, ty: Type) -> Inst {
|
||||
let rc_dst = dst_reg.to_reg().get_class();
|
||||
let rc_src = src_reg.get_class();
|
||||
@@ -2710,6 +2743,17 @@ impl MachInst for Inst {
|
||||
RegClass::I64
|
||||
}
|
||||
|
||||
fn gen_value_label_marker(label: ValueLabel, reg: Reg) -> Self {
|
||||
Inst::ValueLabelMarker { label, reg }
|
||||
}
|
||||
|
||||
fn defines_value_label(&self) -> Option<(ValueLabel, Reg)> {
|
||||
match self {
|
||||
Inst::ValueLabelMarker { label, reg } => Some((*label, *reg)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
type LabelUse = LabelUse;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user