public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] RISC-V: Add required_extensions in function_group
@ 2023-12-18  3:28 Feng Wang
  2023-12-18  6:34 ` juzhe.zhong
  2023-12-19  1:15 ` juzhe.zhong
  0 siblings, 2 replies; 3+ messages in thread
From: Feng Wang @ 2023-12-18  3:28 UTC (permalink / raw)
  To: gcc-patches; +Cc: kito.cheng, jeffreyalaw, juzhe.zhong, Feng Wang

In order to add other vector related extensions in the future, this
patch add one more parameter in the function_group_info, it will be
used to determine whether intrinsic registration processing is required.

gcc/ChangeLog:

	* config/riscv/riscv-vector-builtins-functions.def (REQUIRED_EXTENSIONS):
					Add new macro for match function.
	* config/riscv/riscv-vector-builtins.cc (DEF_RVV_FUNCTION):
					Add one more parameter for macro expanding.
	(handle_pragma_vector): Add match function calls.
	* config/riscv/riscv-vector-builtins.h (enum required_ext):
				Add enum defination for required extension.
	(struct function_group_info): Add one more parameter for checking required-ext.
---
 .../riscv/riscv-vector-builtins-functions.def |  2 +
 gcc/config/riscv/riscv-vector-builtins.cc     |  7 ++-
 gcc/config/riscv/riscv-vector-builtins.h      | 46 +++++++++++++++++++
 3 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/gcc/config/riscv/riscv-vector-builtins-functions.def b/gcc/config/riscv/riscv-vector-builtins-functions.def
index 1c37fd5fffe..03421d5bc10 100644
--- a/gcc/config/riscv/riscv-vector-builtins-functions.def
+++ b/gcc/config/riscv/riscv-vector-builtins-functions.def
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
 #define DEF_RVV_FUNCTION(NAME, SHAPE, PREDS, OPS_INFO)
 #endif
 
+#define REQUIRED_EXTENSIONS VECTOR_EXT
 /* Internal helper functions for gimple fold use.  */
 DEF_RVV_FUNCTION (read_vl, read_vl, none_preds, p_none_void_ops)
 DEF_RVV_FUNCTION (vlenb, vlenb, none_preds, ul_none_void_ops)
