From patchwork Mon Apr 11 15:36:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1615819 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=dpOsV1Ct; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KcXzf65Q8z9sBJ for ; Tue, 12 Apr 2022 01:37:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 216223851450 for ; Mon, 11 Apr 2022 15:37:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id EA7EB3855B87 for ; Mon, 11 Apr 2022 15:37:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EA7EB3855B87 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pl1-x62e.google.com with SMTP id j8so14155790pll.11 for ; Mon, 11 Apr 2022 08:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zLKIL/FlbHh/1djAOECwa9v2Js7sjeRsQqF2RVOS6zE=; b=dpOsV1CtawPUKvdFvMlCYGgM8qaGPjMbz6OHmrM2OI2m4hNavzMH2Dcp5vKmXufVnT eSwRpVj7mFVTQB4VB2i0qAsUYvngD2BxbDgfPD869omq2h9SSqZw43U0yRbwC3o/3hMM CLmCCpxf2hB7o8W1QBQx1sZts88KjWrt2uRv/JanLULDMAr775JXLXfFmoDpuQIJ0hfP Bb1R9ERujh8ljJUvozKW61HeKAvNHMYbLSYDdC6VuV+FO5QovdQSQk0I/NLy3enszAZw SuF/LgFIyL/dR5NwJUba+YrlL799SwMyUvg3GNbeJrHStVldFbFa3A4fe4qLKm/gLuzU BNsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zLKIL/FlbHh/1djAOECwa9v2Js7sjeRsQqF2RVOS6zE=; b=ZUUpuF84iAx6ThfF9Yiv3U9D0a6/ThEVGb//XZAShYZcdW/VI3WsTcgK6kPfBE5Klr MdWNZt+XhgCEYBt+OqqgCLqyGFgw/ZewhZswnAPQFdFjMlCS8joAlUTNV3duka5ITu6d JBhXQ/EzHA4Ky/CpcwKqN0gvxxy59InWivPTfU/TxEjPeb2CTF19q3oisOzH8kekBtim LAjReMJLarpy4lkuB38yHxAHN05yNIvZEbdevNKVI5H0Y+4BRcb++vi4Vg7zXz72BeyB Qdp7yBj7WOJPFeBDNgZ4vFCIuSrpxIoZvq+rhLP44OUZCTD+9hm6TmkMzK6Nh2cWX6Jt yW+g== X-Gm-Message-State: AOAM531eicJVe0twGi/mk8Re2RDZPEPJrmHpv3GO4VpOTRSE0kF1gYQG Tt1wlfOrwthirVQ85fpv2mXVZBWrRrPToQ== X-Google-Smtp-Source: ABdhPJzxd+FOURQrgEMgMKmuv6EG2mIedYMUCBQH21yH+VmdfR2vA+dlrZRWdPM+HSy3XTY1shji9g== X-Received: by 2002:a17:902:c451:b0:158:7729:f240 with SMTP id m17-20020a170902c45100b001587729f240mr2285641plm.17.1649691423547; Mon, 11 Apr 2022 08:37:03 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id w23-20020a17090a029700b001cbaff492f2sm1608782pja.30.2022.04.11.08.37.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Apr 2022 08:37:03 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jim.wilson.gcc@gmail.com Subject: [committed] RISC-V: Support -misa-spec for arch-canonicalize and multilib-generator. [PR104853] Date: Mon, 11 Apr 2022 23:36:59 +0800 Message-Id: <20220411153659.100224-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.34.0 MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kito Cheng Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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. --- gcc/config.gcc | 3 ++- gcc/config/riscv/arch-canonicalize | 32 ++++++++++++++++++++++++----- gcc/config/riscv/multilib-generator | 14 +++++++++---- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/gcc/config.gcc b/gcc/config.gcc index 5382788e267..48a5bbcf787 100644 --- a/gcc/config.gcc +++ b/gcc/config.gcc @@ -4717,7 +4717,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}" @@ -4766,6 +4766,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 diff --git a/gcc/config/riscv/arch-canonicalize b/gcc/config/riscv/arch-canonicalize index 73589af608e..f36a2ca4593 100755 --- a/gcc/config/riscv/arch-canonicalize +++ b/gcc/config/riscv/arch-canonicalize @@ -26,11 +26,12 @@ 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 = "imafdgqlcbjktpvn" LONG_EXT_PREFIXES = ['z', 's', 'h', 'x'] @@ -64,12 +65,16 @@ IMPLIED_EXT = { "zvl65536b" : ["zvl32768b"], } -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]) @@ -86,6 +91,8 @@ def arch_canonicalize(arch): long_exts = [] std_exts = list(arch[5:]) + long_exts += extra_long_ext + # # Handle implied extensions. # @@ -96,6 +103,9 @@ def arch_canonicalize(arch): 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 @@ -115,6 +125,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)) @@ -134,11 +147,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 [*]" % 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)) diff --git a/gcc/config/riscv/multilib-generator b/gcc/config/riscv/multilib-generator index 1ea2fb25566..36698d48f56 100755 --- a/gcc/config/riscv/multilib-generator +++ b/gcc/config/riscv/multilib-generator @@ -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)