]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Support -misa-spec for arch-canonicalize and multilib-generator. [PR104853]
authorKito Cheng <kito.cheng@sifive.com>
Mon, 11 Apr 2022 08:29:34 +0000 (16:29 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Mon, 11 Apr 2022 15:48:21 +0000 (23:48 +0800)
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)

gcc/config.gcc
gcc/config/riscv/arch-canonicalize
gcc/config/riscv/multilib-generator

index d69be8853bc17a74185aeaf2295be0683d3c8dd6..b272518a81368271858588a65043c6597dfebe5b 100644 (file)
@@ -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
index c7df3c8a3137f992306308ab887e9244f8220fc3..3a91cfe687fec5a93674f90051cc579e13c6271f 100755 (executable)
 
 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))
index 358bda948f1d40c9350855dfbdee5db1405a7154..84a8f8008bfffeb7a99b608e8f5e9cd605bbb64b 100755 (executable)
@@ -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)