On Mon, Jun 03, 2024 at 03:40:38PM -0500, Segher Boessenkool wrote:
> > So, either we'd need to add some further GTY extensions, or the following
> > patch instead reworks it such that the fntype members which were the only
> > reason for PCH in those arrays are moved to separate arrays.
> 
> And that just sidesteps the limitation in PCH?

Yes.  But at the same size decreases the sizes of the data sections and
decreases size of the data written to/from PCH files, so I think it is a
win.

> >  void
> >  rs6000_init_generated_builtins ()
> >  {
> > +  bifdata *rs6000_builtin_info_p;
> > +  tree *rs6000_builtin_info_fntype_p;
> > +  ovlddata *rs6000_instance_info_p;
> > +  tree *rs6000_instance_info_fntype_p;
> > +  ovldrecord *rs6000_overload_info_p;
> > +  __asm ("" : "=r" (rs6000_builtin_info_p) : "0" (rs6000_builtin_info));
> 
> Bah.
> 
> It should not be called _p of course, it is not a predicate.  And
> relying on the operand tie to not have to do a much more obvious
> assignment, please don't.  Just *do* write assignments, and then use
> a simple "+r"?
> 
> But you call this a hack anyway, you wouldn't propose to actually
> include this patch :-)

It was a quick hack just to see why the size grew that much.
Ideally some optimization would figure out we have a single function which
has
    461   rs6000_overload_info
   1257   rs6000_builtin_info_fntype
   1768   rs6000_builtin_decls
   2548   rs6000_instance_info_fntype
array references and that maybe it might be a good idea to just preload
the addresses of those arrays into some register if it decreases code size
and doesn't slow things down.
The function actually is called just once and is huge, so code size is even
more important than speed, which is dominated by all the GC allocations
anyway.

Until that is done, here is a slightly cleaner version of the hack, which
makes the function noipa (so that LTO doesn't undo it) for GCC 8.1+ and
passes the 4 arrays as arguments to the function from the caller.
This decreases the function size from 228668 bytes to 207572 bytes.

Bootstrapped/regtested on powerpc64le-linux, ok for trunk?

2024-06-04  Jakub Jelinek  <ja...@redhat.com>

        PR target/115324
        * config/rs6000/rs6000-gen-builtins.cc (write_decls): Change
        declaration of rs6000_init_generated_builtins from no arguments
        to 4 pointer arguments.
        (write_init_bif_table): Change rs6000_builtin_info_fntype to
        builtin_info_fntype and rs6000_builtin_decls to builtin_decls.
        (write_init_ovld_table): Change rs6000_instance_info_fntype to
        instance_info_fntype, rs6000_builtin_decls to builtin_decls and
        rs6000_overload_info to overload_info.
        (write_init_file): Add __noipa__ attribute to
        rs6000_init_generated_builtins for GCC 8.1+ and change the function
        from no arguments to 4 pointer arguments.  Change rs6000_builtin_decls
        to builtin_decls.
        * config/rs6000/rs6000-builtin.cc (rs6000_init_builtins): Adjust
        rs6000_init_generated_builtins caller.

--- gcc/config/rs6000/rs6000-gen-builtins.cc.jj 2024-06-03 23:11:02.662631144 
+0200
+++ gcc/config/rs6000/rs6000-gen-builtins.cc    2024-06-03 23:38:31.727620920 
+0200
@@ -2376,7 +2376,10 @@ write_decls (void)
           "rs6000_instance_info_fntype[RS6000_INST_MAX];\n");
   fprintf (header_file, "extern ovldrecord rs6000_overload_info[];\n\n");
 
