Coverage Report

Created: 2025-12-04 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wasmtime/winch/codegen/src/abi/local.rs
Line
Count
Source
1
use wasmtime_environ::WasmValType;
2
3
/// Base register used to address the local slot.
4
///
5
/// Slots for stack arguments are addressed from the frame pointer.
6
/// Slots for function-defined locals and for registers are addressed
7
/// from the stack pointer.
8
#[derive(Clone, Eq, PartialEq, Copy, Debug)]
9
enum Base {
10
    FP,
11
    SP,
12
}
13
14
/// A local slot.
15
///
16
/// Represents the type, location and addressing mode of a local
17
/// in the stack's local and argument area.
18
/// LocalSlots are well known slots in the machine stack, and are generally
19
/// reference by the stack pointer register (SP) or the base pointer register (FP).
20
/// * Local slots that are referenced by the stack pointer register are the
21
///   function defined locals and the param locals.
22
/// * Local slots that represent arguments in the stack, are referenced through the
23
///   base pointer register.
24
///
25
/// A [crate::masm::StackSlot] is a generalized form of a [LocalSlot]: they
26
/// represent dynamic chunks of memory that get created throughout the function
27
/// compilation lifetime when spilling values (register and locals) into the
28
/// machine stack. A [LocalSlot] on the other hand gets created at the beginning
29
/// of a function compilation and gets cleaned up at the end.
30
#[derive(Clone, Copy, Debug)]
31
pub(crate) struct LocalSlot {
32
    /// The offset of the local slot.
33
    pub offset: u32,
34
    /// The type contained by this local slot.
35
    pub ty: WasmValType,
36
    /// Base register associated to this local slot.
37
    base: Base,
38
}
39
40
impl LocalSlot {
41
    /// Creates a local slot for a function defined local or
42
    /// for a spilled argument register.
43
2.00M
    pub fn new(ty: WasmValType, offset: u32) -> Self {
44
2.00M
        Self {
45
2.00M
            ty,
46
2.00M
            offset,
47
2.00M
            base: Base::SP,
48
2.00M
        }
49
2.00M
    }
50
51
    /// Int32 shortcut for `new`.
52
3.05k
    pub fn i32(offset: u32) -> Self {
53
3.05k
        Self {
54
3.05k
            ty: WasmValType::I32,
55
3.05k
            offset,
56
3.05k
            base: Base::SP,
57
3.05k
        }
58
3.05k
    }
59
60
    /// Int64 shortcut for `new`.
61
631k
    pub fn i64(offset: u32) -> Self {
62
631k
        Self {
63
631k
            ty: WasmValType::I64,
64
631k
            offset,
65
631k
            base: Base::SP,
66
631k
        }
67
631k
    }
68
69
    /// Creates a local slot for a stack function argument.
70
436k
    pub fn stack_arg(ty: WasmValType, offset: u32) -> Self {
71
436k
        Self {
72
436k
            ty,
73
436k
            offset,
74
436k
            base: Base::FP,
75
436k
        }
76
436k
    }
77
78
    /// Check if the local is addressed from the stack pointer.
79
2.40M
    pub fn addressed_from_sp(&self) -> bool {
80
2.40M
        self.base == Base::SP
81
2.40M
    }
82
}