From: juzhe.zhong@rivai.ai
To: gcc-patches@gcc.gnu.org
Cc: kito.cheng@gmail.com, Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
Subject: [PATCH] RISC-V: Move function place to make it looks better.
Date: Tue, 11 Oct 2022 12:48:20 +0800 [thread overview]
Message-ID: <20221011044820.312228-1-juzhe.zhong@rivai.ai> (raw)
From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>
gcc/ChangeLog:
* config/riscv/riscv-vector-builtins.cc (rvv_switcher::rvv_switcher): Move down like ARM SVE.
(rvv_switcher::~rvv_switcher): Move down like ARM SVE.
(mangle_builtin_type): Move down to make it together with other global function.
(class rvv_switcher): Move from riscv-vector-builtins.h.
* config/riscv/riscv-vector-builtins.h (class rvv_switcher): Move to riscv-vector-builtins.cc.
---
gcc/config/riscv/riscv-vector-builtins.cc | 79 ++++++++++++++---------
gcc/config/riscv/riscv-vector-builtins.h | 19 ------
2 files changed, 49 insertions(+), 49 deletions(-)
diff --git a/gcc/config/riscv/riscv-vector-builtins.cc b/gcc/config/riscv/riscv-vector-builtins.cc
index 7033b1fc176..6fd1bb0fcb2 100644
--- a/gcc/config/riscv/riscv-vector-builtins.cc
+++ b/gcc/config/riscv/riscv-vector-builtins.cc
@@ -86,23 +86,6 @@ static GTY(()) tree abi_vector_types[NUM_VECTOR_TYPES + 1];
extern GTY(()) tree builtin_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1];
tree builtin_vector_types[MAX_TUPLE_SIZE][NUM_VECTOR_TYPES + 1];
-rvv_switcher::rvv_switcher ()
-{
- /* Set have_regs_of_mode before targetm.init_builtins (). */
- memcpy (m_old_have_regs_of_mode, have_regs_of_mode,
- sizeof (have_regs_of_mode));
- for (int i = 0; i < NUM_MACHINE_MODES; ++i)
- if (riscv_v_ext_enabled_vector_mode_p ((machine_mode) i))
- have_regs_of_mode[i] = true;
-}
-
-rvv_switcher::~rvv_switcher ()
-{
- /* Recover back have_regs_of_mode. */
- memcpy (have_regs_of_mode, m_old_have_regs_of_mode,
- sizeof (have_regs_of_mode));
-}
-
/* Add type attributes to builtin type tree, currently only the mangled name. */
static void
add_vector_type_attribute (tree type, const char *mangled_name)
@@ -140,19 +123,6 @@ lookup_vector_type_attribute (const_tree type)
return lookup_attribute ("RVV type", TYPE_ATTRIBUTES (type));
}
-/* If TYPE is a built-in type defined by the RVV ABI, return the mangled name,
- otherwise return NULL. */
-const char *
-mangle_builtin_type (const_tree type)
-{
- if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
- type = TREE_TYPE (TYPE_NAME (type));
- if (tree attr = lookup_vector_type_attribute (type))
- if (tree id = TREE_VALUE (chain_index (0, TREE_VALUE (attr))))
- return IDENTIFIER_POINTER (id);
- return NULL;
-}
-
/* Register the built-in RVV ABI types, such as __rvv_int32m1_t. */
static void
register_builtin_types ()
@@ -231,6 +201,55 @@ register_vector_type (vector_type_index type)
builtin_vector_types[0][type] = vectype;
}
+/* RAII class for enabling enough RVV features to define the built-in
+ types and implement the riscv_vector.h pragma.
+
+ Note: According to 'TYPE_MODE' macro implementation, we need set
+ have_regs_of_mode[mode] to be true if we want to get the exact mode
+ from 'TYPE_MODE'. However, have_regs_of_mode has not been set yet in
+ targetm.init_builtins (). We need rvv_switcher to set have_regs_of_mode
+ before targetm.init_builtins () and recover back have_regs_of_mode
+ after targetm.init_builtins (). */
+class rvv_switcher
+{
+public:
+ rvv_switcher ();
+ ~rvv_switcher ();
+
+private:
+ bool m_old_have_regs_of_mode[MAX_MACHINE_MODE];
+};
+
+rvv_switcher::rvv_switcher ()
+{
+ /* Set have_regs_of_mode before targetm.init_builtins (). */
+ memcpy (m_old_have_regs_of_mode, have_regs_of_mode,
+ sizeof (have_regs_of_mode));
+ for (int i = 0; i < NUM_MACHINE_MODES; ++i)
+ if (riscv_v_ext_enabled_vector_mode_p ((machine_mode) i))
+ have_regs_of_mode[i] = true;
+}
+
+rvv_switcher::~rvv_switcher ()
+{
+ /* Recover back have_regs_of_mode. */
+ memcpy (have_regs_of_mode, m_old_have_regs_of_mode,
+ sizeof (have_regs_of_mode));
+}
+
+/* If TYPE is a built-in type defined by the RVV ABI, return the mangled name,
+ otherwise return NULL. */
+const char *
+mangle_builtin_type (const_tree type)
+{
+ if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
+ type = TREE_TYPE (TYPE_NAME (type));
+ if (tree attr = lookup_vector_type_attribute (type))
+ if (tree id = TREE_VALUE (chain_index (0, TREE_VALUE (attr))))
+ return IDENTIFIER_POINTER (id);
+ return NULL;
+}
+
/* Initialize all compiler built-ins related to RVV that should be
defined at start-up. */
void
diff --git a/gcc/config/riscv/riscv-vector-builtins.h b/gcc/config/riscv/riscv-vector-builtins.h
index ec85e0b1320..5c01a760657 100644
--- a/gcc/config/riscv/riscv-vector-builtins.h
+++ b/gcc/config/riscv/riscv-vector-builtins.h
@@ -36,25 +36,6 @@ enum vector_type_index
NUM_VECTOR_TYPES
};
-/* RAII class for enabling enough RVV features to define the built-in
- types and implement the riscv_vector.h pragma.
-
- Note: According to 'TYPE_MODE' macro implementation, we need set
- have_regs_of_mode[mode] to be true if we want to get the exact mode
- from 'TYPE_MODE'. However, have_regs_of_mode has not been set yet in
- targetm.init_builtins (). We need rvv_switcher to set have_regs_of_mode
- before targetm.init_builtins () and recover back have_regs_of_mode
- after targetm.init_builtins (). */
-class rvv_switcher
-{
-public:
- rvv_switcher ();
- ~rvv_switcher ();
-
-private:
- bool m_old_have_regs_of_mode[MAX_MACHINE_MODE];
-};
-
} // end namespace riscv_vector
#endif
--
2.36.1
next reply other threads:[~2022-10-11 4:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-11 4:48 juzhe.zhong [this message]
2022-10-12 13:02 ` Kito Cheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221011044820.312228-1-juzhe.zhong@rivai.ai \
--to=juzhe.zhong@rivai.ai \
--cc=gcc-patches@gcc.gnu.org \
--cc=kito.cheng@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).