From patchwork Fri Sep 30 02:05:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp271922wrs; Thu, 29 Sep 2022 19:06:09 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Nnf08YTCBrMOUK4lGtdLddJePNrOJXM9gusTCJfqZNypSVM9uL5w1rVmGneQSIoIhrU2l X-Received: by 2002:a17:907:b04:b0:780:32ea:4fe with SMTP id h4-20020a1709070b0400b0078032ea04femr4860977ejl.452.1664503569016; Thu, 29 Sep 2022 19:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664503569; cv=none; d=google.com; s=arc-20160816; b=Od7WSh3TX2bqEjG6iMACLTW805Ms1B04B3eIW0sQ/5GXWm3zlXBO/7H+9UtiUlzG7q MoYEIAwClGxxZGiUE7voy25fP4iqYFxU6SnG8Nfmy4rlObcgiD9M2s2ClO9VWxkoWkcI 1JYTL1J3+SQ5w4xCZXX1Vrhn9P2Vo2/WhT8BXoEPEDdbMmSRz0jM5u5cP+130x+xC9nP /0OyTY+fWVHq3FpCUPiNLSAkmDY8jlwx3EOAo84MUHjVC9UO1eKeik/oyzSXFA0KLz9x Sciq4VTkwUZP8cnssWCpOKDG/jARa7Qc80tT7gInmLysm3Z8iz6Qrhc/nL/JXnI7/yqZ PXNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=D8g0zS4SGcNPRulvihyx2cTqza+2GxOUSKny1Q4cH14=; b=MiQ1JeW8VhU7DmaQN8XN9PFHvCl+nVJaKEYGC7aOQafhphrNeR8vqb0FzGW4Ct3ZXu PKFT+HfrBfEF//a4uF2IZk6ftlmvvbLuKGFQfNomCTXPb4utgAt862B4bF8BN94gTLAf qrr2k/7U4/p4uZTWrwmCzXzd56JjOsySf8pwvjUbd00V5Hw/ArmNvVuhYffjbVarK8sO jVSgoZPnyy1SvM2Cq2CXPYi6JIL1nBdc060CUwxjn5LwQxjoSxvsBvGaSw4kT1NsCT+B UNglmX3N4BSWo51JRJOYH6Ew7jgqJ7j/uQWNYRcsoFpyUw2AKpp38M9YmiGtkQcgFRgy oE4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=mjnA5G81; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id sd4-20020a1709076e0400b00782f6b6f10asi761764ejc.726.2022.09.29.19.06.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 19:06:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=mjnA5G81; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0EE64385C332 for ; Fri, 30 Sep 2022 02:06:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id E0FCD3858D1E for ; Fri, 30 Sep 2022 02:05:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E0FCD3858D1E 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-x62c.google.com with SMTP id w20so2738448ply.12 for ; Thu, 29 Sep 2022 19:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=D8g0zS4SGcNPRulvihyx2cTqza+2GxOUSKny1Q4cH14=; b=mjnA5G8179+bM9UQUzD4KvlZ9lhgjAzaBzKGiISYoEd/PL0uM5yW3/BXed04lhBVw1 x7XLfbHRxwHXZywkd2HXWBgmbFvwhCYCNjSzApOu38MPRShkXVNo15nvD4X3Y0CKtPjz RUM4OK0DiWIw7zE/xtSAZooM5JuZH+TEX3DPI5ojW1tX5H8OLgdK5jRwE2ISgRP8b/G/ kGZOTOIPSvgWww8qBpfmXMvLhqmVvvIM67bYTVsLWVvLM2DnlK9GLHs+gu891YqVC7Eq 7swgHirMqbXCTwfJQbRDJyAU+Ls5QHjRGKenwUBqLTqp5fVY/bVkNEtrajPRDTIvS1QD PMmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=D8g0zS4SGcNPRulvihyx2cTqza+2GxOUSKny1Q4cH14=; b=uP7onrTJ6JxSucrnmGZm3KAX7TwbpmppEjvklY1fjwZmwhKa5AwpIR2IxavSoqvLgc bWbAUJe9/QZMJczB8ZVtaSGIm/o9fBeeFiPLfCw1/b6UZVchmS4aTp4oZ9YnDPvf/viE I1WqanCiJeiPkYhv2KgOykKZiFYDU/6uEnY20j9e4SI1zAs2NT/sckDzv5y7EZyDz8q+ H5E8ktIoA1kMdY741DRk7Xiuq85KIWLag8MApQo6+B6I0G/yG0P2aG/yJBDTPaLypoon vJDvoFB2hxXOtRnGx55jTwWGu3w0l5o6+J6bK0WadopOB537OiWbtKcj+PhaV3R5Bn7x ziug== X-Gm-Message-State: ACrzQf3dudUlh5VzL+wQR7ExG8BBpwsj2FhCx79ikylutUNDX8stllRN fTmgJHouab8BiHtLSbt5uOMavTNPx6t8n22fp1aTj+D6WjIAlG2wJZfo4kb4CvuNNBqoQ8dCs8B CFx5HvqiU3owgFAgySEl1eWnp9FDfUUCm0Wvsg8jTmQDCZe5cvN0MqomGL54j78m5smWX69qh/A == X-Received: by 2002:a17:90b:1d05:b0:202:809c:2d52 with SMTP id on5-20020a17090b1d0500b00202809c2d52mr6725766pjb.215.1664503531149; Thu, 29 Sep 2022 19:05:31 -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 k27-20020aa7999b000000b0052dbad1ea2esm394687pfh.6.2022.09.29.19.05.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Sep 2022 19:05:30 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, jim.wilson.gcc@gmail.com, palmer@dabbelt.com Subject: [PATCH] RISC-V: Support --target-help for -mcpu/-mtune Date: Fri, 30 Sep 2022 10:05:23 +0800 Message-Id: <20220930020523.21483-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745358494778148925?= X-GMAIL-MSGID: =?utf-8?q?1745358494778148925?= gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_tunes): New. (riscv_get_valid_option_values): New. (TARGET_GET_VALID_OPTION_VALUES): New. * config/riscv/riscv-cores.def (RISCV_TUNE): New, define options for tune here. (RISCV_CORE): Fix comment. * config/riscv/riscv.cc (riscv_tune_info_table): Move definition to riscv-cores.def. --- gcc/common/config/riscv/riscv-common.cc | 46 +++++++++++++++++++++++++ gcc/config/riscv/riscv-cores.def | 35 ++++++++++++++++--- gcc/config/riscv/riscv.cc | 9 ++--- 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index c39ed2e2696..697bfe435c8 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -224,6 +224,14 @@ static const riscv_cpu_info riscv_cpu_tables[] = {NULL, NULL, NULL} }; +static const char *riscv_tunes[] = +{ +#define RISCV_TUNE(TUNE_NAME, PIPELINE_MODEL, TUNE_INFO) \ + TUNE_NAME, +#include "../../../config/riscv/riscv-cores.def" + NULL +}; + static const char *riscv_supported_std_ext (void); static riscv_subset_list *current_subset_list = NULL; @@ -1683,6 +1691,41 @@ riscv_compute_multilib ( return xstrdup (multilib_infos[best_match_multi_lib].path.c_str ()); } +vec +riscv_get_valid_option_values (int option_code, + const char *prefix ATTRIBUTE_UNUSED) +{ + vec v; + v.create (0); + opt_code opt = (opt_code) option_code; + + switch (opt) + { + case OPT_mtune_: + { + const char **tune = &riscv_tunes[0]; + for (;*tune; ++tune) + v.safe_push (*tune); + + const riscv_cpu_info *cpu_info = &riscv_cpu_tables[0]; + for (;cpu_info->name; ++cpu_info) + v.safe_push (cpu_info->name); + } + break; + case OPT_mcpu_: + { + const riscv_cpu_info *cpu_info = &riscv_cpu_tables[0]; + for (;cpu_info->name; ++cpu_info) + v.safe_push (cpu_info->name); + } + break; + default: + break; + } + + return v; +} + #undef TARGET_COMPUTE_MULTILIB #define TARGET_COMPUTE_MULTILIB riscv_compute_multilib #endif @@ -1701,4 +1744,7 @@ static const struct default_options riscv_option_optimization_table[] = #undef TARGET_HANDLE_OPTION #define TARGET_HANDLE_OPTION riscv_handle_option +#undef TARGET_GET_VALID_OPTION_VALUES +#define TARGET_GET_VALID_OPTION_VALUES riscv_get_valid_option_values + struct gcc_targetm_common targetm_common = TARGETM_COMMON_INITIALIZER; diff --git a/gcc/config/riscv/riscv-cores.def b/gcc/config/riscv/riscv-cores.def index ecb5e213d98..b84ad999ac1 100644 --- a/gcc/config/riscv/riscv-cores.def +++ b/gcc/config/riscv/riscv-cores.def @@ -17,19 +17,46 @@ along with GCC; see the file COPYING3. If not see . */ +/* This is a list of tune that implement RISC-V. + + Before using #include to read this file, define a macro: + + RISCV_TUNE(TUNE_NAME, PIPELINE_MODEL, TUNE_INFO) + + The TUNE_NAME is the name of the micro-arch, represented as a string. + The PIPELINE_MODEL is the pipeline model of the micro-arch, represented as a + string, defined in riscv.md. + The TUNE_INFO is the detail cost model for this core, represented as an + identifier, reference to riscv.cc. */ + +#ifndef RISCV_TUNE +#define RISCV_TUNE(TUNE_NAME, PIPELINE_MODEL, TUNE_INFO) +#endif + +RISCV_TUNE("rocket", generic, rocket_tune_info) +RISCV_TUNE("sifive-3-series", generic, rocket_tune_info) +RISCV_TUNE("sifive-5-series", generic, rocket_tune_info) +RISCV_TUNE("sifive-7-series", generic, sifive_7_tune_info) +RISCV_TUNE("thead-c906", generic, thead_c906_tune_info) +RISCV_TUNE("size", generic, optimize_size_tune_info) + +#undef RISCV_TUNE + /* This is a list of cores that implement RISC-V. Before using #include to read this file, define a macro: - RISCV_CORE(CORE_NAME, ARCH, MICRO_ARCH, TUNE_INFO) + RISCV_CORE(CORE_NAME, ARCH, MICRO_ARCH) The CORE_NAME is the name of the core, represented as a string. The ARCH is the default arch of the core, represented as a string, can be NULL if no default arch. The MICRO_ARCH is the name of the core for which scheduling decisions - will be made, represented as an identifier. - The TUNE_INFO is the detail cost model for this core, represented as an - identifier, reference to riscv-tunes.def. */ + will be made, represented as an identifier. */ + +#ifndef RISCV_CORE +#define RISCV_CORE(CORE_NAME, ARCH, MICRO_ARCH) +#endif RISCV_CORE("sifive-e20", "rv32imc", "rocket") RISCV_CORE("sifive-e21", "rv32imac", "rocket") diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 0d618315828..00b7df02e2e 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -395,12 +395,9 @@ static const unsigned gpr_save_reg_order[] = { /* A table describing all the processors GCC knows about. */ static const struct riscv_tune_info riscv_tune_info_table[] = { - { "rocket", generic, &rocket_tune_info }, - { "sifive-3-series", generic, &rocket_tune_info }, - { "sifive-5-series", generic, &rocket_tune_info }, - { "sifive-7-series", sifive_7, &sifive_7_tune_info }, - { "thead-c906", generic, &thead_c906_tune_info }, - { "size", generic, &optimize_size_tune_info }, +#define RISCV_TUNE(TUNE_NAME, PIPELINE_MODEL, TUNE_INFO) \ + { TUNE_NAME, PIPELINE_MODEL, & TUNE_INFO}, +#include "riscv-cores.def" }; void riscv_frame_info::reset(void)