From patchwork Mon Aug 5 08:20:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1142037 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506190-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="x6IW3ZT2"; dkim=pass (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="YuGWBVWd"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4629hJ4X3Wz9s3Z for ; Mon, 5 Aug 2019 18:21:02 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; q=dns; s=default; b=rL9KpNNb/kJS /cG29FY2op5iEbd2nTKebn543vCH9BNsnpSeEvKs7EL8TrK4suTkmHJSRA7ebMDT QLDRBscFb2zLOF58vPwg9wXJOWsYmSM/nmKDFu7uUPHQk/3mpoGhU3FIv6SNwi5H Bs6VDrRu/nfX13Fro3RaA+cHiZPfw7U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id; s=default; bh=TDFzCJscEuT6O4v/zR 8Q3TXky2s=; b=x6IW3ZT2SrfC7ooL/PHdmf2McgiDjQ2/8+RhYonMZqkIe7jhY6 cbhiygOdgrRrx1gb/ew42RtnWZ7leonnvnn4WrEHADPfUTT5y8ClqQlXLpd/cvSM HeWsOl8+yZuQcemHsS894g8p/2w7Meo/Uj1kzE0D5+vDWwx79iwIszWtg= Received: (qmail 67784 invoked by alias); 5 Aug 2019 08:20:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 67772 invoked by uid 89); 5 Aug 2019 08:20:55 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=alt, 36, H*r:sk:mail-pf, HX-HELO:sk:mail-pf X-HELO: mail-pf1-f170.google.com Received: from mail-pf1-f170.google.com (HELO mail-pf1-f170.google.com) (209.85.210.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Aug 2019 08:20:54 +0000 Received: by mail-pf1-f170.google.com with SMTP id t16so39219955pfe.11 for ; Mon, 05 Aug 2019 01:20:54 -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; bh=HwiC3OP5sjyJlkgWOQlkQzmTRaprpUHOe/vOmT2dln8=; b=YuGWBVWd9iRE52io4frJa7yEQsHa454boxRXj9nhpvMyF3BGkYx8cPzW/T/wODtNIf wVpbRoRNEoM03Xq/LB9b9pKDg+3ln8mGkbMcdt//7p9Lpgd0yyCHbtUuYX95EQ7qQW8H J4asVqOGasfVQ/jmnWnIi+rEfK/zXEQfdhjwQw4BKNaOkK8Ix2mS8TCP9c1C5zzqs8A/ lAFbUAmTiUYuvOdtYi+t/xMTsTekYLH0sRMz8IzDixW6BCTBaoC5pUGb2Hxwxu4nk8Ix d0ERarM2FWZs/i8f4Zf4jJF+ixBfYkHkhXNVsEvlwQbsN9JOIwua5Boh8uBuj9PLo/Jo SmOw== Received: from localhost.localdomain (220-132-236-182.HINET-IP.hinet.net. [220.132.236.182]) by smtp.gmail.com with ESMTPSA id a6sm13739953pjs.31.2019.08.05.01.20.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 05 Aug 2019 01:20:51 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jimw@sifive.com, palmer@sifive.com Cc: Kito Cheng Subject: [PATCH] RISC-V: Handle extensions combination correctly in multilib-generator. Date: Mon, 5 Aug 2019 16:20:17 +0800 Message-Id: <20190805082017.26702-1-kito.cheng@sifive.com> Input string consist of four parts: --- and generator doing combination with 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: Handle extensions combination correctly. --- gcc/config/riscv/multilib-generator | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/gcc/config/riscv/multilib-generator b/gcc/config/riscv/multilib-generator index a711153b3a3..52cef276509 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 spce. + # TODO: Support extesnion version. + new_arch = "" + if arch[:5] in ['rv32e', 'rv32i', 'rv64i']: + new_arch = arch[:5] + else: + raise Exception("Unexpect arch: `%d`" % arch[:5]) + + # Find any Z, S, H or X + long_ext_prefixs = ['z', 's', 'h', 'x'] + long_ext_prefixs_idx = map(lambda x: arch.find(x), long_ext_prefixs) + + # Filter out any non exist index. + long_ext_prefixs_idx = list(filter(lambda x: x != -1, long_ext_prefixs_idx)) + if long_ext_prefixs_idx: + first_long_ext_idx = min(long_ext_prefixs_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 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))