From patchwork Wed Feb 12 10:03:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lulu Cheng X-Patchwork-Id: 106365 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 16950385780D for ; Wed, 12 Feb 2025 10:04:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16950385780D 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 37BEE3858408 for ; Wed, 12 Feb 2025 10:03:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37BEE3858408 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 37BEE3858408 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=1739354594; cv=none; b=O8+G17YCi4kzLmo03D8W9mdr+LruqenNCZXxbC1rEFbiEAiauUe0E9t/oNAyv+uU5ATZZDGxMLqCzpauHPq8NvrP4a2oQbGihonVaxISzhsWJ1jC86GabPsWOchlsQcRQ23Oz6tNze9HRUSMt00GYAvkNfT6aXJIStp1lNrXj9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1739354594; c=relaxed/simple; bh=P3wijspRxOv1V968ikIpMHkSHVcnbG+p9msQK0KjBGA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=AXMrlXOuXgkAGJFan8JM+157Kg9ewNz1LxENGgYOv1CbxULDYtHS/bKLAZLywOGcYO39lhlFpW42A5Qw7BVwdwYAdQkNYo847iiNKYmHeuh6Dk0kAi2UJd7Of1RRNqIRvesYD32+BTSS/NSSavtbtwdWE99pDPHzpm2v7WH8XIM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37BEE3858408 Received: from loongson.cn (unknown [10.20.4.107]) by gateway (Coremail) with SMTP id _____8DxdWnecaxn7ARzAA--.3638S3; Wed, 12 Feb 2025 18:03:10 +0800 (CST) Received: from loongson-pc.loongson.cn (unknown [10.20.4.107]) by front1 (Coremail) with SMTP id qMiowMCx7MTacaxnpXsNAA--.49752S5; Wed, 12 Feb 2025 18:03:10 +0800 (CST) From: Lulu Cheng To: gcc-patches@gcc.gnu.org Cc: xry111@xry111.site, i.swmail@xen0n.name, xuchenghua@loongson.cn, chenglulu@loongson.cn Subject: [PATCH v2 3/4] LoongArch: After setting the compilation options, update the predefined macros. Date: Wed, 12 Feb 2025 18:03:48 +0800 Message-Id: <20250212100349.11909-4-chenglulu@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20250212100349.11909-1-chenglulu@loongson.cn> References: <20250212100349.11909-1-chenglulu@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: qMiowMCx7MTacaxnpXsNAA--.49752S5 X-CM-SenderInfo: xfkh0wpoxo3qxorr0wxvrqhubq/ X-Coremail-Antispam: 1Uk129KBj93XoWxKr4UCry7XFykXF1ktFyfXwc_yoWxZw4UpF Zrur1rtr48JrZ3JrnxJa4Yqrnaqrn7Wryava4ftry8Cw47Jry8Xr1kJr9xZF13G3WUG34S vr4S93W5uF1jv3gCm3ZEXasCq-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 PR target/118828 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. * gcc.target/loongarch/pr118828-2.c: New test. * gcc.target/loongarch/pr118828-3.c: New test. * gcc.target/loongarch/pr118828-4.c: New test. Change-Id: I13f7b44b11bba2080db797157a0389cc1bd65ac6 --- gcc/config/loongarch/loongarch-c.cc | 14 +++++ .../gcc.target/loongarch/pr118828-2.c | 30 ++++++++++ .../gcc.target/loongarch/pr118828-3.c | 55 +++++++++++++++++++ .../gcc.target/loongarch/pr118828-4.c | 55 +++++++++++++++++++ gcc/testsuite/gcc.target/loongarch/pr118828.c | 34 ++++++++++++ 5 files changed, 188 insertions(+) create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828-2.c create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828-3.c create mode 100644 gcc/testsuite/gcc.target/loongarch/pr118828-4.c 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 9a8de1ec381..66ae77ad665 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) @@ -212,6 +213,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-2.c b/gcc/testsuite/gcc.target/loongarch/pr118828-2.c new file mode 100644 index 00000000000..3d32fcc15c9 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/pr118828-2.c @@ -0,0 +1,30 @@ +/* { dg-do preprocess } */ +/* { dg-options "-mno-lsx" } */ + +#ifdef __loongarch_sx +#error LSX should not be available here +#endif + +#ifdef __loongarch_simd_width +#error simd width shuold not be available here +#endif + +#pragma GCC push_options +#pragma GCC target("lsx") +#ifndef __loongarch_sx +#error LSX should be available here +#endif +#ifndef __loongarch_simd_width +#error simd width should be available here +#elif __loongarch_simd_width != 128 +#error simd width should be 128 +#endif +#pragma GCC pop_options + +#ifdef __loongarch_sx +#error LSX should become unavailable again +#endif + +#ifdef __loongarch_simd_width +#error simd width shuold become unavailable again +#endif diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-3.c b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c new file mode 100644 index 00000000000..a682ae4a356 --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/pr118828-3.c @@ -0,0 +1,55 @@ +/* { dg-do run } */ +/* { dg-options "-march=loongarch64" } */ + +#include +#include +#include + +#ifndef __loongarch_arch +#error __loongarch_arch should not be available here +#endif + +void +test1 (void) +{ + if (strcmp (__loongarch_arch, "loongarch64") != 0) + { + printf ("__loongarch_arch should be loongarch64 here.\n"); + abort (); + } +} + + +#pragma GCC push_options +#pragma GCC target("arch=la64v1.1") + +void +test2 (void) +{ + if (strcmp (__loongarch_arch, "la64v1.1") != 0) + { + printf ("__loongarch_arch should be la464 here.\n"); + abort (); + } +} +#pragma GCC pop_options + +void +test3 (void) +{ + if (strcmp (__loongarch_arch, "loongarch64") != 0) + { + printf ("__loongarch_arch should be loongarch64 here.\n"); + abort (); + } +} + +int +main (int argc, char **argv) +{ + test1 (); + test2 (); + test3 (); + + return 0; +} diff --git a/gcc/testsuite/gcc.target/loongarch/pr118828-4.c b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c new file mode 100644 index 00000000000..3b3a7c6078c --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/pr118828-4.c @@ -0,0 +1,55 @@ +/* { dg-do run } */ +/* { dg-options "-mtune=la464" } */ + +#include +#include +#include + +#ifndef __loongarch_tune +#error __loongarch_tune should not be available here +#endif + +void +test1 (void) +{ + if (strcmp (__loongarch_tune, "la464") != 0) + { + printf ("__loongarch_tune should be la464 here.\n"); + abort (); + } +} + + +#pragma GCC push_options +#pragma GCC target("arch=la664") + +void +test2 (void) +{ + if (strcmp (__loongarch_tune, "la664") != 0) + { + printf ("__loongarch_tune should be la664 here.\n"); + abort (); + } +} +#pragma GCC pop_options + +void +test3 (void) +{ + if (strcmp (__loongarch_tune, "la464") != 0) + { + printf ("__loongarch_tune should be la464 here.\n"); + abort (); + } +} + +int +main (int argc, char **argv) +{ + test1 (); + test2 (); + test3 (); + + return 0; +} 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