public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>,
	Jonathan Wakely <jwakely@redhat.com>,
	gcc-patches@gcc.gnu.org
Subject: [PATCH] c++, v2: Emit fundamental tinfos for all _Float*/decltype(0.0bf16) types unconditionally [PR108883]
Date: Wed, 1 Mar 2023 10:19:48 +0100	[thread overview]
Message-ID: <Y/8YtP5QiQzQ9spF@tucnak> (raw)
In-Reply-To: <Y/3RuhY7f0bkoZA+@tucnak>

On Tue, Feb 28, 2023 at 11:04:42AM +0100, Jakub Jelinek via Gcc-patches wrote:
> On Tue, Feb 28, 2023 at 12:51:06AM +0100, Jakub Jelinek via Gcc-patches wrote:
> > And then there is a question whether we want to emit rtti for
> > _Float{16,32,64,128}, _Float{32,64,128}x and decltype(0.0bf16) regardless
> > of whether the target supports them at all or not.
> 
> If the answer to that is yes, we want them all, then the following patch
> arranges that (had to force immediate emit_tinfo_decl to get rid of the
> fallback_* stuff), these days it doesn't mean it will be emitted right away
> anyway, just it will be registered with varpool and have initializers
> created.
> 
> If the answer is yes, except _Float128x, we could in the patch just move
> that &float128x_type_node to the other initializer.
> 
> If the answer is no, then I think we need a target hook which would tell us
> which fundamentals should be forced this way, could have e.g. a form
> of returning a vector of global tree addresses to be treated that way in
> addition to the standard ones (dfloat*), or a hook that would take
> a callback pointer and be called with &emit_support_tinfo_1 and the backend
> would call the callback on any types it wants to handle that way.

Here is an actually bootstrapped/regtested version of that patch - had to add
bfloat16_type_node mangling to cp/mangle.cc, otherwise it ICEd e.g. on
i686-linux when not compiled with -msse2, but also on any non-x86 target.

Though, if the answer to the earlier question is no, I think the version with
a callback passed to target hook would be better because e.g. target might
need to specify some particular TYPE_MODE or similar things on the fallback
type for a particular case.

2023-03-01  Jakub Jelinek  <jakub@redhat.com>

	PR target/108883
	* cp-tree.h (enum cp_tree_index): Remove CPTI_FALLBACK_DFLOAT*_TYPE
	enumerators.
	(fallback_dfloat32_type, fallback_dfloat64_type,
	fallback_dfloat128_type): Remove.
	* rtti.cc (emit_support_tinfo_1): If not emitted already, call
	emit_tinfo_decl and remove from unemitted_tinfo_decls right away.
	(emit_support_tinfos): Move &dfloat*_type_node, &bfloat16-type_node
	and &float[0-9]*_type_node from fundamentals array into new
	fundamentals_with_fallback array.  Call emit_support_tinfo_1
	on elements of that array too, with the difference that if
	the type is NULL, use a fallback REAL_TYPE for it temporarily.
	Drop the !targetm.decimal_float_supported_p () handling.
	* mangle.cc (write_builtin_type): Remove references to
	fallback_dfloat*_type.  Handle bfloat16_type_node mangling.

--- gcc/cp/cp-tree.h.jj	2023-02-18 12:38:30.910023526 +0100
+++ gcc/cp/cp-tree.h	2023-02-28 10:39:22.377379948 +0100
@@ -235,10 +235,6 @@ enum cp_tree_index
 
     CPTI_PSEUDO_CONTRACT_VIOLATION,
 
-    CPTI_FALLBACK_DFLOAT32_TYPE,
-    CPTI_FALLBACK_DFLOAT64_TYPE,
-    CPTI_FALLBACK_DFLOAT128_TYPE,
-
     CPTI_MAX
 };
 
@@ -397,13 +393,6 @@ extern GTY(()) tree cp_global_trees[CPTI
    access nodes in tree.h.  */
 
 #define access_default_node		null_node
-
-/* Variant of dfloat{32,64,128}_type_node only used for fundamental
-   rtti purposes if DFP is disabled.  */
-#define fallback_dfloat32_type		cp_global_trees[CPTI_FALLBACK_DFLOAT32_TYPE]
-#define fallback_dfloat64_type		cp_global_trees[CPTI_FALLBACK_DFLOAT64_TYPE]
-#define fallback_dfloat128_type		cp_global_trees[CPTI_FALLBACK_DFLOAT128_TYPE]
-
 \f
 #include "name-lookup.h"
 
--- gcc/cp/rtti.cc.jj	2023-02-22 15:58:50.137998090 +0100
+++ gcc/cp/rtti.cc	2023-02-28 10:31:53.693893021 +0100
@@ -1577,6 +1577,15 @@ emit_support_tinfo_1 (tree bltn)
 	  gcc_assert (TREE_PUBLIC (tinfo) && !DECL_COMDAT (tinfo));
 	  DECL_INTERFACE_KNOWN (tinfo) = 1;
 	}
+
+      /* Emit it right away if not emitted already.  */
+      if (DECL_INITIAL (tinfo) == NULL_TREE)
+	{
+	  gcc_assert (unemitted_tinfo_decls->last () == tinfo);
+	  bool ok = emit_tinfo_decl (tinfo);
+	  gcc_assert (ok);
+	  unemitted_tinfo_decls->pop ();
+	}
     }
 }
 
