pub struct RegSet(/* private fields */);Expand description
A set of physical registers: 128 bits, one per PReg index.
Used for class membership, allocatable sets, callee- and caller-saved sets, and per-instruction clobbers. Every operation is a few word operations; iteration yields registers in index order.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::{RAX, RCX, RDX};
let set = RegSet::EMPTY.with(RAX).with(RDX);
assert!(set.contains(RDX));
assert!(!set.contains(RCX));
assert_eq!(set.iter().collect::<Vec<_>>(), [RAX, RDX]);
assert_eq!(set.len(), 2);Implementations§
Source§impl RegSet
impl RegSet
Sourcepub const fn of(regs: &[PReg]) -> RegSet
pub const fn of(regs: &[PReg]) -> RegSet
The set holding exactly the registers in regs.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::{R11, RCX};
let set = RegSet::of(&[RCX, R11]);
assert!(set.contains(R11));Sourcepub const fn with(self, reg: PReg) -> RegSet
pub const fn with(self, reg: PReg) -> RegSet
The set with reg added.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::RBX;
assert!(RegSet::EMPTY.with(RBX).contains(RBX));Sourcepub const fn without(self, reg: PReg) -> RegSet
pub const fn without(self, reg: PReg) -> RegSet
The set with reg removed.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::RBX;
assert!(RegSet::of(&[RBX]).without(RBX).is_empty());Sourcepub const fn contains(self, reg: PReg) -> bool
pub const fn contains(self, reg: PReg) -> bool
Whether reg is in the set.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::{RAX, RBX};
assert!(RegSet::of(&[RAX]).contains(RAX));
assert!(!RegSet::of(&[RAX]).contains(RBX));Sourcepub const fn union(self, other: RegSet) -> RegSet
pub const fn union(self, other: RegSet) -> RegSet
The registers in either set.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::{RAX, RBX};
assert_eq!(RegSet::of(&[RAX]).union(RegSet::of(&[RBX])).len(), 2);Sourcepub const fn intersect(self, other: RegSet) -> RegSet
pub const fn intersect(self, other: RegSet) -> RegSet
The registers in both sets.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::{RAX, RBX};
let a = RegSet::of(&[RAX, RBX]);
assert_eq!(a.intersect(RegSet::of(&[RBX])), RegSet::of(&[RBX]));Sourcepub const fn difference(self, other: RegSet) -> RegSet
pub const fn difference(self, other: RegSet) -> RegSet
The registers in self but not in other.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::{RAX, RBX};
let a = RegSet::of(&[RAX, RBX]);
assert_eq!(a.difference(RegSet::of(&[RAX])), RegSet::of(&[RBX]));Sourcepub const fn len(self) -> usize
pub const fn len(self) -> usize
The number of registers in the set.
§Examples
use backend_lang::x86_64::{self, GPR};
assert_eq!(x86_64::TARGET.class(GPR).regs().len(), 16);Sourcepub const fn first(self) -> Option<PReg>
pub const fn first(self) -> Option<PReg>
The lowest-numbered register in the set.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::{RCX, R9};
assert_eq!(RegSet::of(&[R9, RCX]).first(), Some(RCX));
assert_eq!(RegSet::EMPTY.first(), None);Sourcepub fn iter(self) -> RegSetIter ⓘ
pub fn iter(self) -> RegSetIter ⓘ
The registers in the set, in index order.
§Examples
use backend_lang::RegSet;
use backend_lang::x86_64::{RAX, R15};
let v: Vec<_> = RegSet::of(&[R15, RAX]).iter().collect();
assert_eq!(v, [RAX, R15]);Trait Implementations§
impl Copy for RegSet
impl Eq for RegSet
Source§impl FromIterator<PReg> for RegSet
impl FromIterator<PReg> for RegSet
impl StructuralPartialEq for RegSet
Auto Trait Implementations§
impl Freeze for RegSet
impl RefUnwindSafe for RegSet
impl Send for RegSet
impl Sync for RegSet
impl Unpin for RegSet
impl UnsafeUnpin for RegSet
impl UnwindSafe for RegSet
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more