Skip to content

Commit 2527f08

Browse files
committed
ZJIT: Use for_each_operand_mut in Function::find
No need to repeat this matching logic manually.
1 parent 33744d2 commit 2527f08

1 file changed

Lines changed: 5 additions & 236 deletions

File tree

zjit/src/hir.rs

Lines changed: 5 additions & 236 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,243 +2783,12 @@ impl Function {
27832783
}
27842784
};
27852785
}
2786-
macro_rules! find_vec {
2787-
( $x:expr ) => {
2788-
{
2789-
$x.iter().map(|arg| find!(*arg)).collect()
2790-
}
2791-
};
2792-
}
2793-
macro_rules! find_branch_edge {
2794-
( $edge:ident ) => {
2795-
{
2796-
BranchEdge {
2797-
target: $edge.target,
2798-
args: find_vec!($edge.args),
2799-
}
2800-
}
2801-
};
2802-
}
28032786
let insn_id = find!(insn_id);
2804-
use Insn::*;
2805-
match &self.insns[insn_id.0] {
2806-
result@(Const {..}
2807-
| Param
2808-
| LoadArg {..}
2809-
| Entries {..}
2810-
| GetConstantPath {..}
2811-
| PatchPoint {..}
2812-
| PutSpecialObject {..}
2813-
| GetGlobal {..}
2814-
| SideExit {..}
2815-
| EntryPoint {..}
2816-
| LoadPC
2817-
| LoadSP
2818-
| LoadEC
2819-
| GetEP {..}
2820-
| LoadSelf
2821-
| BreakPoint
2822-
| IncrCounterPtr {..}
2823-
| IncrCounter(_)) => result.clone(),
2824-
&Snapshot { state: FrameState { iseq, insn_idx, pc, ref stack, ref locals } } =>
2825-
Snapshot {
2826-
state: FrameState {
2827-
iseq,
2828-
insn_idx,
2829-
pc,
2830-
stack: find_vec!(stack),
2831-
locals: find_vec!(locals),
2832-
}
2833-
},
2834-
&Return { val } => Return { val: find!(val) },
2835-
&FixnumBitCheck { val, index } => FixnumBitCheck { val: find!(val), index },
2836-
&Throw { throw_state, val, state } => Throw { throw_state, val: find!(val), state },
2837-
&StringCopy { val, chilled, state } => StringCopy { val: find!(val), chilled, state },
2838-
&StringIntern { val, state } => StringIntern { val: find!(val), state: find!(state) },
2839-
&StringConcat { ref strings, state } => StringConcat { strings: find_vec!(strings), state: find!(state) },
2840-
&StringGetbyte { string, index } => StringGetbyte { string: find!(string), index: find!(index) },
2841-
&StringSetbyteFixnum { string, index, value } => StringSetbyteFixnum { string: find!(string), index: find!(index), value: find!(value) },
2842-
&StringAppend { recv, other, state } => StringAppend { recv: find!(recv), other: find!(other), state: find!(state) },
2843-
&StringAppendCodepoint { recv, other, state } => StringAppendCodepoint { recv: find!(recv), other: find!(other), state: find!(state) },
2844-
&StringEqual { left, right } => StringEqual { left: find!(left), right: find!(right) },
2845-
&ToRegexp { opt, ref values, state } => ToRegexp { opt, values: find_vec!(values), state },
2846-
&Test { val } => Test { val: find!(val) },
2847-
&IsNil { val } => IsNil { val: find!(val) },
2848-
&IsMethodCfunc { val, cd, cfunc, state } => IsMethodCfunc { val: find!(val), cd, cfunc, state },
2849-
&IsBitEqual { left, right } => IsBitEqual { left: find!(left), right: find!(right) },
2850-
&IsBitNotEqual { left, right } => IsBitNotEqual { left: find!(left), right: find!(right) },
2851-
&BoxBool { val } => BoxBool { val: find!(val) },
2852-
&BoxFixnum { val, state } => BoxFixnum { val: find!(val), state: find!(state) },
2853-
&UnboxFixnum { val } => UnboxFixnum { val: find!(val) },
2854-
&FixnumAref { recv, index } => FixnumAref { recv: find!(recv), index: find!(index) },
2855-
Jump(target) => Jump(find_branch_edge!(target)),
2856-
&IfTrue { val, ref target } => IfTrue { val: find!(val), target: find_branch_edge!(target) },
2857-
&IfFalse { val, ref target } => IfFalse { val: find!(val), target: find_branch_edge!(target) },
2858-
&RefineType { val, new_type } => RefineType { val: find!(val), new_type },
2859-
&HasType { val, expected } => HasType { val: find!(val), expected },
2860-
&GuardType { val, guard_type, state } => GuardType { val: find!(val), guard_type, state },
2861-
&GuardTypeNot { val, guard_type, state } => GuardTypeNot { val: find!(val), guard_type, state },
2862-
&GuardBitEquals { val, expected, reason, state, recompile } => GuardBitEquals { val: find!(val), expected, reason, state, recompile },
2863-
&GuardAnyBitSet { val, mask, mask_name, reason, state } => GuardAnyBitSet { val: find!(val), mask, mask_name, reason, state },
2864-
&GuardNoBitsSet { val, mask, mask_name, reason, state } => GuardNoBitsSet { val: find!(val), mask, mask_name, reason, state },
2865-
&GuardGreaterEq { left, right, reason, state } => GuardGreaterEq { left: find!(left), right: find!(right), reason, state },
2866-
&GuardLess { left, right, state } => GuardLess { left: find!(left), right: find!(right), state },
2867-
&IsBlockGiven { lep } => IsBlockGiven { lep: find!(lep) },
2868-
&IsBlockParamModified { flags } => IsBlockParamModified { flags: find!(flags) },
2869-
&GetBlockParam { level, ep_offset, state } => GetBlockParam { level, ep_offset, state: find!(state) },
2870-
&FixnumAdd { left, right, state } => FixnumAdd { left: find!(left), right: find!(right), state },
2871-
&FixnumSub { left, right, state } => FixnumSub { left: find!(left), right: find!(right), state },
2872-
&FixnumMult { left, right, state } => FixnumMult { left: find!(left), right: find!(right), state },
2873-
&FixnumDiv { left, right, state } => FixnumDiv { left: find!(left), right: find!(right), state },
2874-
&FixnumMod { left, right, state } => FixnumMod { left: find!(left), right: find!(right), state },
2875-
&FloatAdd { recv, other, state } => FloatAdd { recv: find!(recv), other: find!(other), state },
2876-
&FloatSub { recv, other, state } => FloatSub { recv: find!(recv), other: find!(other), state },
2877-
&FloatMul { recv, other, state } => FloatMul { recv: find!(recv), other: find!(other), state },
2878-
&FloatDiv { recv, other, state } => FloatDiv { recv: find!(recv), other: find!(other), state },
2879-
&FloatToInt { recv, state } => FloatToInt { recv: find!(recv), state },
2880-
&FixnumNeq { left, right } => FixnumNeq { left: find!(left), right: find!(right) },
2881-
&FixnumEq { left, right } => FixnumEq { left: find!(left), right: find!(right) },
2882-
&FixnumGt { left, right } => FixnumGt { left: find!(left), right: find!(right) },
2883-
&FixnumGe { left, right } => FixnumGe { left: find!(left), right: find!(right) },
2884-
&FixnumLt { left, right } => FixnumLt { left: find!(left), right: find!(right) },
2885-
&FixnumLe { left, right } => FixnumLe { left: find!(left), right: find!(right) },
2886-
&FixnumAnd { left, right } => FixnumAnd { left: find!(left), right: find!(right) },
2887-
&FixnumOr { left, right } => FixnumOr { left: find!(left), right: find!(right) },
2888-
&FixnumXor { left, right } => FixnumXor { left: find!(left), right: find!(right) },
2889-
&IntAnd { left, right } => IntAnd { left: find!(left), right: find!(right) },
2890-
&IntOr { left, right } => IntOr { left: find!(left), right: find!(right) },
2891-
&FixnumLShift { left, right, state } => FixnumLShift { left: find!(left), right: find!(right), state },
2892-
&FixnumRShift { left, right } => FixnumRShift { left: find!(left), right: find!(right) },
2893-
&ObjToString { val, cd, state } => ObjToString {
2894-
val: find!(val),
2895-
cd,
2896-
state,
2897-
},
2898-
&AnyToString { val, str, state } => AnyToString {
2899-
val: find!(val),
2900-
str: find!(str),
2901-
state,
2902-
},
2903-
&SendDirect { recv, cd, cme, iseq, ref args, kw_bits, block, state } => SendDirect {
2904-
recv: find!(recv),
2905-
cd,
2906-
cme,
2907-
iseq,
2908-
args: find_vec!(args),
2909-
kw_bits,
2910-
block,
2911-
state,
2912-
},
2913-
&Send { recv, cd, block, ref args, state, reason } => Send {
2914-
recv: find!(recv),
2915-
cd,
2916-
block,
2917-
args: find_vec!(args),
2918-
state,
2919-
reason,
2920-
},
2921-
&SendForward { recv, cd, blockiseq, ref args, state, reason } => SendForward {
2922-
recv: find!(recv),
2923-
cd,
2924-
blockiseq,
2925-
args: find_vec!(args),
2926-
state,
2927-
reason,
2928-
},
2929-
&InvokeSuper { recv, cd, blockiseq, ref args, state, reason } => InvokeSuper {
2930-
recv: find!(recv),
2931-
cd,
2932-
blockiseq,
2933-
args: find_vec!(args),
2934-
state,
2935-
reason,
2936-
},
2937-
&InvokeSuperForward { recv, cd, blockiseq, ref args, state, reason } => InvokeSuperForward {
2938-
recv: find!(recv),
2939-
cd,
2940-
blockiseq,
2941-
args: find_vec!(args),
2942-
state,
2943-
reason,
2944-
},
2945-
&InvokeBlock { cd, ref args, state, reason } => InvokeBlock {
2946-
cd,
2947-
args: find_vec!(args),
2948-
state,
2949-
reason,
2950-
},
2951-
&InvokeBlockIfunc { cd, block_handler, ref args, state } => InvokeBlockIfunc {
2952-
cd,
2953-
block_handler: find!(block_handler),
2954-
args: find_vec!(args),
2955-
state: find!(state),
2956-
},
2957-
&InvokeProc { recv, ref args, state, kw_splat } => InvokeProc {
2958-
recv: find!(recv),
2959-
args: find_vec!(args),
2960-
state: find!(state),
2961-
kw_splat,
2962-
},
2963-
&InvokeBuiltin { bf, recv, ref args, state, leaf, return_type } => InvokeBuiltin { bf, recv: find!(recv), args: find_vec!(args), state, leaf, return_type },
2964-
&ArrayDup { val, state } => ArrayDup { val: find!(val), state },
2965-
&HashDup { val, state } => HashDup { val: find!(val), state },
2966-
&HashAref { hash, key, state } => HashAref { hash: find!(hash), key: find!(key), state },
2967-
&HashAset { hash, key, val, state } => HashAset { hash: find!(hash), key: find!(key), val: find!(val), state },
2968-
&ObjectAlloc { val, state } => ObjectAlloc { val: find!(val), state },
2969-
&ObjectAllocClass { class, state } => ObjectAllocClass { class, state: find!(state) },
2970-
&CCall { cfunc, recv, ref args, name, owner, return_type, elidable } => CCall { cfunc, recv: find!(recv), args: find_vec!(args), name, owner, return_type, elidable },
2971-
&CCallWithFrame { cd, cfunc, recv, ref args, cme, name, state, return_type, elidable, block } => CCallWithFrame {
2972-
cd,
2973-
cfunc,
2974-
recv: find!(recv),
2975-
args: find_vec!(args),
2976-
cme,
2977-
name,
2978-
state: find!(state),
2979-
return_type,
2980-
elidable,
2981-
block,
2982-
},
2983-
&CCallVariadic { cfunc, recv, ref args, cme, name, state, return_type, elidable, block } => CCallVariadic {
2984-
cfunc, recv: find!(recv), args: find_vec!(args), cme, name, state, return_type, elidable, block
2985-
},
2986-
&CheckMatch { target, pattern, flag, state } => CheckMatch { target: find!(target), pattern: find!(pattern), flag, state: find!(state) },
2987-
&Defined { op_type, obj, pushval, v, lep_level, state } => Defined { op_type, obj, pushval, v: find!(v), lep_level, state: find!(state) },
2988-
&DefinedIvar { self_val, pushval, id, state } => DefinedIvar { self_val: find!(self_val), pushval, id, state },
2989-
&GetConstant { klass, id, allow_nil, state } => GetConstant { klass: find!(klass), id, allow_nil: find!(allow_nil), state },
2990-
&NewArray { ref elements, state } => NewArray { elements: find_vec!(elements), state: find!(state) },
2991-
&NewHash { ref elements, state } => NewHash { elements: find_vec!(elements), state: find!(state) },
2992-
&NewRange { low, high, flag, state } => NewRange { low: find!(low), high: find!(high), flag, state: find!(state) },
2993-
&NewRangeFixnum { low, high, flag, state } => NewRangeFixnum { low: find!(low), high: find!(high), flag, state: find!(state) },
2994-
&ArrayAref { array, index } => ArrayAref { array: find!(array), index: find!(index) },
2995-
&ArrayAset { array, index, val } => ArrayAset { array: find!(array), index: find!(index), val: find!(val) },
2996-
&ArrayPop { array, state } => ArrayPop { array: find!(array), state: find!(state) },
2997-
&ArrayLength { array } => ArrayLength { array: find!(array) },
2998-
&AdjustBounds { index, length } => AdjustBounds { index: find!(index), length: find!(length) },
2999-
&ArrayMax { ref elements, state } => ArrayMax { elements: find_vec!(elements), state: find!(state) },
3000-
&ArrayMin { ref elements, state } => ArrayMin { elements: find_vec!(elements), state: find!(state) },
3001-
&ArrayInclude { ref elements, target, state } => ArrayInclude { elements: find_vec!(elements), target: find!(target), state: find!(state) },
3002-
&ArrayPackBuffer { ref elements, fmt, ref buffer, state } => ArrayPackBuffer { elements: find_vec!(elements), fmt: find!(fmt), buffer: (*buffer).map(|buffer| find!(buffer)), state: find!(state) },
3003-
&DupArrayInclude { ary, target, state } => DupArrayInclude { ary, target: find!(target), state: find!(state) },
3004-
&ArrayHash { ref elements, state } => ArrayHash { elements: find_vec!(elements), state },
3005-
&SetGlobal { id, val, state } => SetGlobal { id, val: find!(val), state },
3006-
&GetIvar { self_val, id, ic, state } => GetIvar { self_val: find!(self_val), id, ic, state },
3007-
&LoadField { recv, id, offset, return_type } => LoadField { recv: find!(recv), id, offset, return_type },
3008-
&StoreField { recv, id, offset, val } => StoreField { recv: find!(recv), id, offset, val: find!(val) },
3009-
&WriteBarrier { recv, val } => WriteBarrier { recv: find!(recv), val: find!(val) },
3010-
&SetIvar { self_val, id, ic, val, state } => SetIvar { self_val: find!(self_val), id, ic, val: find!(val), state },
3011-
&GetClassVar { id, ic, state } => GetClassVar { id, ic, state },
3012-
&SetClassVar { id, val, ic, state } => SetClassVar { id, val: find!(val), ic, state },
3013-
&SetLocal { val, ep_offset, level } => SetLocal { val: find!(val), ep_offset, level },
3014-
&GetSpecialSymbol { symbol_type, state } => GetSpecialSymbol { symbol_type, state },
3015-
&GetSpecialNumber { nth, state } => GetSpecialNumber { nth, state },
3016-
&ToArray { val, state } => ToArray { val: find!(val), state },
3017-
&ToNewArray { val, state } => ToNewArray { val: find!(val), state },
3018-
&ArrayExtend { left, right, state } => ArrayExtend { left: find!(left), right: find!(right), state },
3019-
&ArrayPush { array, val, state } => ArrayPush { array: find!(array), val: find!(val), state },
3020-
&CheckInterrupts { state } => CheckInterrupts { state },
3021-
&IsA { val, class } => IsA { val: find!(val), class: find!(class) },
3022-
}
2787+
let mut result = self.insns[insn_id.0].clone();
2788+
result.for_each_operand_mut(&mut |operand: &mut InsnId| {
2789+
*operand = find!(*operand);
2790+
});
2791+
result
30232792
}
30242793

30252794
/// Update DynamicSendReason for the instruction at insn_id

0 commit comments

Comments
 (0)