aboutsummaryrefslogtreecommitdiff
path: root/gcc/common
diff options
context:
space:
mode:
authorKito Cheng <kito.cheng@sifive.com>2024-01-19 10:29:10 +0800
committerKito Cheng <kito.cheng@sifive.com>2024-02-16 14:41:14 +0800
commit7af0f1e107a480fbfe882cb985603960114aefb5 (patch)
treecf915098915dc011964bf6e3a65af823d809b0f9 /gcc/common
parentf436a2ab6ad15968275c9bbf3bd56647e5559e68 (diff)
downloadgcc-7af0f1e107a480fbfe882cb985603960114aefb5.zip
gcc-7af0f1e107a480fbfe882cb985603960114aefb5.tar.gz
gcc-7af0f1e107a480fbfe882cb985603960114aefb5.tar.bz2
RISC-V: Add new option -march=help to print all supported extensions
The output of -march=help is like below: ``` All available -march extensions for RISC-V: Name Version i 2.0, 2.1 e 2.0 m 2.0 a 2.0, 2.1 f 2.0, 2.2 d 2.0, 2.2 ... ``` Also support -print-supported-extensions and --print-supported-extensions for clang compatibility. gcc/ChangeLog: PR target/109349 * common/config/riscv/riscv-common.cc (riscv_arch_help): New. * config/riscv/riscv-protos.h (RISCV_MAJOR_VERSION_BASE): New. (RISCV_MINOR_VERSION_BASE): Ditto. (RISCV_REVISION_VERSION_BASE): Ditto. * config/riscv/riscv-c.cc (riscv_ext_version_value): Use enum rather than magic number. * config/riscv/riscv.h (riscv_arch_help): New. (EXTRA_SPEC_FUNCTIONS): Add riscv_arch_help. (DRIVER_SELF_SPECS): Handle -march=help, -print-supported-extensions and --print-supported-extensions. * config/riscv/riscv.opt (march=help): New. (print-supported-extensions): New. (-print-supported-extensions): New. * doc/invoke.texi (RISC-V Options): Document -march=help. Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu>
Diffstat (limited to 'gcc/common')
-rw-r--r--gcc/common/config/riscv/riscv-common.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc
index 631ce83..48efef4 100644
--- a/gcc/common/config/riscv/riscv-common.cc
+++ b/gcc/common/config/riscv/riscv-common.cc
@@ -21,6 +21,8 @@ along with GCC; see the file COPYING3. If not see
#include <vector>
#define INCLUDE_STRING
+#define INCLUDE_SET
+#define INCLUDE_MAP
#include "config.h"
#include "system.h"
#include "coretypes.h"
@@ -2225,6 +2227,50 @@ riscv_get_valid_option_values (int option_code,
return v;
}
+const char *
+riscv_arch_help (int, const char **)
+{
+ /* Collect all exts, and sort it in canonical order. */
+ struct extension_comparator {
+ bool operator()(const std::string& a, const std::string& b) const {
+ return subset_cmp(a, b) >= 1;
+ }
+ };
+ std::map<std::string, std::set<unsigned>, extension_comparator> all_exts;
+ for (const riscv_ext_version &ext : riscv_ext_version_table)
+ {
+ if (!ext.name)
+ break;
+ if (ext.name[0] == 'g')
+ continue;
+ unsigned version_value = (ext.major_version * RISCV_MAJOR_VERSION_BASE)
+ + (ext.minor_version
+ * RISCV_MINOR_VERSION_BASE);
+ all_exts[ext.name].insert(version_value);
+ }
+
+ printf("All available -march extensions for RISC-V:\n");
+ printf("\t%-20sVersion\n", "Name");
+ for (auto const &ext_info : all_exts)
+ {
+ printf("\t%-20s\t", ext_info.first.c_str());
+ bool first = true;
+ for (auto version : ext_info.second)
+ {
+ if (first)
+ first = false;
+ else
+ printf(", ");
+ unsigned major = version / RISCV_MAJOR_VERSION_BASE;
+ unsigned minor = (version % RISCV_MAJOR_VERSION_BASE)
+ / RISCV_MINOR_VERSION_BASE;
+ printf("%u.%u", major, minor);
+ }
+ printf("\n");
+ }
+ exit (0);
+}
+
/* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */
static const struct default_options riscv_option_optimization_table[] =
{