Skip to main content

InstData

Enum InstData 

Source
#[non_exhaustive]
pub enum InstData {
Show 25 variants Const { ty: Type, bits: u64, }, Unary { op: UnaryOp, policy: Policy, arg: Value, }, Binary { op: BinaryOp, policy: Policy, args: [Value; 2], }, Fma { args: [Value; 3], }, Compare { op: CmpOp, args: [Value; 2], }, Convert { op: ConvOp, policy: Policy, to: Type, arg: Value, }, Select { cond: Value, args: [Value; 2], }, StackAddr { slot: StackSlot, }, GlobalAddr { global: GlobalId, }, FuncAddr { func: FuncId, }, FieldAddr { base: Value, agg: AggId, field: u32, }, ElemAddr { base: Value, elem: MemType, index: Value, }, PtrOffset { base: Value, offset: Value, }, Load { ty: Type, addr: Value, flags: MemFlags, }, Store { value: Value, addr: Value, flags: MemFlags, }, AtomicLoad { ty: Type, addr: Value, order: MemOrder, }, AtomicStore { value: Value, addr: Value, order: MemOrder, }, AtomicRmw { op: RmwOp, addr: Value, value: Value, order: MemOrder, }, CmpXchg { addr: Value, expected: Value, new: Value, success: MemOrder, failure: MemOrder, }, Fence { order: MemOrder, }, MemCopy { dst: Value, src: Value, len: Value, flags: MemFlags, }, MemMove { dst: Value, src: Value, len: Value, flags: MemFlags, }, MemSet { dst: Value, byte: Value, len: Value, flags: MemFlags, }, Call(Box<Call>), Safepoint { gc: Box<[Value]>, },
}
Expand description

The data of one non-terminator instruction.

Result types are not stored here: each result value carries its type, and the validator checks it against the type the instruction produces. Instructions with a policy whose fields include error are only valid inside a Terminator::Check; as plain instructions they are rejected.

§Examples

use ir_lang::{BinaryOp, InstData, Overflow, Policy, Value};

let add = InstData::Binary {
    op: BinaryOp::Add,
    policy: Policy::overflow(Overflow::Wrap),
    args: [Value::from_u32(0), Value::from_u32(1)],
};
let mut used = Vec::new();
add.for_each_operand(|v| used.push(v));
assert_eq!(used.len(), 2);
assert!(!add.has_side_effects());

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Const

A constant of a scalar type. bits holds the value’s bit pattern masked to the type’s width (integers as two’s complement, floats as IEEE bits, bool as 0/1, ptr/ref only 0, the null address/reference).

Fields

§ty: Type

The constant’s type.

§bits: u64

The bit pattern.

§

Unary

A unary operation.

Fields

§op: UnaryOp

The operation.

§policy: Policy

Its policy.

§arg: Value

The operand.

§

Binary

A binary operation.

Fields

§op: BinaryOp

The operation.

§policy: Policy

Its policy.

§args: [Value; 2]

The operands.

§

Fma

Fused multiply-add a * b + c on floats, correctly rounded once.

Fields

§args: [Value; 3]

a, b, c.

§

Compare

A comparison giving bool.

Fields

§op: CmpOp

The comparison.

§args: [Value; 2]

The operands.

§

Convert

A conversion to to.

Fields

§op: ConvOp

The conversion.

§policy: Policy

Its policy.

§to: Type

The result type.

§arg: Value

The operand.

§

Select

cond ? args[0] : args[1].

Fields

§cond: Value

The bool condition.

§args: [Value; 2]

The values chosen when true and when false.

§

StackAddr

The address of a stack slot of this function.

Fields

§slot: StackSlot

The slot.

§

GlobalAddr

The address of a global.

Fields

§global: GlobalId

The global.

§

FuncAddr

The address of a function (for indirect calls).

Fields

§func: FuncId

The function.

§

FieldAddr

base plus the offset of field field of struct agg.

Fields

§base: Value

The struct’s address.

§agg: AggId

The struct type.

§field: u32

The field index.

§

ElemAddr

base + index * size(elem), wrapping at the address width. A signed index is sign-extended, an unsigned one zero-extended.

Fields

§base: Value

The first element’s address.

§elem: MemType

The element type (its size is the stride).

§index: Value

The element index (any integer type).

§

PtrOffset

base + offset bytes, wrapping at the address width.

Fields

