public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-2917] RISC-V: Allow multi-lib build with different code model
@ 2021-08-16  4:32 Kito Cheng
  0 siblings, 0 replies; only message in thread
From: Kito Cheng @ 2021-08-16  4:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:fdd40498d1981fde0720a0886d6f59ea5fb7ab40

commit r12-2917-gfdd40498d1981fde0720a0886d6f59ea5fb7ab40
Author: Kito Cheng <kito.cheng@sifive.com>
Date:   Tue Jul 20 10:53:18 2021 +0800

    RISC-V: Allow multi-lib build with different code model
    
    --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.

Diff:
---
 gcc/config/riscv/multilib-generator | 86 ++++++++++++++++++++++++-------------
 gcc/doc/install.texi                | 17 ++++++++
 2 files changed, 73 insertions(+), 30 deletions(-)

diff --git a/gcc/config/riscv/multilib-generator b/gcc/config/riscv/multilib-generator
index a20454374c9..358bda948f1 100755
--- a/gcc/config/riscv/multilib-generator
+++ b/gcc/config/riscv/multilib-generator
@@ -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))
diff --git a/gcc/doc/install.texi b/gcc/doc/install.texi
index 6eee1bb43d4..8e974d2952e 100644
--- a/gcc/doc/install.texi
+++ b/gcc/doc/install.texi
@@ -1328,6 +1328,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*-*-*.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-16  4:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16  4:32 [gcc r12-2917] RISC-V: Allow multi-lib build with different code model Kito Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).