Skip to main content

MoveResolver

Struct MoveResolver 

Source
pub struct MoveResolver { /* private fields */ }
Expand description

Resolves parallel copies. Keeps its buffers between calls.

§Examples

A rotation of three registers and a register into a slot, with a free register to break the cycle when swaps are off:

use backend_lang::RegSet;
use backend_lang::mir::StackSlot;
use backend_lang::moves::{Loc, Move, MoveEnv, MoveResolver, Source, Step};
use backend_lang::x86_64::{self, GPR, RAX, RBX, RCX, R11};

let moves = [
    Move::new(RAX, RBX, GPR),
    Move::new(RBX, RCX, GPR),
    Move::new(RCX, RAX, GPR),
    Move::new(StackSlot::new(0), RAX, GPR),
];
let env = MoveEnv::new().with_free(RegSet::of(&[R11])).with_swap(false);
let mut steps = Vec::new();
MoveResolver::new().resolve(&x86_64::TARGET, &moves, &env, &mut steps)?;
// The slot copy of rax doubles as the cycle's saved value: four moves.
assert_eq!(steps.len(), 4);
assert_eq!(steps[0], Step::Move { dst: Loc::Slot(StackSlot::new(0)), src: Source::from(RAX), class: GPR });

Implementations§

Source§

impl MoveResolver

Source

pub fn new() -> MoveResolver

A resolver with empty buffers.

§Examples
use backend_lang::moves::MoveResolver;

let _r = MoveResolver::new();
Source

pub fn resolve( &mut self, target: &Target, moves: &[Move], env: &MoveEnv, out: &mut Vec<Step>, ) -> Result<Resolved, MoveError>

Resolves the parallel copy moves on target, appending the steps to out.

Moves whose source is their destination are dropped. Executing the appended steps in order leaves every destination holding its source’s value from before the copy, and every other location unchanged except env.free registers (which are dead) and the scratch and victim slots.

§Errors

MoveError::DuplicateDestination, MoveError::ClassMismatch, MoveError::NoScratch or MoveError::NoTemp when a scratch or temporary is needed and env provides none, MoveError::TooMany. On error, out may hold a partial sequence; discard it.

§Examples
use backend_lang::mir::StackSlot;
use backend_lang::moves::{Loc, Move, MoveEnv, MoveResolver, Source, Step};
use backend_lang::x86_64::{self, GPR, RAX, R11};
use backend_lang::RegSet;

// Slot to slot on x86-64 goes through a register.
let copy = [Move::new(StackSlot::new(1), StackSlot::new(0), GPR)];
let env = MoveEnv::new().with_free(RegSet::of(&[R11]));
let mut out = Vec::new();
MoveResolver::new().resolve(&x86_64::TARGET, &copy, &env, &mut out)?;
assert_eq!(out, [
    Step::Move { dst: Loc::Reg(R11), src: Source::from(StackSlot::new(0)), class: GPR },
    Step::Move { dst: Loc::Slot(StackSlot::new(1)), src: Source::from(R11), class: GPR },
]);

Trait Implementations§

Source§

impl Clone for MoveResolver

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 Debug for MoveResolver

Source§

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

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

impl Default for MoveResolver

Source§

fn default() -> Self

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

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.