Skip to main content

RegSet

Struct RegSet 

Source
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

Source

pub const EMPTY: RegSet

The empty set.

Source

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));
Source

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));
Source

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());
Source

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));
Source

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);
Source

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]));
Source

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]));
Source

pub const fn is_empty(self) -> bool

Whether the set is empty.

§Examples
use backend_lang::RegSet;

assert!(RegSet::EMPTY.is_empty());
Source

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);
Source

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);
Source

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§

Source§

impl Clone for RegSet

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for RegSet

Source§

impl Debug for RegSet

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RegSet

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for RegSet

Source§

impl FromIterator<PReg> for RegSet

Source§

fn from_iter<I: IntoIterator<Item = PReg>>(iter: I) -> RegSet

Creates a value from an iterator. Read more
Source§

impl Hash for RegSet

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for RegSet

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RegSet

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.