§base: Value

The address.

§offset: Value

The byte offset (any integer type; signed is sign-extended).

§

Load

Read a ty from addr.

Fields

§ty: Type

The loaded type.

§addr: Value

The address.

§flags: MemFlags

Alignment and volatility.

§

Store

Write value to addr.

Fields

§value: Value

The stored value.

§addr: Value

The address.

§flags: MemFlags

Alignment and volatility.

§

AtomicLoad

Atomically read a ty (an integer or ptr) from naturally aligned addr.

Fields

§ty: Type

The loaded type.

§addr: Value

The address.

§order: MemOrder

The ordering.

§

AtomicStore

Atomically write value (an integer or ptr) to naturally aligned addr.

Fields

§value: Value

The stored value.

§addr: Value

The address.

§order: MemOrder

The ordering.

§

AtomicRmw

Atomically replace the integer at addr with op(old, value); gives old.

Fields

§op: RmwOp

The operation.

§addr: Value

The address.

§value: Value

The operand.

§order: MemOrder

The ordering.

§

CmpXchg

Atomic compare-exchange; gives the old value and whether it was replaced.

Fields

§addr: Value

The address.

§expected: Value

The expected old value.

§new: Value

The replacement.

§success: MemOrder

The ordering on success.

§failure: MemOrder

The ordering on failure.

§

Fence

A memory fence.

Fields

§order: MemOrder

The ordering (not relaxed).

§

MemCopy

Copy len bytes from src to dst; the ranges must not overlap.

Fields

§dst: Value

Destination address.

§src: Value

Source address.

§len: Value

Byte count (an unsigned integer).

§flags: MemFlags

Alignment of both addresses, and volatility.

§

MemMove

Copy len bytes from src to dst; the ranges may overlap.

Fields

§dst: Value

Destination address.

§src: Value

Source address.

§len: Value

Byte count (an unsigned integer).

§flags: MemFlags

Alignment of both addresses, and volatility.

§

MemSet

Set len bytes at dst to byte (a u8).

Fields

§dst: Value

Destination address.

§byte: Value

The fill byte.

§len: Value

Byte count (an unsigned integer).

§flags: MemFlags

Alignment and volatility.

§

Call(Box<Call>)

A call. Results: the callee’s returns, then one relocated ref per gc entry.

§

Safepoint

An explicit safepoint (a GC poll). Results: one relocated ref per gc entry.

Fields

§gc: Box<[Value]>

The ref values relocated.

Implementations§

Source§

impl InstData

Source

pub fn for_each_operand(&self, f: impl FnMut(Value))

Calls f on every value the instruction reads, in operand order.

§Examples
use ir_lang::{InstData, Value};

let mut n = 0;
InstData::Fma { args: [Value::from_u32(0); 3] }.for_each_operand(|_| n += 1);
assert_eq!(n, 3);
Source

pub fn map_operands(&mut self, f: impl FnMut(Value) -> Value)

Rewrites every value the instruction reads.

§Examples
use ir_lang::{InstData, UnaryOp, Policy, Value};

let mut i = InstData::Unary { op: UnaryOp::Not, policy: Policy::NONE, arg: Value::from_u32(1) };
i.map_operands(|v| Value::from_u32(v.as_u32() + 10));
assert_eq!(i, InstData::Unary { op: UnaryOp::Not, policy: Policy::NONE, arg: Value::from_u32(11) });
Source

pub fn has_side_effects(&self) -> bool

Whether the instruction may do anything besides computing its results: write memory, read volatile memory, synchronize, call, poll the GC, or trap under a trap policy. An instruction without side effects whose results are unused can be removed.

§Examples
use ir_lang::{BinaryOp, InstData, Overflow, Policy, Value};

let v = Value::from_u32(0);
let trapping = InstData::Binary { op: BinaryOp::Add, policy: Policy::overflow(Overflow::Trap), args: [v, v] };
assert!(trapping.has_side_effects());
Source

pub fn opcode(&self) -> &'static str

The textual opcode of the instruction (add, load, call, …).

§Examples
use ir_lang::{InstData, Type};

assert_eq!(InstData::Const { ty: Type::I8, bits: 0 }.opcode(), "const");

Trait Implementations§

Source§

impl Clone for InstData

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 InstData

Source§

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

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

impl Eq for InstData

Source§

impl Hash for InstData

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 InstData

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 InstData

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.