#[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
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).
Unary
A unary operation.
Binary
A binary operation.
Fma
Fused multiply-add a * b + c on floats, correctly rounded once.
Compare
A comparison giving bool.
Convert
A conversion to to.
Fields
Select
cond ? args[0] : args[1].
StackAddr
The address of a stack slot of this function.
GlobalAddr
The address of a global.
FuncAddr
The address of a function (for indirect calls).
FieldAddr
base plus the offset of field field of struct agg.
ElemAddr
base + index * size(elem), wrapping at the address width. A signed index
is sign-extended, an unsigned one zero-extended.
Fields
PtrOffset
base + offset bytes, wrapping at the address width.
Fields
Load
Read a ty from addr.
Store
Write value to addr.
Fields
AtomicLoad
Atomically read a ty (an integer or ptr) from naturally aligned addr.
AtomicStore
Atomically write value (an integer or ptr) to naturally aligned addr.
AtomicRmw
Atomically replace the integer at addr with op(old, value); gives old.
Fields
CmpXchg
Atomic compare-exchange; gives the old value and whether it was replaced.
Fields
Fence
A memory fence.
MemCopy
Copy len bytes from src to dst; the ranges must not overlap.
Fields
MemMove
Copy len bytes from src to dst; the ranges may overlap.
Fields
MemSet
Set len bytes at dst to byte (a u8).
Fields
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.
Implementations§
Source§impl InstData
impl InstData
Sourcepub fn for_each_operand(&self, f: impl FnMut(Value))
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);Sourcepub fn map_operands(&mut self, f: impl FnMut(Value) -> Value)
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) });Sourcepub fn has_side_effects(&self) -> bool
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());