From patchwork Thu Feb 23 10:23:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 60886 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp236767wrd; Thu, 23 Feb 2023 02:24:22 -0800 (PST) X-Google-Smtp-Source: AK7set82SixIy5XwrnU0GySOB1apGuin7qfEAiIl9GgslgfME/uP8Lq/h5gyd0a2cMNL4TY3EhhN X-Received: by 2002:a05:6402:916:b0:4af:63a7:7485 with SMTP id g22-20020a056402091600b004af63a77485mr4735158edz.17.1677147862032; Thu, 23 Feb 2023 02:24:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677147862; cv=none; d=google.com; s=arc-20160816; b=RbGGDA8peLzgFk2qEn4KQfyQWzhhCG/SuDb+y9a2KkPC0K/XoHgbCajQipnufy6LDi NjUbVs2tk/nX6w5nkM+2g6Omn3/YKIXQmWFoUioQbskJ7Ff1eMsB5E+KiKROBHckxAwv n2g6hpKQgfTN9MtNM7clKTABKnF3fkp423w9XpFkEoOIm4R0CiC4DqYF1mX4JG1wlLSQ 8cB+a2RMfLBtydtUh3h7XRL4V6/ATQtVxQibGyHtJlcPq3EEhYGReNHltWT4BzeO91fm RhjLvolLNC/Ojr8BMgTgKBq7zKIOj3qvQqHMI7LKqcAts74dhAU2scTEef2AdWC9Csck /zCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Ncq8MTx77VeLaORqlzU9IWkz3DhdaCqln8qxScqRx+Y=; b=hPnklHmzTs1bIxt6wxn/yCI1AFKbn49wDdMLBelqMLMiOeWOFqDrFWpz3AT5nWgAlF 1BzRnSztRSu5GsypNINMfNg9WU+NOlJDQjIUIVkKejgYDuOOswhMznOI9Ocp6QSyD7TX 20cvFk6P3ZM5mDoZmffeNoARAzfsNgr9NfKtshxgilKu04jJUjRiPmor455vsgkU0iSD twe0rupHj+WH4TqpZRfZUhCrzRGoH196LPpEGLEvzGzmWGFgYKFlXd5ueIJ7rO/3tXm8 3Mko4ksy7eL5euH57HMGsLhqANvdsZv/MnaSB4Tgn0QuYaV2vVHz1/UTHhtKsly74vcN /lgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="yknm/a9G"; 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=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id j11-20020aa7c0cb000000b004ad0878cfd6si2520089edp.612.2023.02.23.02.24.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Feb 2023 02:24:22 -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=@gcc.gnu.org header.s=default header.b="yknm/a9G"; 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=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CEB563858002 for ; Thu, 23 Feb 2023 10:24:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CEB563858002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677147860; bh=Ncq8MTx77VeLaORqlzU9IWkz3DhdaCqln8qxScqRx+Y=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=yknm/a9GpkrWArzDVWcc0KkqM1PQ2tP2N1hAjx9j3aZA08Q09S+wa69ikHhcGq67C f72Kldg9yryVTzovSHVbVNn09cygGd1G43g4lx6SGRcueVBWi0KOETTXVU3ImsejzD Eioo0Adi5I16nl4q4b2Uz+C0/AH9GzEpZIh01e4c= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 72B893858C5E for ; Thu, 23 Feb 2023 10:23:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72B893858C5E Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-512-ag55JyhTMgmf2xSkLYhYyA-1; Thu, 23 Feb 2023 05:23:25 -0500 X-MC-Unique: ag55JyhTMgmf2xSkLYhYyA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A395788434B for ; Thu, 23 Feb 2023 10:23:25 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 63D0D1121314; Thu, 23 Feb 2023 10:23:25 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 31NANNgQ507486 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 23 Feb 2023 11:23:23 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 31NANMql507485; Thu, 23 Feb 2023 11:23:22 +0100 Date: Thu, 23 Feb 2023 11:23:22 +0100 To: Jason Merrill , Jonathan Wakely Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Add target hook for emit_support_tinfos [PR108883] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758616996916105640?= X-GMAIL-MSGID: =?utf-8?q?1758616996916105640?= Hi! _Float16 and decltype(0.0bf16) types are on x86 supported only with -msse2. On x86_64 that is the default, but on ia32 it is not. We should still emit fundamental type tinfo for those types in libsupc++.a/libstdc++.*, regardless of whether libsupc++/libstdc++ is compiled with -msse2 or not, as user programs can be compiled with different ISA flags from libsupc++/libstdc++ and if they are compiled with -msse2 and use std::float16_t or std::bfloat16_t and need RTTI for it, it should work out of the box. Furthermore, libstdc++ ABI on ia32 shouldn't depend on whether the library is compiled with -mno-sse or -msse2. Unfortunately, just hacking up libsupc++ Makefile/configure so that a single source is compiled with -msse2 isn't appropriate, because that TU emits also code and the code should be able to run on CPUs which libstdc++ supports. We could add [[gnu::attribute ("no-sse2")]] there perhaps conditionally, but it all gets quite ugly. The following patch instead adds a target hook which allows the backend to temporarily tweak registered types such that emit_support_tinfos emits whatever is needed. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-02-23 Jakub Jelinek PR target/108883 * hooks.h (hook_void_bool): Declare. * hooks.cc (hook_void_bool): New function. * target.def (emit_support_tinfos): New target hook. * doc/tm.texi.in (emit_support_tinfos): Document it. * doc/tm.texi: Regenerated. * config/i386/i386.cc (ix86_emit_support_tinfos): New function. (TARGET_EMIT_SUPPORT_TINFOS): Redefine. * rtti.cc (emit_support_tinfos): Call targetm.emit_support_tinfos before and after emit_support_tinfo_1 calls. Jakub --- gcc/hooks.h.jj 2023-01-02 09:32:29.418183667 +0100 +++ gcc/hooks.h 2023-02-22 12:34:32.144973558 +0100 @@ -77,6 +77,7 @@ extern bool hook_bool_wint_wint_uint_boo unsigned int, bool); extern void hook_void_void (void); +extern void hook_void_bool (bool); extern void hook_void_constcharptr (const char *); extern void hook_void_rtx_insn_int (rtx_insn *, int); extern void hook_void_FILEptr_constcharptr (FILE *, const char *); --- gcc/hooks.cc.jj 2023-01-02 09:32:49.675890970 +0100 +++ gcc/hooks.cc 2023-02-22 12:36:46.241035355 +0100 @@ -271,6 +271,11 @@ hook_hwi_void_0 (void) } void +hook_void_bool (bool) +{ +} + +void hook_void_tree (tree) { } --- gcc/target.def.jj 2023-01-04 10:45:50.117881714 +0100 +++ gcc/target.def 2023-02-22 12:33:39.715731356 +0100 @@ -2606,6 +2606,20 @@ types.", const char *, (const_tree type), hook_constcharptr_const_tree_null) +/* Temporarily add conditional target specific types for the purpose of + emitting C++ fundamental type tinfos. */ +DEFHOOK +(emit_support_tinfos, + "If your target defines any fundamental types which depend on ISA flags,\n\ +they might need C++ tinfo symbols in libsupc++/libstdc++ regardless of\n\ +ISA flags the library is compiled with.\n\ +The hook is called with @var{add} @code{true} at the start of C++ FE\n\ +@code{emit_support_tinfos} and with @var{add} @code{false} at the end of it\n\ +and can temporarily create fundamental types that are not supposed to be\n\ +otherwise created due to the ISA options.", + void, (bool add), + hook_void_bool) + /* Make any adjustments to libfunc names needed for this target. */ DEFHOOK (init_libfuncs, --- gcc/doc/tm.texi.in.jj 2023-01-16 11:52:16.124733460 +0100 +++ gcc/doc/tm.texi.in 2023-02-22 12:46:37.951482849 +0100 @@ -1286,6 +1286,8 @@ pattern needs to support both a 32- and @hook TARGET_MANGLE_TYPE +@hook TARGET_EMIT_SUPPORT_TINFOS + @node Type Layout @section Layout of Source Language Data Types --- gcc/doc/tm.texi.jj 2023-01-16 11:52:16.123733475 +0100 +++ gcc/doc/tm.texi 2023-02-22 12:46:41.741428081 +0100 @@ -1525,6 +1525,16 @@ appropriate for a target that does not d types. @end deftypefn +@deftypefn {Target Hook} void TARGET_EMIT_SUPPORT_TINFOS (bool @var{add}) +If your target defines any fundamental types which depend on ISA flags, +they might need C++ tinfo symbols in libsupc++/libstdc++ regardless of +ISA flags the library is compiled with. +The hook is called with @var{add} @code{true} at the start of C++ FE +@code{emit_support_tinfos} and with @var{add} @code{false} at the end of it +and can temporarily create fundamental types that are not supposed to be +otherwise created due to the ISA options. +@end deftypefn + @node Type Layout @section Layout of Source Language Data Types --- gcc/config/i386/i386.cc.jj 2023-02-16 10:13:23.701210667 +0100 +++ gcc/config/i386/i386.cc 2023-02-22 12:59:55.110960505 +0100 @@ -22775,6 +22775,30 @@ ix86_mangle_type (const_tree type) } } +/* Temporarily tweak the set of fundamental types for C++ + emit_support_tinfos purposes. */ + +static void +ix86_emit_support_tinfos (bool add) +{ + extern tree ix86_float16_type_node; + extern tree ix86_bf16_type_node; + + if (TARGET_SSE2) + return; + if (add) + { + gcc_checking_assert (!float16_type_node && !bfloat16_type_node); + float16_type_node = ix86_float16_type_node; + bfloat16_type_node = ix86_bf16_type_node; + } + else + { + float16_type_node = NULL_TREE; + bfloat16_type_node = NULL_TREE; + } +} + static GTY(()) tree ix86_tls_stack_chk_guard_decl; static tree @@ -24954,6 +24978,9 @@ ix86_libgcc_floating_mode_supported_p #undef TARGET_MANGLE_TYPE #define TARGET_MANGLE_TYPE ix86_mangle_type +#undef TARGET_EMIT_SUPPORT_TINFOS +#define TARGET_EMIT_SUPPORT_TINFOS ix86_emit_support_tinfos + #undef TARGET_STACK_PROTECT_GUARD #define TARGET_STACK_PROTECT_GUARD ix86_stack_protect_guard --- gcc/cp/rtti.cc.jj 2023-01-16 11:52:16.090733961 +0100 +++ gcc/cp/rtti.cc 2023-02-22 12:40:10.078089124 +0100 @@ -1623,6 +1623,9 @@ emit_support_tinfos (void) if (!dtor || DECL_EXTERNAL (dtor)) return; + /* Tell target code that support tinfos are about to be emitted. */ + targetm.emit_support_tinfos (true); + /* All these are really builtins. So set the location. */ location_t saved_loc = input_location; input_location = BUILTINS_LOCATION; @@ -1652,6 +1655,9 @@ emit_support_tinfos (void) emit_support_tinfo_1 (fallback_dfloat128_type); } input_location = saved_loc; + + /* Tell target code that support tinfos have been emitted. */ + targetm.emit_support_tinfos (false); } /* Finish a type info decl. DECL_PTR is a pointer to an unemitted