-  fprintf (header_file, "extern void rs6000_init_generated_builtins ();\n\n");
+  fprintf (header_file,
+          "extern void rs6000_init_generated_builtins (tree *, tree *,\n");
+  fprintf (header_file,
+          "\t\t\t\t\t    ovldrecord *, tree *);\n\n");
   fprintf (header_file,
           "extern bool rs6000_builtin_is_supported (rs6000_gen_builtins);\n");
   fprintf (header_file,
@@ -2651,7 +2654,7 @@ write_init_bif_table (void)
   for (int i = 0; i <= curr_bif; i++)
     {
       fprintf (init_file,
-              "  rs6000_builtin_info_fntype[RS6000_BIF_%s]"
+              "  builtin_info_fntype[RS6000_BIF_%s]"
               "\n    = %s;\n",
               bifs[i].idname, bifs[i].fndecl);
 
@@ -2678,7 +2681,7 @@ write_init_bif_table (void)
        }
 
       fprintf (init_file,
-              "  rs6000_builtin_decls[(int)RS6000_BIF_%s] = t\n",
+              "  builtin_decls[(int)RS6000_BIF_%s] = t\n",
               bifs[i].idname);
       fprintf (init_file,
               "    = add_builtin_function (\"%s\",\n",
@@ -2719,7 +2722,7 @@ write_init_bif_table (void)
          fprintf (init_file, "    }\n");
          fprintf (init_file, "  else\n");
          fprintf (init_file, "    {\n");
-         fprintf (init_file, "      rs6000_builtin_decls"
+         fprintf (init_file, "      builtin_decls"
                   "[(int)RS6000_BIF_%s] = NULL_TREE;\n", bifs[i].idname);
          fprintf (init_file, "    }\n");
        }
@@ -2740,7 +2743,7 @@ write_init_ovld_table (void)
   for (int i = 0; i <= curr_ovld; i++)
     {
       fprintf (init_file,
-              "  rs6000_instance_info_fntype[RS6000_INST_%s]"
+              "  instance_info_fntype[RS6000_INST_%s]"
               "\n    = %s;\n",
               ovlds[i].ovld_id_name, ovlds[i].fndecl);
 
@@ -2772,7 +2775,7 @@ write_init_ovld_table (void)
            }
 
          fprintf (init_file,
-                  "  rs6000_builtin_decls[(int)RS6000_OVLD_%s] = t\n",
+                  "  builtin_decls[(int)RS6000_OVLD_%s] = t\n",
                   stanza->stanza_id);
          fprintf (init_file,
                   "    = add_builtin_function (\"%s\",\n",
@@ -2793,7 +2796,7 @@ write_init_ovld_table (void)
          fprintf (init_file, "\n");
 
          fprintf (init_file,
-                  "  rs6000_overload_info[RS6000_OVLD_%s - base]"
+                  "  overload_info[RS6000_OVLD_%s - base]"
                   ".first_instance\n",
                   stanza->stanza_id);
          fprintf (init_file,
@@ -2826,19 +2829,30 @@ write_init_file (void)
   write_bif_static_init ();
   write_ovld_static_init ();
 
+  /* The reason to pass pointers to the function instead of accessing
+     the rs6000_{{builtin,instance}_info_fntype,overload_info,builtin_decls}
+     arrays directly is to decrease size of the already large function and
+     noipa prevents the compiler with LTO to undo that optimization.  */
+  fprintf (init_file, "#if GCC_VERSION >= 8001\n");
+  fprintf (init_file, "__attribute__((__noipa__))\n");
+  fprintf (init_file, "#endif\n");
   fprintf (init_file, "void\n");
-  fprintf (init_file, "rs6000_init_generated_builtins ()\n");
+  fprintf (init_file,
+          "rs6000_init_generated_builtins (tree *builtin_info_fntype,\n");
+  fprintf (init_file, "\t\t\t\ttree *instance_info_fntype,\n");
+  fprintf (init_file, "\t\t\t\tovldrecord *overload_info,\n");
+  fprintf (init_file, "\t\t\t\ttree *builtin_decls)\n");
   fprintf (init_file, "{\n");
   fprintf (init_file, "  tree t;\n");
   rbt_inorder_callback (&fntype_rbt, fntype_rbt.rbt_root, write_fntype_init);
   fprintf (init_file, "\n");
 
   fprintf (init_file,
-          "  rs6000_builtin_decls[RS6000_BIF_NONE] = NULL_TREE;\n");
+          "  builtin_decls[RS6000_BIF_NONE] = NULL_TREE;\n");
   fprintf (init_file,
-          "  rs6000_builtin_decls[RS6000_BIF_MAX] = NULL_TREE;\n");
+          "  builtin_decls[RS6000_BIF_MAX] = NULL_TREE;\n");
   fprintf (init_file,
-          "  rs6000_builtin_decls[RS6000_OVLD_NONE] = NULL_TREE;\n\n");
+          "  builtin_decls[RS6000_OVLD_NONE] = NULL_TREE;\n\n");
 
   write_init_bif_table ();
   write_init_ovld_table ();
--- gcc/config/rs6000/rs6000-builtin.cc.jj      2024-06-03 23:11:02.662631144 
+0200
+++ gcc/config/rs6000/rs6000-builtin.cc 2024-06-03 23:39:39.699745339 +0200
@@ -835,7 +835,10 @@ rs6000_init_builtins (void)
                                                TYPE_QUAL_CONST));
 
   /* Execute the autogenerated initialization code for builtins.  */
-  rs6000_init_generated_builtins ();
+  rs6000_init_generated_builtins (rs6000_builtin_info_fntype,
+                                 rs6000_instance_info_fntype,
+                                 rs6000_overload_info,
+                                 rs6000_builtin_decls);
 
   if (TARGET_DEBUG_BUILTIN)
     {

        Jakub

Reply via email to