cranelift_codegen/isa/x64/inst/
emit_state.rs

1use super::*;
2use crate::ir;
3use cranelift_control::ControlPlane;
4
5/// State carried between emissions of a sequence of instructions.
6#[derive(Default, Clone, Debug)]
7pub struct EmitState {
8    /// The user stack map for the upcoming instruction, as provided to
9    /// `pre_safepoint()`.
10    user_stack_map: Option<ir::UserStackMap>,
11
12    /// Only used during fuzz-testing. Otherwise, it is a zero-sized struct and
13    /// optimized away at compiletime. See [cranelift_control].
14    ctrl_plane: ControlPlane,
15
16    /// A copy of the frame layout, used during the emission of `Inst::ReturnCallKnown` and
17    /// `Inst::ReturnCallUnknown` instructions.
18    frame_layout: FrameLayout,
19}
20
21impl MachInstEmitState<Inst> for EmitState {
22    fn new(abi: &Callee<X64ABIMachineSpec>, ctrl_plane: ControlPlane) -> Self {
23        EmitState {
24            user_stack_map: None,
25            ctrl_plane,
26            frame_layout: abi.frame_layout().clone(),
27        }
28    }
29
30    fn pre_safepoint(&mut self, user_stack_map: Option<ir::UserStackMap>) {
31        self.user_stack_map = user_stack_map;
32    }
33
34    fn ctrl_plane_mut(&mut self) -> &mut ControlPlane {
35        &mut self.ctrl_plane
36    }
37
38    fn take_ctrl_plane(self) -> ControlPlane {
39        self.ctrl_plane
40    }
41
42    fn frame_layout(&self) -> &FrameLayout {
43        &self.frame_layout
44    }
45}
46
47impl EmitState {
48    pub(crate) fn take_stack_map(&mut self) -> Option<ir::UserStackMap> {
49        self.user_stack_map.take()
50    }
51
52    pub(crate) fn clear_post_insn(&mut self) {
53        self.user_stack_map = None;
54    }
55}