summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Bernstein <tekknolagi@gmail.com>2026-05-08 16:00:32 -0400
committerGitHub <noreply@github.com>2026-05-08 16:00:32 -0400
commit3a5bfb8a144cbc1d8021fd3709e007fc6f5b1261 (patch)
tree2fe197696b3c0b46df0fdce8262f1fda96e1f2d3
parent97aa28abab6dc65e2aa0373796546d4ebf2df717 (diff)
ZJIT: Use Insn::for_each_operand_mut in Function::find (#16902)
ZJIT: Use for_each_operand_mut in Function::find No need to repeat this matching logic manually.
-rw-r--r--zjit/src/hir.rs241
1 files changed, 5 insertions, 236 deletions
diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs
index 4d006af1ab..27bf5df427 100644
--- a/zjit/src/hir.rs
+++ b/zjit/src/hir.rs
@@ -2783,243 +2783,12 @@ impl Function {
}
};
}
- macro_rules! find_vec {
- ( $x:expr ) => {
- {
- $x.iter().map(|arg| find!(*arg)).collect()
- }
- };
- }
- macro_rules! find_branch_edge {
- ( $edge:ident ) => {
- {
- BranchEdge {
- target: $edge.target,
- args: find_vec!($edge.args),
- }
- }
- };
- }
let insn_id = find!(insn_id);
- use Insn::*;
- match &self.insns[insn_id.0] {
- result@(Const {..}
- | Param
- | LoadArg {..}
- | Entries {..}
- | GetConstantPath {..}
- | PatchPoint {..}
- | PutSpecialObject {..}
- | GetGlobal {..}
- | SideExit {..}
- | EntryPoint {..}
- | LoadPC
- | LoadSP
- | LoadEC
- | GetEP {..}
- | LoadSelf
- | BreakPoint
- | IncrCounterPtr {..}
- | IncrCounter(_)) => result.clone(),
- &Snapshot { state: FrameState { iseq, insn_idx, pc, ref stack, ref locals } } =>
- Snapshot {
- state: FrameState {
- iseq,
- insn_idx,
- pc,
- stack: find_vec!(stack),
- locals: find_vec!(locals),
- }
- },
- &Return { val } => Return { val: find!(val) },
- &FixnumBitCheck { val, index } => FixnumBitCheck { val: find!(val), index },
- &Throw { throw_state, val, state } => Throw { throw_state, val: find!(val), state },
- &StringCopy { val, chilled, state } => StringCopy { val: find!(val), chilled, state },
- &StringIntern { val, state } => StringIntern { val: find!(val), state: find!(state) },
- &StringConcat { ref strings, state } => StringConcat { strings: find_vec!(strings), state: find!(state) },
- &StringGetbyte { string, index } => StringGetbyte { string: find!(string), index: find!(index) },
- &StringSetbyteFixnum { string, index, value } => StringSetbyteFixnum { string: find!(string), index: find!(index), value: find!(value) },
- &StringAppend { recv, other, state } => StringAppend { recv: find!(recv), other: find!(other), state: find!(state) },
- &StringAppendCodepoint { recv, other, state } => StringAppendCodepoint { recv: find!(recv), other: find!(other), state: find!(state) },
- &StringEqual { left, right } => StringEqual { left: find!(left), right: find!(right) },
- &ToRegexp { opt, ref values, state } => ToRegexp { opt, values: find_vec!(values), state },
- &Test { val } => Test { val: find!(val) },
- &IsNil { val } => IsNil { val: find!(val) },
- &IsMethodCfunc { val, cd, cfunc, state } => IsMethodCfunc { val: find!(val), cd, cfunc, state },
- &IsBitEqual { left, right } => IsBitEqual { left: find!(left), right: find!(right) },
- &IsBitNotEqual { left, right } => IsBitNotEqual { left: find!(left), right: find!(right) },
- &BoxBool { val } => BoxBool { val: find!(val) },
- &BoxFixnum { val, state } => BoxFixnum { val: find!(val), state: find!(state) },
- &UnboxFixnum { val } => UnboxFixnum { val: find!(val) },
- &FixnumAref { recv, index } => FixnumAref { recv: find!(recv), index: find!(index) },
- Jump(target) => Jump(find_branch_edge!(target)),
- &IfTrue { val, ref target } => IfTrue { val: find!(val), target: find_branch_edge!(target) },
- &IfFalse { val, ref target } => IfFalse { val: find!(val), target: find_branch_edge!(target) },
- &RefineType { val, new_type } => RefineType { val: find!(val), new_type },
- &HasType { val, expected } => HasType { val: find!(val), expected },
- &GuardType { val, guard_type, state } => GuardType { val: find!(val), guard_type, state },
- &GuardTypeNot { val, guard_type, state } => GuardTypeNot { val: find!(val), guard_type, state },
- &GuardBitEquals { val, expected, reason, state, recompile } => GuardBitEquals { val: find!(val), expected, reason, state, recompile },
- &GuardAnyBitSet { val, mask, mask_name, reason, state } => GuardAnyBitSet { val: find!(val), mask, mask_name, reason, state },
- &GuardNoBitsSet { val, mask, mask_name, reason, state } => GuardNoBitsSet { val: find!(val), mask, mask_name, reason, state },
- &GuardGreaterEq { left, right, reason, state } => GuardGreaterEq { left: find!(left), right: find!(right), reason, state },
- &GuardLess { left, right, state } => GuardLess { left: find!(left), right: find!(right), state },
- &IsBlockGiven { lep } => IsBlockGiven { lep: find!(lep) },
- &IsBlockParamModified { flags } => IsBlockParamModified { flags: find!(flags) },
- &GetBlockParam { level, ep_offset, state } => GetBlockParam { level, ep_offset, state: find!(state) },
- &FixnumAdd { left, right, state } => FixnumAdd { left: find!(left), right: find!(right), state },
- &FixnumSub { left, right, state } => FixnumSub { left: find!(left), right: find!(right), state },
- &FixnumMult { left, right, state } => FixnumMult { left: find!(left), right: find!(right), state },
- &FixnumDiv { left, right, state } => FixnumDiv { left: find!(left), right: find!(right), state },
- &FixnumMod { left, right, state } => FixnumMod { left: find!(left), right: find!(right), state },
- &FloatAdd { recv, other, state } => FloatAdd { recv: find!(recv), other: find!(other), state },
- &FloatSub { recv, other, state } => FloatSub { recv: find!(recv), other: find!(other), state },
- &FloatMul { recv, other, state } => FloatMul { recv: find!(recv), other: find!(other), state },
- &FloatDiv { recv, other, state } => FloatDiv { recv: find!(recv), other: find!(other), state },
- &FloatToInt { recv, state } => FloatToInt { recv: find!(recv), state },
- &FixnumNeq { left, right } => FixnumNeq { left: find!(left), right: find!(right) },
- &FixnumEq { left, right } => FixnumEq { left: find!(left), right: find!(right) },
- &FixnumGt { left, right } => FixnumGt { left: find!(left), right: find!(right) },
- &FixnumGe { left, right } => FixnumGe { left: find!(left), right: find!(right) },
- &FixnumLt { left, right } => FixnumLt { left: find!(left), right: find!(right) },
- &FixnumLe { left, right } => FixnumLe { left: find!(left), right: find!(right) },
- &FixnumAnd { left, right } => FixnumAnd { left: find!(left), right: find!(right) },
- &FixnumOr { left, right } => FixnumOr { left: find!(left), right: find!(right) },
- &FixnumXor { left, right } => FixnumXor { left: find!(left), right: find!(right) },
- &IntAnd { left, right } => IntAnd { left: find!(left), right: find!(right) },
- &IntOr { left, right } => IntOr { left: find!(left), right: find!(right) },
- &FixnumLShift { left, right, state } => FixnumLShift { left: find!(left), right: find!(right), state },
- &FixnumRShift { left, right } => FixnumRShift { left: find!(left), right: find!(right) },
- &ObjToString { val, cd, state } => ObjToString {
- val: find!(val),
- cd,
- state,
- },
- &AnyToString { val, str, state } => AnyToString {
- val: find!(val),
- str: find!(str),
- state,
- },
- &SendDirect { recv, cd, cme, iseq, ref args, kw_bits, block, state } => SendDirect {
- recv: find!(recv),
- cd,
- cme,
- iseq,
- args: find_vec!(args),
- kw_bits,
- block,
- state,
- },
- &Send { recv, cd, block, ref args, state, reason } => Send {
- recv: find!(recv),
- cd,
- block,
- args: find_vec!(args),
- state,
- reason,
- },
- &SendForward { recv, cd, blockiseq, ref args, state, reason } => SendForward {
- recv: find!(recv),
- cd,
- blockiseq,
- args: find_vec!(args),
- state,
- reason,
- },
- &InvokeSuper { recv, cd, blockiseq, ref args, state, reason } => InvokeSuper {
- recv: find!(recv),
- cd,
- blockiseq,
- args: find_vec!(args),
- state,
- reason,
- },
- &InvokeSuperForward { recv, cd, blockiseq, ref args, state, reason } => InvokeSuperForward {
- recv: find!(recv),
- cd,
- blockiseq,
- args: find_vec!(args),
- state,
- reason,
- },
- &InvokeBlock { cd, ref args, state, reason } => InvokeBlock {
- cd,
- args: find_vec!(args),
- state,
- reason,
- },
- &InvokeBlockIfunc { cd, block_handler, ref args, state } => InvokeBlockIfunc {
- cd,
- block_handler: find!(block_handler),
- args: find_vec!(args),
- state: find!(state),
- },
- &InvokeProc { recv, ref args, state, kw_splat } => InvokeProc {
- recv: find!(recv),
- args: find_vec!(args),
- state: find!(state),
- kw_splat,
- },
- &InvokeBuiltin { bf, recv, ref args, state, leaf, return_type } => InvokeBuiltin { bf, recv: find!(recv), args: find_vec!(args), state, leaf, return_type },
- &ArrayDup { val, state } => ArrayDup { val: find!(val), state },
- &HashDup { val, state } => HashDup { val: find!(val), state },
- &HashAref { hash, key, state } => HashAref { hash: find!(hash), key: find!(key), state },
- &HashAset { hash, key, val, state } => HashAset { hash: find!(hash), key: find!(key), val: find!(val), state },
- &ObjectAlloc { val, state } => ObjectAlloc { val: find!(val), state },
- &ObjectAllocClass { class, state } => ObjectAllocClass { class, state: find!(state) },
- &CCall { cfunc, recv, ref args, name, owner, return_type, elidable } => CCall { cfunc, recv: find!(recv), args: find_vec!(args), name, owner, return_type, elidable },
- &CCallWithFrame { cd, cfunc, recv, ref args, cme, name, state, return_type, elidable, block } => CCallWithFrame {
- cd,
- cfunc,
- recv: find!(recv),
- args: find_vec!(args),
- cme,
- name,
- state: find!(state),
- return_type,
- elidable,
- block,
- },
- &CCallVariadic { cfunc, recv, ref args, cme, name, state, return_type, elidable, block } => CCallVariadic {
- cfunc, recv: find!(recv), args: find_vec!(args), cme, name, state, return_type, elidable, block
- },
- &CheckMatch { target, pattern, flag, state } => CheckMatch { target: find!(target), pattern: find!(pattern), flag, state: find!(state) },
- &Defined { op_type, obj, pushval, v, lep_level, state } => Defined { op_type, obj, pushval, v: find!(v), lep_level, state: find!(state) },
- &DefinedIvar { self_val, pushval, id, state } => DefinedIvar { self_val: find!(self_val), pushval, id, state },
- &GetConstant { klass, id, allow_nil, state } => GetConstant { klass: find!(klass), id, allow_nil: find!(allow_nil), state },
- &NewArray { ref elements, state } => NewArray { elements: find_vec!(elements), state: find!(state) },
- &NewHash { ref elements, state } => NewHash { elements: find_vec!(elements), state: find!(state) },
- &NewRange { low, high, flag, state } => NewRange { low: find!(low), high: find!(high), flag, state: find!(state) },
- &NewRangeFixnum { low, high, flag, state } => NewRangeFixnum { low: find!(low), high: find!(high), flag, state: find!(state) },
- &ArrayAref { array, index } => ArrayAref { array: find!(array), index: find!(index) },
- &ArrayAset { array, index, val } => ArrayAset { array: find!(array), index: find!(index), val: find!(val) },
- &ArrayPop { array, state } => ArrayPop { array: find!(array), state: find!(state) },
- &ArrayLength { array } => ArrayLength { array: find!(array) },
- &AdjustBounds { index, length } => AdjustBounds { index: find!(index), length: find!(length) },
- &ArrayMax { ref elements, state } => ArrayMax { elements: find_vec!(elements), state: find!(state) },
- &ArrayMin { ref elements, state } => ArrayMin { elements: find_vec!(elements), state: find!(state) },
- &ArrayInclude { ref elements, target, state } => ArrayInclude { elements: find_vec!(elements), target: find!(target), state: find!(state) },
- &ArrayPackBuffer { ref elements, fmt, ref buffer, state } => ArrayPackBuffer { elements: find_vec!(elements), fmt: find!(fmt), buffer: (*buffer).map(|buffer| find!(buffer)), state: find!(state) },
- &DupArrayInclude { ary, target, state } => DupArrayInclude { ary, target: find!(target), state: find!(state) },
- &ArrayHash { ref elements, state } => ArrayHash { elements: find_vec!(elements), state },
- &SetGlobal { id, val, state } => SetGlobal { id, val: find!(val), state },
- &GetIvar { self_val, id, ic, state } => GetIvar { self_val: find!(self_val), id, ic, state },
- &LoadField { recv, id, offset, return_type } => LoadField { recv: find!(recv), id, offset, return_type },
- &StoreField { recv, id, offset, val } => StoreField { recv: find!(recv), id, offset, val: find!(val) },
- &WriteBarrier { recv, val } => WriteBarrier { recv: find!(recv), val: find!(val) },
- &SetIvar { self_val, id, ic, val, state } => SetIvar { self_val: find!(self_val), id, ic, val: find!(val), state },
- &GetClassVar { id, ic, state } => GetClassVar { id, ic, state },
- &SetClassVar { id, val, ic, state } => SetClassVar { id, val: find!(val), ic, state },
- &SetLocal { val, ep_offset, level } => SetLocal { val: find!(val), ep_offset, level },
- &GetSpecialSymbol { symbol_type, state } => GetSpecialSymbol { symbol_type, state },
- &GetSpecialNumber { nth, state } => GetSpecialNumber { nth, state },
- &ToArray { val, state } => ToArray { val: find!(val), state },
- &ToNewArray { val, state } => ToNewArray { val: find!(val), state },
- &ArrayExtend { left, right, state } => ArrayExtend { left: find!(left), right: find!(right), state },
- &ArrayPush { array, val, state } => ArrayPush { array: find!(array), val: find!(val), state },
- &CheckInterrupts { state } => CheckInterrupts { state },
- &IsA { val, class } => IsA { val: find!(val), class: find!(class) },
- }
+ let mut result = self.insns[insn_id.0].clone();
+ result.for_each_operand_mut(&mut |operand: &mut InsnId| {
+ *operand = find!(*operand);
+ });
+ result
}
/// Update DynamicSendReason for the instruction at insn_id