From patchwork Mon Dec 4 06:40:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 81249 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 788E23857BA4 for ; Mon, 4 Dec 2023 06:40:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 30A12385800B for ; Mon, 4 Dec 2023 06:40:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 30A12385800B Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 30A12385800B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701672017; cv=none; b=uJ9O3vrWwKC5XyzifgHCEJYHshiyCx/3VuNk4h7IMVfwPi69jiDoNMvwSdRAmKMLWnv2u3pqP6sFxhpP5ZMT1TT39ZB6gyIspO6d1emGwl9H9ql9/c/M7cSGNUOF8wxIWDzaO7h7Rs81jf4Z3INA6zasFsSCoTP+CxbOQ5DgjrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701672017; c=relaxed/simple; bh=XQ+UmBItLCal0c1OJZozfw8Wnj7ybWeaFkrc3gSYcUI=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=POvy6cRJQT2B+6BBvPo3yrJOPxfJj3pdZ0eeJdzGiBE/usdthqRKmitpbfLKEShUroBnFi1edsoz1PLwp0RP5ZM/RYDrDW6vIyY3jvQzkdy0pYAcOqfdxYErkMpGUQ7VjQFB7/BnLPsOr6MWhieRKM9ST3m2xcwL4W5yeYRv8T0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6cc02e77a9cso4080785b3a.0 for ; Sun, 03 Dec 2023 22:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1701672015; x=1702276815; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=EBofneDNu23VYeoEwC1rwokOh2F7RUtGau0MelrU274=; b=HaM85eepobVD1Ca2FOAzyug9o5y9q3Q8V0kT1sht4xSvobpKAG6lIb6UPWKuDhwuCj FjwnNrMnoCuuj0dJhV9q7xKDX2gBv27utcwmoCKdd43y+UJAPBsMeyB8LGLK0kFX5z6U d5QR9kXuYZl6Q144BARlzjonsohoEeB5ZAQ9j91rhmzzGWo3Mpws//IT2qYFg7Fvhy7/ bqJbenimI04/u3zGw3zHKHrxKG2aFdUZ3nX+3y9ICJKxcc7RU7rc/vEOMA2uzX9Ef51l NKwqmZDkaMh57/gmUeGy1Jbj/PUZ2f2P3Wk03jl1iY682YB16XJitNpeE+MP/nqug1Cw Al9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701672015; x=1702276815; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EBofneDNu23VYeoEwC1rwokOh2F7RUtGau0MelrU274=; b=SE3mEx3phpil/VcYmOmbXYRfLYlFtbHA0+ju5MTxODFEDDp2E03wzoNm3cMlxkMtcZ Zax7J262YIWF+PQli8Y4U9l/2uAr23v7AlBaJ2rEflYnZUcYcdn6W1TTD6/p38VNSCvT 8B4iqJgLNttUJYioJUxQ/7f9SCTVJVbM7ge9+XUsC7YGq/W04AJXga479qj1/cbA55g9 la1GJuap4hAIiTFHR4a7EVeqhUfG24Qm1hL1ieO9VTiCzskTje9BBQpttxVKM1GmlHj/ 6koRCA9g9CFgoYX2rT8SkmO0m3dYH73quJcvByqZKD1L3K5eeAs0Ql4zaL29tb/Cm526 TtxA== X-Gm-Message-State: AOJu0YwzxoaSwb2+nzKajK2UW9Lr2rr8KYqwnbKZkmlNwfQAe+l86xX2 iV3rzf8bawksPKpIvcrzlE+0rOTv/43Yx7BNjkP/5g9e6jMAaiglqiCfi+dcvlWLnjlYCCBUsxE QBjkf0ygTDptY39ZSyEjHVKbDg2xB+BNdA7giepJsueWXOR6kXZJxH7zo7aWyoFDC0qle8xx+5x r11Bs= X-Google-Smtp-Source: AGHT+IGd9j3MhwdmRWTvnsDENupKsfctQAiTUP4JVTilIyAcDOsjgRvwhaoa1W2x3WFwYgGFNwpN8g== X-Received: by 2002:a62:6584:0:b0:6ce:4780:8ea4 with SMTP id z126-20020a626584000000b006ce47808ea4mr1582095pfb.49.1701672014509; Sun, 03 Dec 2023 22:40:14 -0800 (PST) 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 f24-20020a633818000000b005ac384b71cbsm2133252pga.60.2023.12.03.22.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Dec 2023 22:40:13 -0800 (PST) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com Cc: Kito Cheng Subject: [committed] RISC-V: Refactor riscv_implied_info_t to make it able to handle conditional implication [NFC] Date: Mon, 4 Dec 2023 14:40:10 +0800 Message-Id: <20231204064010.80032-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.9 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.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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org RISC-V ISA implication rules become little bit complicated than before, it may come with condition, so this commit extend the capability of riscv_implied_info_t, also make it more...C++ize. gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_implied_predicator_t): New. (riscv_implied_info_t::riscv_implied_info_t): New. (riscv_implied_info_t::match): New. (riscv_implied_info): New entry for zcf. (riscv_subset_list::handle_implied_ext): Use riscv_implied_info_t::match. (riscv_subset_list::check_implied_ext): Ditto. (riscv_subset_list::handle_combine_ext): Ditto. (riscv_subset_list::parse): Move zcf implication handling to riscv_implied_infos. --- gcc/common/config/riscv/riscv-common.cc | 44 ++++++++++++++++++------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index de793f96fa5..aecb342b164 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -38,11 +38,36 @@ along with GCC; see the file COPYING3. If not see #define TARGET_DEFAULT_TARGET_FLAGS (MASK_BIG_ENDIAN) #endif +typedef bool (*riscv_implied_predicator_t) (const riscv_subset_list *); + /* Type for implied ISA info. */ struct riscv_implied_info_t { + constexpr riscv_implied_info_t (const char *ext, const char *implied_ext, + riscv_implied_predicator_t predicator + = nullptr) + : ext (ext), implied_ext (implied_ext), predicator (predicator){}; + + bool match (const riscv_subset_list *subset_list, const char *ext_name) const + { + if (strcmp (ext_name, ext) != 0) + return false; + + if (predicator && !predicator (subset_list)) + return false; + + return true; + } + + bool match (const riscv_subset_list *subset_list, + const riscv_subset_t *subset) const + { + return match (subset_list, subset->name.c_str()); + } + const char *ext; const char *implied_ext; + riscv_implied_predicator_t predicator; }; /* Implied ISA info, must end with NULL sentinel. */ @@ -143,6 +168,11 @@ static const riscv_implied_info_t riscv_implied_info[] = {"zcmp", "zca"}, {"zcmt", "zca"}, {"zcmt", "zicsr"}, + {"zcf", "f", + [] (const riscv_subset_list *subset_list) -> bool + { + return subset_list->xlen () == 32 && subset_list->lookup ("f"); + }}, {"smaia", "ssaia"}, {"smstateen", "ssstateen"}, @@ -1093,7 +1123,7 @@ riscv_subset_list::handle_implied_ext (const char *ext) implied_info->ext; ++implied_info) { - if (strcmp (ext, implied_info->ext) != 0) + if (!implied_info->match (this, ext)) continue; /* Skip if implied extension already present. */ @@ -1131,7 +1161,7 @@ riscv_subset_list::check_implied_ext () for (implied_info = &riscv_implied_info[0]; implied_info->ext; ++implied_info) { - if (strcmp (itr->name.c_str(), implied_info->ext) != 0) + if (!implied_info->match (this, itr)) continue; if (!lookup (implied_info->implied_ext)) @@ -1160,8 +1190,7 @@ riscv_subset_list::handle_combine_ext () for (implied_info = &riscv_implied_info[0]; implied_info->ext; ++implied_info) { - /* Skip if implied extension don't match combine extension */ - if (strcmp (combine_info->name, implied_info->ext) != 0) + if (!implied_info->match (this, combine_info->name)) continue; if (lookup (implied_info->implied_ext)) @@ -1502,13 +1531,6 @@ riscv_subset_list::parse (const char *arch, location_t loc) subset_list->handle_implied_ext (itr->name.c_str ()); } - /* Zce only implies zcf when RV32 and 'f' extension exist. */ - if (subset_list->lookup ("zce") != NULL - && subset_list->m_xlen == 32 - && subset_list->lookup ("f") != NULL - && subset_list->lookup ("zcf") == NULL) - subset_list->add ("zcf", false); - /* Make sure all implied extensions are included. */ gcc_assert (subset_list->check_implied_ext ());