[gcc r11-9809] RISC-V: Support -misa-spec for arch-canonicalize and multilib-generator. [PR104853]
Kito Cheng
kito@gcc.gnu.org
Mon Apr 11 16:02:58 GMT 2022
https://gcc.gnu.org/g:fa21fcfb67587837c1704703a710496999393c1d
commit r11-9809-gfa21fcfb67587837c1704703a710496999393c1d
Author: Kito Cheng <kito.cheng@sifive.com>
Date: Mon Apr 11 16:29:34 2022 +0800
RISC-V: Support -misa-spec for arch-canonicalize and multilib-generator. [PR104853]
We migrate the default ISA spec version from 2.2 to 20191213, but those scripts
aren't updated at the same time, this patch is making both scripts support
different ISA spec versions.
gcc/ChangeLog:
PR target/104853
* config.gcc: Pass -misa-spec to arch-canonicalize and
multilib-generator.
* config/riscv/arch-canonicalize: Adding -misa-spec option.
(SUPPORTED_ISA_SPEC): New.
(arch_canonicalize): New argument `isa_spec`.
Handle multiple ISA spec versions.
* config/riscv/multilib-generator: Adding -misa-spec option.
(cherry picked from commit 4132f6ba9583e128a00d55961ae8c8e7245b2223)
Diff:
---
gcc/config.gcc | 3 ++-
gcc/config/riscv/arch-canonicalize | 51 ++++++++++++++++++++++++++++---------
gcc/config/riscv/multilib-generator | 14 +++++++---
3 files changed, 51 insertions(+), 17 deletions(-)
diff --git a/gcc/config.gcc b/gcc/config.gcc
index d69be8853bc..b272518a813 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4692,7 +4692,7 @@ case "${target}" in
esac
PYTHON=`which python || which python3 || which python2`
if test "x${PYTHON}" != x; then
- with_arch=`${PYTHON} ${srcdir}/config/riscv/arch-canonicalize ${with_arch}`
+ with_arch=`${PYTHON} ${srcdir}/config/riscv/arch-canonicalize -misa-spec=${with_isa_spec} ${with_arch}`
fi
tm_defines="${tm_defines} TARGET_RISCV_DEFAULT_ARCH=${with_arch}"
@@ -4741,6 +4741,7 @@ case "${target}" in
case "${target}" in
riscv*-*-elf*)
if ${srcdir}/config/riscv/multilib-generator \
+ -misa-spec=${with_isa_spec} \
`echo ${with_multilib_generator} | sed 's/;/ /g'`\
> t-multilib-config;
then
diff --git a/gcc/config/riscv/arch-canonicalize b/gcc/config/riscv/arch-canonicalize
index c7df3c8a313..3a91cfe687f 100755
--- a/gcc/config/riscv/arch-canonicalize
+++ b/gcc/config/riscv/arch-canonicalize
@@ -23,11 +23,12 @@
from __future__ import print_function
import sys
+import argparse
import collections
import itertools
from functools import reduce
-
+SUPPORTED_ISA_SPEC = ["2.2", "20190608", "20191213"]
CANONICAL_ORDER = "imafdgqlcbjtpvn"
LONG_EXT_PREFIXES = ['z', 's', 'h', 'x']
@@ -35,15 +36,20 @@ LONG_EXT_PREFIXES = ['z', 's', 'h', 'x']
# IMPLIED_EXT(ext) -> implied extension list.
#
IMPLIED_EXT = {
- "d" : ["f"],
+ "d" : ["f", "zicsr"],
+ "f" : ["zicsr"],
}
-def arch_canonicalize(arch):
+def arch_canonicalize(arch, isa_spec):
# TODO: Support extension version.
+ is_isa_spec_2p2 = isa_spec == '2.2'
new_arch = ""
+ extra_long_ext = []
if arch[:5] in ['rv32e', 'rv32i', 'rv32g', 'rv64i', 'rv64g']:
- # TODO: We should expand g to imad_zifencei once we support newer spec.
new_arch = arch[:5].replace("g", "imafd")
+ if arch[:5] in ['rv32g', 'rv64g']:
+ if not is_isa_spec_2p2:
+ extra_long_ext = ['zicsr', 'zifencei']
else:
raise Exception("Unexpected arch: `%s`" % arch[:5])
@@ -60,15 +66,24 @@ def arch_canonicalize(arch):
long_exts = []
std_exts = list(arch[5:])
+ long_exts += extra_long_ext
+
#
# Handle implied extensions.
#
- for ext in std_exts + long_exts:
- if ext in IMPLIED_EXT:
- implied_exts = IMPLIED_EXT[ext]
- for implied_ext in implied_exts:
- if implied_ext not in std_exts + long_exts:
- long_exts.append(implied_ext)
+ any_change = True
+ while any_change:
+ any_change = False
+ for ext in std_exts + long_exts:
+ if ext in IMPLIED_EXT:
+ implied_exts = IMPLIED_EXT[ext]
+ for implied_ext in implied_exts:
+ if implied_ext == 'zicsr' and is_isa_spec_2p2:
+ continue
+
+ if implied_ext not in std_exts + long_exts:
+ long_exts.append(implied_ext)
+ any_change = True
# Single letter extension might appear in the long_exts list,
# becasue we just append extensions list to the arch string.
@@ -85,6 +100,9 @@ def arch_canonicalize(arch):
return (exts.startswith("x"), exts.startswith("zxm"),
LONG_EXT_PREFIXES.index(exts[0]), canonical_sort, exts[1:])
+ # Removing duplicates.
+ long_exts = list(set(long_exts))
+
# Multi-letter extension must be in lexicographic order.
long_exts = list(sorted(filter(lambda x:len(x) != 1, long_exts),
key=longext_sort))
@@ -104,11 +122,20 @@ def arch_canonicalize(arch):
# Concat rest of the multi-char extensions.
if long_exts:
new_arch += "_" + "_".join(long_exts)
+
return new_arch
if len(sys.argv) < 2:
print ("Usage: %s <arch_str> [<arch_str>*]" % sys.argv)
sys.exit(1)
-for arg in sys.argv[1:]:
- print (arch_canonicalize(arg))
+parser = argparse.ArgumentParser()
+parser.add_argument('-misa-spec', type=str,
+ default='20191213',
+ choices=SUPPORTED_ISA_SPEC)
+parser.add_argument('arch_strs', nargs=argparse.REMAINDER)
+
+args = parser.parse_args()
+
+for arch in args.arch_strs:
+ print (arch_canonicalize(arch, args.misa_spec))
diff --git a/gcc/config/riscv/multilib-generator b/gcc/config/riscv/multilib-generator
index 358bda948f1..84a8f8008bf 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -46,16 +46,18 @@ import argparse
# TODO: Add test for this script.
#
+SUPPORTED_ISA_SPEC = ["2.2", "20190608", "20191213"]
arches = collections.OrderedDict()
abis = collections.OrderedDict()
required = []
reuse = []
-def arch_canonicalize(arch):
+def arch_canonicalize(arch, isa_spec):
this_file = os.path.abspath(os.path.join( __file__))
arch_can_script = \
os.path.join(os.path.dirname(this_file), "arch-canonicalize")
- proc = subprocess.Popen([sys.executable, arch_can_script, arch],
+ proc = subprocess.Popen([sys.executable, arch_can_script,
+ '-misa-spec=%s' % isa_spec, arch],
stdout=subprocess.PIPE)
out, err = proc.communicate()
return out.decode().strip()
@@ -133,6 +135,9 @@ options = filter(lambda x:x.startswith("--"), sys.argv[1:])
parser = argparse.ArgumentParser()
parser.add_argument("--cmodel", type=str)
+parser.add_argument('-misa-spec', type=str,
+ default='20191213',
+ choices=SUPPORTED_ISA_SPEC)
parser.add_argument("cfgs", type=str, nargs='*')
args = parser.parse_args()
@@ -158,13 +163,14 @@ for cmodel in cmodels:
if cmodel == "compact" and arch.startswith("rv32"):
continue
- arch = arch_canonicalize (arch)
+ arch = arch_canonicalize (arch, args.misa_spec)
arches[arch] = 1
abis[abi] = 1
extra = list(filter(None, extra.split(',')))
ext_combs = expand_combination(ext)
alts = sum([[x] + [x + y for y in ext_combs] for x in [arch] + extra], [])
- alts = list(map(arch_canonicalize, alts))
+ alts = filter(lambda x: len(x) != 0, alts)
+ alts = list(map(lambda a : arch_canonicalize(a, args.misa_spec), alts))
# Drop duplicated entry.
alts = unique(alts)
More information about the Gcc-cvs
mailing list