LCOV - code coverage report
Current view: top level - gcc/lto - lto.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 79.3 % 300 238
Test Date: 2024-03-23 14:05:01 Functions: 83.3 % 12 10
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Top-level LTO routines.
       2                 :             :    Copyright (C) 2009-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by CodeSourcery, Inc.
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it under
       8                 :             : the terms of the GNU General Public License as published by the Free
       9                 :             : Software Foundation; either version 3, or (at your option) any later
      10                 :             : version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             : for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : #define INCLUDE_STRING
      22                 :             : #include "config.h"
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "tm.h"
      26                 :             : #include "function.h"
      27                 :             : #include "bitmap.h"
      28                 :             : #include "basic-block.h"
      29                 :             : #include "tree.h"
      30                 :             : #include "gimple.h"
      31                 :             : #include "cfghooks.h"
      32                 :             : #include "alloc-pool.h"
      33                 :             : #include "tree-pass.h"
      34                 :             : #include "tree-streamer.h"
      35                 :             : #include "cgraph.h"
      36                 :             : #include "opts.h"
      37                 :             : #include "toplev.h"
      38                 :             : #include "stor-layout.h"
      39                 :             : #include "symbol-summary.h"
      40                 :             : #include "tree-vrp.h"
      41                 :             : #include "sreal.h"
      42                 :             : #include "ipa-cp.h"
      43                 :             : #include "ipa-prop.h"
      44                 :             : #include "debug.h"
      45                 :             : #include "lto.h"
      46                 :             : #include "lto-section-names.h"
      47                 :             : #include "splay-tree.h"
      48                 :             : #include "lto-partition.h"
      49                 :             : #include "context.h"
      50                 :             : #include "pass_manager.h"
      51                 :             : #include "ipa-fnsummary.h"
      52                 :             : #include "ipa-utils.h"
      53                 :             : #include "gomp-constants.h"
      54                 :             : #include "lto-symtab.h"
      55                 :             : #include "stringpool.h"
      56                 :             : #include "fold-const.h"
      57                 :             : #include "attribs.h"
      58                 :             : #include "builtins.h"
      59                 :             : #include "lto-common.h"
      60                 :             : #include "opts-jobserver.h"
      61                 :             : 
      62                 :             : /* Number of parallel tasks to run.  */
      63                 :             : static int lto_parallelism;
      64                 :             : 
      65                 :             : /* Number of active WPA streaming processes.  */
      66                 :             : static int nruns = 0;
      67                 :             : 
      68                 :             : /* GNU make's jobserver info.  */
      69                 :             : static jobserver_info *jinfo = NULL;
      70                 :             : 
      71                 :             : /* Return true when NODE has a clone that is analyzed (i.e. we need
      72                 :             :    to load its body even if the node itself is not needed).  */
      73                 :             : 
      74                 :             : static bool
      75                 :       14868 : has_analyzed_clone_p (struct cgraph_node *node)
      76                 :             : {
      77                 :       14868 :   struct cgraph_node *orig = node;
      78                 :       14868 :   node = node->clones;
      79                 :       14868 :   if (node)
      80                 :        3186 :     while (node != orig)
      81                 :             :       {
      82                 :        3186 :         if (node->analyzed)
      83                 :             :           return true;
      84                 :         400 :         if (node->clones)
      85                 :             :           node = node->clones;
      86                 :           0 :         else if (node->next_sibling_clone)
      87                 :             :           node = node->next_sibling_clone;
      88                 :             :         else
      89                 :             :           {
      90                 :           0 :             while (node != orig && !node->next_sibling_clone)
      91                 :           0 :               node = node->clone_of;
      92                 :           0 :             if (node != orig)
      93                 :           0 :               node = node->next_sibling_clone;
      94                 :             :           }
      95                 :             :       }
      96                 :             :   return false;
      97                 :             : }
      98                 :             : 
      99                 :             : /* Read the function body for the function associated with NODE.  */
     100                 :             : 
     101                 :             : static void
     102                 :      152522 : lto_materialize_function (struct cgraph_node *node)
     103                 :             : {
     104                 :      152522 :   tree decl;
     105                 :             : 
     106                 :      152522 :   decl = node->decl;
     107                 :             :   /* Read in functions with body (analyzed nodes)
     108                 :             :      and also functions that are needed to produce virtual clones.  */
     109                 :      137318 :   if ((node->has_gimple_body_p () && node->analyzed)
     110                 :       15205 :       || node->used_as_abstract_origin
     111                 :      167390 :       || has_analyzed_clone_p (node))
     112                 :             :     {
     113                 :             :       /* Clones don't need to be read.  */
     114                 :      140440 :       if (node->clone_of)
     115                 :             :         return;
     116                 :      118111 :       if (DECL_FUNCTION_PERSONALITY (decl) && !first_personality_decl)
     117                 :         593 :         first_personality_decl = DECL_FUNCTION_PERSONALITY (decl);
     118                 :             :       /* If the file contains a function with a language specific EH
     119                 :             :          personality set or with EH enabled initialize the backend EH
     120                 :             :          machinery.  */
     121                 :      118111 :       if (DECL_FUNCTION_PERSONALITY (decl)
     122                 :      118111 :           || opt_for_fn (decl, flag_exceptions))
     123                 :       40341 :         lto_init_eh ();
     124                 :             :     }
     125                 :             : 
     126                 :             :   /* Let the middle end know about the function.  */
     127                 :      130193 :   rest_of_decl_compilation (decl, 1, 0);
     128                 :             : }
     129                 :             : 
     130                 :             : /* Materialize all the bodies for all the nodes in the callgraph.  */
     131                 :             : 
     132                 :             : static void
     133                 :       22028 : materialize_cgraph (void)
     134                 :             : {
     135                 :       22028 :   struct cgraph_node *node;
     136                 :       22028 :   timevar_id_t lto_timer;
     137                 :             : 
     138                 :       22028 :   if (!quiet_flag)
     139                 :           0 :     fprintf (stderr,
     140                 :           0 :              flag_wpa ? "Materializing decls:" : "Reading function bodies:");
     141                 :             : 
     142                 :             :   /* Start the appropriate timer depending on the mode that we are
     143                 :             :      operating in.  */
     144                 :       22028 :   lto_timer = (flag_wpa) ? TV_WHOPR_WPA
     145                 :       13231 :               : (flag_ltrans) ? TV_WHOPR_LTRANS
     146                 :             :               : TV_LTO;
     147                 :       22028 :   timevar_push (lto_timer);
     148                 :             : 
     149                 :      416182 :   FOR_EACH_FUNCTION (node)
     150                 :             :     {
     151                 :      186063 :       if (node->lto_file_data)
     152                 :             :         {
     153                 :      152522 :           lto_materialize_function (node);
     154                 :      152522 :           lto_stats.num_input_cgraph_nodes++;
     155                 :             :         }
     156                 :             :     }
     157                 :             : 
     158                 :       22028 :   current_function_decl = NULL;
     159                 :       22028 :   set_cfun (NULL);
     160                 :             : 
     161                 :       22028 :   if (!quiet_flag)
     162                 :           0 :     fprintf (stderr, "\n");
     163                 :             : 
     164                 :       22028 :   timevar_pop (lto_timer);
     165                 :       22028 : }
     166                 :             : 
     167                 :             : /* Actually stream out ENCODER into TEMP_FILENAME.  */
     168                 :             : 
     169                 :             : static void
     170                 :        9154 : stream_out (char *temp_filename, lto_symtab_encoder_t encoder, int part)
     171                 :             : {
     172                 :        9154 :   lto_file *file = lto_obj_file_open (temp_filename, true);
     173                 :        9154 :   if (!file)
     174                 :           0 :     fatal_error (input_location, "%<lto_obj_file_open()%> failed");
     175                 :        9154 :   lto_set_current_out_file (file);
     176                 :             : 
     177                 :        9154 :   gcc_assert (!dump_file);
     178                 :        9154 :   streamer_dump_file = dump_begin (TDI_lto_stream_out, NULL, part);
     179                 :        9154 :   ipa_write_optimization_summaries (encoder);
     180                 :             : 
     181                 :        9154 :   free (CONST_CAST (char *, file->filename));
     182                 :             : 
     183                 :        9154 :   lto_set_current_out_file (NULL);
     184                 :        9154 :   lto_obj_file_close (file);
     185                 :        9154 :   free (file);
     186                 :        9154 :   if (streamer_dump_file)
     187                 :             :     {
     188                 :           0 :       dump_end (TDI_lto_stream_out, streamer_dump_file);
     189                 :           0 :       streamer_dump_file = NULL;
     190                 :             :     }
     191                 :        9154 : }
     192                 :             : 
     193                 :             : /* Wait for forked process and signal errors.  */
     194                 :             : #ifdef HAVE_WORKING_FORK
     195                 :             : static void
     196                 :           0 : wait_for_child ()
     197                 :             : {
     198                 :           0 :   int status;
     199                 :           0 :   do
     200                 :             :     {
     201                 :             : #ifndef WCONTINUED
     202                 :             : #define WCONTINUED 0
     203                 :             : #endif
     204                 :           0 :       int w = waitpid (0, &status, WUNTRACED | WCONTINUED);
     205                 :           0 :       if (w == -1)
     206                 :           0 :         fatal_error (input_location, "waitpid failed");
     207                 :             : 
     208                 :           0 :       if (WIFEXITED (status) && WEXITSTATUS (status))
     209                 :           0 :         fatal_error (input_location, "streaming subprocess failed");
     210                 :           0 :       else if (WIFSIGNALED (status))
     211                 :           0 :         fatal_error (input_location,
     212                 :             :                      "streaming subprocess was killed by signal");
     213                 :             :     }
     214                 :           0 :   while (!WIFEXITED (status) && !WIFSIGNALED (status));
     215                 :             : 
     216                 :           0 :   --nruns;
     217                 :             : 
     218                 :             :   /* Return token to the jobserver if active.  */
     219                 :           0 :   if (jinfo != NULL && jinfo->is_connected)
     220                 :           0 :     jinfo->return_token ();
     221                 :           0 : }
     222                 :             : #endif
     223                 :             : 
     224                 :             : static void
     225                 :        9138 : stream_out_partitions_1 (char *temp_filename, int blen, int min, int max)
     226                 :             : {
     227                 :             :    /* Write all the nodes in SET.  */
     228                 :       18292 :    for (int p = min; p < max; p ++)
     229                 :             :      {
     230                 :        9154 :        sprintf (temp_filename + blen, "%u.o", p);
     231                 :        9154 :        stream_out (temp_filename, ltrans_partitions[p]->encoder, p);
     232                 :        9154 :        ltrans_partitions[p]->encoder = NULL;
     233                 :             :      }
     234                 :        9138 : }
     235                 :             : 
     236                 :             : /* Stream out ENCODER into TEMP_FILENAME
     237                 :             :    Fork if that seems to help.  */
     238                 :             : 
     239                 :             : static void
     240                 :        9138 : stream_out_partitions (char *temp_filename, int blen, int min, int max,
     241                 :             :                        bool ARG_UNUSED (last))
     242                 :             : {
     243                 :             : #ifdef HAVE_WORKING_FORK
     244                 :        9138 :   if (lto_parallelism <= 1)
     245                 :             :     {
     246                 :        8606 :       stream_out_partitions_1 (temp_filename, blen, min, max);
     247                 :        8606 :       return;
     248                 :             :     }
     249                 :             : 
     250                 :         532 :   if (lto_parallelism > 0 && nruns >= lto_parallelism)
     251                 :           0 :     wait_for_child ();
     252                 :             : 
     253                 :             :   /* If this is not the last parallel partition, execute new
     254                 :             :      streaming process.  */
     255                 :         532 :   if (!last)
     256                 :             :     {
     257                 :         341 :       if (jinfo != NULL && jinfo->is_connected)
     258                 :         341 :         while (true)
     259                 :             :           {
     260                 :         341 :             if (jinfo->get_token ())
     261                 :             :               break;
     262                 :         341 :             if (nruns > 0)
     263                 :           0 :               wait_for_child ();
     264                 :             :             else
     265                 :             :               {
     266                 :             :                 /* There are no free tokens, lets do the job outselves.  */
     267                 :         341 :                 stream_out_partitions_1 (temp_filename, blen, min, max);
     268                 :         341 :                 asm_nodes_output = true;
     269                 :         341 :                 return;
     270                 :             :               }
     271                 :             :           }
     272                 :             : 
     273                 :           0 :       pid_t cpid = fork ();
     274                 :             : 
     275                 :           0 :       if (!cpid)
     276                 :             :         {
     277                 :           0 :           setproctitle ("lto1-wpa-streaming");
     278                 :           0 :           stream_out_partitions_1 (temp_filename, blen, min, max);
     279                 :           0 :           exit (0);
     280                 :             :         }
     281                 :             :       /* Fork failed; lets do the job ourseleves.  */
     282                 :           0 :       else if (cpid == -1)
     283                 :           0 :         stream_out_partitions_1 (temp_filename, blen, min, max);
     284                 :             :       else
     285                 :           0 :         nruns++;
     286                 :             :     }
     287                 :             :   /* Last partition; stream it and wait for all children to die.  */
     288                 :             :   else
     289                 :             :     {
     290                 :         191 :       stream_out_partitions_1 (temp_filename, blen, min, max);
     291                 :         382 :       while (nruns > 0)
     292                 :           0 :         wait_for_child ();
     293                 :             : 
     294                 :         191 :       if (jinfo != NULL && jinfo->is_connected)
     295                 :         191 :         jinfo->disconnect ();
     296                 :             :     }
     297                 :         191 :   asm_nodes_output = true;
     298                 :             : #else
     299                 :             :   stream_out_partitions_1 (temp_filename, blen, min, max);
     300                 :             : #endif
     301                 :             : }
     302                 :             : 
     303                 :             : /* Write all output files in WPA mode and the file with the list of
     304                 :             :    LTRANS units.  */
     305                 :             : 
     306                 :             : static void
     307                 :        8797 : lto_wpa_write_files (void)
     308                 :             : {
     309                 :        8797 :   unsigned i, n_sets;
     310                 :        8797 :   ltrans_partition part;
     311                 :        8797 :   FILE *ltrans_output_list_stream;
     312                 :        8797 :   char *temp_filename;
     313                 :        8797 :   auto_vec <char *>temp_filenames;
     314                 :        8797 :   auto_vec <int>temp_priority;
     315                 :        8797 :   size_t blen;
     316                 :             : 
     317                 :             :   /* Open the LTRANS output list.  */
     318                 :        8797 :   if (!ltrans_output_list)
     319                 :           0 :     fatal_error (input_location, "no LTRANS output list filename provided");
     320                 :             : 
     321                 :        8797 :   timevar_push (TV_WHOPR_WPA);
     322                 :             : 
     323                 :       26748 :   FOR_EACH_VEC_ELT (ltrans_partitions, i, part)
     324                 :       18308 :     lto_stats.num_output_symtab_nodes
     325                 :       18299 :     += lto_symtab_encoder_size (part->encoder);
     326                 :             : 
     327                 :        8797 :   timevar_pop (TV_WHOPR_WPA);
     328                 :             : 
     329                 :        8797 :   timevar_push (TV_WHOPR_WPA_IO);
     330                 :             : 
     331                 :        8797 :   cgraph_node *node;
     332                 :             :   /* Do body modifications needed for streaming before we fork out
     333                 :             :      worker processes.  */
     334                 :      177206 :   FOR_EACH_FUNCTION (node)
     335                 :       79806 :     if (!node->clone_of && gimple_has_body_p (node->decl))
     336                 :        5325 :       lto_prepare_function_for_streaming (node);
     337                 :             : 
     338                 :        8797 :   ggc_trim ();
     339                 :        8797 :   report_heap_memory_use ();
     340                 :             : 
     341                 :             :   /* Generate a prefix for the LTRANS unit files.  */
     342                 :        8797 :   blen = strlen (ltrans_output_list);
     343                 :        8797 :   temp_filename = (char *) xmalloc (blen + sizeof ("2147483648.o"));
     344                 :        8797 :   strcpy (temp_filename, ltrans_output_list);
     345                 :        8797 :   if (blen > sizeof (".out")
     346                 :        8797 :       && strcmp (temp_filename + blen - sizeof (".out") + 1,
     347                 :             :                  ".out") == 0)
     348                 :        8797 :     temp_filename[blen - sizeof (".out") + 1] = '\0';
     349                 :        8797 :   blen = strlen (temp_filename);
     350                 :             : 
     351                 :        8797 :   n_sets = ltrans_partitions.length ();
     352                 :        8797 :   unsigned sets_per_worker = n_sets;
     353                 :        8797 :   if (lto_parallelism > 1)
     354                 :             :     {
     355                 :        8719 :       if (lto_parallelism > (int)n_sets)
     356                 :        8715 :         lto_parallelism = n_sets;
     357                 :        8719 :       sets_per_worker = (n_sets + lto_parallelism - 1) / lto_parallelism;
     358                 :             :     }
     359                 :             : 
     360                 :       17951 :   for (i = 0; i < n_sets; i++)
     361                 :             :     {
     362                 :        9154 :       ltrans_partition part = ltrans_partitions[i];
     363                 :             : 
     364                 :             :       /* Write all the nodes in SET.  */
     365                 :        9154 :       sprintf (temp_filename + blen, "%u.o", i);
     366                 :             : 
     367                 :        9154 :       if (!quiet_flag)
     368                 :           0 :         fprintf (stderr, " %s (%s %i insns)", temp_filename, part->name,
     369                 :             :                  part->insns);
     370                 :        9154 :       if (symtab->dump_file)
     371                 :             :         {
     372                 :           1 :           lto_symtab_encoder_iterator lsei;
     373                 :             : 
     374                 :           1 :           fprintf (symtab->dump_file,
     375                 :             :                    "Writing partition %s to file %s, %i insns\n",
     376                 :             :                    part->name, temp_filename, part->insns);
     377                 :           1 :           fprintf (symtab->dump_file, "  Symbols in partition: ");
     378                 :           1 :           for (lsei = lsei_start_in_partition (part->encoder);
     379                 :          16 :                !lsei_end_p (lsei);
     380                 :           7 :                lsei_next_in_partition (&lsei))
     381                 :             :             {
     382                 :           7 :               symtab_node *node = lsei_node (lsei);
     383                 :           7 :               fprintf (symtab->dump_file, "%s ", node->dump_asm_name ());
     384                 :             :             }
     385                 :           1 :           fprintf (symtab->dump_file, "\n  Symbols in boundary: ");
     386                 :          16 :           for (lsei = lsei_start (part->encoder); !lsei_end_p (lsei);
     387                 :           7 :                lsei_next (&lsei))
     388                 :             :             {
     389                 :           7 :               symtab_node *node = lsei_node (lsei);
     390                 :           7 :               if (!lto_symtab_encoder_in_partition_p (part->encoder, node))
     391                 :             :                 {
     392                 :           0 :                   fprintf (symtab->dump_file, "%s ", node->dump_asm_name ());
     393                 :           0 :                   cgraph_node *cnode = dyn_cast <cgraph_node *> (node);
     394                 :           0 :                   if (cnode
     395                 :           0 :                       && lto_symtab_encoder_encode_body_p (part->encoder,
     396                 :             :                                                            cnode))
     397                 :           0 :                     fprintf (symtab->dump_file, "(body included)");
     398                 :             :                   else
     399                 :             :                     {
     400                 :           7 :                       varpool_node *vnode = dyn_cast <varpool_node *> (node);
     401                 :           0 :                       if (vnode
     402                 :           0 :                           && lto_symtab_encoder_encode_initializer_p (part->encoder,
     403                 :             :                                                                       vnode))
     404                 :           0 :                         fprintf (symtab->dump_file, "(initializer included)");
     405                 :             :                     }
     406                 :             :                 }
     407                 :             :             }
     408                 :           1 :           fprintf (symtab->dump_file, "\n");
     409                 :             :         }
     410                 :        9154 :       gcc_checking_assert (lto_symtab_encoder_size (part->encoder) || !i);
     411                 :             : 
     412                 :        9154 :       temp_priority.safe_push (part->insns);
     413                 :        9154 :       temp_filenames.safe_push (xstrdup (temp_filename));
     414                 :             :     }
     415                 :        8797 :   memory_block_pool::trim (0);
     416                 :             : 
     417                 :       17935 :   for (int set = 0; set < MAX (lto_parallelism, 1); set++)
     418                 :             :     {
     419                 :        9138 :       stream_out_partitions (temp_filename, blen, set * sets_per_worker,
     420                 :        9138 :                              MIN ((set + 1) * sets_per_worker, n_sets),
     421                 :        9138 :                              set == MAX (lto_parallelism, 1) - 1);
     422                 :             :     }
     423                 :             : 
     424                 :        8797 :   ltrans_output_list_stream = fopen (ltrans_output_list, "w");
     425                 :        8797 :   if (ltrans_output_list_stream == NULL)
     426                 :           0 :     fatal_error (input_location,
     427                 :             :                  "opening LTRANS output list %s: %m", ltrans_output_list);
     428                 :       17951 :   for (i = 0; i < n_sets; i++)
     429                 :             :     {
     430                 :        9154 :       unsigned int len = strlen (temp_filenames[i]);
     431                 :        9154 :       if (fprintf (ltrans_output_list_stream, "%i\n", temp_priority[i]) < 0
     432                 :        9154 :           || fwrite (temp_filenames[i], 1, len, ltrans_output_list_stream) < len
     433                 :       18308 :           || fwrite ("\n", 1, 1, ltrans_output_list_stream) < 1)
     434                 :           0 :         fatal_error (input_location, "writing to LTRANS output list %s: %m",
     435                 :             :                      ltrans_output_list);
     436                 :        9154 :      free (temp_filenames[i]);
     437                 :             :     }
     438                 :             : 
     439                 :        8797 :   lto_stats.num_output_files += n_sets;
     440                 :             : 
     441                 :             :   /* Close the LTRANS output list.  */
     442                 :        8797 :   if (fclose (ltrans_output_list_stream))
     443                 :           0 :     fatal_error (input_location,
     444                 :             :                  "closing LTRANS output list %s: %m", ltrans_output_list);
     445                 :             : 
     446                 :        8797 :   free_ltrans_partitions ();
     447                 :        8797 :   free (temp_filename);
     448                 :             : 
     449                 :        8797 :   timevar_pop (TV_WHOPR_WPA_IO);
     450                 :        8797 : }
     451                 :             : 
     452                 :             : /* Create artificial pointers for "omp declare target link" vars.  */
     453                 :             : 
     454                 :             : static void
     455                 :        4077 : offload_handle_link_vars (void)
     456                 :             : {
     457                 :             : #ifdef ACCEL_COMPILER
     458                 :             :   varpool_node *var;
     459                 :             :   FOR_EACH_VARIABLE (var)
     460                 :             :     if (lookup_attribute ("omp declare target link",
     461                 :             :                           DECL_ATTRIBUTES (var->decl)))
     462                 :             :       {
     463                 :             :         tree type = build_pointer_type (TREE_TYPE (var->decl));
     464                 :             :         tree link_ptr_var = build_decl (UNKNOWN_LOCATION, VAR_DECL,
     465                 :             :                                         clone_function_name (var->decl,
     466                 :             :                                                              "linkptr"), type);
     467                 :             :         TREE_USED (link_ptr_var) = 1;
     468                 :             :         TREE_STATIC (link_ptr_var) = 1;
     469                 :             :         TREE_PUBLIC (link_ptr_var) = TREE_PUBLIC (var->decl);
     470                 :             :         DECL_ARTIFICIAL (link_ptr_var) = 1;
     471                 :             :         SET_DECL_ASSEMBLER_NAME (link_ptr_var, DECL_NAME (link_ptr_var));
     472                 :             :         SET_DECL_VALUE_EXPR (var->decl, build_simple_mem_ref (link_ptr_var));
     473                 :             :         DECL_HAS_VALUE_EXPR_P (var->decl) = 1;
     474                 :             :       }
     475                 :             : #endif
     476                 :        4077 : }
     477                 :             : 
     478                 :             : /* Perform whole program analysis (WPA) on the callgraph and write out the
     479                 :             :    optimization plan.  */
     480                 :             : 
     481                 :             : static void
     482                 :        8797 : do_whole_program_analysis (void)
     483                 :             : {
     484                 :        8797 :   symtab_node *node;
     485                 :             : 
     486                 :        8797 :   lto_parallelism = 1;
     487                 :             : 
     488                 :        8797 :   if (!strcmp (flag_wpa, "jobserver"))
     489                 :             :     {
     490                 :        8719 :       jinfo = new jobserver_info ();
     491                 :        8719 :       if (jinfo->is_active)
     492                 :        8719 :         jinfo->connect ();
     493                 :             : 
     494                 :        8719 :       lto_parallelism = param_max_lto_streaming_parallelism;
     495                 :             :     }
     496                 :             :   else
     497                 :             :     {
     498                 :          78 :       lto_parallelism = atoi (flag_wpa);
     499                 :          78 :       if (lto_parallelism <= 0)
     500                 :          78 :         lto_parallelism = 0;
     501                 :          78 :       if (lto_parallelism >= param_max_lto_streaming_parallelism)
     502                 :           0 :         lto_parallelism = param_max_lto_streaming_parallelism;
     503                 :             :     }
     504                 :             : 
     505                 :        8797 :   timevar_start (TV_PHASE_OPT_GEN);
     506                 :             : 
     507                 :             :   /* Note that since we are in WPA mode, materialize_cgraph will not
     508                 :             :      actually read in all the function bodies.  It only materializes
     509                 :             :      the decls and cgraph nodes so that analysis can be performed.  */
     510                 :        8797 :   materialize_cgraph ();
     511                 :             : 
     512                 :             :   /* Reading in the cgraph uses different timers, start timing WPA now.  */
     513                 :        8797 :   timevar_push (TV_WHOPR_WPA);
     514                 :             : 
     515                 :        8797 :   if (pre_ipa_mem_report)
     516                 :           0 :     dump_memory_report ("Memory consumption before IPA");
     517                 :             : 
     518                 :        8797 :   symtab->function_flags_ready = true;
     519                 :             : 
     520                 :        8797 :   if (symtab->dump_file)
     521                 :           1 :     symtab->dump (symtab->dump_file);
     522                 :        8797 :   bitmap_obstack_initialize (NULL);
     523                 :        8797 :   symtab->state = IPA_SSA;
     524                 :             : 
     525                 :        8797 :   execute_ipa_pass_list (g->get_passes ()->all_regular_ipa_passes);
     526                 :             : 
     527                 :             :   /* When WPA analysis raises errors, do not bother to output anything.  */
     528                 :        8797 :   if (seen_error ())
     529                 :             :     return;
     530                 :             : 
     531                 :             :   /* We are about to launch the final LTRANS phase, stop the WPA timer.  */
     532                 :        8797 :   timevar_pop (TV_WHOPR_WPA);
     533                 :             : 
     534                 :             :   /* We are no longer going to stream in anything.  Free some memory.  */
     535                 :        8797 :   lto_free_file_name_hash ();
     536                 :             : 
     537                 :             : 
     538                 :        8797 :   timevar_push (TV_WHOPR_PARTITIONING);
     539                 :             : 
     540                 :        8797 :   gcc_assert (!dump_file);
     541                 :        8797 :   dump_file = dump_begin (partition_dump_id, NULL);
     542                 :             : 
     543                 :        8797 :   if (dump_file)
     544                 :           0 :     symtab->dump (dump_file);
     545                 :             : 
     546                 :        8797 :   symtab_node::checking_verify_symtab_nodes ();
     547                 :        8797 :   bitmap_obstack_release (NULL);
     548                 :        8797 :   if (flag_lto_partition == LTO_PARTITION_1TO1)
     549                 :         295 :     lto_1_to_1_map ();
     550                 :        8502 :   else if (flag_lto_partition == LTO_PARTITION_MAX)
     551                 :          11 :     lto_max_map ();
     552                 :        8491 :   else if (flag_lto_partition == LTO_PARTITION_ONE)
     553                 :          70 :     lto_balanced_map (1, INT_MAX);
     554                 :        8421 :   else if (flag_lto_partition == LTO_PARTITION_BALANCED)
     555                 :        8421 :     lto_balanced_map (param_lto_partitions,
     556                 :             :                       param_max_partition_size);
     557                 :             :   else
     558                 :           0 :     gcc_unreachable ();
     559                 :             : 
     560                 :             :   /* Size summaries are needed for balanced partitioning.  Free them now so
     561                 :             :      the memory can be used for streamer caches.  */
     562                 :        8797 :   ipa_free_size_summary ();
     563                 :             : 
     564                 :             :   /* AUX pointers are used by partitioning code to bookkeep number of
     565                 :             :      partitions symbol is in.  This is no longer needed.  */
     566                 :      112193 :   FOR_EACH_SYMBOL (node)
     567                 :      103396 :     node->aux = NULL;
     568                 :             : 
     569                 :        8797 :   lto_stats.num_cgraph_partitions += ltrans_partitions.length ();
     570                 :             : 
     571                 :             :   /* Find out statics that need to be promoted
     572                 :             :      to globals with hidden visibility because they are accessed from multiple
     573                 :             :      partitions.  */
     574                 :        8797 :   lto_promote_cross_file_statics ();
     575                 :        8797 :   offload_handle_link_vars ();
     576                 :        8797 :   if (dump_file)
     577                 :           0 :      dump_end (partition_dump_id, dump_file);
     578                 :        8797 :   dump_file = NULL;
     579                 :        8797 :   timevar_pop (TV_WHOPR_PARTITIONING);
     580                 :             : 
     581                 :        8797 :   timevar_stop (TV_PHASE_OPT_GEN);
     582                 :             : 
     583                 :             :   /* Collect a last time - in lto_wpa_write_files we may end up forking
     584                 :             :      with the idea that this doesn't increase memory usage.  So we
     585                 :             :      absoultely do not want to collect after that.  */
     586                 :        8797 :   ggc_collect ();
     587                 :             : 
     588                 :        8797 :   timevar_start (TV_PHASE_STREAM_OUT);
     589                 :        8797 :   if (!quiet_flag)
     590                 :             :     {
     591                 :           0 :       fprintf (stderr, "\nStreaming out");
     592                 :           0 :       fflush (stderr);
     593                 :             :     }
     594                 :        8797 :   lto_wpa_write_files ();
     595                 :        8797 :   if (!quiet_flag)
     596                 :           0 :     fprintf (stderr, "\n");
     597                 :        8797 :   timevar_stop (TV_PHASE_STREAM_OUT);
     598                 :             : 
     599                 :        8797 :   if (post_ipa_mem_report)
     600                 :           0 :     dump_memory_report ("Memory consumption after IPA");
     601                 :             : 
     602                 :             :   /* Show the LTO report before launching LTRANS.  */
     603                 :        8797 :   if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
     604                 :           0 :     print_lto_report_1 ();
     605                 :        8797 :   if (mem_report_wpa)
     606                 :           0 :     dump_memory_report ("Final");
     607                 :             : }
     608                 :             : 
     609                 :             : unsigned int
     610                 :       47589 : lto_option_lang_mask (void)
     611                 :             : {
     612                 :       47589 :   return CL_LTO;
     613                 :             : }
     614                 :             : 
     615                 :             : /* Main entry point for the GIMPLE front end.  This front end has
     616                 :             :    three main personalities:
     617                 :             : 
     618                 :             :    - LTO (-flto).  All the object files on the command line are
     619                 :             :      loaded in memory and processed as a single translation unit.
     620                 :             :      This is the traditional link-time optimization behavior.
     621                 :             : 
     622                 :             :    - WPA (-fwpa).  Only the callgraph and summary information for
     623                 :             :      files in the command file are loaded.  A single callgraph
     624                 :             :      (without function bodies) is instantiated for the whole set of
     625                 :             :      files.  IPA passes are only allowed to analyze the call graph
     626                 :             :      and make transformation decisions.  The callgraph is
     627                 :             :      partitioned, each partition is written to a new object file
     628                 :             :      together with the transformation decisions.
     629                 :             : 
     630                 :             :    - LTRANS (-fltrans).  Similar to -flto but it prevents the IPA
     631                 :             :      summary files from running again.  Since WPA computed summary
     632                 :             :      information and decided what transformations to apply, LTRANS
     633                 :             :      simply applies them.  */
     634                 :             : 
     635                 :             : void
     636                 :       22028 : lto_main (void)
     637                 :             : {
     638                 :             :   /* LTO is called as a front end, even though it is not a front end.
     639                 :             :      Because it is called as a front end, TV_PHASE_PARSING and
     640                 :             :      TV_PARSE_GLOBAL are active, and we need to turn them off while
     641                 :             :      doing LTO.  Later we turn them back on so they are active up in
     642                 :             :      toplev.cc.  */
     643                 :       22028 :   timevar_pop (TV_PARSE_GLOBAL);
     644                 :       22028 :   timevar_stop (TV_PHASE_PARSING);
     645                 :             : 
     646                 :       22028 :   timevar_start (TV_PHASE_SETUP);
     647                 :             : 
     648                 :             :   /* Initialize the LTO front end.  */
     649                 :       22028 :   lto_fe_init ();
     650                 :             : 
     651                 :       22028 :   timevar_stop (TV_PHASE_SETUP);
     652                 :       22028 :   timevar_start (TV_PHASE_STREAM_IN);
     653                 :             : 
     654                 :             :   /* Read all the symbols and call graph from all the files in the
     655                 :             :      command line.  */
     656                 :       22028 :   read_cgraph_and_symbols (num_in_fnames, in_fnames);
     657                 :             : 
     658                 :       22028 :   timevar_stop (TV_PHASE_STREAM_IN);
     659                 :             : 
     660                 :       22028 :   if (!seen_error ())
     661                 :             :     {
     662                 :       22028 :       offload_handle_link_vars ();
     663                 :             : 
     664                 :             :       /* If WPA is enabled analyze the whole call graph and create an
     665                 :             :          optimization plan.  Otherwise, read in all the function
     666                 :             :          bodies and continue with optimization.  */
     667                 :       22028 :       if (flag_wpa)
     668                 :        8797 :         do_whole_program_analysis ();
     669                 :             :       else
     670                 :             :         {
     671                 :       13231 :           timevar_start (TV_PHASE_OPT_GEN);
     672                 :             : 
     673                 :       13231 :           materialize_cgraph ();
     674                 :       13231 :           if (!flag_ltrans)
     675                 :             :             {
     676                 :        4077 :               lto_promote_statics_nonwpa ();
     677                 :        4077 :               offload_handle_link_vars ();
     678                 :             :             }
     679                 :             : 
     680                 :             :           /* Annotate the CU DIE and mark the early debug phase as finished.  */
     681                 :       13231 :           debuginfo_early_start ();
     682                 :       13231 :           debug_hooks->early_finish ("<artificial>");
     683                 :       13231 :           debuginfo_early_stop ();
     684                 :             : 
     685                 :             :           /* Let the middle end know that we have read and merged all of
     686                 :             :              the input files.  */
     687                 :       13231 :           symtab->compile ();
     688                 :             : 
     689                 :       13231 :           timevar_stop (TV_PHASE_OPT_GEN);
     690                 :             : 
     691                 :             :           /* FIXME lto, if the processes spawned by WPA fail, we miss
     692                 :             :              the chance to print WPA's report, so WPA will call
     693                 :             :              print_lto_report before launching LTRANS.  If LTRANS was
     694                 :             :              launched directly by the driver we would not need to do
     695                 :             :              this.  */
     696                 :       13231 :           if (flag_lto_report || (flag_wpa && flag_lto_report_wpa))
     697                 :           0 :             print_lto_report_1 ();
     698                 :             :         }
     699                 :             :     }
     700                 :             : 
     701                 :             :   /* Here we make LTO pretend to be a parser.  */
     702                 :       22028 :   timevar_start (TV_PHASE_PARSING);
     703                 :       22028 :   timevar_push (TV_PARSE_GLOBAL);
     704                 :       22028 : }
        

Generated by: LCOV version 2.0-1

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.