cranelift_codegen/
value_label.rs

1use crate::ir::{SourceLoc, ValueLabel};
2use crate::machinst::Reg;
3use crate::HashMap;
4use alloc::vec::Vec;
5use core::cmp::Ordering;
6use core::convert::From;
7use core::ops::Deref;
8
9#[cfg(feature = "enable-serde")]
10use serde::{Deserialize, Serialize};
11
12/// Value location range.
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
15pub struct ValueLocRange {
16    /// The ValueLoc containing a ValueLabel during this range.
17    pub loc: LabelValueLoc,
18    /// The start of the range. It is an offset in the generated code.
19    pub start: u32,
20    /// The end of the range. It is an offset in the generated code.
21    pub end: u32,
22}
23
24/// The particular location for a value.
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
27pub enum LabelValueLoc {
28    /// New-backend Reg.
29    Reg(Reg),
30    /// New-backend offset from stack pointer.
31    SPOffset(i64),
32}
33
34/// Resulting map of Value labels and their ranges/locations.
35pub type ValueLabelsRanges = HashMap<ValueLabel, Vec<ValueLocRange>>;
36
37#[derive(Eq, Clone, Copy)]
38pub struct ComparableSourceLoc(SourceLoc);
39
40impl From<SourceLoc> for ComparableSourceLoc {
41    fn from(s: SourceLoc) -> Self {
42        Self(s)
43    }
44}
45
46impl Deref for ComparableSourceLoc {
47    type Target = SourceLoc;
48    fn deref(&self) -> &SourceLoc {
49        &self.0
50    }
51}
52
53impl PartialOrd for ComparableSourceLoc {
54    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
55        Some(self.cmp(other))
56    }
57}
58
59impl Ord for ComparableSourceLoc {
60    fn cmp(&self, other: &Self) -> Ordering {
61        self.0.bits().cmp(&other.0.bits())
62    }
63}
64
65impl PartialEq for ComparableSourceLoc {
66    fn eq(&self, other: &Self) -> bool {
67        self.0 == other.0
68    }
69}