Skip to content

Commit 9db6e77

Browse files
committed
Make the stackslot offsets available for debuginfo
1 parent 256cc8a commit 9db6e77

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

cranelift/codegen/src/isa/x64/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ impl MachBackend for X64Backend {
6262
let buffer = buffer.finish();
6363
let frame_size = vcode.frame_size();
6464
let unwind_info = vcode.unwind_info()?;
65-
let value_labels_ranges = vcode.value_labels_ranges()?;
65+
let value_labels_ranges = vcode.value_labels_ranges();
66+
let stackslot_offsets = vcode.stackslot_offsets().clone();
6667

6768
let disasm = if want_disasm {
6869
Some(vcode.show_rru(Some(&create_reg_universe_systemv(flags))))
@@ -76,6 +77,7 @@ impl MachBackend for X64Backend {
7677
disasm,
7778
unwind_info,
7879
value_labels_ranges,
80+
stackslot_offsets,
7981
})
8082
}
8183

cranelift/codegen/src/machinst/abi.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ pub trait ABICallee {
5757
/// Number of stack slots (not spill slots).
5858
fn num_stackslots(&self) -> usize;
5959

60+
/// The offsets of all stack slots (not spill slots) for debuginfo purposes.
61+
fn stackslot_offsets(&self) -> &PrimaryMap<StackSlot, u32>;
62+
6063
/// Generate an instruction which copies an argument to a destination
6164
/// register.
6265
fn gen_copy_arg_to_regs(

cranelift/codegen/src/machinst/abi_impl.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ pub struct ABICalleeImpl<M: ABIMachineSpec> {
506506
/// Signature: arg and retval regs.
507507
sig: ABISig,
508508
/// Offsets to each stackslot.
509-
stackslots: Vec<u32>,
509+
stackslots: PrimaryMap<StackSlot, u32>,
510510
/// Total stack size of all stackslots.
511511
stackslots_size: u32,
512512
/// Stack size to be reserved for outgoing arguments.
@@ -584,7 +584,7 @@ impl<M: ABIMachineSpec> ABICalleeImpl<M> {
584584

585585
// Compute stackslot locations and total stackslot size.
586586
let mut stack_offset: u32 = 0;
587-
let mut stackslots = vec![];
587+
let mut stackslots = PrimaryMap::new();
588588
for (stackslot, data) in f.stack_slots.iter() {
589589
let off = stack_offset;
590590
stack_offset += data.size;
@@ -926,6 +926,10 @@ impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
926926
self.stackslots.len()
927927
}
928928

929+
fn stackslot_offsets(&self) -> &PrimaryMap<StackSlot, u32> {
930+
&self.stackslots
931+
}
932+
929933
fn gen_copy_arg_to_regs(
930934
&self,
931935
idx: usize,
@@ -1101,7 +1105,7 @@ impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
11011105
) -> SmallInstVec<Self::I> {
11021106
// Offset from beginning of stackslot area, which is at nominal SP (see
11031107
// [MemArg::NominalSPOffset] for more details on nominal SP tracking).
1104-
let stack_off = self.stackslots[slot.as_u32() as usize] as i64;
1108+
let stack_off = self.stackslots[slot] as i64;
11051109
let sp_off: i64 = stack_off + (offset as i64);
11061110
trace!("load_stackslot: slot {} -> sp_off {}", slot, sp_off);
11071111
gen_load_stack_multi::<M>(StackAMode::NominalSPOffset(sp_off, ty), into_regs, ty)
@@ -1117,7 +1121,7 @@ impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
11171121
) -> SmallInstVec<Self::I> {
11181122
// Offset from beginning of stackslot area, which is at nominal SP (see
11191123
// [MemArg::NominalSPOffset] for more details on nominal SP tracking).
1120-
let stack_off = self.stackslots[slot.as_u32() as usize] as i64;
1124+
let stack_off = self.stackslots[slot] as i64;
11211125
let sp_off: i64 = stack_off + (offset as i64);
11221126
trace!("store_stackslot: slot {} -> sp_off {}", slot, sp_off);
11231127
gen_store_stack_multi::<M>(StackAMode::NominalSPOffset(sp_off, ty), from_regs, ty)
@@ -1127,7 +1131,7 @@ impl<M: ABIMachineSpec> ABICallee for ABICalleeImpl<M> {
11271131
fn stackslot_addr(&self, slot: StackSlot, offset: u32, into_reg: Writable<Reg>) -> Self::I {
11281132
// Offset from beginning of stackslot area, which is at nominal SP (see
11291133
// [MemArg::NominalSPOffset] for more details on nominal SP tracking).
1130-
let stack_off = self.stackslots[slot.as_u32() as usize] as i64;
1134+
let stack_off = self.stackslots[slot] as i64;
11311135
let sp_off: i64 = stack_off + (offset as i64);
11321136
M::gen_get_stack_addr(StackAMode::NominalSPOffset(sp_off, I8), into_reg, I8)
11331137
}

cranelift/codegen/src/machinst/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@
6262
6363
use crate::binemit::{CodeInfo, CodeOffset, StackMap};
6464
use crate::ir::condcodes::IntCC;
65-
use crate::ir::{Function, SourceLoc, Type, ValueLabel};
65+
use crate::ir::{Function, SourceLoc, Type, ValueLabel, StackSlot};
66+
use cranelift_entity::PrimaryMap;
6667
use crate::isa::unwind::input as unwind_input;
6768
use crate::result::CodegenResult;
6869
use crate::settings::Flags;
@@ -343,6 +344,8 @@ pub struct MachCompileResult {
343344
pub unwind_info: Option<unwind_input::UnwindInfo<Reg>>,
344345
/// Debug info: value labels to registers/stackslots at code offsets.
345346
pub value_labels_ranges: Option<ValueLabelsRanges>,
347+
/// Debug info: stackslots to stack pointer offsets.
348+
pub stackslot_offsets: PrimaryMap<StackSlot, u32>,
346349
}
347350

348351
impl MachCompileResult {

cranelift/codegen/src/machinst/vcode.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,17 +617,22 @@ impl<I: VCodeInst> VCode<I> {
617617
}
618618

619619
/// Generates value-label ranges.
620-
pub fn value_labels_ranges(&self) -> crate::result::CodegenResult<Option<ValueLabelsRanges>> {
620+
pub fn value_labels_ranges(&self) -> Option<ValueLabelsRanges> {
621621
if !self.has_value_labels {
622-
return Ok(None);
622+
return None;
623623
}
624624

625625
let layout = &self.insts_layout.borrow();
626-
Ok(Some(debug::compute(
626+
Some(debug::compute(
627627
&self.insts,
628628
&layout.0[..],
629629
&layout.1[..],
630-
)))
630+
))
631+
}
632+
633+
/// Get the offsets of stackslots.
634+
pub fn stackslot_offsets(&self) -> &PrimaryMap<StackSlot, u32> {
635+
self.abi.stackslot_offsets()
631636
}
632637

633638
/// Get the IR block for a BlockIndex, if one exists.

0 commit comments

Comments
 (0)