aboutsummaryrefslogtreecommitdiff
path: root/gcc/common
diff options
context:
space:
mode:
authorKito Cheng <kito.cheng@sifive.com>2020-10-13 15:07:21 +0800
committerKito Cheng <kito.cheng@sifive.com>2020-10-15 11:12:39 +0800
commit72eb8335848be77649ac1c5229b8c26352ab8949 (patch)
tree0e37516358d838fad0ff170d9e98d863be23e7e2 /gcc/common
parent83927c63897ec25b2efb5dac58f20a0561d28f26 (diff)
downloadgcc-72eb8335848be77649ac1c5229b8c26352ab8949.zip
gcc-72eb8335848be77649ac1c5229b8c26352ab8949.tar.gz
gcc-72eb8335848be77649ac1c5229b8c26352ab8949.tar.bz2
RISC-V: Add support for -mcpu option.
- The behavior of -mcpu basically equal to -march plus -mtune, but it has lower priority than -march and -mtune. - The behavior and available options has sync with clang except we don't add few LLVM specific value, and add more sifive processor to the list. - -mtune also accept all available options of -mcpu, and use it setting. gcc/ChangeLog: * common/config/riscv/riscv-common.c (riscv_cpu_tables): New. (riscv_arch_str): Return empty string if current_subset_list is NULL. (riscv_find_cpu): New. (riscv_handle_option): Verify option value of -mcpu. (riscv_expand_arch): Using std::string. (riscv_default_mtune): New. (riscv_expand_arch_from_cpu): Ditto. * config/riscv/riscv-cores.def: New. * config/riscv/riscv-protos.h (riscv_find_cpu): New. (riscv_cpu_info): New. * config/riscv/riscv.c (riscv_tune_info): Rename ... (riscv_tune_param): ... to this. (riscv_cpu_info): Rename ... (riscv_tune_info): ... to this. (tune_info): Rename ... (tune_param): ... to this. (rocket_tune_info): Update data type name. (sifive_7_tune_info): Ditto. (optimize_size_tune_info): Ditto. (riscv_cpu_info_table): Rename ... (riscv_tune_info_table): ... to this. (riscv_parse_cpu): Rename ... (riscv_parse_tune): ... to this, and translate valid -mcpu option to -mtune option. (riscv_rtx_costs): Rename tune_info to tune_param. (riscv_class_max_nregs): Ditto. (riscv_memory_move_cost): Ditto. (riscv_init_machine_status): Use value of -mcpu if -mtune is not given, and rename tune_info to tune_param. * config/riscv/riscv.h (riscv_expand_arch_from_cpu): New. (riscv_default_mtune): Ditto. (EXTRA_SPEC_FUNCTIONS): Add riscv_expand_arch_from_cpu and riscv_default_mtune. (OPTION_DEFAULT_SPECS): Handle default value of -march/-mabi. (DRIVER_SELF_SPECS): Expand -march from -mcpu if -march is not given. * config/riscv/riscv.opt (-mcpu): New option. * config/riscv/t-riscv ($(common_out_file)): Add riscv-cores.def to dependency. * doc/invoke.texi (RISC-V Option): Add -mcpu, and update the description of default value for -mtune and -march. gcc/testsuite/ChangeLog: * gcc.target/riscv/mcpu-1.c: New. * gcc.target/riscv/mcpu-2.c: Ditto. * gcc.target/riscv/mcpu-3.c: Ditto. * gcc.target/riscv/mcpu-4.c: Ditto. * gcc.target/riscv/mcpu-5.c: Ditto. * gcc.target/riscv/mcpu-6.c: Ditto. * gcc.target/riscv/mcpu-7.c: Ditto.
Diffstat (limited to 'gcc/common')
-rw-r--r--gcc/common/config/riscv/riscv-common.c91
1 files changed, 86 insertions, 5 deletions
diff --git a/gcc/common/config/riscv/riscv-common.c b/gcc/common/config/riscv/riscv-common.c
index 82c5154..4b6bdf8 100644
--- a/gcc/common/config/riscv/riscv-common.c
+++ b/gcc/common/config/riscv/riscv-common.c
@@ -60,6 +60,14 @@ riscv_implied_info_t riscv_implied_info[] =
{NULL, NULL}
};
+static const riscv_cpu_info riscv_cpu_tables[] =
+{
+#define RISCV_CORE(CORE_NAME, ARCH, TUNE) \
+ {CORE_NAME, ARCH, TUNE},
+#include "../../../config/riscv/riscv-cores.def"
+ {NULL, NULL, NULL}
+};
+
/* Subset list. */
class riscv_subset_list
{
@@ -604,8 +612,10 @@ fail:
std::string
riscv_arch_str (bool version_p)
{
- gcc_assert (current_subset_list);
- return current_subset_list->to_string (version_p);
+ if (current_subset_list)
+ return current_subset_list->to_string (version_p);
+ else
+ return std::string();
}
/* Parse a RISC-V ISA string into an option mask. Must clear or set all arch
@@ -653,6 +663,21 @@ riscv_parse_arch_string (const char *isa, int *flags, location_t loc)
current_subset_list = subset_list;
}
+/* Return the riscv_cpu_info entry for CPU, NULL if not found. */
+
+const riscv_cpu_info *
+riscv_find_cpu (const char *cpu)
+{
+ const riscv_cpu_info *cpu_info = &riscv_cpu_tables[0];
+ for (;cpu_info->name != NULL; ++cpu_info)
+ {
+ const char *name = cpu_info->name;
+ if (strcmp (cpu, name) == 0)
+ return cpu_info;
+ }
+ return NULL;
+}
+
/* Implement TARGET_HANDLE_OPTION. */
static bool
@@ -667,6 +692,12 @@ riscv_handle_option (struct gcc_options *opts,
riscv_parse_arch_string (decoded->arg, &opts->x_target_flags, loc);
return true;
+ case OPT_mcpu_:
+ if (riscv_find_cpu (decoded->arg) == NULL)
+ error_at (loc, "%<-mcpu=%s%>: unknown CPU",
+ decoded->arg);
+ return true;
+
default:
return true;
}
@@ -678,15 +709,65 @@ const char *
riscv_expand_arch (int argc ATTRIBUTE_UNUSED,
const char **argv)
{
- static char *_arch_buf;
gcc_assert (argc == 1);
int flags;
location_t loc = UNKNOWN_LOCATION;
riscv_parse_arch_string (argv[0], &flags, loc);
- _arch_buf = xstrdup (riscv_arch_str (false).c_str ());
- return _arch_buf;
+ const std::string arch = riscv_arch_str (false);
+ if (arch.length())
+ return xasprintf ("-march=%s", arch.c_str());
+ else
+ return "";
}
+/* Expand default -mtune option from -mcpu option, use default --with-tune value
+ if -mcpu don't have valid value. */
+
+const char *
+riscv_default_mtune (int argc, const char **argv)
+{
+ gcc_assert (argc == 2);
+ const riscv_cpu_info *cpu = riscv_find_cpu (argv[0]);
+ const char *default_mtune = argv[1];
+ if (cpu)
+ return cpu->tune;
+ else
+ return default_mtune;
+}
+
+/* Expand arch string with implied extensions from -mcpu option. */
+
+const char *
+riscv_expand_arch_from_cpu (int argc ATTRIBUTE_UNUSED,
+ const char **argv)
+{
+ gcc_assert (argc > 0 && argc <= 2);
+ const char *default_arch_str = NULL;
+ const char *arch_str = NULL;
+ if (argc >= 2)
+ default_arch_str = argv[1];
+
+ const riscv_cpu_info *cpu = riscv_find_cpu (argv[0]);
+
+ if (cpu == NULL)
+ {
+ if (default_arch_str == NULL)
+ return "";
+ else
+ arch_str = default_arch_str;
+ }
+ else
+ arch_str = cpu->arch;
+
+ location_t loc = UNKNOWN_LOCATION;
+ int flags;
+
+ riscv_parse_arch_string (arch_str, &flags, loc);
+ const std::string arch = riscv_arch_str (false);
+ return xasprintf ("-march=%s", arch.c_str());
+}
+
+
/* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
static const struct default_options riscv_option_optimization_table[] =
{