Struct regalloc2::Operand

source ·
pub struct Operand { /* private fields */ }
Expand description

An Operand encodes everything about a mention of a register in an instruction: virtual register number, and any constraint that applies to the register at this program point.

An Operand may be a use or def (this corresponds to LUse and LAllocation in Ion).

Generally, regalloc2 considers operands to have their effects at one of two points that exist in an instruction: “Early” or “Late”. All operands at a given program-point are assigned non-conflicting locations based on their constraints. Each operand has a “kind”, one of use/def/mod, corresponding to read/write/read-write, respectively.

Usually, an instruction’s inputs will be “early uses” and outputs will be “late defs”, though there are valid use-cases for other combinations too. For example, a single “instruction” seen by the regalloc that lowers into multiple machine instructions and reads some of its inputs after it starts to write outputs must either make those input(s) “late uses” or those output(s) “early defs” so that the conflict (overlap) is properly accounted for. See comments on the constructors below for more.

Implementations§

source§

impl Operand

source

pub fn new( vreg: VReg, constraint: OperandConstraint, kind: OperandKind, pos: OperandPos ) -> Self

Construct a new operand.

source

pub fn reg_use(vreg: VReg) -> Self

Create an Operand that designates a use of a VReg that must be in a register, and that is used at the “before” point, i.e., can be overwritten by a result.

source

pub fn reg_use_at_end(vreg: VReg) -> Self

Create an Operand that designates a use of a VReg that must be in a register, and that is used up until the “after” point, i.e., must not conflict with any results.

source

pub fn reg_def(vreg: VReg) -> Self

Create an Operand that designates a definition of a VReg that must be in a register, and that occurs at the “after” point, i.e. may reuse a register that carried a use into this instruction.

source

pub fn reg_def_at_start(vreg: VReg) -> Self

Create an Operand that designates a definition of a VReg that must be in a register, and that occurs early at the “before” point, i.e., must not conflict with any input to the instruction.

Note that the register allocator will ensure that such an early-def operand is live throughout the instruction, i.e., also at the after-point. Hence it will also avoid conflicts with all outputs to the instruction. As such, early defs are appropriate for use as “temporary registers” that an instruction can use throughout its execution separately from the inputs and outputs.

source

pub fn reg_temp(vreg: VReg) -> Self

Create an Operand that designates a def (and use) of a temporary within the instruction. This register is assumed to be written by the instruction, and will not conflict with any input or output, but should not be used after the instruction completes.

Note that within a single instruction, the dedicated scratch register (as specified in the MachineEnv) is also always available for use. The register allocator may use the register between instructions in order to implement certain sequences of moves, but will never hold a value live in the scratch register across an instruction.

source

pub fn reg_reuse_def(vreg: VReg, idx: usize) -> Self

Create an Operand that designates a def of a vreg that must reuse the register assigned to an input to the instruction. The input is identified by idx (is the idxth Operand for the instruction) and must be constraint to a register, i.e., be the result of Operand::reg_use(vreg).

source

pub fn reg_fixed_use(vreg: VReg, preg: PReg) -> Self

Create an Operand that designates a use of a vreg and ensures that it is placed in the given, fixed PReg at the use. It is guaranteed that the Allocation resulting for this operand will be preg.

source

pub fn reg_fixed_def(vreg: VReg, preg: PReg) -> Self

Create an Operand that designates a def of a vreg and ensures that it is placed in the given, fixed PReg at the def. It is guaranteed that the Allocation resulting for this operand will be preg.

source

pub fn any_use(vreg: VReg) -> Self

Create an Operand that designates a use of a vreg and places no constraints on its location (i.e., it can be allocated into either a register or on the stack).

source

pub fn any_def(vreg: VReg) -> Self

Create an Operand that designates a def of a vreg and places no constraints on its location (i.e., it can be allocated into either a register or on the stack).

source

pub fn fixed_nonallocatable(preg: PReg) -> Self

Create an Operand that always results in an assignment to the given fixed preg, without tracking liveranges in that preg. Must only be used for non-allocatable registers.

source

pub fn vreg(self) -> VReg

Get the virtual register designated by an operand. Every operand must name some virtual register, even if it constrains the operand to a fixed physical register as well; the vregs are used to track dataflow.

source

pub fn class(self) -> RegClass

Get the register class used by this operand.

source

pub fn kind(self) -> OperandKind

Get the “kind” of this operand: a definition (write) or a use (read).

source

pub fn pos(self) -> OperandPos

Get the “position” of this operand, i.e., where its read and/or write occurs: either before the instruction executes, or after it does. Ordinarily, uses occur at “before” and defs at “after”, though there are cases where this is not true.

source

pub fn constraint(self) -> OperandConstraint

Get the “constraint” of this operand, i.e., what requirements its allocation must fulfill.

source

pub fn as_fixed_nonallocatable(self) -> Option<PReg>

If this operand is for a fixed non-allocatable register (see [Operand::fixed]), then returns the physical register that it will be assigned to.

source

pub fn bits(self) -> u32

Get the raw 32-bit encoding of this operand’s fields.

source

pub fn from_bits(bits: u32) -> Self

Construct an Operand from the raw 32-bit encoding returned from bits().

Trait Implementations§

source§

impl Clone for Operand

source§

fn clone(&self) -> Operand

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for Operand

source§

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

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

impl Display for Operand

source§

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

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

impl Hash for Operand

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 Ord for Operand

source§

fn cmp(&self, other: &Operand) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Operand

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Operand

source§

fn partial_cmp(&self, other: &Operand) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Operand

source§

impl Eq for Operand

source§

impl StructuralEq for Operand

source§

impl StructuralPartialEq for Operand

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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 Twhere 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 Twhere T: Clone,

§

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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.