Add get_altfmt(rtx) helper function to extract the altfmt operand value
from RTL operands.  Also add ALTFMT_ANY enum value.

This allows instructions with an altfmt operand to use the "altfmt"
machine attribute to pass that operand to the vsetvl pass, e.g.:

  (define_attr "altfmt" ""
    (cond [(eq_attr "type" "some_type")
           (symbol_ref "riscv_vector::get_altfmt(operands[N])")]
          (const_int INVALID_ATTRIBUTE)))

The ALTFMT_ANY value is handled specially: it returns INVALID_ATTRIBUTE
to indicate no specific altfmt preference.

Signed-off-by: tanshanshan <[email protected]>
---
 gcc/config/riscv/riscv-protos.h | 2 ++
 gcc/config/riscv/riscv-v.cc     | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/gcc/config/riscv/riscv-protos.h b/gcc/config/riscv/riscv-protos.h
index 5fd2328062d9..a497ecdfe587 100644
--- a/gcc/config/riscv/riscv-protos.h
+++ b/gcc/config/riscv/riscv-protos.h
@@ -648,6 +648,7 @@ unsigned int get_nf (machine_mode);
 machine_mode get_subpart_mode (machine_mode);
 int get_ta (rtx);
 int get_ma (rtx);
+int get_altfmt (rtx);
 int get_avl_type (rtx);
 unsigned int calculate_ratio (unsigned int, enum vlmul_type);
 enum tail_policy
@@ -673,6 +674,7 @@ enum altfmt_type
 {
   ALTFMT_NONE = 0,
   ALTFMT_ALT = 1,
+  ALTFMT_ANY = 2,
 };
 
 /* Return true if VALUE is agnostic or any policy.  */
diff --git a/gcc/config/riscv/riscv-v.cc b/gcc/config/riscv/riscv-v.cc
index 431aaa1e7616..bda73845571b 100644
--- a/gcc/config/riscv/riscv-v.cc
+++ b/gcc/config/riscv/riscv-v.cc
@@ -2132,6 +2132,15 @@ get_ma (rtx ma)
   return INTVAL (ma);
 }
 
+/* Get altfmt according to operand[altfmt_op_idx].  */
+int
+get_altfmt (rtx ma)
+{
+  if (INTVAL (ma) == ALTFMT_ANY)
+    return INVALID_ATTRIBUTE;
+  return INTVAL (ma);
+}
+
 /* Get preferred tail policy.  */
 enum tail_policy
 get_prefer_tail_policy ()
-- 
2.43.0

Reply via email to