@@ -650,5 +651,6 @@ DEF_RVV_FUNCTION (vsoxseg, seg_indexed_loadstore, none_m_preds, tuple_v_scalar_p
 DEF_RVV_FUNCTION (vsoxseg, seg_indexed_loadstore, none_m_preds, tuple_v_scalar_ptr_eew32_index_ops)
 DEF_RVV_FUNCTION (vsoxseg, seg_indexed_loadstore, none_m_preds, tuple_v_scalar_ptr_eew64_index_ops)
 DEF_RVV_FUNCTION (vlsegff, seg_fault_load, full_preds, tuple_v_scalar_const_ptr_size_ptr_ops)
+#undef REQUIRED_EXTENSIONS
 
 #undef DEF_RVV_FUNCTION
diff --git a/gcc/config/riscv/riscv-vector-builtins.cc b/gcc/config/riscv/riscv-vector-builtins.cc
index 6330a3a41c3..4e2c66c2de7 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -2685,7 +2685,7 @@ static CONSTEXPR const function_type_info function_types[] = {
 /* A list of all RVV intrinsic functions.  */
 static function_group_info function_groups[] = {
 #define DEF_RVV_FUNCTION(NAME, SHAPE, PREDS, OPS_INFO)                         \
-  {#NAME, &bases::NAME, &shapes::SHAPE, PREDS, OPS_INFO},
+  {#NAME, &bases::NAME, &shapes::SHAPE, PREDS, OPS_INFO, REQUIRED_EXTENSIONS},
 #include "riscv-vector-builtins-functions.def"
 };
 
@@ -4413,7 +4413,10 @@ handle_pragma_vector ()
     = new hash_table<non_overloaded_registered_function_hasher> (1023);
   function_builder builder;
   for (unsigned int i = 0; i < ARRAY_SIZE (function_groups); ++i)
-    builder.register_function_group (function_groups[i]);
+  {
+    if (function_groups[i].match (function_groups[i].required_extensions))
+      builder.register_function_group (function_groups[i]);
+  }
 }
 
 /* Return the function decl with RVV function subcode CODE, or error_mark_node
diff --git a/gcc/config/riscv/riscv-vector-builtins.h b/gcc/config/riscv/riscv-vector-builtins.h
index cd8ccab1724..4f38c09d73d 100644
--- a/gcc/config/riscv/riscv-vector-builtins.h
+++ b/gcc/config/riscv/riscv-vector-builtins.h
@@ -110,6 +110,21 @@ static const unsigned int CP_WRITE_CSR = 1U << 5;
 #define RVV_REQUIRE_MIN_VLEN_64 (1 << 5)	/* Require TARGET_MIN_VLEN >= 64.  */
 #define RVV_REQUIRE_ELEN_FP_16 (1 << 6) /* Require FP ELEN >= 32.  */
 
+/* Enumerates the required extensions.  */
+enum required_ext
+{
+  VECTOR_EXT,   /* Vector extension */
+  ZVBB_EXT,    /* Cryto vector Zvbb sub-ext */
+  ZVBB_OR_ZVKB_EXT, /* Cryto vector Zvbb or zvkb sub-ext */
+  ZVBC_EXT,    /* Crypto vector Zvbc sub-ext */
+  ZVKG_EXT,    /* Crypto vector Zvkg sub-ext */
+  ZVKNED_EXT,  /* Crypto vector Zvkned sub-ext */
+  ZVKNHA_OR_ZVKNHB_EXT, /* Crypto vector Zvknh[ab] sub-ext */
+  ZVKNHB_EXT,  /* Crypto vector Zvknhb sub-ext */
+  ZVKSED_EXT,  /* Crypto vector Zvksed sub-ext */
+  ZVKSH_EXT,   /* Crypto vector Zvksh sub-ext */
+};
+
 /* Enumerates the RVV operand types.  */
 enum operand_type_index
 {
@@ -212,6 +227,35 @@ class function_shape;
 /* Static information about a set of functions.  */
 struct function_group_info
 {
+  /* Return true if required extension is enabled */
+  bool match (required_ext ext_value) const
+  {
+    switch (ext_value)
+    {
+      case VECTOR_EXT:
+        return TARGET_VECTOR;
+      case ZVBB_EXT:
+        return TARGET_ZVBB;
+      case ZVBB_OR_ZVKB_EXT:
+        return (TARGET_ZVBB || TARGET_ZVKB);
+      case ZVBC_EXT:
+        return TARGET_ZVBC;
+      case ZVKG_EXT:
+        return TARGET_ZVKG;
+      case ZVKNED_EXT:
+        return TARGET_ZVKNED;
+      case ZVKNHA_OR_ZVKNHB_EXT:
+        return (TARGET_ZVKNHA || TARGET_ZVKNHB);
+      case ZVKNHB_EXT:
+        return TARGET_ZVKNHB;
+      case ZVKSED_EXT:
+        return TARGET_ZVKSED;
+      case ZVKSH_EXT:
+        return TARGET_ZVKSH;
+      default:
+        gcc_unreachable ();
+    }
+  }
   /* The base name, as a string.  */
   const char *base_name;
 
@@ -232,6 +276,8 @@ struct function_group_info
      on the index value.  */
   const predication_type_index *preds;
   const rvv_op_info ops_infos;
+  /* The required extension value, using it to get the enabled flag.  */
+  required_ext required_extensions;
 };
 
 class GTY ((user)) function_instance
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: Add required_extensions in function_group
  2023-12-18  3:28 [PATCH] RISC-V: Add required_extensions in function_group Feng Wang
@ 2023-12-18  6:34 ` juzhe.zhong
  2023-12-19  1:15 ` juzhe.zhong
  1 sibling, 0 replies; 3+ messages in thread
From: juzhe.zhong @ 2023-12-18  6:34 UTC (permalink / raw)
  To: wangfeng, gcc-patches; +Cc: kito.cheng, jeffreyalaw, wangfeng

[-- Attachment #1: Type: text/plain, Size: 5944 bytes --]

LGTM from my side.
Give kito 1 day to chime in,



juzhe.zhong@rivai.ai
 
From: Feng Wang
Date: 2023-12-18 11:28
To: gcc-patches
CC: kito.cheng; jeffreyalaw; juzhe.zhong; Feng Wang
Subject: [PATCH] RISC-V: Add required_extensions in function_group
In order to add other vector related extensions in the future, this
patch add one more parameter in the function_group_info, it will be
used to determine whether intrinsic registration processing is required.
 
gcc/ChangeLog:
 
* config/riscv/riscv-vector-builtins-functions.def (REQUIRED_EXTENSIONS):
Add new macro for match function.
* config/riscv/riscv-vector-builtins.cc (DEF_RVV_FUNCTION):
Add one more parameter for macro expanding.
(handle_pragma_vector): Add match function calls.
* config/riscv/riscv-vector-builtins.h (enum required_ext):
Add enum defination for required extension.
(struct function_group_info): Add one more parameter for checking required-ext.
---
.../riscv/riscv-vector-builtins-functions.def |  2 +
gcc/config/riscv/riscv-vector-builtins.cc     |  7 ++-
gcc/config/riscv/riscv-vector-builtins.h      | 46 +++++++++++++++++++
3 files changed, 53 insertions(+), 2 deletions(-)
 
diff --git a/gcc/config/riscv/riscv-vector-builtins-functions.def b/gcc/config/riscv/riscv-vector-builtins-functions.def
index 1c37fd5fffe..03421d5bc10 100644
--- a/gcc/config/riscv/riscv-vector-builtins-functions.def
+++ b/gcc/config/riscv/riscv-vector-builtins-functions.def
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
#define DEF_RVV_FUNCTION(NAME, SHAPE, PREDS, OPS_INFO)
#endif
+#define REQUIRED_EXTENSIONS VECTOR_EXT
/* Internal helper functions for gimple fold use.  */
DEF_RVV_FUNCTION (read_vl, read_vl, none_preds, p_none_void_ops)
DEF_RVV_FUNCTION (vlenb, vlenb, none_preds, ul_none_void_ops)
@@ -650,5 +651,6 @@ DEF_RVV_FUNCTION (vsoxseg, seg_indexed_loadstore, none_m_preds, tuple_v_scalar_p
DEF_RVV_FUNCTION (vsoxseg, seg_indexed_loadstore, none_m_preds, tuple_v_scalar_ptr_eew32_index_ops)
DEF_RVV_FUNCTION (vsoxseg, seg_indexed_loadstore, none_m_preds, tuple_v_scalar_ptr_eew64_index_ops)
DEF_RVV_FUNCTION (vlsegff, seg_fault_load, full_preds, tuple_v_scalar_const_ptr_size_ptr_ops)
+#undef REQUIRED_EXTENSIONS
#undef DEF_RVV_FUNCTION
diff --git a/gcc/config/riscv/riscv-vector-builtins.cc b/gcc/config/riscv/riscv-vector-builtins.cc
index 6330a3a41c3..4e2c66c2de7 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -2685,7 +2685,7 @@ static CONSTEXPR const function_type_info function_types[] = {
/* A list of all RVV intrinsic functions.  */
static function_group_info function_groups[] = {
#define DEF_RVV_FUNCTION(NAME, SHAPE, PREDS, OPS_INFO)                         \
-  {#NAME, &bases::NAME, &shapes::SHAPE, PREDS, OPS_INFO},
+  {#NAME, &bases::NAME, &shapes::SHAPE, PREDS, OPS_INFO, REQUIRED_EXTENSIONS},
#include "riscv-vector-builtins-functions.def"
};
@@ -4413,7 +4413,10 @@ handle_pragma_vector ()
     = new hash_table<non_overloaded_registered_function_hasher> (1023);
   function_builder builder;
   for (unsigned int i = 0; i < ARRAY_SIZE (function_groups); ++i)
-    builder.register_function_group (function_groups[i]);
+  {
+    if (function_groups[i].match (function_groups[i].required_extensions))
+      builder.register_function_group (function_groups[i]);
+  }
}
/* Return the function decl with RVV function subcode CODE, or error_mark_node
diff --git a/gcc/config/riscv/riscv-vector-builtins.h b/gcc/config/riscv/riscv-vector-builtins.h
index cd8ccab1724..4f38c09d73d 100644
--- a/gcc/config/riscv/riscv-vector-builtins.h
+++ b/gcc/config/riscv/riscv-vector-builtins.h
@@ -110,6 +110,21 @@ static const unsigned int CP_WRITE_CSR = 1U << 5;
#define RVV_REQUIRE_MIN_VLEN_64 (1 << 5) /* Require TARGET_MIN_VLEN >= 64.  */
#define RVV_REQUIRE_ELEN_FP_16 (1 << 6) /* Require FP ELEN >= 32.  */
+/* Enumerates the required extensions.  */
+enum required_ext
+{
+  VECTOR_EXT,   /* Vector extension */
+  ZVBB_EXT,    /* Cryto vector Zvbb sub-ext */
+  ZVBB_OR_ZVKB_EXT, /* Cryto vector Zvbb or zvkb sub-ext */
+  ZVBC_EXT,    /* Crypto vector Zvbc sub-ext */
+  ZVKG_EXT,    /* Crypto vector Zvkg sub-ext */
+  ZVKNED_EXT,  /* Crypto vector Zvkned sub-ext */
+  ZVKNHA_OR_ZVKNHB_EXT, /* Crypto vector Zvknh[ab] sub-ext */
+  ZVKNHB_EXT,  /* Crypto vector Zvknhb sub-ext */
+  ZVKSED_EXT,  /* Crypto vector Zvksed sub-ext */
+  ZVKSH_EXT,   /* Crypto vector Zvksh sub-ext */
+};
+
/* Enumerates the RVV operand types.  */
enum operand_type_index
{
@@ -212,6 +227,35 @@ class function_shape;
/* Static information about a set of functions.  */
struct function_group_info
{
+  /* Return true if required extension is enabled */
+  bool match (required_ext ext_value) const
+  {
+    switch (ext_value)
+    {
+      case VECTOR_EXT:
+        return TARGET_VECTOR;
+      case ZVBB_EXT:
+        return TARGET_ZVBB;
+      case ZVBB_OR_ZVKB_EXT:
+        return (TARGET_ZVBB || TARGET_ZVKB);
+      case ZVBC_EXT:
+        return TARGET_ZVBC;
+      case ZVKG_EXT:
+        return TARGET_ZVKG;
+      case ZVKNED_EXT:
+        return TARGET_ZVKNED;
+      case ZVKNHA_OR_ZVKNHB_EXT:
+        return (TARGET_ZVKNHA || TARGET_ZVKNHB);
+      case ZVKNHB_EXT:
+        return TARGET_ZVKNHB;
+      case ZVKSED_EXT:
+        return TARGET_ZVKSED;
+      case ZVKSH_EXT:
+        return TARGET_ZVKSH;
+      default:
+        gcc_unreachable ();
+    }
+  }
   /* The base name, as a string.  */
   const char *base_name;
@@ -232,6 +276,8 @@ struct function_group_info
      on the index value.  */
   const predication_type_index *preds;
   const rvv_op_info ops_infos;
+  /* The required extension value, using it to get the enabled flag.  */
+  required_ext required_extensions;
};
class GTY ((user)) function_instance
-- 
2.17.1
 
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RISC-V: Add required_extensions in function_group
  2023-12-18  3:28 [PATCH] RISC-V: Add required_extensions in function_group Feng Wang
  2023-12-18  6:34 ` juzhe.zhong
@ 2023-12-19  1:15 ` juzhe.zhong
  1 sibling, 0 replies; 3+ messages in thread
From: juzhe.zhong @ 2023-12-19  1:15 UTC (permalink / raw)
  To: wangfeng, gcc-patches; +Cc: kito.cheng, jeffreyalaw, wangfeng

[-- Attachment #1: Type: text/plain, Size: 5956 bytes --]

Thanks for refactor it.  You can commit it today.

Thanks.



juzhe.zhong@rivai.ai
 
From: Feng Wang
Date: 2023-12-18 11:28
To: gcc-patches
CC: kito.cheng; jeffreyalaw; juzhe.zhong; Feng Wang
Subject: [PATCH] RISC-V: Add required_extensions in function_group
In order to add other vector related extensions in the future, this
patch add one more parameter in the function_group_info, it will be
used to determine whether intrinsic registration processing is required.
 
gcc/ChangeLog:
 
* config/riscv/riscv-vector-builtins-functions.def (REQUIRED_EXTENSIONS):
Add new macro for match function.
* config/riscv/riscv-vector-builtins.cc (DEF_RVV_FUNCTION):
Add one more parameter for macro expanding.
(handle_pragma_vector): Add match function calls.
* config/riscv/riscv-vector-builtins.h (enum required_ext):
Add enum defination for required extension.
(struct function_group_info): Add one more parameter for checking required-ext.
---
.../riscv/riscv-vector-builtins-functions.def |  2 +
gcc/config/riscv/riscv-vector-builtins.cc     |  7 ++-
gcc/config/riscv/riscv-vector-builtins.h      | 46 +++++++++++++++++++
3 files changed, 53 insertions(+), 2 deletions(-)
 
diff --git a/gcc/config/riscv/riscv-vector-builtins-functions.def b/gcc/config/riscv/riscv-vector-builtins-functions.def
index 1c37fd5fffe..03421d5bc10 100644
--- a/gcc/config/riscv/riscv-vector-builtins-functions.def
+++ b/gcc/config/riscv/riscv-vector-builtins-functions.def
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
#define DEF_RVV_FUNCTION(NAME, SHAPE, PREDS, OPS_INFO)
#endif
+#define REQUIRED_EXTENSIONS VECTOR_EXT
/* Internal helper functions for gimple fold use.  */
DEF_RVV_FUNCTION (read_vl, read_vl, none_preds, p_none_void_ops)
DEF_RVV_FUNCTION (vlenb, vlenb, none_preds, ul_none_void_ops)
@@ -650,5 +651,6 @@ DEF_RVV_FUNCTION (vsoxseg, seg_indexed_loadstore, none_m_preds, tuple_v_scalar_p
DEF_RVV_FUNCTION (vsoxseg, seg_indexed_loadstore, none_m_preds, tuple_v_scalar_ptr_eew32_index_ops)
DEF_RVV_FUNCTION (vsoxseg, seg_indexed_loadstore, none_m_preds, tuple_v_scalar_ptr_eew64_index_ops)
DEF_RVV_FUNCTION (vlsegff, seg_fault_load, full_preds, tuple_v_scalar_const_ptr_size_ptr_ops)
+#undef REQUIRED_EXTENSIONS
#undef DEF_RVV_FUNCTION
diff --git a/gcc/config/riscv/riscv-vector-builtins.cc b/gcc/config/riscv/riscv-vector-builtins.cc
index 6330a3a41c3..4e2c66c2de7 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -2685,7 +2685,7 @@ static CONSTEXPR const function_type_info function_types[] = {
/* A list of all RVV intrinsic functions.  */
static function_group_info function_groups[] = {
#define DEF_RVV_FUNCTION(NAME, SHAPE, PREDS, OPS_INFO)                         \
-  {#NAME, &bases::NAME, &shapes::SHAPE, PREDS, OPS_INFO},
+  {#NAME, &bases::NAME, &shapes::SHAPE, PREDS, OPS_INFO, REQUIRED_EXTENSIONS},
#include "riscv-vector-builtins-functions.def"
};
@@ -4413,7 +4413,10 @@ handle_pragma_vector ()
     = new hash_table<non_overloaded_registered_function_hasher> (1023);
   function_builder builder;
   for (unsigned int i = 0; i < ARRAY_SIZE (function_groups); ++i)
-    builder.register_function_group (function_groups[i]);
+  {
+    if (function_groups[i].match (function_groups[i].required_extensions))
+      builder.register_function_group (function_groups[i]);
+  }
}
/* Return the function decl with RVV function subcode CODE, or error_mark_node
diff --git a/gcc/config/riscv/riscv-vector-builtins.h b/gcc/config/riscv/riscv-vector-builtins.h
index cd8ccab1724..4f38c09d73d 100644
--- a/gcc/config/riscv/riscv-vector-builtins.h
+++ b/gcc/config/riscv/riscv-vector-builtins.h
@@ -110,6 +110,21 @@ static const unsigned int CP_WRITE_CSR = 1U << 5;
#define RVV_REQUIRE_MIN_VLEN_64 (1 << 5) /* Require TARGET_MIN_VLEN >= 64.  */
#define RVV_REQUIRE_ELEN_FP_16 (1 << 6) /* Require FP ELEN >= 32.  */
+/* Enumerates the required extensions.  */
+enum required_ext
+{
+  VECTOR_EXT,   /* Vector extension */
+  ZVBB_EXT,    /* Cryto vector Zvbb sub-ext */
+  ZVBB_OR_ZVKB_EXT, /* Cryto vector Zvbb or zvkb sub-ext */
+  ZVBC_EXT,    /* Crypto vector Zvbc sub-ext */
+  ZVKG_EXT,    /* Crypto vector Zvkg sub-ext */
+  ZVKNED_EXT,  /* Crypto vector Zvkned sub-ext */
+  ZVKNHA_OR_ZVKNHB_EXT, /* Crypto vector Zvknh[ab] sub-ext */
+  ZVKNHB_EXT,  /* Crypto vector Zvknhb sub-ext */
+  ZVKSED_EXT,  /* Crypto vector Zvksed sub-ext */
+  ZVKSH_EXT,   /* Crypto vector Zvksh sub-ext */
+};
+
/* Enumerates the RVV operand types.  */
enum operand_type_index
{
@@ -212,6 +227,35 @@ class function_shape;
/* Static information about a set of functions.  */
struct function_group_info
{
+  /* Return true if required extension is enabled */
+  bool match (required_ext ext_value) const
+  {
+    switch (ext_value)
+    {
+      case VECTOR_EXT:
+        return TARGET_VECTOR;
+      case ZVBB_EXT:
+        return TARGET_ZVBB;
+      case ZVBB_OR_ZVKB_EXT:
+        return (TARGET_ZVBB || TARGET_ZVKB);
+      case ZVBC_EXT:
+        return TARGET_ZVBC;
+      case ZVKG_EXT:
+        return TARGET_ZVKG;
+      case ZVKNED_EXT:
+        return TARGET_ZVKNED;
+      case ZVKNHA_OR_ZVKNHB_EXT:
+        return (TARGET_ZVKNHA || TARGET_ZVKNHB);
+      case ZVKNHB_EXT:
+        return TARGET_ZVKNHB;
+      case ZVKSED_EXT:
+        return TARGET_ZVKSED;
+      case ZVKSH_EXT:
+        return TARGET_ZVKSH;
+      default:
+        gcc_unreachable ();
+    }
+  }
   /* The base name, as a string.  */
   const char *base_name;
@@ -232,6 +276,8 @@ struct function_group_info
      on the index value.  */
   const predication_type_index *preds;
   const rvv_op_info ops_infos;
+  /* The required extension value, using it to get the enabled flag.  */
+  required_ext required_extensions;
};
class GTY ((user)) function_instance
-- 
2.17.1
 
 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-19  1:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-18  3:28 [PATCH] RISC-V: Add required_extensions in function_group Feng Wang
2023-12-18  6:34 ` juzhe.zhong
2023-12-19  1:15 ` juzhe.zhong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).