From patchwork Tue Feb 11 12:49:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cheng X-Patchwork-Id: 106329 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 A40A03858CDA for ; Tue, 11 Feb 2025 12:51:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A40A03858CDA X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 2D5EC3858C51 for ; Tue, 11 Feb 2025 12:48:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D5EC3858C51 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2D5EC3858C51 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739278132; cv=none; b=xzeNKJYlZd5aanQdEh5eYpxkKogCxSPwdHIh90aq4lVzjl/G9rgoiCxCBXYKHJJqj3aiBUmsITXBBayVvNkL2VaDYFGv45tGxKzwmHmJaQfMnuosvxxJkWHyzHnigswx83evuVyfWRxTShoL3/JWjpH6IoDAHGNMZlwmc6Tyaq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739278132; c=relaxed/simple; bh=+VNLT4Ve9hWJOyxxJT4T7VN52t5IhdR4yJrzEbKVkoI=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=uwbx2VW7MrmHjeS4jLo99lOHkKHQmxxRMQutkWfluS19JAUYTzEPZmqde8Jh+ajJCP9dA8ctzxuU+Y2cLVrXIHZv9P0Ksv2wBGTB68nqlLeOJPN1Ds9x4ySU+DU/AMMv2CdfqoZqTJXPunlZRPWKv2ZkCn1ukbe4+m1rog67U18= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D5EC3858C51 Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8AxquAuR6tn4ChyAA--.24942S3; Tue, 11 Feb 2025 20:48:46 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by front1 (Coremail) with SMTP id qMiowMDxH+UjR6tnQAMMAA--.47337S3; Tue, 11 Feb 2025 20:48:45 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn Subject: [PATCH 1/3] LoongArch: Move the function loongarch_register_pragmas to loongarch-c.cc. Date: Tue, 11 Feb 2025 20:49:15 +0800 Message-Id: <20250211124917.28685-2-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250211124917.28685-1-chenglulu@loongson.cn> References: <20250211124917.28685-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowMDxH+UjR6tnQAMMAA--.47337S3 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoW3WrW3GF1Utw15AF1fJF48Xwc_yoW7Aw4Dpr 9rury5tw4rJrZ3Gw4Dta4rX3Z8Jr17GrW29Fyftr40kw47Kry7ZryrKr9IqF1jy3y5Wry2 vF10ya1UZa1UAwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU8529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkjb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r106r15M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v2 6r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwI xGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k2 6cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jY38nUUUUU= X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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.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 gcc/ChangeLog: * config/loongarch/loongarch-target-attr.cc (loongarch_pragma_target_parse): Move to ... (loongarch_register_pragmas): Move to ... * config/loongarch/loongarch-c.cc (loongarch_pragma_target_parse): ... here. (loongarch_register_pragmas): ... here. * config/loongarch/loongarch-protos.h (loongarch_process_target_attr): Function Declaration. Change-Id: I12751a6ce2f1b2f587699db3c80188066f193d2d --- gcc/config/loongarch/loongarch-c.cc | 51 +++++++++++++++++++ gcc/config/loongarch/loongarch-protos.h | 1 + gcc/config/loongarch/loongarch-target-attr.cc | 48 ----------------- 3 files changed, 52 insertions(+), 48 deletions(-) diff --git a/gcc/config/loongarch/loongarch-c.cc b/gcc/config/loongarch/loongarch-c.cc index c95c0f373be..5d8c02e094b 100644 --- a/gcc/config/loongarch/loongarch-c.cc +++ b/gcc/config/loongarch/loongarch-c.cc @@ -23,9 +23,11 @@ along with GCC; see the file COPYING3. If not see #include "config.h" #include "system.h" #include "coretypes.h" +#include "target.h" #include "tm.h" #include "c-family/c-common.h" #include "cpplib.h" +#include "tm_p.h" #define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM) #define builtin_define(TXT) cpp_define (pfile, TXT) @@ -145,3 +147,52 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile) builtin_define_with_int_value ("_LOONGARCH_SPFPSET", 32); } + +/* Hook to validate the current #pragma GCC target and set the state, and + update the macros based on what was changed. If ARGS is NULL, then + POP_TARGET is used to reset the options. */ + +static bool +loongarch_pragma_target_parse (tree args, tree pop_target) +{ + /* If args is not NULL then process it and setup the target-specific + information that it specifies. */ + if (args) + { + if (!loongarch_process_target_attr (args, NULL)) + return false; + + loongarch_option_override_internal (&la_target, + &global_options, + &global_options_set); + } + + /* args is NULL, restore to the state described in pop_target. */ + else + { + pop_target = pop_target ? pop_target : target_option_default_node; + cl_target_option_restore (&global_options, &global_options_set, + TREE_TARGET_OPTION (pop_target)); + } + + target_option_current_node + = build_target_option_node (&global_options, &global_options_set); + + loongarch_reset_previous_fndecl (); + + /* If we're popping or reseting make sure to update the globals so that + the optab availability predicates get recomputed. */ + if (pop_target) + loongarch_save_restore_target_globals (pop_target); + + return true; +} + +/* Implement REGISTER_TARGET_PRAGMAS. */ + +void +loongarch_register_pragmas (void) +{ + /* Update pragma hook to allow parsing #pragma GCC target. */ + targetm.target_option.pragma_parse = loongarch_pragma_target_parse; +} diff --git a/gcc/config/loongarch/loongarch-protos.h b/gcc/config/loongarch/loongarch-protos.h index 94d3e33cb9a..9659d5ae26e 100644 --- a/gcc/config/loongarch/loongarch-protos.h +++ b/gcc/config/loongarch/loongarch-protos.h @@ -222,4 +222,5 @@ extern void loongarch_save_restore_target_globals (tree new_tree); extern void loongarch_register_pragmas (void); extern rtx loongarch_gen_stepped_int_parallel (unsigned int nelts, int base, int step); +extern bool loongarch_process_target_attr (tree args, tree fndecl); #endif /* ! GCC_LOONGARCH_PROTOS_H */ diff --git a/gcc/config/loongarch/loongarch-target-attr.cc b/gcc/config/loongarch/loongarch-target-attr.cc index cee7031ca1e..cb537446dff 100644 --- a/gcc/config/loongarch/loongarch-target-attr.cc +++ b/gcc/config/loongarch/loongarch-target-attr.cc @@ -422,51 +422,3 @@ loongarch_option_valid_attribute_p (tree fndecl, tree, tree args, int) return ret; } -/* Hook to validate the current #pragma GCC target and set the state, and - update the macros based on what was changed. If ARGS is NULL, then - POP_TARGET is used to reset the options. */ - -static bool -loongarch_pragma_target_parse (tree args, tree pop_target) -{ - /* If args is not NULL then process it and setup the target-specific - information that it specifies. */ - if (args) - { - if (!loongarch_process_target_attr (args, NULL)) - return false; - - loongarch_option_override_internal (&la_target, - &global_options, - &global_options_set); - } - - /* args is NULL, restore to the state described in pop_target. */ - else - { - pop_target = pop_target ? pop_target : target_option_default_node; - cl_target_option_restore (&global_options, &global_options_set, - TREE_TARGET_OPTION (pop_target)); - } - - target_option_current_node - = build_target_option_node (&global_options, &global_options_set); - - loongarch_reset_previous_fndecl (); - - /* If we're popping or reseting make sure to update the globals so that - the optab availability predicates get recomputed. */ - if (pop_target) - loongarch_save_restore_target_globals (pop_target); - - return true; -} - -/* Implement REGISTER_TARGET_PRAGMAS. */ - -void -loongarch_register_pragmas (void) -{ - /* Update pragma hook to allow parsing #pragma GCC target. */ - targetm.target_option.pragma_parse = loongarch_pragma_target_parse; -} From patchwork Tue Feb 11 12:49:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cheng X-Patchwork-Id: 106328 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 1E4373858428 for ; Tue, 11 Feb 2025 12:49:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E4373858428 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id 017083858D33 for ; Tue, 11 Feb 2025 12:48:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 017083858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 017083858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739278130; cv=none; b=Tn/VtR94Auabbtr1S3eaQV+I3Fx0hOG0iFKyemJFtnPlg5/cMwmmPiUT76B+8Ttn9PQOuDCeM3xIbix4Jg+vgHvaAWSYRX5On7RVNMZZYjCzEYceIQClXINFzLV/o1E8g+1l9GuYYRx1zs7MxROjydP/qSllbVrYFx+2KgwsNX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739278130; c=relaxed/simple; bh=PEmAMIzvf0uG0HWpZ5qXEEY2gboBl7UL7Rf56ROch38=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=ENXW+oHxGpxSFAdEP7g++ZKeFqA4OdolY1d6QD0DH3bwR+gWpD/ljF1ahpisO0gdI4LzvcQiUWisKdPj5ZnKEo0ZwMltBdMDzoKhIVuGi7jrFGdDINkRkLD6x03i/ewTc6y/KWZeW1/zJvugq0uA46NpSVv4Sx8EspwjEFsS7VM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 017083858D33 Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8Bx12kvR6tn4yhyAA--.2107S3; Tue, 11 Feb 2025 20:48:47 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by front1 (Coremail) with SMTP id qMiowMDxH+UjR6tnQAMMAA--.47337S4; Tue, 11 Feb 2025 20:48:46 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn Subject: [PATCH 2/3] LoongArch: Split the function loongarch_cpu_cpp_builtins into two functions. Date: Tue, 11 Feb 2025 20:49:16 +0800 Message-Id: <20250211124917.28685-3-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250211124917.28685-1-chenglulu@loongson.cn> References: <20250211124917.28685-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowMDxH+UjR6tnQAMMAA--.47337S4 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoW3JF48uw1DCFWDXr4DtF45twc_yoW7WFWxpr yUuryYyrW8XFsxA393A398Xrs0vr1UW34IvFyaqrW8CFW8G340qr1FkrZ8XF1UXaykJ3Wj 9r1xJay7uF4UAwcCm3ZEXasCq-sJn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkjb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v2 6r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwI xGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k2 6cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07jOb18UUUUU= X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, PROLO_LEO1, 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.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 Split the implementation of the function loongarch_cpu_cpp_builtins into two parts: 1. Macro definitions that do not change (only considering 64-bit architecture) 2. Macro definitions that change with different compilation options. gcc/ChangeLog: * config/loongarch/loongarch-c.cc (builtin_undef): New macro. (loongarch_cpu_cpp_builtins): Split to loongarch_update_cpp_builtins and loongarch_define_unconditional_macros. (loongarch_def_or_undef): New functions. (loongarch_define_unconditional_macros): Likewise. (loongarch_update_cpp_builtins): Likewise. Change-Id: Ifae73ffa2a07a595ed2a7f6ab7b82d8f51328a2a --- gcc/config/loongarch/loongarch-c.cc | 109 +++++++++++++++++----------- 1 file changed, 66 insertions(+), 43 deletions(-) diff --git a/gcc/config/loongarch/loongarch-c.cc b/gcc/config/loongarch/loongarch-c.cc index 5d8c02e094b..9fe911325ab 100644 --- a/gcc/config/loongarch/loongarch-c.cc +++ b/gcc/config/loongarch/loongarch-c.cc @@ -31,13 +31,21 @@ along with GCC; see the file COPYING3. If not see #define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM) #define builtin_define(TXT) cpp_define (pfile, TXT) +#define builtin_undef(TXT) cpp_undef (pfile, TXT) #define builtin_assert(TXT) cpp_assert (pfile, TXT) -void -loongarch_cpu_cpp_builtins (cpp_reader *pfile) +static void +loongarch_def_or_undef (bool def_p, const char *macro, cpp_reader *pfile) +{ + if (def_p) + cpp_define (pfile, macro); + else + cpp_undef (pfile, macro); +} + +static void +loongarch_define_unconditional_macros (cpp_reader *pfile) { - builtin_assert ("machine=loongarch"); - builtin_assert ("cpu=loongarch"); builtin_define ("__loongarch__"); builtin_define_with_value ("__loongarch_arch", @@ -66,45 +74,6 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile) builtin_define ("__loongarch_lp64"); } - /* These defines reflect the ABI in use, not whether the - FPU is directly accessible. */ - if (TARGET_DOUBLE_FLOAT_ABI) - builtin_define ("__loongarch_double_float=1"); - else if (TARGET_SINGLE_FLOAT_ABI) - builtin_define ("__loongarch_single_float=1"); - - if (TARGET_DOUBLE_FLOAT_ABI || TARGET_SINGLE_FLOAT_ABI) - builtin_define ("__loongarch_hard_float=1"); - else - builtin_define ("__loongarch_soft_float=1"); - - - /* ISA Extensions. */ - if (TARGET_DOUBLE_FLOAT) - builtin_define ("__loongarch_frlen=64"); - else if (TARGET_SINGLE_FLOAT) - builtin_define ("__loongarch_frlen=32"); - else - builtin_define ("__loongarch_frlen=0"); - - if (TARGET_HARD_FLOAT && ISA_HAS_FRECIPE) - builtin_define ("__loongarch_frecipe"); - - if (ISA_HAS_LSX) - { - builtin_define ("__loongarch_simd"); - builtin_define ("__loongarch_sx"); - - if (!ISA_HAS_LASX) - builtin_define ("__loongarch_simd_width=128"); - } - - if (ISA_HAS_LASX) - { - builtin_define ("__loongarch_asx"); - builtin_define ("__loongarch_simd_width=256"); - } - /* ISA evolution features */ int max_v_major = 1, max_v_minor = 0; @@ -145,7 +114,61 @@ loongarch_cpu_cpp_builtins (cpp_reader *pfile) builtin_define_with_int_value ("_LOONGARCH_SZPTR", POINTER_SIZE); builtin_define_with_int_value ("_LOONGARCH_FPSET", 32); builtin_define_with_int_value ("_LOONGARCH_SPFPSET", 32); +} + +static void +loongarch_update_cpp_builtins (cpp_reader *pfile) +{ + builtin_undef ("__loongarch_double_float"); + builtin_undef ("__loongarch_single_float"); + /* These defines reflect the ABI in use, not whether the + FPU is directly accessible. */ + if (TARGET_DOUBLE_FLOAT_ABI) + builtin_define ("__loongarch_double_float=1"); + else if (TARGET_SINGLE_FLOAT_ABI) + builtin_define ("__loongarch_single_float=1"); + + builtin_undef ("__loongarch_soft_float"); + builtin_undef ("__loongarch_hard_float"); + if (TARGET_DOUBLE_FLOAT_ABI || TARGET_SINGLE_FLOAT_ABI) + builtin_define ("__loongarch_hard_float=1"); + else + builtin_define ("__loongarch_soft_float=1"); + + + /* ISA Extensions. */ + if (TARGET_DOUBLE_FLOAT) + builtin_define ("__loongarch_frlen=64"); + else if (TARGET_SINGLE_FLOAT) + builtin_define ("__loongarch_frlen=32"); + else + builtin_define ("__loongarch_frlen=0"); + + loongarch_def_or_undef (TARGET_HARD_FLOAT && ISA_HAS_FRECIPE, + "__loongarch_frecipe", pfile); + + loongarch_def_or_undef (ISA_HAS_LSX, "__loongarch_simd", pfile); + loongarch_def_or_undef (ISA_HAS_LSX, "__loongarch_sx", pfile); + loongarch_def_or_undef (ISA_HAS_LASX, "__loongarch_asx", pfile); + + builtin_undef ("__loongarch_simd_width"); + if (ISA_HAS_LSX) + { + if (ISA_HAS_LASX) + builtin_define ("__loongarch_simd_width=256"); + else + builtin_define ("__loongarch_simd_width=128"); + } +} + +void +loongarch_cpu_cpp_builtins (cpp_reader *pfile) +{ + builtin_assert ("machine=loongarch"); + builtin_assert ("cpu=loongarch"); + loongarch_define_unconditional_macros (pfile); + loongarch_update_cpp_builtins (pfile); } /* Hook to validate the current #pragma GCC target and set the state, and From patchwork Tue Feb 11 12:49:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cheng X-Patchwork-Id: 106327 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 D909A3858C5F for ; Tue, 11 Feb 2025 12:49:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D909A3858C5F X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by sourceware.org (Postfix) with ESMTP id BAB333858CDA for ; Tue, 11 Feb 2025 12:48:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BAB333858CDA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=loongson.cn ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BAB333858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739278133; cv=none; b=tssQkOJIpyOdjGgK9a9lHErMtRvmjQ90FF8chZud+SQTPE6PWTr5dLy+dcx+5we9RouKLkRnkxHZODRyVPyZ7h4f6lAisEyR/E/IC5VHAyLMRWdO/vpitGThJJ3VHhqnRkB4eh6tAjB+NZURhmfBF/bdfbzl6OZvNS4jPPLWVYw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739278133; c=relaxed/simple; bh=qkY/kr4pLX/9mMxVE/ZoaBEd2YPj+kpNmiIr6zgrjp8=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=wFOXxWAJW6rG7aLhIRBXpYx1aD6nWit+N+oImxdJRNnp5nSahrlc/iFQowrtf0f4NxlctM1lCfTvaroFtRmeO+zQHcdK4JO3F4/z0rKKir/4RzR4RcoX5ihd5AEBTcHbxV14StF+iJ93XyIeapTAbjzrHUz3FBA3GLTlJpAyMi4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAB333858CDA Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8CxdXAvR6tn5ihyAA--.2160S3; Tue, 11 Feb 2025 20:48:47 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by front1 (Coremail) with SMTP id qMiowMDxH+UjR6tnQAMMAA--.47337S5; Tue, 11 Feb 2025 20:48:47 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn Subject: [PATCH 3/3] LoongArch: After setting the compilation options, update the predefined macros. Date: Tue, 11 Feb 2025 20:49:17 +0800 Message-Id: <20250211124917.28685-4-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250211124917.28685-1-chenglulu@loongson.cn> References: <20250211124917.28685-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowMDxH+UjR6tnQAMMAA--.47337S5 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoWxWFy8try7Cr18KF47uFWDZFc_yoW5Aw13pF ZruF1FyF48JrZ7G3sxJa43Xrn3Jrn7WrW2vF4ft340kr43Jry8Zr18GF9xXF15Xa1DWrya 9r4Sk3W5ua1jvwcCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUkjb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4 xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE14v2 6r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwI xGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480 Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7 IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k2 6cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxV AFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07josjUUUUUU= X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, 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.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 target/PR118828 gcc/ChangeLog: * config/loongarch/loongarch-c.cc (loongarch_pragma_target_parse): Update the predefined macros. gcc/testsuite/ChangeLog: * gcc.target/loongarch/pr118828.c: New test. Change-Id: I13f7b44b11bba2080db797157a0389cc1bd65ac6 --- gcc/config/loongarch/loongarch-c.cc | 14 ++++++++ gcc/testsuite/gcc.target/loongarch/pr118828.c | 34 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828.c diff --git a/gcc/config/loongarch/loongarch-c.cc b/gcc/config/loongarch/loongarch-c.cc index 9fe911325ab..83df82c1361 100644 --- a/gcc/config/loongarch/loongarch-c.cc +++ b/gcc/config/loongarch/loongarch-c.cc @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "tm.h" #include "c-family/c-common.h" #include "cpplib.h" +#include "c-family/c-pragma.h" #include "tm_p.h" #define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM) @@ -203,6 +204,19 @@ loongarch_pragma_target_parse (tree args, tree pop_target) loongarch_reset_previous_fndecl (); + /* For the definitions, ensure all newly defined macros are considered + as used for -Wunused-macros. There is no point warning about the + compiler predefined macros. */ + cpp_options *cpp_opts = cpp_get_options (parse_in); + unsigned char saved_warn_unused_macros = cpp_opts->warn_unused_macros; + cpp_opts->warn_unused_macros = 0; + + cpp_force_token_locations (parse_in, BUILTINS_LOCATION); + loongarch_update_cpp_builtins (parse_in); + cpp_stop_forcing_token_locations (parse_in); + + cpp_opts->warn_unused_macros = saved_warn_unused_macros; + /* If we're popping or reseting make sure to update the globals so that the optab availability predicates get recomputed. */ if (pop_target) diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828.c b/gcc/testsuite/gcc.target/loongarch/pr118828.c new file mode 100644 index 00000000000..abdda24c758 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/pr118828.c @@ -0,0 +1,34 @@ +/* { dg-do preprocess } */ +/* { dg-options "-mno-lasx" } */ + +#ifdef __loongarch_asx +#error LASX should not be available here +#endif + +#ifdef __loongarch_simd_width +#if __loongarch_simd_width == 256 +#error simd width shuold not be 256 +#endif +#endif + +#pragma GCC push_options +#pragma GCC target("lasx") +#ifndef __loongarch_asx +#error LASX should be available here +#endif +#ifndef __loongarch_simd_width +#error simd width should be available here +#elif __loongarch_simd_width != 256 +#error simd width should be 256 +#endif +#pragma GCC pop_options + +#ifdef __loongarch_asx +#error LASX should become unavailable again +#endif + +#ifdef __loongarch_simd_width +#if __loongarch_simd_width == 256 +#error simd width shuold not be 256 again +#endif +#endif