LCOV - code coverage report
Current view: top level - gcc - lto-opts.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 85.4 % 96 82
Test Date: 2024-12-21 13:15:12 Functions: 100.0 % 2 2
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* LTO IL options.
       2                 :             : 
       3                 :             :    Copyright (C) 2009-2024 Free Software Foundation, Inc.
       4                 :             :    Contributed by Simon Baldwin <simonb@google.com>
       5                 :             : 
       6                 :             : This file is part of GCC.
       7                 :             : 
       8                 :             : GCC is free software; you can redistribute it and/or modify it under
       9                 :             : the terms of the GNU General Public License as published by the Free
      10                 :             : Software Foundation; either version 3, or (at your option) any later
      11                 :             : version.
      12                 :             : 
      13                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      14                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      15                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      16                 :             : for more details.
      17                 :             : 
      18                 :             : You should have received a copy of the GNU General Public License
      19                 :             : along with GCC; see the file COPYING3.  If not see
      20                 :             : <http://www.gnu.org/licenses/>.  */
      21                 :             : 
      22                 :             : #include "config.h"
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "backend.h"
      26                 :             : #include "target.h"
      27                 :             : #include "tree.h"
      28                 :             : #include "gimple.h"
      29                 :             : #include "cgraph.h"
      30                 :             : #include "lto-streamer.h"
      31                 :             : #include "opts.h"
      32                 :             : #include "toplev.h"
      33                 :             : 
      34                 :             : /* Append the option piece OPT to the COLLECT_GCC_OPTIONS string
      35                 :             :    set up by OB, appropriately quoted and separated by spaces
      36                 :             :    (if !*FIRST_P).  */
      37                 :             : 
      38                 :             : static void
      39                 :      488816 : append_to_collect_gcc_options (struct obstack *ob,
      40                 :             :                                bool *first_p, const char *opt)
      41                 :             : {
      42                 :      488816 :   const char *p, *q = opt;
      43                 :      488816 :   if (!*first_p)
      44                 :      455635 :     obstack_grow (ob, " ", 1);
      45                 :      488816 :   obstack_grow (ob, "'", 1);
      46                 :      488816 :   while ((p = strchr (q, '\'')))
      47                 :             :     {
      48                 :           0 :       obstack_grow (ob, q, p - q);
      49                 :           0 :       obstack_grow (ob, "'\\''", 4);
      50                 :           0 :       q = ++p;
      51                 :             :     }
      52                 :      488816 :   obstack_grow (ob, q, strlen (q));
      53                 :      488816 :   obstack_grow (ob, "'", 1);
      54                 :      488816 :   *first_p = false;
      55                 :      488816 : }
      56                 :             : 
      57                 :             : /* Write currently held options to an LTO IL section.  */
      58                 :             : 
      59                 :             : void
      60                 :       33181 : lto_write_options (void)
      61                 :             : {
      62                 :       33181 :   char *section_name;
      63                 :       33181 :   struct obstack temporary_obstack;
      64                 :       33181 :   unsigned int i, j;
      65                 :       33181 :   char *args;
      66                 :       33181 :   bool first_p = true;
      67                 :             : 
      68                 :       33181 :   section_name = lto_get_section_name (LTO_section_opts, NULL, 0, NULL);
      69                 :       33181 :   lto_begin_section (section_name, false);
      70                 :             : 
      71                 :       33181 :   obstack_init (&temporary_obstack);
      72                 :             : 
      73                 :       33181 :   if (!OPTION_SET_P (flag_openmp)
      74                 :       23890 :       && !global_options.x_flag_openmp)
      75                 :       23890 :     append_to_collect_gcc_options (&temporary_obstack, &first_p,
      76                 :             :                                    "-fno-openmp");
      77                 :       33181 :   if (!OPTION_SET_P (flag_openacc)
      78                 :       23934 :       && !global_options.x_flag_openacc)
      79                 :       23934 :     append_to_collect_gcc_options (&temporary_obstack, &first_p,
      80                 :             :                                    "-fno-openacc");
      81                 :             :   /* Append PIC/PIE mode because its default depends on target and it is
      82                 :             :      subject of merging in lto-wrapper.  */
      83                 :       33181 :   if (!OPTION_SET_P (flag_pic) && !OPTION_SET_P (flag_pie))
      84                 :             :     {
      85                 :       23641 :        append_to_collect_gcc_options (&temporary_obstack, &first_p,
      86                 :       23641 :                                       global_options.x_flag_pic == 2
      87                 :             :                                       ? "-fPIC"
      88                 :             :                                       : global_options.x_flag_pic == 1
      89                 :       23641 :                                       ? "-fpic"
      90                 :       23641 :                                       : global_options.x_flag_pie == 2
      91                 :       23641 :                                       ? "-fPIE"
      92                 :             :                                       : global_options.x_flag_pie == 1
      93                 :       23641 :                                       ? "-fpie"
      94                 :             :                                       : "-fno-pie");
      95                 :             :     }
      96                 :             : 
      97                 :       33181 :   if (!OPTION_SET_P (flag_cf_protection))
      98                 :             :     {
      99                 :       23898 :       append_to_collect_gcc_options (
     100                 :             :         &temporary_obstack, &first_p,
     101                 :       23898 :         global_options.x_flag_cf_protection == CF_NONE
     102                 :             :         ? "-fcf-protection=none"
     103                 :             :         : global_options.x_flag_cf_protection == CF_FULL
     104                 :             :         ? "-fcf-protection=full"
     105                 :             :         : global_options.x_flag_cf_protection == CF_BRANCH
     106                 :             :         ? "-fcf-protection=branch"
     107                 :             :         : global_options.x_flag_cf_protection == CF_RETURN
     108                 :             :         ? "-fcf-protection=return"
     109                 :             :         : "");
     110                 :             :     }
     111                 :             : 
     112                 :             :   /* If debug info is enabled append -g.  */
     113                 :       33181 :   if (debug_info_level > DINFO_LEVEL_NONE)
     114                 :        1930 :     append_to_collect_gcc_options (&temporary_obstack, &first_p, "-g");
     115                 :             : 
     116                 :             :   /* Append options from target hook and store them to offload_lto section.  */
     117                 :       33181 :   if (lto_stream_offload_p)
     118                 :             :     {
     119                 :           0 :       char *offload_opts = targetm.offload_options ();
     120                 :           0 :       char *offload_ptr = offload_opts;
     121                 :           0 :       while (offload_ptr)
     122                 :             :        {
     123                 :           0 :          char *next = strchr (offload_ptr, ' ');
     124                 :           0 :          if (next)
     125                 :           0 :            *next++ = '\0';
     126                 :           0 :          append_to_collect_gcc_options (&temporary_obstack, &first_p,
     127                 :             :                                         offload_ptr);
     128                 :           0 :          offload_ptr = next;
     129                 :             :        }
     130                 :           0 :       free (offload_opts);
     131                 :             :     }
     132                 :             : 
     133                 :             :   /* Output explicitly passed options.  */
     134                 :      858707 :   for (i = 1; i < save_decoded_options_count; ++i)
     135                 :             :     {
     136                 :      825526 :       struct cl_decoded_option *option = &save_decoded_options[i];
     137                 :             : 
     138                 :             :       /* Skip explicitly some common options that we do not need.  */
     139                 :      825526 :       switch (option->opt_index)
     140                 :             :       {
     141                 :       94737 :         case OPT_dumpbase:
     142                 :       94737 :         case OPT_SPECIAL_unknown:
     143                 :       94737 :         case OPT_SPECIAL_ignore:
     144                 :       94737 :         case OPT_SPECIAL_warn_removed:
     145                 :       94737 :         case OPT_SPECIAL_program_name:
     146                 :       94737 :         case OPT_SPECIAL_input_file:
     147                 :       94737 :         case OPT_dumpdir:
     148                 :       94737 :         case OPT_fresolution_:
     149                 :       94737 :         case OPT_fdebug_prefix_map_:
     150                 :       94737 :         case OPT_ffile_prefix_map_:
     151                 :       94737 :         case OPT_fmacro_prefix_map_:
     152                 :       94737 :         case OPT_fprofile_prefix_map_:
     153                 :       94737 :         case OPT_fcanon_prefix_map:
     154                 :       94737 :         case OPT_fwhole_program:
     155                 :       94737 :         case OPT_fltrans_output_list_:
     156                 :       94737 :         case OPT_flto_incremental_:
     157                 :       94737 :         case OPT_flto_incremental_cache_size_:
     158                 :       94737 :           continue;
     159                 :             : 
     160                 :      730789 :         default:
     161                 :      730789 :           break;
     162                 :             :       }
     163                 :             : 
     164                 :             :       /* Skip frontend and driver specific options here.  */
     165                 :      730789 :       if (!(cl_options[option->opt_index].flags & (CL_COMMON|CL_TARGET|CL_LTO)))
     166                 :      105087 :         continue;
     167                 :             : 
     168                 :             :       /* Do not store target-specific options in offload_lto section.  */
     169                 :      625702 :       if ((cl_options[option->opt_index].flags & CL_TARGET)
     170                 :       72202 :           && lto_stream_offload_p)
     171                 :           0 :        continue;
     172                 :             : 
     173                 :             :       /* Drop options created from the gcc driver that will be rejected
     174                 :             :          when passed on to the driver again.  */
     175                 :      625702 :       if (cl_options[option->opt_index].cl_reject_driver)
     176                 :       56058 :         continue;
     177                 :             : 
     178                 :             :       /* Also drop all options that are handled by the driver as well,
     179                 :             :          which includes things like -o and -v or -fhelp for example.
     180                 :             :          We do not need those.  The only exception is -foffload option, if we
     181                 :             :          write it in offload_lto section.  Also drop all diagnostic options.  */
     182                 :      569644 :       if ((cl_options[option->opt_index].flags & (CL_DRIVER|CL_WARNING))
     183                 :      178121 :           && (!lto_stream_offload_p
     184                 :           0 :               || option->opt_index != OPT_foffload_options_))
     185                 :      178121 :         continue;
     186                 :             : 
     187                 :      783046 :       for (j = 0; j < option->canonical_option_num_elements; ++j)
     188                 :      391523 :         append_to_collect_gcc_options (&temporary_obstack, &first_p,
     189                 :             :                                        option->canonical_option[j]);
     190                 :             :     }
     191                 :             : 
     192                 :       33181 :   const char *collect_as_options = getenv ("COLLECT_AS_OPTIONS");
     193                 :       33181 :   if (collect_as_options)
     194                 :           2 :     prepend_xassembler_to_collect_as_options (collect_as_options,
     195                 :             :                                               &temporary_obstack);
     196                 :             : 
     197                 :       33181 :   obstack_grow (&temporary_obstack, "\0", 1);
     198                 :       33181 :   args = XOBFINISH (&temporary_obstack, char *);
     199                 :       33181 :   lto_write_data (args, strlen (args) + 1);
     200                 :       33181 :   lto_end_section ();
     201                 :             : 
     202                 :       33181 :   obstack_free (&temporary_obstack, NULL);
     203                 :       33181 :   free (section_name);
     204                 :       33181 : }
        

Generated by: LCOV version 2.1-beta

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.