cranelift_codegen/machinst/
inst_common.rs

1//! A place to park MachInst::Inst fragments which are common across multiple architectures.
2
3use crate::ir::{self, Inst as IRInst};
4
5//============================================================================
6// Instruction input "slots".
7//
8// We use these types to refer to operand numbers, and result numbers, together
9// with the associated instruction, in a type-safe way.
10
11/// Identifier for a particular input of an instruction.
12#[derive(Clone, Copy, Debug, PartialEq, Eq)]
13pub(crate) struct InsnInput {
14    pub(crate) insn: IRInst,
15    pub(crate) input: usize,
16}
17
18/// Identifier for a particular output of an instruction.
19#[derive(Clone, Copy, Debug, PartialEq, Eq)]
20pub(crate) struct InsnOutput {
21    pub(crate) insn: IRInst,
22    pub(crate) output: usize,
23}
24
25//============================================================================
26// Atomic instructions.
27
28/// Atomic memory update operations.
29#[derive(Clone, Copy, Debug, PartialEq, Eq)]
30#[repr(u8)]
31pub enum MachAtomicRmwOp {
32    /// Add
33    Add,
34    /// Sub
35    Sub,
36    /// And
37    And,
38    /// Nand
39    Nand,
40    /// Or
41    Or,
42    /// Exclusive Or
43    Xor,
44    /// Exchange (swap operands)
45    Xchg,
46    /// Unsigned min
47    Umin,
48    /// Unsigned max
49    Umax,
50    /// Signed min
51    Smin,
52    /// Signed max
53    Smax,
54}
55
56impl MachAtomicRmwOp {
57    /// Converts an `ir::AtomicRmwOp` to the corresponding
58    /// `inst_common::AtomicRmwOp`.
59    pub fn from(ir_op: ir::AtomicRmwOp) -> Self {
60        match ir_op {
61            ir::AtomicRmwOp::Add => MachAtomicRmwOp::Add,
62            ir::AtomicRmwOp::Sub => MachAtomicRmwOp::Sub,
63            ir::AtomicRmwOp::And => MachAtomicRmwOp::And,
64            ir::AtomicRmwOp::Nand => MachAtomicRmwOp::Nand,
65            ir::AtomicRmwOp::Or => MachAtomicRmwOp::Or,
66            ir::AtomicRmwOp::Xor => MachAtomicRmwOp::Xor,
67            ir::AtomicRmwOp::Xchg => MachAtomicRmwOp::Xchg,
68            ir::AtomicRmwOp::Umin => MachAtomicRmwOp::Umin,
69            ir::AtomicRmwOp::Umax => MachAtomicRmwOp::Umax,
70            ir::AtomicRmwOp::Smin => MachAtomicRmwOp::Smin,
71            ir::AtomicRmwOp::Smax => MachAtomicRmwOp::Smax,
72        }
73    }
74}