Skip to content

Commit

Permalink
RISC-V: Refactor riscv_implied_info_t to make it able to handle condi…
Browse files Browse the repository at this point in the history
…tional implication [NFC]

RISC-V ISA implication rules become little bit complicated than before,
it may come with condition, so this commit extend the capability of
riscv_implied_info_t, also make it more...C++ize.

gcc/ChangeLog:

	* common/config/riscv/riscv-common.cc (riscv_implied_predicator_t): New.
	(riscv_implied_info_t::riscv_implied_info_t): New.
	(riscv_implied_info_t::match): New.
	(riscv_implied_info): New entry for zcf.
	(riscv_subset_list::handle_implied_ext): Use
	riscv_implied_info_t::match.
	(riscv_subset_list::check_implied_ext): Ditto.
	(riscv_subset_list::handle_combine_ext): Ditto.
	(riscv_subset_list::parse): Move zcf implication handling to
	riscv_implied_infos.
  • Loading branch information
kito-cheng committed Dec 4, 2023
1 parent 26b1599 commit 9e12010
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions gcc/common/config/riscv/riscv-common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,36 @@ along with GCC; see the file COPYING3. If not see
#define TARGET_DEFAULT_TARGET_FLAGS (MASK_BIG_ENDIAN)
#endif

typedef bool (*riscv_implied_predicator_t) (const riscv_subset_list *);

/* Type for implied ISA info. */
struct riscv_implied_info_t
{
constexpr riscv_implied_info_t (const char *ext, const char *implied_ext,
riscv_implied_predicator_t predicator
= nullptr)
: ext (ext), implied_ext (implied_ext), predicator (predicator){};

bool match (const riscv_subset_list *subset_list, const char *ext_name) const
{
if (strcmp (ext_name, ext) != 0)
return false;

if (predicator && !predicator (subset_list))
return false;

return true;
}

bool match (const riscv_subset_list *subset_list,
const riscv_subset_t *subset) const
{
return match (subset_list, subset->name.c_str());
}

const char *ext;
const char *implied_ext;
riscv_implied_predicator_t predicator;
};

/* Implied ISA info, must end with NULL sentinel. */
Expand Down Expand Up @@ -143,6 +168,11 @@ static const riscv_implied_info_t riscv_implied_info[] =
{"zcmp", "zca"},
{"zcmt", "zca"},
{"zcmt", "zicsr"},
{"zcf", "f",
[] (const riscv_subset_list *subset_list) -> bool
{
return subset_list->xlen () == 32 && subset_list->lookup ("f");
}},

{"smaia", "ssaia"},
{"smstateen", "ssstateen"},
Expand Down Expand Up @@ -1093,7 +1123,7 @@ riscv_subset_list::handle_implied_ext (const char *ext)
implied_info->ext;
++implied_info)
{
if (strcmp (ext, implied_info->ext) != 0)
if (!implied_info->match (this, ext))
continue;

/* Skip if implied extension already present. */
Expand Down Expand Up @@ -1131,7 +1161,7 @@ riscv_subset_list::check_implied_ext ()
for (implied_info = &riscv_implied_info[0]; implied_info->ext;
++implied_info)
{
if (strcmp (itr->name.c_str(), implied_info->ext) != 0)
if (!implied_info->match (this, itr))
continue;

if (!lookup (implied_info->implied_ext))
Expand Down Expand Up @@ -1160,8 +1190,7 @@ riscv_subset_list::handle_combine_ext ()
for (implied_info = &riscv_implied_info[0]; implied_info->ext;
++implied_info)
{
/* Skip if implied extension don't match combine extension */
if (strcmp (combine_info->name, implied_info->ext) != 0)
if (!implied_info->match (this, combine_info->name))
continue;

if (lookup (implied_info->implied_ext))
Expand Down Expand Up @@ -1502,13 +1531,6 @@ riscv_subset_list::parse (const char *arch, location_t loc)
subset_list->handle_implied_ext (itr->name.c_str ());
}

/* Zce only implies zcf when RV32 and 'f' extension exist. */
if (subset_list->lookup ("zce") != NULL
&& subset_list->m_xlen == 32
&& subset_list->lookup ("f") != NULL
&& subset_list->lookup ("zcf") == NULL)
subset_list->add ("zcf", false);

/* Make sure all implied extensions are included. */
gcc_assert (subset_list->check_implied_ext ());

Expand Down

0 comments on commit 9e12010

Please sign in to comment.