From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2093) id 7775B384C810; Mon, 16 Aug 2021 04:32:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7775B384C810 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Kito Cheng To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-2917] RISC-V: Allow multi-lib build with different code model X-Act-Checkin: gcc X-Git-Author: Kito Cheng X-Git-Refname: refs/heads/master X-Git-Oldrev: 94974e8b580919ded10c3e73348d7af68e74736a X-Git-Newrev: fdd40498d1981fde0720a0886d6f59ea5fb7ab40 Message-Id: <20210816043222.7775B384C810@sourceware.org> Date: Mon, 16 Aug 2021 04:32:22 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Aug 2021 04:32:22 -0000 https://gcc.gnu.org/g:fdd40498d1981fde0720a0886d6f59ea5fb7ab40 commit r12-2917-gfdd40498d1981fde0720a0886d6f59ea5fb7ab40 Author: Kito Cheng 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, ---\n" - " and 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, ---\n" + " and 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*-*-*.