From patchwork Tue Mar 12 12:11:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1910979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Ssc6b5Lz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TvCF92pZ8z1yWy for ; Tue, 12 Mar 2024 23:12:13 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 451113858014 for ; Tue, 12 Mar 2024 12:12:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 678F83858D39 for ; Tue, 12 Mar 2024 12:11:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 678F83858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 678F83858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::534 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710245510; cv=none; b=HQXOARqFUqFaMqBvThk8q74uoco5v0rBIX5kdEi7Ra/vWsW9DQ+SJC5B/105Lx/psXZzF0FqHqvVLwWgGyJzCWyUPrpTbIKVM26NwMIw9uMWGqwme9pgGhYI/dSm1dhegbcLOXZGMC28Y6XiiisRw8wtZ4mXWssbuySR0fR13c8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710245510; c=relaxed/simple; bh=XVUjoKOWpCFWBpLbl4vlGN1KP7P38xvX+kr0Hd8CfH4=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=Z8Zh00sLRMLk5EoNnh67kPj16ZwI2CzoonkvNXJLFHmjyQ/uygPD+sinVDLJ/vvBnX8wBnEI6kCUPuvbx9nhHYUlc3NHXQSJgPtGTeLgs4hWvT06ApyuqP33p8B4xvzh3gCkGc4xDMVb5BZOY7p0XFakaBlWqWpR0pjPGlxeWTM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5dc949f998fso4984157a12.3 for ; Tue, 12 Mar 2024 05:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710245506; x=1710850306; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=Fb2B5GU8s7K9gFoPpAvTAwpWOTwPac2gQBNV6ww36t0=; b=Ssc6b5LzVSs1I1YMfZiz3ishrxhHnVgAW3YSnqcXAVnTu+rdGcOSeU/UJFVpMPQb8p JIFfWmWTv3RMxWSVE59Eegw3sg3MpPf1oWnrimDzLHK74B3h+ji/vvj9eeS/qOSmoIXL vG6szclvY2JPztITjASvAmqvqcByLnElSL1OiZP1yrd0MlyYMGiR6Q/a9oJAZ8Z8f+gj xf2iS6/jKvjNd+hzVBQHiO3F/81V4Dd0i0fzobEe5qBA53+MFsg4wm158v/z/HWDaWNW wCQVhttbcdZYDUgRCiBjDdGT8v7G+NJQTsc7yqtnorA5R8lvnPkideK0JT5q7A1G5E6G T3Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710245506; x=1710850306; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Fb2B5GU8s7K9gFoPpAvTAwpWOTwPac2gQBNV6ww36t0=; b=Ok/xJ3Rla9yCC+KpcoY4xo8ux0X/HeIANBlTgyW3YZRHOYpaSFzix8nR2W5lOMz6ze D9tAELDgsLbmkTy2Kro719gvaSzKg0pnCThhzV6aoLbtaVOiDaygXQE7IbCSBxC5n8dT Aggna5P6AOpFQkGTicdXE6VbKQwmNRekZCy/iS69nxOb4tMaUQ/a7/ep6eZkZRj0IARU dwKyyDSu57dK1Itd7Z3Z1gLrEi20l73ltDufoFu8yPxL1g0DpiTxSIfqFTg9jcNp5ucL wvflsSIkyNAa4WugvRhyqrJ7UGBM8LrMlW8/NFxKQhDioASNVTYDvBxDDTVBuWw3Ccr/ 1AUw== X-Gm-Message-State: AOJu0YyyrRSs2bOYwwBrLxT//kMZALd/KPDKAYWWyJbgmSm+HWby4FyT u+Bltl6loy6swmw7Ml2PF1QXcThQvVcQZwzXAl/+zTZWxNLjGFLp X-Google-Smtp-Source: AGHT+IE5O/uKJAItXb5a/o0YVjmTQrDNPh/Hxkx90Ze3iIr+QLRcWc/6gQ67oK1l9DMQBh7Gzwsa9A== X-Received: by 2002:a17:902:7847:b0:1dc:abf0:14ee with SMTP id e7-20020a170902784700b001dcabf014eemr1189204pln.22.1710245506014; Tue, 12 Mar 2024 05:11:46 -0700 (PDT) Received: from Thaum. (202-161-100-107.tpgi.com.au. [202.161.100.107]) by smtp.gmail.com with ESMTPSA id d16-20020a170902ced000b001d8aa88f59esm6547104plg.110.2024.03.12.05.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 05:11:45 -0700 (PDT) Message-ID: <65f04681.170a0220.35b00.1f01@mx.google.com> X-Google-Original-Message-ID: Date: Tue, 12 Mar 2024 23:11:40 +1100 From: Nathaniel Shead To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, Jason Merrill , Nathan Sidwell Subject: [PATCH v2] c++: Support target-specific nodes with streaming [PR98645,PR111224] References: <65ed9f0f.170a0220.64a2e.2144@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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+incoming=patchwork.ozlabs.org@gcc.gnu.org On Mon, Mar 11, 2024 at 10:36:06AM -0400, Patrick Palka wrote: > On Sun, 10 Mar 2024, Nathaniel Shead wrote: > > > Bootstrapped and regtested on x86_64-pc-linux-gnu and > > aarch64-unknown-linux-gnu, OK for trunk? > > > > It's worth noting that the AArch64 machines I had available to test with > > didn't have a new enough glibc to reproduce the ICEs in the PR, but this > > patch will be necessary (albeit possibly not sufficient) to fix it. > > > > -- >8 -- > > > > Some targets make use of POLY_INT_CSTs and other custom builtin types, > > which currently violate some assumptions when streaming. This patch adds > > support for them, specifically AArch64 SVE types like __fp16. > > It seems other built-in types are handled by adding them to the > fixed_trees vector in init_modules (and then we install them first > during streaming). Could we just add all the target-specific types to > fixed_trees too? > Yes, that works too. Seems cleaner as well, though I had to add it as a separate loop because the set of builtin types registered is not determined until runtiem (depending on e.g. ABI flags). I also noticed that this fixes another PR, on PowerPC, so I've added a test for it. Thanks! Bootstrapped and regtested on x86_64-pc-linux-gnu, aarch64-unknown-linux-gnu, and powerpc64le-unknown-linux-gnu; OK for trunk? -- >8 -- Some targets make use of POLY_INT_CSTs and other custom builtin types, which currently violate some assumptions when streaming. This patch adds support for them, such as types like Aarch64 __fp16, PowerPC __ibm128, and vector types thereof. This patch doesn't provide "full" support of AArch64 SVE, however, since for that we would need to support 'target' nodes (tracked in PR108080). Adding the new builtin types means that on Aarch64 we now have 217 global trees created on initialisation (up from 191), so this patch also slightly bumps the initial size of the fixed_trees allocation to 250. PR c++/98645 PR c++/111224 gcc/cp/ChangeLog: * module.cc (enum tree_tag): Add new tag for builtin types. (trees_out::start): POLY_INT_CSTs can be emitted. (trees_in::start): Likewise. (trees_out::core_vals): Stream POLY_INT_CSTs. (trees_in::core_vals): Likewise. (trees_out::type_node): Handle vectors with multiple coeffs. (trees_in::tree_node): Likewise. (init_modules): Register target-specific builtin types. Bump initial capacity slightly. gcc/testsuite/ChangeLog: * g++.dg/modules/target-aarch64-1_a.C: New test. * g++.dg/modules/target-aarch64-1_b.C: New test. * g++.dg/modules/target-powerpc-1_a.C: New test. * g++.dg/modules/target-powerpc-1_b.C: New test. Signed-off-by: Nathaniel Shead Reviewed-by: Patrick Palka --- gcc/cp/module.cc | 32 +++++++++++++------ .../g++.dg/modules/target-aarch64-1_a.C | 17 ++++++++++ .../g++.dg/modules/target-aarch64-1_b.C | 13 ++++++++ .../g++.dg/modules/target-powerpc-1_a.C | 7 ++++ .../g++.dg/modules/target-powerpc-1_b.C | 10 ++++++ 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/target-aarch64-1_a.C create mode 100644 gcc/testsuite/g++.dg/modules/target-aarch64-1_b.C create mode 100644 gcc/testsuite/g++.dg/modules/target-powerpc-1_a.C create mode 100644 gcc/testsuite/g++.dg/modules/target-powerpc-1_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 99055523d91..8aab9ea0bae 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -5173,7 +5173,6 @@ trees_out::start (tree t, bool code_streamed) break; case FIXED_CST: - case POLY_INT_CST: gcc_unreachable (); /* Not supported in C++. */ break; @@ -5259,7 +5258,6 @@ trees_in::start (unsigned code) case FIXED_CST: case IDENTIFIER_NODE: - case POLY_INT_CST: case SSA_NAME: case TARGET_MEM_REF: case TRANSLATION_UNIT_DECL: @@ -6106,7 +6104,10 @@ trees_out::core_vals (tree t) break; case POLY_INT_CST: - gcc_unreachable (); /* Not supported in C++. */ + if (streaming_p ()) + for (unsigned ix = 0; ix != NUM_POLY_INT_COEFFS; ix++) + WT (POLY_INT_CST_COEFF (t, ix)); + break; case REAL_CST: if (streaming_p ()) @@ -6615,8 +6616,9 @@ trees_in::core_vals (tree t) break; case POLY_INT_CST: - /* Not suported in C++. */ - return false; + for (unsigned ix = 0; ix != NUM_POLY_INT_COEFFS; ix++) + RT (POLY_INT_CST_COEFF (t, ix)); + break; case REAL_CST: if (const void *bytes = buf (sizeof (real_value))) @@ -9068,8 +9070,8 @@ trees_out::type_node (tree type) if (streaming_p ()) { poly_uint64 nunits = TYPE_VECTOR_SUBPARTS (type); - /* to_constant asserts that only coeff[0] is of interest. */ - wu (static_cast (nunits.to_constant ())); + for (unsigned ix = 0; ix != NUM_POLY_INT_COEFFS; ix++) + wu (nunits.coeffs[ix]); } break; } @@ -9630,9 +9632,11 @@ trees_in::tree_node (bool is_use) case VECTOR_TYPE: { - unsigned HOST_WIDE_INT nunits = wu (); + poly_uint64 nunits; + for (unsigned ix = 0; ix != NUM_POLY_INT_COEFFS; ix++) + nunits.coeffs[ix] = wu (); if (!get_overrun ()) - res = build_vector_type (res, static_cast (nunits)); + res = build_vector_type (res, nunits); } break; } @@ -20151,7 +20155,7 @@ init_modules (cpp_reader *reader) some global trees are lazily created and we don't want that to mess with our syndrome of fixed trees. */ unsigned crc = 0; - vec_alloc (fixed_trees, 200); + vec_alloc (fixed_trees, 250); dump () && dump ("+Creating globals"); /* Insert the TRANSLATION_UNIT_DECL. */ @@ -20169,6 +20173,14 @@ init_modules (cpp_reader *reader) dump () && dump ("+%u", v); } } + /* OS- and machine-specific types are dynamically registered at + runtime, so cannot be part of global_tree_arys. */ + registered_builtin_types && dump ("") && dump ("+\tB:"); + for (tree t = registered_builtin_types; t; t = TREE_CHAIN (t)) + { + unsigned v = maybe_add_global (TREE_VALUE (t), crc); + dump () && dump ("+%u", v); + } global_crc = crc32_unsigned (crc, fixed_trees->length ()); dump ("") && dump ("Created %u unique globals, crc=%x", fixed_trees->length (), global_crc); diff --git a/gcc/testsuite/g++.dg/modules/target-aarch64-1_a.C b/gcc/testsuite/g++.dg/modules/target-aarch64-1_a.C new file mode 100644 index 00000000000..6c699053cdc --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/target-aarch64-1_a.C @@ -0,0 +1,17 @@ +// PR c++/111224 +// { dg-do compile { target aarch64*-*-* } } +// { dg-require-effective-target aarch64_asm_sve_ok } +// { dg-additional-options "-fmodules-ts -march=armv8.2-a+sve" } + +module; + +// We can't do a header unit of this right now because this +// uses target attributes, that we don't yet support. +// See also PR c++/108080. +#include + +export module M; + +export inline void foo(svbool_t x, svfloat16_t f) { + svabs_f16_x(x, f); +} diff --git a/gcc/testsuite/g++.dg/modules/target-aarch64-1_b.C b/gcc/testsuite/g++.dg/modules/target-aarch64-1_b.C new file mode 100644 index 00000000000..c18691dcf8a --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/target-aarch64-1_b.C @@ -0,0 +1,13 @@ +// PR c++/111224 +// { dg-module-do link { target aarch64*-*-* } } +// { dg-require-effective-target aarch64_asm_sve_ok } +// { dg-additional-options "-fmodules-ts -fno-module-lazy -march=armv8.2-a+sve" } + +#include +import M; + +int main() { + svbool_t x = svptrue_b8 (); + svfloat16_t f = svdup_n_f16(1.0); + foo(x, f); +} diff --git a/gcc/testsuite/g++.dg/modules/target-powerpc-1_a.C b/gcc/testsuite/g++.dg/modules/target-powerpc-1_a.C new file mode 100644 index 00000000000..693ed101ed5 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/target-powerpc-1_a.C @@ -0,0 +1,7 @@ +// PR c++/98645 +// { dg-do compile { target powerpc*-*-* } } +// { dg-require-effective-target ppc_float128_sw } +// { dg-additional-options "-fmodules-ts -mfloat128 -mabi=ieeelongdouble" } + +export module M; +export __ibm128 i = 0.0; diff --git a/gcc/testsuite/g++.dg/modules/target-powerpc-1_b.C b/gcc/testsuite/g++.dg/modules/target-powerpc-1_b.C new file mode 100644 index 00000000000..d6b684b556d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/target-powerpc-1_b.C @@ -0,0 +1,10 @@ +// PR c++/98645 +// { dg-module-do compile { target powerpc*-*-* } } +// { dg-require-effective-target ppc_float128_sw } +// { dg-additional-options "-fmodules-ts -mfloat128 -mabi=ieeelongdouble" } + +import M; + +int main() { + __ibm128 j = i; +}