From patchwork Thu Nov 16 13:18:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 165805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp3204912vqg; Thu, 16 Nov 2023 05:21:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHfn9y2L9nycjfDmM2mPq3XjASCK7s98I7ePcqElYybcMK7C5SMKEAhw8OEF6FkWxG3TEbg X-Received: by 2002:a05:6214:2cd7:b0:671:3493:61e5 with SMTP id lf23-20020a0562142cd700b00671349361e5mr8434609qvb.31.1700140871989; Thu, 16 Nov 2023 05:21:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700140871; cv=pass; d=google.com; s=arc-20160816; b=fu9bLaHp7K97C8zdWiTpCkSYkqRyHGvSJ0nyR9AUf8dSz8sxwNslXY2999lReCyZut fNdfU1kC80zlAbkrauBw84PVXqy/YVcNVsSbWBF3AHJXrL9DSswfQ3G852XSPAeNauqv gydwOfR+GocFwrzvPqGQgQi5r4H2ITcA0QwAXSqiJN2Ve5+IPZXfuJ5SfU4iazNGMuKd 2kUMXPZROuvejL/3PgWw566XGyaPwjIYbX4r6AAg4t0kM8ySMQMebZyt2MV9IGzbkn4j WMJ+DDtRh88TQTfKJ5fkE+uk4DLbwUzMCSD2d6UYDTDxwghMgoi+YhPNZBJBqg1ffhfV l6eA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=wKggsYProhqVs2bDgVDf8a7tohQNZQ0UJJHoXACh6p0=; fh=oUCfM/eMlWtMCtZZKY1bglzxCo7b3kw9D5LTFFWuz38=; b=ZznecfX+huzSZ6z6V7/09sYvE7+YSs0SKI3VBfcVGbYJY5niz5Ajs1cs3ZJJV5voAH cAlsAy7V6TqN9vHW/EgZCQ5ZM1e6I1f3GvdC22Tphg3N/TLpqAX2ghMpdSbDIDkhv205 68T6EdKxGsCzUr1iVVIfCJOOd/8Iot91aGEfuFLIzDoLEQHAaVv/96fDTxvvyNOYmaL+ yBxFAGjJwfAns45Xu3SkSLQTmpgZpBptOgpv9NRE2YJQfKY7UynyBqmM8cdIVzsOZr7P ZwzHFDPxnSoB3prN9y/KcLj1BINf0MapKA9+boNRCZ/9jjjIbmVrbD+zr9d7cUHMiCUw LVYw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=IKLWBHR7; arc=pass (i=1); 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"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i18-20020ad44112000000b0064f80d285e7si11142235qvp.275.2023.11.16.05.21.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 05:21:11 -0800 (PST) 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=@xry111.site header.s=default header.b=IKLWBHR7; arc=pass (i=1); 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"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E08D93857C43 for ; Thu, 16 Nov 2023 13:20:24 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 0D0D23858D39 for ; Thu, 16 Nov 2023 13:19:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0D0D23858D39 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0D0D23858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700140765; cv=none; b=YCUm15fSYrGr3feNT3ka/E1bAcpY38lDq86t5S5xgdo3mvvxVTixFcbdZVDS17pypLZ8CgjGvpxYy8ORw9Qhw46gcqKowWaH1Y2/Lzl4uWUlcNlMWG3xA5tFiC5jYi1gU0UmvHSmUXVUDvcnEKcTYFM+99MpOoG6KfhAn0q+XVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700140765; c=relaxed/simple; bh=s9wyrYmE/uC+KhzmurVuCBR1V056QIiGQXK0N6zJmcE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BpD8ElTSHujs9+sPVG5CThF2yq0fcYXX2pDZ89BqENHZBDs4PM6Mro+BtfHmUX9kJCp5drqspypz2a/L4RwjWHiFA8iD3EnyQsjtlKvyPZ+mDifHZdEB+b+0m9VBNKQTnIFBIoUG1P/+GIAJ5yL1FQfTAVDAM/piknsG0YtuTB8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1700140757; bh=s9wyrYmE/uC+KhzmurVuCBR1V056QIiGQXK0N6zJmcE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IKLWBHR7xfuh3PVUk1yrSflm+fEFMfhn55S97SJiRKZZlsPYkHvWnAgct1yso9F/s gArHs82p/4KuwRgvbloWmibstPb0uc6AClQgqGMS54mlq09y1oZRaUWMwh1ALAAKXl V2fdWvRK/Fkkzr4b7ERDvkRH7YO1gU719xGwsTsg= Received: from stargazer.. (unknown [113.200.174.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 9A42966C08; Thu, 16 Nov 2023 08:19:15 -0500 (EST) From: Xi Ruoyao To: gcc-patches@gcc.gnu.org Cc: chenglulu , i@xen0n.name, xuchenghua@loongson.cn, Xi Ruoyao Subject: [PATCH 2/5] LoongArch: genopts: Add infrastructure to generate code for new features in ISA evolution Date: Thu, 16 Nov 2023 21:18:34 +0800 Message-ID: <20231116131836.504699-4-xry111@xry111.site> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231116131836.504699-2-xry111@xry111.site> References: <20231116131836.504699-2-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_FROM, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, WEIRD_QUOTING 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782726914725036743 X-GMAIL-MSGID: 1782726914725036743 LoongArch v1.10 introduced the concept of ISA evolution. During ISA evolution, many independent features can be added and enumerated via CPUCFG. Add a data file into genopts storing the CPUCFG word, bit, the name of the command line option controlling if this feature should be used for compilation, and the text description. Make genstr.sh process these info and add the command line options into loongarch.opt and loongarch-str.h, and generate a new file loongarch-cpucfg-map.h for mapping CPUCFG output to the corresponding option. When handling -march=native, use the information in loongarch-cpucfg-map.h to generate the corresponding option mask. Enable the features implied by -march setting unless the user has explicitly disabled the feature. The added options (-mdiv32 and -mld-seq-sa) are not really handled yet. They'll be used in the following patches. gcc/ChangeLog: * config/loongarch/genopts/isa-evolution.in: New data file. * config/loongarch/genopts/genstr.sh: Translate info in isa-evolution.in when generating loongarch-str.h, loongarch.opt, and loongarch-cpucfg-map.h. * config/loongarch/genopts/loongarch.opt.in (isa_evolution): New variable. * config/loongarch/t-loongarch: (loongarch-cpucfg-map.h): New rule. (loongarch-str.h): Depend on isa-evolution.in. (loongarch.opt): Depend on isa-evolution.in. (loongarch-cpu.o): Depend on loongarch-cpucfg-map.h. * config/loongarch/loongarch-str.h: Regenerate. * config/loongarch/loongarch.opt: Regenerate. * config/loongarch/loongarch-cpucfg-map.h: Generate. * config/loongarch/loongarch-def.h (loongarch_isa): Add field for evolution features. Add helper function to enable features in this field. Probe native CPU capability and save the corresponding options into preset. * config/loongarch/loongarch-cpu.cc (fill_native_cpu_config): Probe native CPU capability and save the corresponding options into preset. * config/loongarch/loongarch.cc (loongarch_option_override_internal): Enable the ISA evolution feature options implied by -march and not explicitly disabled. * config/loongarch/loongarch-def.cc: Define IN_TARGET_CODE to 1 so it's possible to include config.h and system.h for HOST_WIDE_INT. --- gcc/config/loongarch/genopts/genstr.sh | 78 +++++++++++++++++-- gcc/config/loongarch/genopts/isa-evolution.in | 2 + gcc/config/loongarch/genopts/loongarch.opt.in | 7 ++ gcc/config/loongarch/loongarch-cpu.cc | 37 +++++---- gcc/config/loongarch/loongarch-cpucfg-map.h | 36 +++++++++ gcc/config/loongarch/loongarch-def.cc | 3 + gcc/config/loongarch/loongarch-def.h | 11 ++- gcc/config/loongarch/loongarch-str.h | 7 +- gcc/config/loongarch/loongarch.cc | 4 + gcc/config/loongarch/loongarch.opt | 20 ++++- gcc/config/loongarch/t-loongarch | 21 ++++- 11 files changed, 196 insertions(+), 30 deletions(-) create mode 100644 gcc/config/loongarch/genopts/isa-evolution.in create mode 100644 gcc/config/loongarch/loongarch-cpucfg-map.h diff --git a/gcc/config/loongarch/genopts/genstr.sh b/gcc/config/loongarch/genopts/genstr.sh index 04e785576bb..7f461118a97 100755 --- a/gcc/config/loongarch/genopts/genstr.sh +++ b/gcc/config/loongarch/genopts/genstr.sh @@ -25,8 +25,8 @@ cd "$(dirname "$0")" # Generate a header containing definitions from the string table. gen_defines() { cat <. */ + +#ifndef LOONGARCH_CPUCFG_MAP_H +#define LOONGARCH_CPUCFG_MAP_H + +#include "options.h" + +static constexpr struct { + int cpucfg_word; + unsigned int cpucfg_bit; + HOST_WIDE_INT isa_evolution_bit; +} cpucfg_map[] = { +EOF + + # Generate the strings from isa-evolution.in. + awk '{ + gsub(/-/, "_", $3) + print(" { "$1", 1u << "$2", OPTION_MASK_ISA_"toupper($3)" },") + }' isa-evolution.in + + echo "};" + echo + echo "#endif /* LOONGARCH_STR_H */" } main() { case "$1" in + cpucfg-map) gen_cpucfg_map;; header) gen_defines;; opt) gen_options;; - *) echo "Unknown Command: \"$1\". Available: header, opt"; exit 1;; + *) echo "Unknown Command: \"$1\". Available: cpucfg-map, header, opt"; exit 1;; esac } diff --git a/gcc/config/loongarch/genopts/isa-evolution.in b/gcc/config/loongarch/genopts/isa-evolution.in new file mode 100644 index 00000000000..7525be762fb --- /dev/null +++ b/gcc/config/loongarch/genopts/isa-evolution.in @@ -0,0 +1,2 @@ +0x2 26 div32 Support div.w[u] and mod.w[u] instructions with inputs not sign-extended. +0x3 23 ld-seq-sa Do not need load-load barriers (dbar 0x700). diff --git a/gcc/config/loongarch/genopts/loongarch.opt.in b/gcc/config/loongarch/genopts/loongarch.opt.in index 158701d327a..4a22039681f 100644 --- a/gcc/config/loongarch/genopts/loongarch.opt.in +++ b/gcc/config/loongarch/genopts/loongarch.opt.in @@ -241,3 +241,10 @@ Target Undocumented Joined UInteger Var(loongarch_vect_issue_info) Init(4) Integ Indicate how many non memory access vector instructions can be issued per cycle, it's used in unroll factor determination for autovectorizer. The default value is 4. + +; Features added during ISA evolution. This concept is different from ISA +; extension, read Section 1.5 of LoongArch v1.10 Volume 1 for the +; explanation. These features may be implemented and enumerated with +; CPUCFG independantly, so we use bit flags to specify them. +Variable +HOST_WIDE_INT isa_evolution = 0 diff --git a/gcc/config/loongarch/loongarch-cpu.cc b/gcc/config/loongarch/loongarch-cpu.cc index 7a2866f60f9..03acf632353 100644 --- a/gcc/config/loongarch/loongarch-cpu.cc +++ b/gcc/config/loongarch/loongarch-cpu.cc @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "loongarch-def.h" #include "loongarch-opts.h" #include "loongarch-cpu.h" +#include "loongarch-cpucfg-map.h" #include "loongarch-str.h" /* Native CPU detection with "cpucfg" */ @@ -121,11 +122,12 @@ fill_native_cpu_config (struct loongarch_target *tgt) int tmp; tgt->cpu_arch = native_cpu_type; + auto &preset = loongarch_cpu_default_isa[tgt->cpu_arch]; + /* Fill: loongarch_cpu_default_isa[tgt->cpu_arch].base With: base architecture (ARCH) At: cpucfg_words[1][1:0] */ - #define PRESET_ARCH (loongarch_cpu_default_isa[tgt->cpu_arch].base) switch (cpucfg_cache[1] & 0x3) { case 0x02: @@ -140,19 +142,18 @@ fill_native_cpu_config (struct loongarch_target *tgt) } /* Check consistency with PRID presets. */ - if (native_cpu_type != CPU_NATIVE && tmp != PRESET_ARCH) + if (native_cpu_type != CPU_NATIVE && tmp != preset.base) warning (0, "base architecture %qs differs from PRID preset %qs", loongarch_isa_base_strings[tmp], - loongarch_isa_base_strings[PRESET_ARCH]); + loongarch_isa_base_strings[preset.base]); /* Use the native value anyways. */ - PRESET_ARCH = tmp; + preset.base = tmp; /* Fill: loongarch_cpu_default_isa[tgt->cpu_arch].fpu With: FPU type (FP, FP_SP, FP_DP) At: cpucfg_words[2][2:0] */ - #define PRESET_FPU (loongarch_cpu_default_isa[tgt->cpu_arch].fpu) switch (cpucfg_cache[2] & 0x7) { case 0x07: @@ -175,20 +176,19 @@ fill_native_cpu_config (struct loongarch_target *tgt) } /* Check consistency with PRID presets. */ - if (native_cpu_type != CPU_NATIVE && tmp != PRESET_FPU) + if (native_cpu_type != CPU_NATIVE && tmp != preset.fpu) warning (0, "floating-point unit %qs differs from PRID preset %qs", loongarch_isa_ext_strings[tmp], - loongarch_isa_ext_strings[PRESET_FPU]); + loongarch_isa_ext_strings[preset.fpu]); /* Use the native value anyways. */ - PRESET_FPU = tmp; + preset.fpu = tmp; /* Fill: loongarch_cpu_default_isa[CPU_NATIVE].simd With: SIMD extension type (LSX, LASX) At: cpucfg_words[2][7:6] */ - #define PRESET_SIMD (loongarch_cpu_default_isa[tgt->cpu_arch].simd) switch (cpucfg_cache[2] & 0xc0) { case 0xc0: @@ -215,14 +215,19 @@ fill_native_cpu_config (struct loongarch_target *tgt) /* Check consistency with PRID presets. */ /* - if (native_cpu_type != CPU_NATIVE && tmp != PRESET_SIMD) + if (native_cpu_type != CPU_NATIVE && tmp != preset.simd) warning (0, "SIMD extension %qs differs from PRID preset %qs", loongarch_isa_ext_strings[tmp], - loongarch_isa_ext_strings[PRESET_SIMD]); + loongarch_isa_ext_strings[preset.simd]); */ /* Use the native value anyways. */ - PRESET_SIMD = tmp; + preset.simd = tmp; + + /* Features added during ISA evolution. */ + for (const auto &entry: cpucfg_map) + if (cpucfg_cache[entry.cpucfg_word] & entry.cpucfg_bit) + preset.evol_add_feat (entry.isa_evolution_bit); } if (tune_native_p) @@ -233,7 +238,7 @@ fill_native_cpu_config (struct loongarch_target *tgt) With: cache size info At: cpucfg_words[16:20][31:0] */ - #define PRESET_CACHE (loongarch_cpu_cache[tgt->cpu_tune]) + auto &preset_cache = loongarch_cpu_cache[tgt->cpu_tune]; struct loongarch_cache native_cache; int l1d_present = 0, l1u_present = 0; int l2d_present = 0; @@ -264,8 +269,8 @@ fill_native_cpu_config (struct loongarch_target *tgt) >> 10; /* in kibibytes */ /* Use the native value anyways. */ - PRESET_CACHE.l1d_line_size = native_cache.l1d_line_size; - PRESET_CACHE.l1d_size = native_cache.l1d_size; - PRESET_CACHE.l2d_size = native_cache.l2d_size; + preset_cache.l1d_line_size = native_cache.l1d_line_size; + preset_cache.l1d_size = native_cache.l1d_size; + preset_cache.l2d_size = native_cache.l2d_size; } } diff --git a/gcc/config/loongarch/loongarch-cpucfg-map.h b/gcc/config/loongarch/loongarch-cpucfg-map.h new file mode 100644 index 00000000000..78a4acf535b --- /dev/null +++ b/gcc/config/loongarch/loongarch-cpucfg-map.h @@ -0,0 +1,36 @@ +/* Generated automatically by "genstr" from "isa-evolution.in". + Please do not edit this file directly. + + Copyright (C) 2023 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#ifndef LOONGARCH_CPUCFG_MAP_H +#define LOONGARCH_CPUCFG_MAP_H + +#include "options.h" + +static constexpr struct { + int cpucfg_word; + unsigned int cpucfg_bit; + HOST_WIDE_INT isa_evolution_bit; +} cpucfg_map[] = { + { 0x2, 1u << 26, OPTION_MASK_ISA_DIV32 }, + { 0x3, 1u << 23, OPTION_MASK_ISA_LD_SEQ_SA }, +}; + +#endif /* LOONGARCH_STR_H */ diff --git a/gcc/config/loongarch/loongarch-def.cc b/gcc/config/loongarch/loongarch-def.cc index 0200c48f43b..9c2ec1ec135 100644 --- a/gcc/config/loongarch/loongarch-def.cc +++ b/gcc/config/loongarch/loongarch-def.cc @@ -18,6 +18,9 @@ You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see . */ +#define IN_TARGET_CODE +#include "config.h" +#include "system.h" #include "loongarch-def.h" #include "loongarch-str.h" diff --git a/gcc/config/loongarch/loongarch-def.h b/gcc/config/loongarch/loongarch-def.h index d36c2769f78..e74036fda33 100644 --- a/gcc/config/loongarch/loongarch-def.h +++ b/gcc/config/loongarch/loongarch-def.h @@ -120,10 +120,19 @@ struct loongarch_isa int fpu; /* ISA_EXT_FPU_ */ int simd; /* ISA_EXT_SIMD_ */ - loongarch_isa () : base (0), fpu (0), simd (0) {} + /* ISA evolution features implied by cpu_arch or probed for native. */ + HOST_WIDE_INT evolution; + + loongarch_isa () : base (0), fpu (0), simd (0), evolution (0) {} loongarch_isa base_ (int _base) { base = _base; return *this; } loongarch_isa fpu_ (int _fpu) { fpu = _fpu; return *this; } loongarch_isa simd_ (int _simd) { simd = _simd; return *this; } + + loongarch_isa evol_add_feat (HOST_WIDE_INT bit) + { + evolution |= bit; + return *this; + } }; struct loongarch_abi diff --git a/gcc/config/loongarch/loongarch-str.h b/gcc/config/loongarch/loongarch-str.h index 072558c28f1..3fa2ed5fc49 100644 --- a/gcc/config/loongarch/loongarch-str.h +++ b/gcc/config/loongarch/loongarch-str.h @@ -1,5 +1,5 @@ -/* Generated automatically by "genstr" from "loongarch-strings". - Please do not edit this file directly. +/* Generated automatically by "genstr" from "loongarch-strings" and + "isa-evolution.in". Please do not edit this file directly. Copyright (C) 2021-2023 Free Software Foundation, Inc. Contributed by Loongson Ltd. @@ -67,4 +67,7 @@ along with GCC; see the file COPYING3. If not see #define STR_EXPLICIT_RELOCS_NONE "none" #define STR_EXPLICIT_RELOCS_ALWAYS "always" +#define OPTSTR_DIV32 "div32" +#define OPTSTR_LD_SEQ_SA "ld-seq-sa" + #endif /* LOONGARCH_STR_H */ diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 738911661d7..6f89d468795 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -7455,6 +7455,10 @@ loongarch_option_override_internal (struct gcc_options *opts, if (loongarch_branch_cost == 0) loongarch_branch_cost = loongarch_cost->branch_cost; + /* If the user hasn't disabled a feature added during ISA evolution, + use the processor's default. */ + isa_evolution |= (la_target.isa.evolution & + ~global_options_set.x_isa_evolution); /* Enable sw prefetching at -O3 and higher. */ if (opts->x_flag_prefetch_loop_arrays < 0 diff --git a/gcc/config/loongarch/loongarch.opt b/gcc/config/loongarch/loongarch.opt index a5988411fbb..b17df1302f7 100644 --- a/gcc/config/loongarch/loongarch.opt +++ b/gcc/config/loongarch/loongarch.opt @@ -1,9 +1,10 @@ ; Generated by "genstr" from the template "loongarch.opt.in" -; and definitions from "loongarch-strings". +; and definitions from "loongarch-strings" and "isa-evolution.in". ; ; Please do not edit this file directly. ; It will be automatically updated during a gcc build -; if you change "loongarch.opt.in" or "loongarch-strings". +; if you change "loongarch.opt.in", "loongarch-strings", or +; "isa-evolution.in". ; ; Copyright (C) 2021-2023 Free Software Foundation, Inc. ; @@ -248,3 +249,18 @@ Target Undocumented Joined UInteger Var(loongarch_vect_issue_info) Init(4) Integ Indicate how many non memory access vector instructions can be issued per cycle, it's used in unroll factor determination for autovectorizer. The default value is 4. + +; Features added during ISA evolution. This concept is different from ISA +; extension, read Section 1.5 of LoongArch v1.10 Volume 1 for the +; explanation. These features may be implemented and enumerated with +; CPUCFG independantly, so we use bit flags to specify them. +Variable +HOST_WIDE_INT isa_evolution = 0 + +mdiv32 +Target Mask(ISA_DIV32) Var(isa_evolution) +Support div.w[u] and mod.w[u] instructions with inputs not sign-extended. + +mld-seq-sa +Target Mask(ISA_LD_SEQ_SA) Var(isa_evolution) +Do not need load-load barriers (dbar 0x700). diff --git a/gcc/config/loongarch/t-loongarch b/gcc/config/loongarch/t-loongarch index 0a7eaf6271f..10a984f3cb1 100644 --- a/gcc/config/loongarch/t-loongarch +++ b/gcc/config/loongarch/t-loongarch @@ -18,8 +18,9 @@ GTM_H += loongarch-multilib.h -OPTIONS_H_EXTRA += $(srcdir)/config/loongarch/loongarch-def.h \ - $(srcdir)/config/loongarch/loongarch-tune.h +OPTIONS_H_EXTRA += $(srcdir)/config/loongarch/loongarch-def.h \ + $(srcdir)/config/loongarch/loongarch-tune.h \ + $(srcdir)/config/loongarch/loongarch-cpucfg-map.h # Canonical target triplet from config.gcc LA_MULTIARCH_TRIPLET = $(patsubst LA_MULTIARCH_TRIPLET=%,%,$\ @@ -31,7 +32,8 @@ LA_STR_H = $(srcdir)/config/loongarch/loongarch-str.h # String definition header $(LA_STR_H): s-loongarch-str ; @true s-loongarch-str: $(srcdir)/config/loongarch/genopts/genstr.sh \ - $(srcdir)/config/loongarch/genopts/loongarch-strings + $(srcdir)/config/loongarch/genopts/loongarch-strings \ + $(srcdir)/config/loongarch/genopts/isa-evolution.in $(SHELL) $(srcdir)/config/loongarch/genopts/genstr.sh header \ $(srcdir)/config/loongarch/genopts/loongarch-strings > \ tmp-loongarch-str.h @@ -58,7 +60,8 @@ loongarch-driver.o : $(srcdir)/config/loongarch/loongarch-driver.cc $(LA_STR_H) loongarch-opts.o: $(srcdir)/config/loongarch/loongarch-opts.cc $(LA_STR_H) $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< -loongarch-cpu.o: $(srcdir)/config/loongarch/loongarch-cpu.cc $(LA_STR_H) +loongarch-cpu.o: $(srcdir)/config/loongarch/loongarch-cpu.cc $(LA_STR_H) \ + $(srcdir)/config/loongarch/loongarch-cpucfg-map.h $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $< loongarch-def.o: $(srcdir)/config/loongarch/loongarch-def.cc $(LA_STR_H) @@ -67,6 +70,7 @@ loongarch-def.o: $(srcdir)/config/loongarch/loongarch-def.cc $(LA_STR_H) $(srcdir)/config/loongarch/loongarch.opt: s-loongarch-opt ; @true s-loongarch-opt: $(srcdir)/config/loongarch/genopts/genstr.sh \ $(srcdir)/config/loongarch/genopts/loongarch.opt.in \ + $(srcdir)/config/loongarch/genopts/isa-evolution.in \ $(srcdir)/config/loongarch/genopts/loongarch-strings $(LA_STR_H) $(SHELL) $(srcdir)/config/loongarch/genopts/genstr.sh opt \ $(srcdir)/config/loongarch/genopts/loongarch.opt.in \ @@ -74,3 +78,12 @@ s-loongarch-opt: $(srcdir)/config/loongarch/genopts/genstr.sh \ $(SHELL) $(srcdir)/../move-if-change tmp-loongarch.opt \ $(srcdir)/config/loongarch/loongarch.opt $(STAMP) s-loongarch-opt + +$(srcdir)/config/loongarch/loongarch-cpucfg-map.h: s-loongarch-cpucfg-map + @true +s-loongarch-cpucfg-map: $(srcdir)/config/loongarch/genopts/genstr.sh \ + $(srcdir)/config/loongarch/genopts/isa-evolution.in + $(SHELL) $< cpucfg-map > tmp-cpucfg.h + $(SHELL) $(srcdir)/../move-if-change tmp-cpucfg.h \ + $(srcdir)/config/loongarch/loongarch-cpucfg-map.h + $(STAMP) $@