tcg: Add tcg_op_imm_match
Create a function to test whether the second operand of a binary operation allows a given immediate. Reviewed-by: Jim MacArthur <jim.macarthur@linaro.org> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> [rth: Split out from a larger patch; keep the declaration internal.] Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260303010833.1115741-6-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Paolo Bonzini committed
Feb 3, 2026 at 08:53 UTC
bb5b6bbb108b1cb7258585f2cd3d9aeaee054ebf
2 files changed
+22
-4
tcg/tcg-internal.h
+5
@@ -100,4 +100,9 @@ TCGOp *tcg_op_insert_before(TCGContext *s, TCGOp *op,
100
TCGOp *tcg_op_insert_after(TCGContext *s, TCGOp *op,
101
TCGOpcode, TCGType, unsigned nargs);
102
103
+/*
104
+ * For a binary opcode OP, return true if the second input operand allows IMM.
105
+ */
106
+bool tcg_op_imm_match(TCGOpcode op, TCGType type, tcg_target_ulong imm);
107
+
108
#endif /* TCG_INTERNAL_H */
tcg/tcg.c
+17
-4
@@ -3387,11 +3387,9 @@ static void process_constraint_sets(void)
3387
}
3388
}
3389
3390
-static const TCGArgConstraint *opcode_args_ct(const TCGOp *op)
3390
+static const TCGArgConstraint *op_args_ct(TCGOpcode opc, TCGType type,
3391
+ unsigned flags)
3392
{
3392
- TCGOpcode opc = op->opc;
3393
- TCGType type = TCGOP_TYPE(op);
3394
- unsigned flags = TCGOP_FLAGS(op);
3393
const TCGOpDef *def = &tcg_op_defs[opc];
3394
const TCGOutOp *outop = all_outop[opc];
3395
TCGConstraintSetIndex con_set;
@@ -3418,6 +3416,21 @@ static const TCGArgConstraint *opcode_args_ct(const TCGOp *op)
3416
return all_cts[con_set];
3417
}
3418
3419
+static const TCGArgConstraint *opcode_args_ct(const TCGOp *op)
3420
+{
3421
+ return op_args_ct(op->opc, TCGOP_TYPE(op), TCGOP_FLAGS(op));
3422
+}
3423
+
3424
+bool tcg_op_imm_match(TCGOpcode opc, TCGType type, tcg_target_ulong imm)
3425
+{
3426
+ const TCGArgConstraint *args_ct = op_args_ct(opc, type, 0);
3427
+ const TCGOpDef *def = &tcg_op_defs[opc];
3428
+
3429
+ tcg_debug_assert(def->nb_oargs == 1);
3430
+ tcg_debug_assert(def->nb_iargs == 2);
3431
+ return tcg_target_const_match(imm, args_ct[2].ct, type, 0, 0);
3432
+}
3433
+
3434
static void remove_label_use(TCGOp *op, int idx)
3435
{
3436
TCGLabel *label = arg_label(op->args[idx]);