aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKito Cheng <kito.cheng@sifive.com>2019-08-06 03:16:40 +0000
committerKito Cheng <kito@gcc.gnu.org>2019-08-06 03:16:40 +0000
commit7551a6e467c64b3155d5b8f005cd7ea7143b21f3 (patch)
treeec027587fbbaeeab5c1cdfa487be2f7580080228 /gcc
parentc026e33449102076609e084ca2cd4a729b3c504b (diff)
downloadgcc-7551a6e467c64b3155d5b8f005cd7ea7143b21f3.zip
gcc-7551a6e467c64b3155d5b8f005cd7ea7143b21f3.tar.gz
gcc-7551a6e467c64b3155d5b8f005cd7ea7143b21f3.tar.bz2
RISC-V: Handle extensions combination correctly in multilib-generator.
Input string consist of four parts: <primary arch>-<abi>-<additional arches>-<extensions> and generator doing combination with <extensions> part, but it just append the extension at the end of arch string, it might generate invalid arch. For example, without this patch `./multilib-generator rv32imafc-ilp32--d` will generate: MULTILIB_OPTIONS = march=rv32imafc/march=rv32imafcd mabi=ilp32 ^^^^^^^^^^ and rv32imafcd is not in canonical order. Tested with python 2.7 and python 3.6/3.7. gcc/ChangeLog * gcc/config/riscv/multilib-generator: (canonical_order): New. (arch_canonicalize): Dito. Apply arch_canonicalize for alts. From-SVN: r274137
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rwxr-xr-xgcc/config/riscv/multilib-generator37
2 files changed, 43 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 2d18fe3..f19091c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2019-08-06 Kito Cheng <kito.cheng@sifive.com>
+
+ * gcc/config/riscv/multilib-generator: (canonical_order): New.
+ (arch_canonicalize): Dito.
+ Apply arch_canonicalize for alts.
+
2019-08-05 Martin Sebor <msebor@redhat.com>
* doc/extend.texi (Common Variable Attributes): Document alias
diff --git a/gcc/config/riscv/multilib-generator b/gcc/config/riscv/multilib-generator
index a711153..e58231c 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -36,6 +36,41 @@ abis = collections.OrderedDict()
required = []
reuse = []
+canonical_order = "mafdqlcbjtpvn"
+
+def arch_canonicalize(arch):
+ # TODO: Support Z, S, H, or X extensions.
+ # TODO: Support implied extensions, e.g. D implied F in latest spec.
+ # TODO: Support extension version.
+ new_arch = ""
+ if arch[:5] in ['rv32e', 'rv32i', 'rv64i']:
+ new_arch = arch[:5]
+ else:
+ raise Exception("Unexpected arch: `%d`" % arch[:5])
+
+ # Find any Z, S, H or X
+ long_ext_prefixes = ['z', 's', 'h', 'x']
+ long_ext_prefixes_idx = map(lambda x: arch.find(x), long_ext_prefixes)
+
+ # Filter out any non-existent index.
+ long_ext_prefixes_idx = list(filter(lambda x: x != -1, long_ext_prefixes_idx))
+ if long_ext_prefixes_idx:
+ first_long_ext_idx = min(long_ext_prefixes_idx)
+ long_exts = arch[first_long_ext_idx:]
+ std_exts = arch[5:first_long_ext_idx]
+ else:
+ long_exts = ""
+ std_exts = arch[5:]
+
+ # Put extensions in canonical order.
+ for ext in canonical_order:
+ if ext in std_exts:
+ new_arch += ext
+
+ # Concat rest of the multi-char extensions.
+ new_arch += long_exts
+ return new_arch
+
for cfg in sys.argv[1:]:
(arch, abi, extra, ext) = cfg.split('-')
arches[arch] = 1
@@ -43,7 +78,9 @@ for cfg in sys.argv[1:]:
extra = list(filter(None, extra.split(',')))
ext = list(filter(None, ext.split(',')))
alts = sum([[x] + [x + y for y in ext] for x in [arch] + extra], [])
+ # TODO: We should expand g to imadzifencei once we support newer spec.
alts = alts + [x.replace('imafd', 'g') for x in alts if 'imafd' in x]
+ alts = list(map(arch_canonicalize, alts))
for alt in alts[1:]:
arches[alt] = 1
reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt, abi))