]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Allow multi-lib build with different code model
authorKito Cheng <kito.cheng@sifive.com>
Tue, 20 Jul 2021 02:53:18 +0000 (10:53 +0800)
committerKito Cheng <kito.cheng@sifive.com>
Mon, 11 Apr 2022 15:47:28 +0000 (23:47 +0800)
--with-multilib-generator was only support for different ISA/ABI
combination, however code model is effect the code gen a lots it
should able to handled in multilib mechanism.

Adding `--cmodel=` option to `--with-multilib-generator` to generating
multilib combination with different code model.

E.g.
--with-multilib-generator="rv64ima-lp64--;--cmodel=medlow,medany"
will generate 3 multi-lib suppport:
1) rv64ima with lp64
2) rv64ima with lp64 and medlow code model
3) rv64ima with lp64 and medany code model

gcc/

* config/riscv/multilib-generator: Support code model option for
multi-lib.
* doc/install.texi: Add document of new option for
--with-multilib-generator.

(cherry picked from commit fdd40498d1981fde0720a0886d6f59ea5fb7ab40)

gcc/config/riscv/multilib-generator
gcc/doc/install.texi

index a20454374c96da021773f3c43aaf962516d2e6e6..358bda948f1d40c9350855dfbdee5db1405a7154 100755 (executable)
@@ -40,6 +40,7 @@ import collections
 import itertools
 from functools import reduce
 import subprocess
+import argparse
 
 #
 # TODO: Add test for this script.
@@ -127,44 +128,69 @@ def expand_combination(ext):
 
   return ext
 
-for cfg in sys.argv[1:]:
-  try:
-    (arch, abi, extra, ext) = cfg.split('-')
-  except:
-    print ("Invalid configure string %s, <arch>-<abi>-<extra>-<extensions>\n"
-           "<extra> and <extensions> can be empty, "
-           "e.g. rv32imafd-ilp32--" % cfg)
-    sys.exit(1)
-
-  arch = arch_canonicalize (arch)
-  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))
+multilib_cfgs = filter(lambda x:not x.startswith("--"), sys.argv[1:])
+options = filter(lambda x:x.startswith("--"), sys.argv[1:])
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--cmodel", type=str)
+parser.add_argument("cfgs", type=str, nargs='*')
+args = parser.parse_args()
+
+if args.cmodel:
+  cmodels = [None] + args.cmodel.split(",")
+else:
+  cmodels = [None]
+
+cmodel_options = '/'.join(['mcmodel=%s' % x for x in cmodels[1:]])
+cmodel_dirnames = ' \\\n'.join(cmodels[1:])
+
+for cmodel in cmodels:
+  for cfg in args.cfgs:
+    try:
+      (arch, abi, extra, ext) = cfg.split('-')
+    except:
+      print ("Invalid configure string %s, <arch>-<abi>-<extra>-<extensions>\n"
+             "<extra> and <extensions> can be empty, "
+             "e.g. rv32imafd-ilp32--" % cfg)
+      sys.exit(1)
+
+    # Compact code model only support rv64.
+    if cmodel == "compact" and arch.startswith("rv32"):
+      continue
 
-  # Drop duplicated entry.
-  alts = unique(alts)
+    arch = arch_canonicalize (arch)
+    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))
 
-  for alt in alts:
-    if alt == arch:
-      continue
-    arches[alt] = 1
-    reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt, abi))
-  required.append('march=%s/mabi=%s' % (arch, abi))
+    # Drop duplicated entry.
+    alts = unique(alts)
+
+    for alt in alts[1:]:
+      if alt == arch:
+        continue
+      arches[alt] = 1
+      reuse.append('march.%s/mabi.%s=march.%s/mabi.%s' % (arch, abi, alt, abi))
+
+    if cmodel:
+      required.append('march=%s/mabi=%s/mcmodel=%s' % (arch, abi, cmodel))
+    else:
+      required.append('march=%s/mabi=%s' % (arch, abi))
 
-arch_options = '/'.join(['march=%s' % x for x in arches.keys()])
-arch_dirnames = ' \\\n'.join(arches.keys())
+  arch_options = '/'.join(['march=%s' % x for x in arches.keys()])
+  arch_dirnames = ' \\\n'.join(arches.keys())
 
-abi_options = '/'.join(['mabi=%s' % x for x in abis.keys()])
-abi_dirnames = ' \\\n'.join(abis.keys())
+  abi_options = '/'.join(['mabi=%s' % x for x in abis.keys()])
+  abi_dirnames = ' \\\n'.join(abis.keys())
 
 prog = sys.argv[0].split('/')[-1]
 print('# This file was generated by %s with the command:' % prog)
 print('#  %s' % ' '.join(sys.argv))
 
-print('MULTILIB_OPTIONS = %s %s' % (arch_options, abi_options))
-print('MULTILIB_DIRNAMES = %s %s' % (arch_dirnames, abi_dirnames))
+print('MULTILIB_OPTIONS = %s %s %s' % (arch_options, abi_options, cmodel_options))
+print('MULTILIB_DIRNAMES = %s %s %s' % (arch_dirnames, abi_dirnames, cmodel_dirnames))
 print('MULTILIB_REQUIRED = %s' % ' \\\n'.join(required))
 print('MULTILIB_REUSE = %s' % ' \\\n'.join(reuse))
index 4c38244ae5899258c920615de966819cc95646bf..7a9e041d2ce7bfe654ce702cf32ca70b2b9a4efd 100644 (file)
@@ -1286,6 +1286,23 @@ rv64imac with lp64 and rv64imafc with lp64 will reuse this multi-lib set.
 rv64ima-lp64--f,c,fc
 @end smallexample
 
+@option{--with-multilib-generator} have an optional configuration argument
+@option{--cmodel=val} for code model, this option will expand with other
+config options, @var{val} is a comma separated list of possible code model,
+currently we support medlow and medany.
+
+Example 5: Add multi-lib suppport for rv64ima with lp64; rv64ima with lp64 and
+medlow code model
+@smallexample
+rv64ima-lp64--;--cmodel=medlow
+@end smallexample
+
+Example 6: Add multi-lib suppport for rv64ima with lp64; rv64ima with lp64 and
+medlow code model; rv64ima with lp64 and medany code model
+@smallexample
+rv64ima-lp64--;--cmodel=medlow,medany
+@end smallexample
+
 @item --with-endian=@var{endians}
 Specify what endians to use.
 Currently only implemented for sh*-*-*.