@@ -1602,10 +1611,17 @@ emit_support_tinfos (void)
     &long_integer_type_node, &long_unsigned_type_node,
     &long_long_integer_type_node, &long_long_unsigned_type_node,
     &float_type_node, &double_type_node, &long_double_type_node,
+    &nullptr_type_node,
+    0
+  };
+  /* Similar, but for floating point types only which should get type info
+     regardless whether they are non-NULL or NULL.  */
+  static tree *const fundamentals_with_fallback[] =
+  {
     &dfloat32_type_node, &dfloat64_type_node, &dfloat128_type_node,
     &bfloat16_type_node, &float16_type_node, &float32_type_node,
     &float64_type_node, &float128_type_node, &float32x_type_node,
-    &float64x_type_node, &float128x_type_node, &nullptr_type_node,
+    &float64x_type_node, &float128x_type_node,
     0
   };
   int ix;
@@ -1627,8 +1643,20 @@ emit_support_tinfos (void)
   location_t saved_loc = input_location;
   input_location = BUILTINS_LOCATION;
   doing_runtime = 1;
+  tree fallback = NULL_TREE;
   for (ix = 0; fundamentals[ix]; ix++)
     emit_support_tinfo_1 (*fundamentals[ix]);
+  for (ix = 0; fundamentals_with_fallback[ix]; ix++)
+    if (*fundamentals_with_fallback[ix])
+      emit_support_tinfo_1 (*fundamentals_with_fallback[ix]);
+    else
+      {
+	if (fallback == NULL_TREE)
+	  fallback = make_node (REAL_TYPE);
+	*fundamentals_with_fallback[ix] = fallback;
+	emit_support_tinfo_1 (fallback);
+	*fundamentals_with_fallback[ix] = NULL_TREE;
+      }
   for (ix = 0; ix < NUM_INT_N_ENTS; ix ++)
     if (int_n_enabled_p[ix])
       {
@@ -1637,20 +1665,6 @@ emit_support_tinfos (void)
       }
   for (tree t = registered_builtin_types; t; t = TREE_CHAIN (t))
     emit_support_tinfo_1 (TREE_VALUE (t));
-  /* For compatibility, emit DFP typeinfos even when DFP isn't enabled,
-     because we've emitted that in the past.  */
-  if (!targetm.decimal_float_supported_p ())
-    {
-      gcc_assert (dfloat32_type_node == NULL_TREE
-		  && dfloat64_type_node == NULL_TREE
-		  && dfloat128_type_node == NULL_TREE);
-      fallback_dfloat32_type = make_node (REAL_TYPE);
-      fallback_dfloat64_type = make_node (REAL_TYPE);
-      fallback_dfloat128_type = make_node (REAL_TYPE);
-      emit_support_tinfo_1 (fallback_dfloat32_type);
-      emit_support_tinfo_1 (fallback_dfloat64_type);
-      emit_support_tinfo_1 (fallback_dfloat128_type);
-    }
   input_location = saved_loc;
 }
 
--- gcc/cp/mangle.cc.jj	2023-02-09 09:31:48.900375193 +0100
+++ gcc/cp/mangle.cc	2023-02-28 23:55:06.912039890 +0100
@@ -2732,11 +2732,11 @@ write_builtin_type (tree type)
 	write_char ('d');
       else if (type == long_double_type_node)
 	write_char ('e');
-      else if (type == dfloat32_type_node || type == fallback_dfloat32_type)
+      else if (type == dfloat32_type_node)
 	write_string ("Df");
-      else if (type == dfloat64_type_node || type == fallback_dfloat64_type)
+      else if (type == dfloat64_type_node)
 	write_string ("Dd");
-      else if (type == dfloat128_type_node || type == fallback_dfloat128_type)
+      else if (type == dfloat128_type_node)
 	write_string ("De");
       else if (type == float16_type_node)
 	write_string ("DF16_");
@@ -2752,6 +2752,8 @@ write_builtin_type (tree type)
 	write_string ("DF64x");
       else if (type == float128x_type_node)
 	write_string ("DF128x");
+      else if (type == bfloat16_type_node)
+	write_string ("DF16b");
       else
 	gcc_unreachable ();
       break;


	Jakub


  reply	other threads:[~2023-03-01  9:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 10:23 [PATCH] c++: Add target hook for emit_support_tinfos [PR108883] Jakub Jelinek
2023-02-27 23:26 ` Jason Merrill
2023-02-27 23:51   ` Jakub Jelinek
2023-02-28 10:04     ` [PATCH] c++: Emit fundamental tinfos for all _Float*/decltype(0.0bf16) types unconditionally [PR108883] Jakub Jelinek
2023-03-01  9:19       ` Jakub Jelinek [this message]
2023-03-01 22:50     ` [PATCH] c++: Add target hook for emit_support_tinfos [PR108883] Jason Merrill
2023-03-02 11:20       ` [PATCH] c++, v3: Emit fundamental tinfos for _Float16/decltype(0.0bf16) types on ia32 with -mno-sse2 [PR108883] Jakub Jelinek
2023-03-02 16:32         ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y/8YtP5QiQzQ9spF@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=jwakely@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).