diff options
author | Martin Liska <mliska@suse.cz> | 2022-09-05 10:44:56 +0200 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2022-09-05 10:44:56 +0200 |
commit | d8e441f4b8698f38e4564fe1bbe9ff112814ecff (patch) | |
tree | 62aac45da0a2358e1ea29a07ab734f607a201e5b /gcc/common | |
parent | 4483fe115cef3eea1d64e913816e2d117b38ac73 (diff) | |
parent | ca60bd93e216ae0425f790e1d4f4dc4a48763c0e (diff) | |
download | gcc-d8e441f4b8698f38e4564fe1bbe9ff112814ecff.zip gcc-d8e441f4b8698f38e4564fe1bbe9ff112814ecff.tar.gz gcc-d8e441f4b8698f38e4564fe1bbe9ff112814ecff.tar.bz2 |
Merge branch 'master' into devel/sphinx
Diffstat (limited to 'gcc/common')
-rw-r--r-- | gcc/common/common-target.def | 25 | ||||
-rw-r--r-- | gcc/common/common-targhooks.cc | 15 | ||||
-rw-r--r-- | gcc/common/common-targhooks.h | 11 | ||||
-rw-r--r-- | gcc/common/config/cr16/cr16-common.cc | 27 | ||||
-rw-r--r-- | gcc/common/config/riscv/riscv-common.cc | 377 | ||||
-rw-r--r-- | gcc/common/config/s390/s390-common.cc | 5 |
6 files changed, 433 insertions, 27 deletions
diff --git a/gcc/common/common-target.def b/gcc/common/common-target.def index c4d1144..c4c6230 100644 --- a/gcc/common/common-target.def +++ b/gcc/common/common-target.def @@ -84,6 +84,31 @@ The result will be pruned to cases with PREFIX if not NULL.", vec<const char *>, (int option_code, const char *prefix), default_get_valid_option_values) +DEFHOOK +(compute_multilib, + "Some targets like RISC-V might have complicated multilib reuse rules which\n\ +are hard to implement with the current multilib scheme. This hook allows\n\ +targets to override the result from the built-in multilib mechanism.\n\ +@var{switches} is the raw option list with @var{n_switches} items;\n\ +@var{multilib_dir} is the multi-lib result which is computed by the built-in\n\ +multi-lib mechanism;\n\ +@var{multilib_defaults} is the default options list for multi-lib;\n\ +@var{multilib_select} is the string containing the list of supported\n\ +multi-libs, and the option checking list.\n\ +@var{multilib_matches}, @var{multilib_exclusions}, and @var{multilib_reuse}\n\ +are corresponding to @var{MULTILIB_MATCHES}, @var{MULTILIB_EXCLUSIONS},\n\ +and @var{MULTILIB_REUSE}.\n\ +The default definition does nothing but return @var{multilib_dir} directly.", + const char *, (const struct switchstr *switches, + int n_switches, + const char *multilib_dir, + const char *multilib_defaults, + const char *multilib_select, + const char *multilib_matches, + const char *multilib_exclusions, + const char *multilib_reuse), + default_compute_multilib) + /* Leave the boolean fields at the end. */ /* True if unwinding tables should be generated by default. */ diff --git a/gcc/common/common-targhooks.cc b/gcc/common/common-targhooks.cc index 46f5c61..7499be2 100644 --- a/gcc/common/common-targhooks.cc +++ b/gcc/common/common-targhooks.cc @@ -90,3 +90,18 @@ const struct default_options empty_optimization_table[] = { { OPT_LEVELS_NONE, 0, NULL, 0 } }; + +/* Default version of TARGET_COMPUTE_MULTILIB. */ +const char * +default_compute_multilib( + const struct switchstr *, + int, + const char *multilib, + const char *, + const char *, + const char *, + const char *, + const char *) +{ + return multilib; +} diff --git a/gcc/common/common-targhooks.h b/gcc/common/common-targhooks.h index cd49c7d..1f03495 100644 --- a/gcc/common/common-targhooks.h +++ b/gcc/common/common-targhooks.h @@ -32,4 +32,15 @@ extern vec<const char *> default_get_valid_option_values (int, const char *); extern const struct default_options empty_optimization_table[]; +const char * +default_compute_multilib( + const struct switchstr *, + int, + const char *multilib, + const char *, + const char *, + const char *, + const char *, + const char *); + #endif diff --git a/gcc/common/config/cr16/cr16-common.cc b/gcc/common/config/cr16/cr16-common.cc deleted file mode 100644 index 6d0b2be..0000000 --- a/gcc/common/config/cr16/cr16-common.cc +++ /dev/null @@ -1,27 +0,0 @@ -/* Common hooks for CR16. - Copyright (C) 2012-2022 Free Software Foundation, Inc. - - This file is part of GCC. - - GCC is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - GCC is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with GCC; see the file COPYING3. If not see - <http://www.gnu.org/licenses/>. */ - -#include "config.h" -#include "system.h" -#include "coretypes.h" -#include "tm.h" -#include "common/common-target.h" -#include "common/common-target-def.h" - -struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER; diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index 4ee1b31..cb3a5d2 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -18,6 +18,7 @@ along with GCC; see the file COPYING3. If not see <http://www.gnu.org/licenses/>. */ #include <sstream> +#include <vector> #define INCLUDE_STRING #include "config.h" @@ -230,6 +231,26 @@ const riscv_subset_list *riscv_current_subset_list () return current_subset_list; } +/* struct for recording multi-lib info. */ +struct riscv_multi_lib_info_t { + std::string path; + std::string arch_str; + std::string abi_str; + std::vector<std::string> conds; + riscv_subset_list *subset_list; + + static bool parse (struct riscv_multi_lib_info_t *, + const std::string &, + const std::vector<std::string> &); +}; + +/* Flag for checking if there is no suitable multi-lib found. */ +static bool riscv_no_matched_multi_lib; + +/* Used for record value of -march and -mabi. */ +static std::string riscv_current_arch_str; +static std::string riscv_current_abi_str; + riscv_subset_t::riscv_subset_t () : name (), major_version (0), minor_version (0), next (NULL), explicit_version_p (false), implied_p (false) @@ -255,6 +276,42 @@ riscv_subset_list::~riscv_subset_list () } } +/* Compute the match score of two arch string, return 0 if incompatible. */ +int +riscv_subset_list::match_score (riscv_subset_list *list) const +{ + riscv_subset_t *s; + int score = 0; + bool has_a_ext, list_has_a_ext; + + /* Impossible to match if XLEN is different. */ + if (list->m_xlen != this->m_xlen) + return 0; + + /* There is different code gen in libstdc++ and libatomic between w/ A-ext + and w/o A-ext, and it not work if using soft and hard atomic mechanism + at same time, so they are incompatible. */ + has_a_ext = this->lookup ("a") != NULL; + list_has_a_ext = list->lookup ("a") != NULL; + + if (has_a_ext != list_has_a_ext) + return 0; + + + /* list must be subset of current this list, otherwise it not safe to + link. + TODO: We might give different weight for each extension, but the rule could + be complicated. + TODO: We might consider the version of each extension. */ + for (s = list->m_head; s != NULL; s = s->next) + if (this->lookup (s->name.c_str ()) != NULL) + score++; + else + return 0; + + return score; +} + /* Get the rank for single-letter subsets, lower value meaning higher priority. */ @@ -1305,6 +1362,326 @@ riscv_expand_arch_from_cpu (int argc ATTRIBUTE_UNUSED, return xasprintf ("-march=%s", arch.c_str()); } +/* Find last switch with the prefix, options are take last one in general, + return NULL if not found, and return the option value if found, it could + return empty string if the option has no value. */ + +static const char * +find_last_appear_switch ( + const struct switchstr *switches, + int n_switches, + const char *prefix) +{ + int i; + size_t len = strlen (prefix); + + for (i = 0; i < n_switches; ++i) + { + const struct switchstr *this_switch = &switches[n_switches - i - 1]; + + if (this_switch->live_cond & SWITCH_FALSE) + continue; + + if (strncmp (this_switch->part1, prefix, len) == 0) + return this_switch->part1 + len; + } + + return NULL; +} + +/* Utils functions to check STR is start with PREFIX or not. */ + +static bool +prefixed_with (const std::string &str, const char *prefix) +{ + return strncmp (prefix, str.c_str (), strlen (prefix)) == 0; +} + +/* Parse the path and cond string into riscv_multi_lib_info_t, return false + if parsing failed. */ + +bool +riscv_multi_lib_info_t::parse ( + struct riscv_multi_lib_info_t *multi_lib_info, + const std::string &path, + const std::vector<std::string> &conds) +{ + const char *default_arch_str = STRINGIZING (TARGET_RISCV_DEFAULT_ARCH); + const char *default_abi_str = STRINGIZING (TARGET_RISCV_DEFAULT_ABI); + multi_lib_info->conds = conds; + if (path == ".") + { + multi_lib_info->arch_str = default_arch_str; + multi_lib_info->abi_str = default_abi_str; + } + else + { + std::vector<std::string>::const_iterator itr; + for (itr = conds.begin (); itr != conds.end (); ++itr) + if (prefixed_with (*itr, "march=")) + multi_lib_info->arch_str = itr->c_str () + strlen ("march="); + else if (prefixed_with (*itr, "mabi=")) + multi_lib_info->abi_str = itr->c_str () + strlen ("mabi="); + + /* Skip this multi-lib if this configuration is exactly same as + default multi-lib settings. */ + if (multi_lib_info->arch_str == default_arch_str + && multi_lib_info->abi_str == default_abi_str) + return false; + } + + multi_lib_info->subset_list = + riscv_subset_list::parse (multi_lib_info->arch_str.c_str (), input_location); + + return true; +} + +/* Report error if not found suitable multilib. */ +const char * +riscv_multi_lib_check (int argc ATTRIBUTE_UNUSED, + const char **argv ATTRIBUTE_UNUSED) +{ + if (riscv_no_matched_multi_lib) + fatal_error ( + input_location, + "Can't find suitable multilib set for %<-march=%s%>/%<-mabi=%s%>", + riscv_current_arch_str.c_str (), + riscv_current_abi_str.c_str ()); + + return ""; +} + +/* Checking ARG is not appeared in SWITCHES if NOT_ARG is set or + ARG is appeared if NOT_ARG is not set. */ + +static bool +riscv_check_cond ( + const struct switchstr *switches, + int n_switches, + const std::string &arg, + bool not_arg) +{ + int i; + for (i = 0; i < n_switches; ++i) + { + const struct switchstr *this_switch = &switches[n_switches - i - 1]; + + if ((this_switch->live_cond & SWITCH_IGNORE) != 0) + continue; + + if (this_switch->live_cond & SWITCH_FALSE) + continue; + + /* ARG should not appear if NOT_ARG is set. */ + if (arg == this_switch->part1) + return not_arg ? false : true; + } + + /* Not found ARG? that's ok if NOT_ARG is not set. */ + return not_arg ? true : false; +} + +/* Check the other cond is found or not, return -1 if we should reject this + multi-lib option set, otherwise return updated MATCH_SCORE. */ + +static int +riscv_check_conds ( + const struct switchstr *switches, + int n_switches, + int match_score, + const std::vector<std::string> &conds) +{ + bool not_arg; + bool ok; + int ok_count = 0; + std::vector<std::string>::const_iterator itr; + const char *checking_arg; + + if (match_score == 0) + return 0; + + for (itr = conds.begin (); itr != conds.end (); ++itr) + { + /* We'll check march= and mabi= in ohter place. */ + if (prefixed_with (*itr, "march=") || prefixed_with (*itr, "mabi=")) + continue; + + checking_arg = itr->c_str (); + if (checking_arg[0] == '!') + { + not_arg = true; + /* Skip '!'. */ + checking_arg = checking_arg + 1; + } + else + not_arg = false; + + ok = riscv_check_cond (switches, n_switches, checking_arg, not_arg); + + if (!ok) + return -1; + + ok_count++; + } + + /* 100 is magic number, it's just used for make sure this multi-lib has + higher priority if we found any some option is listed in the option check + list. */ + return match_score + ok_count * 100; +} + +/* We only override this in bare-metal toolchain. */ +#ifdef RISCV_USE_CUSTOMISED_MULTI_LIB + +/* Implement TARGET_COMPUTE_MULTILIB. */ +static const char * +riscv_compute_multilib ( + const struct switchstr *switches, + int n_switches, + const char *multilib_dir, + const char *multilib_defaults ATTRIBUTE_UNUSED, + const char *multilib_select, + const char *multilib_matches ATTRIBUTE_UNUSED, + const char *multilib_exclusions ATTRIBUTE_UNUSED, + const char *multilib_reuse ATTRIBUTE_UNUSED) +{ + const char *p; + const char *this_path; + size_t this_path_len; + bool result; + riscv_no_matched_multi_lib = false; + riscv_subset_list *subset_list = NULL; + + std::vector<riscv_multi_lib_info_t> multilib_infos; + std::vector<std::string> option_conds; + std::string option_cond; + riscv_multi_lib_info_t multilib_info; + + /* Already found suitable, multi-lib, just use that. */ + if (multilib_dir != NULL) + return multilib_dir; + + /* Find march. */ + riscv_current_arch_str = + find_last_appear_switch (switches, n_switches, "march="); + /* Find mabi. */ + riscv_current_abi_str = + find_last_appear_switch (switches, n_switches, "mabi="); + + /* Failed to find -march or -mabi, but it should not happened since we have + set both in OPTION_DEFAULT_SPECS. */ + if (riscv_current_arch_str.empty () || riscv_current_abi_str.empty ()) + return multilib_dir; + + subset_list = riscv_subset_list::parse (riscv_current_arch_str.c_str (), + input_location); + + /* Failed to parse -march, fallback to using what gcc use. */ + if (subset_list == NULL) + return multilib_dir; + + /* Parsing MULTILIB_SELECT, ignore MULTILIB_REUSE here, we have our own rules. + TODO: most codes are grab from gcc.c, maybe we should refine that? */ + p = multilib_select; + + while (*p != '\0') + { + /* Ignore newlines. */ + if (*p == '\n') + { + ++p; + continue; + } + + /* Format of each multilib: + <path> <opt1> <opt2> ... <optN>; */ + /* Get the path. */ + this_path = p; + while (*p != ' ') + { + if (*p == '\0') + { + fatal_error (input_location, "multilib select %qs %qs is invalid", + multilib_select, multilib_reuse); + } + ++p; + } + + this_path_len = p - this_path; + multilib_info.path = std::string (this_path, this_path_len); + + option_conds.clear (); + /* Pasrse option check list into vector<string>. + e.g. "march=rv64imafd mabi=lp64 !mcmodel=medany" to + ["march=rv64imafd", "mabi=lp64", "!mcmodel=medany"]. */ + while (*p != ';') + { + option_cond = ""; + /* Skip space. */ + while (*p == ' ') p++; + + while (*p && *p != ' ' && *p != ';') + option_cond.push_back (*p++); + + /* Ignore `!march=` and `!mabi=`, we will handle march and mabi + later. */ + if (option_cond.size () + && !prefixed_with (option_cond, "!march=") + && !prefixed_with (option_cond, "!mabi=")) + option_conds.push_back (option_cond); + } + + result = + riscv_multi_lib_info_t::parse ( + &multilib_info, + std::string (this_path, this_path_len), + option_conds); + + if (result) + multilib_infos.push_back (multilib_info); + + p++; + } + + int match_score = 0; + int max_match_score = 0; + int best_match_multi_lib = -1; + /* Try to decision which set we should used. */ + /* We have 3 level decision tree here, ABI, check input arch/ABI must + be superset of multi-lib arch, and other rest option checking. */ + for (size_t i = 0; i < multilib_infos.size (); ++i) + { + /* Check ABI is same first. */ + if (riscv_current_abi_str != multilib_infos[i].abi_str) + continue; + + /* Found a potential compatible multi-lib setting! + Calculate the match score. */ + match_score = subset_list->match_score (multilib_infos[i].subset_list); + + /* Checking other cond in the multi-lib setting. */ + match_score = riscv_check_conds (switches, + n_switches, + match_score, + multilib_infos[i].conds); + + /* Record highest match score multi-lib setting. */ + if (match_score > max_match_score) + best_match_multi_lib = i; + } + + if (best_match_multi_lib == -1) + { + riscv_no_matched_multi_lib = true; + return multilib_dir; + } + else + return xstrdup (multilib_infos[best_match_multi_lib].path.c_str ()); +} + +#undef TARGET_COMPUTE_MULTILIB +#define TARGET_COMPUTE_MULTILIB riscv_compute_multilib +#endif /* Implement TARGET_OPTION_OPTIMIZATION_TABLE. */ static const struct default_options riscv_option_optimization_table[] = diff --git a/gcc/common/config/s390/s390-common.cc b/gcc/common/config/s390/s390-common.cc index 72a5ef4..be3e6f2 100644 --- a/gcc/common/config/s390/s390-common.cc +++ b/gcc/common/config/s390/s390-common.cc @@ -64,6 +64,11 @@ static const struct default_options s390_option_optimization_table[] = /* Enable -fsched-pressure by default when optimizing. */ { OPT_LEVELS_1_PLUS, OPT_fsched_pressure, NULL, 1 }, + /* Enable -munroll-only-small-loops with -funroll-loops to unroll small + loops at -O2 and above by default. */ + { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_funroll_loops, NULL, 1 }, + { OPT_LEVELS_2_PLUS_SPEED_ONLY, OPT_munroll_only_small_loops, NULL, 1 }, + /* ??? There are apparently still problems with -fcaller-saves. */ { OPT_LEVELS_ALL, OPT_fcaller_saves, NULL, 0 }, |