LCOV - code coverage report
Current view: top level - gcc - data-streamer-out.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 171 184 92.9 %
Date: 2020-04-04 11:58:09 Functions: 15 17 88.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Routines for saving various data types to a file stream.  This deals
       2                 :            :    with various data types like strings, integers, enums, etc.
       3                 :            : 
       4                 :            :    Copyright (C) 2011-2020 Free Software Foundation, Inc.
       5                 :            :    Contributed by Diego Novillo <dnovillo@google.com>
       6                 :            : 
       7                 :            : This file is part of GCC.
       8                 :            : 
       9                 :            : GCC is free software; you can redistribute it and/or modify it under
      10                 :            : the terms of the GNU General Public License as published by the Free
      11                 :            : Software Foundation; either version 3, or (at your option) any later
      12                 :            : version.
      13                 :            : 
      14                 :            : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      15                 :            : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      16                 :            : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      17                 :            : for more details.
      18                 :            : 
      19                 :            : You should have received a copy of the GNU General Public License
      20                 :            : along with GCC; see the file COPYING3.  If not see
      21                 :            : <http://www.gnu.org/licenses/>.  */
      22                 :            : 
      23                 :            : #include "config.h"
      24                 :            : #include "system.h"
      25                 :            : #include "coretypes.h"
      26                 :            : #include "backend.h"
      27                 :            : #include "tree.h"
      28                 :            : #include "gimple.h"
      29                 :            : #include "cgraph.h"
      30                 :            : #include "data-streamer.h"
      31                 :            : 
      32                 :            : 
      33                 :            : /* Adds a new block to output stream OBS.  */
      34                 :            : 
      35                 :            : void
      36                 :     546358 : lto_append_block (struct lto_output_stream *obs)
      37                 :            : {
      38                 :     546358 :   struct lto_char_ptr_base *new_block;
      39                 :            : 
      40                 :     546358 :   gcc_assert (obs->left_in_block == 0);
      41                 :            : 
      42                 :     546358 :   if (obs->first_block == NULL)
      43                 :            :     {
      44                 :            :       /* This is the first time the stream has been written
      45                 :            :          into.  */
      46                 :     496485 :       obs->block_size = 1024;
      47                 :     496485 :       new_block = (struct lto_char_ptr_base*) xmalloc (obs->block_size);
      48                 :     496485 :       obs->first_block = new_block;
      49                 :            :     }
      50                 :            :   else
      51                 :            :     {
      52                 :      49873 :       struct lto_char_ptr_base *tptr;
      53                 :            :       /* Get a new block that is twice as big as the last block
      54                 :            :          and link it into the list.  */
      55                 :      49873 :       obs->block_size *= 2;
      56                 :      49873 :       new_block = (struct lto_char_ptr_base*) xmalloc (obs->block_size);
      57                 :            :       /* The first bytes of the block are reserved as a pointer to
      58                 :            :          the next block.  Set the chain of the full block to the
      59                 :            :          pointer to the new block.  */
      60                 :      49873 :       tptr = obs->current_block;
      61                 :      49873 :       tptr->ptr = (char *) new_block;
      62                 :            :     }
      63                 :            : 
      64                 :            :   /* Set the place for the next char at the first position after the
      65                 :            :      chain to the next block.  */
      66                 :     546358 :   obs->current_pointer
      67                 :     546358 :     = ((char *) new_block) + sizeof (struct lto_char_ptr_base);
      68                 :     546358 :   obs->current_block = new_block;
      69                 :            :   /* Null out the newly allocated block's pointer to the next block.  */
      70                 :     546358 :   new_block->ptr = NULL;
      71                 :     546358 :   obs->left_in_block = obs->block_size - sizeof (struct lto_char_ptr_base);
      72                 :     546358 : }
      73                 :            : 
      74                 :            : 
      75                 :            : /* Return index used to reference STRING of LEN characters in the string table
      76                 :            :    in OB.  The string might or might not include a trailing '\0'.
      77                 :            :    Then put the index onto the INDEX_STREAM.  
      78                 :            :    When PERSISTENT is set, the string S is supposed to not change during
      79                 :            :    duration of the OB and thus OB can keep pointer into it.  */
      80                 :            : 
      81                 :            : static unsigned
      82                 :    1684150 : streamer_string_index (struct output_block *ob, const char *s, unsigned int len,
      83                 :            :                        bool persistent)
      84                 :            : {
      85                 :    1684150 :   struct string_slot **slot;
      86                 :    1684150 :   struct string_slot s_slot;
      87                 :            : 
      88                 :    1684150 :   s_slot.s = s;
      89                 :    1684150 :   s_slot.len = len;
      90                 :    1684150 :   s_slot.slot_num = 0;
      91                 :            : 
      92                 :    1684150 :   slot = ob->string_hash_table->find_slot (&s_slot, INSERT);
      93                 :    1684150 :   if (*slot == NULL)
      94                 :            :     {
      95                 :    1571340 :       struct lto_output_stream *string_stream = ob->string_stream;
      96                 :    1571340 :       unsigned int start = string_stream->total_size;
      97                 :    1571340 :       struct string_slot *new_slot = XOBNEW (&ob->obstack, struct string_slot);
      98                 :    1571340 :       const char *string;
      99                 :            : 
     100                 :    1571340 :       if (!persistent)
     101                 :            :         {
     102                 :          0 :           char *tmp;
     103                 :          0 :           string = tmp = XOBNEWVEC (&ob->obstack, char, len);
     104                 :          0 :           memcpy (tmp, s, len);
     105                 :            :         }
     106                 :            :       else
     107                 :            :         string = s;
     108                 :            : 
     109                 :    1571340 :       new_slot->s = string;
     110                 :    1571340 :       new_slot->len = len;
     111                 :    1571340 :       new_slot->slot_num = start;
     112                 :    1571340 :       *slot = new_slot;
     113                 :    1571340 :       streamer_write_uhwi_stream (string_stream, len);
     114                 :    1571340 :       streamer_write_data_stream (string_stream, string, len);
     115                 :    1571340 :       return start + 1;
     116                 :            :     }
     117                 :            :   else
     118                 :            :     {
     119                 :     112809 :       struct string_slot *old_slot = *slot;
     120                 :     112809 :       return old_slot->slot_num + 1;
     121                 :            :     }
     122                 :            : }
     123                 :            : 
     124                 :            : 
     125                 :            : /* Output STRING of LEN characters to the string table in OB. The
     126                 :            :    string might or might not include a trailing '\0'. Then put the
     127                 :            :    index onto the INDEX_STREAM. 
     128                 :            :    When PERSISTENT is set, the string S is supposed to not change during
     129                 :            :    duration of the OB and thus OB can keep pointer into it.  */
     130                 :            : 
     131                 :            : void
     132                 :    1379970 : streamer_write_string_with_length (struct output_block *ob,
     133                 :            :                                    struct lto_output_stream *index_stream,
     134                 :            :                                    const char *s, unsigned int len,
     135                 :            :                                    bool persistent)
     136                 :            : {
     137                 :    1379970 :   if (s)
     138                 :    1379950 :     streamer_write_uhwi_stream (index_stream,
     139                 :    1379950 :                                 streamer_string_index (ob, s, len, persistent));
     140                 :            :   else
     141                 :         22 :     streamer_write_char_stream (index_stream, 0);
     142                 :    1379970 : }
     143                 :            : 
     144                 :            : 
     145                 :            : /* Output the '\0' terminated STRING to the string
     146                 :            :    table in OB.  Then put the index onto the INDEX_STREAM.
     147                 :            :    When PERSISTENT is set, the string S is supposed to not change during
     148                 :            :    duration of the OB and thus OB can keep pointer into it.  */
     149                 :            : 
     150                 :            : void
     151                 :    1356520 : streamer_write_string (struct output_block *ob,
     152                 :            :                        struct lto_output_stream *index_stream,
     153                 :            :                        const char *string, bool persistent)
     154                 :            : {
     155                 :    1356520 :   if (string)
     156                 :      46517 :     streamer_write_string_with_length (ob, index_stream, string,
     157                 :      46517 :                                        strlen (string) + 1,
     158                 :            :                                        persistent);
     159                 :            :   else
     160                 :    1310000 :     streamer_write_char_stream (index_stream, 0);
     161                 :    1356520 : }
     162                 :            : 
     163                 :            : 
     164                 :            : /* Output STRING of LEN characters to the string table in OB.  Then
     165                 :            :    put the index into BP.
     166                 :            :    When PERSISTENT is set, the string S is supposed to not change during
     167                 :            :    duration of the OB and thus OB can keep pointer into it.  */
     168                 :            : 
     169                 :            : void
     170                 :          0 : bp_pack_string_with_length (struct output_block *ob, struct bitpack_d *bp,
     171                 :            :                             const char *s, unsigned int len, bool persistent)
     172                 :            : {
     173                 :          0 :   unsigned index = 0;
     174                 :          0 :   if (s)
     175                 :          0 :     index = streamer_string_index (ob, s, len, persistent);
     176                 :          0 :   bp_pack_var_len_unsigned (bp, index);
     177                 :          0 : }
     178                 :            : 
     179                 :            : 
     180                 :            : /* Output the '\0' terminated STRING to the string
     181                 :            :    table in OB.  Then put the index onto the bitpack BP.
     182                 :            :    When PERSISTENT is set, the string S is supposed to not change during
     183                 :            :    duration of the OB and thus OB can keep pointer into it.  */
     184                 :            : 
     185                 :            : void
     186                 :     397743 : bp_pack_string (struct output_block *ob, struct bitpack_d *bp,
     187                 :            :                 const char *s, bool persistent)
     188                 :            : {
     189                 :     397743 :   unsigned index = 0;
     190                 :     397743 :   if (s)
     191                 :     304195 :     index = streamer_string_index (ob, s, strlen (s) + 1, persistent);
     192                 :     397743 :   bp_pack_var_len_unsigned (bp, index);
     193                 :     397743 : }
     194                 :            : 
     195                 :            : 
     196                 :            : 
     197                 :            : /* Write a zero to the output stream.  */
     198                 :            : 
     199                 :            : void
     200                 :    5489000 : streamer_write_zero (struct output_block *ob)
     201                 :            : {
     202                 :    5489000 :   streamer_write_char_stream (ob->main_stream, 0);
     203                 :    5489000 : }
     204                 :            : 
     205                 :            : 
     206                 :            : /* Write an unsigned HOST_WIDE_INT value WORK to OB->main_stream.  */
     207                 :            : 
     208                 :            : void
     209                 :   42291200 : streamer_write_uhwi (struct output_block *ob, unsigned HOST_WIDE_INT work)
     210                 :            : {
     211                 :   42291200 :   streamer_write_uhwi_stream (ob->main_stream, work);
     212                 :   42291200 : }
     213                 :            : 
     214                 :            : 
     215                 :            : /* Write a HOST_WIDE_INT value WORK to OB->main_stream.  */
     216                 :            : 
     217                 :            : void
     218                 :    5443970 : streamer_write_hwi (struct output_block *ob, HOST_WIDE_INT work)
     219                 :            : {
     220                 :    5443970 :   streamer_write_hwi_stream (ob->main_stream, work);
     221                 :    5443970 : }
     222                 :            : 
     223                 :            : /* Write a poly_uint64 value WORK to OB->main_stream.  */
     224                 :            : 
     225                 :            : void
     226                 :          0 : streamer_write_poly_uint64 (struct output_block *ob, poly_uint64 work)
     227                 :            : {
     228                 :          0 :   for (int i = 0; i < NUM_POLY_INT_COEFFS; ++i)
     229                 :          0 :     streamer_write_uhwi_stream (ob->main_stream, work.coeffs[i]);
     230                 :          0 : }
     231                 :            : 
     232                 :            : /* Write a gcov counter value WORK to OB->main_stream.  */
     233                 :            : 
     234                 :            : void
     235                 :     625869 : streamer_write_gcov_count (struct output_block *ob, gcov_type work)
     236                 :            : {
     237                 :     625869 :   streamer_write_gcov_count_stream (ob->main_stream, work);
     238                 :     625869 : }
     239                 :            : 
     240                 :            : /* Write an unsigned HOST_WIDE_INT value WORK to OBS.  */
     241                 :            : 
     242                 :            : void
     243                 :  143031000 : streamer_write_uhwi_stream (struct lto_output_stream *obs,
     244                 :            :                             unsigned HOST_WIDE_INT work)
     245                 :            : {
     246                 :  143031000 :   if (obs->left_in_block == 0)
     247                 :     385889 :     lto_append_block (obs);
     248                 :  143031000 :   char *current_pointer = obs->current_pointer;
     249                 :  143031000 :   unsigned int left_in_block = obs->left_in_block;
     250                 :  143031000 :   unsigned int size = 0;
     251                 :  237858000 :   do
     252                 :            :     {
     253                 :  237858000 :       unsigned int byte = (work & 0x7f);
     254                 :  237858000 :       work >>= 7;
     255                 :  237858000 :       if (work != 0)
     256                 :            :         /* More bytes to follow.  */
     257                 :   94844400 :         byte |= 0x80;
     258                 :            : 
     259                 :  237858000 :       *(current_pointer++) = byte;
     260                 :  237858000 :       left_in_block--;
     261                 :  237858000 :       size++;
     262                 :            :     }
     263                 :  237858000 :   while (work != 0 && left_in_block > 0);
     264                 :  143031000 :   if (work != 0)
     265                 :            :     {
     266                 :      17308 :       obs->left_in_block = 0;
     267                 :      17308 :       lto_append_block (obs);
     268                 :      17308 :       current_pointer = obs->current_pointer;
     269                 :      17308 :       left_in_block = obs->left_in_block;
     270                 :      41767 :       do
     271                 :            :         {
     272                 :      41767 :           unsigned int byte = (work & 0x7f);
     273                 :      41767 :           work >>= 7;
     274                 :      41767 :           if (work != 0)
     275                 :            :             /* More bytes to follow.  */
     276                 :      24459 :             byte |= 0x80;
     277                 :            : 
     278                 :      41767 :           *(current_pointer++) = byte;
     279                 :      41767 :           left_in_block--;
     280                 :      41767 :           size++;
     281                 :            :         }
     282                 :      41767 :       while (work != 0);
     283                 :            :     }
     284                 :  143031000 :   obs->current_pointer = current_pointer;
     285                 :  143031000 :   obs->left_in_block = left_in_block;
     286                 :  143031000 :   obs->total_size += size;
     287                 :  143031000 : }
     288                 :            : 
     289                 :            : 
     290                 :            : /* Write a HOST_WIDE_INT value WORK to OBS.  */
     291                 :            : 
     292                 :            : void
     293                 :   11204600 : streamer_write_hwi_stream (struct lto_output_stream *obs, HOST_WIDE_INT work)
     294                 :            : {
     295                 :   11204600 :   if (obs->left_in_block == 0)
     296                 :      12925 :     lto_append_block (obs);
     297                 :   11204600 :   char *current_pointer = obs->current_pointer;
     298                 :   11204600 :   unsigned int left_in_block = obs->left_in_block;
     299                 :   11204600 :   unsigned int size = 0;
     300                 :   23186200 :   bool more;
     301                 :   23186200 :   do
     302                 :            :     {
     303                 :   23186200 :       unsigned int byte = (work & 0x7f);
     304                 :            :       /* If the lower 7-bits are sign-extended 0 or -1 we are finished.  */
     305                 :   23186200 :       work >>= 6;
     306                 :   23186200 :       more = !(work == 0 || work == -1);
     307                 :   23186200 :       if (more)
     308                 :            :         {
     309                 :            :           /* More bits to follow.  */
     310                 :   11983100 :           work >>= 1;
     311                 :   11983100 :           byte |= 0x80;
     312                 :            :         }
     313                 :            : 
     314                 :   23186200 :       *(current_pointer++) = byte;
     315                 :   23186200 :       left_in_block--;
     316                 :   23186200 :       size++;
     317                 :            :     }
     318                 :   23186200 :   while (more && left_in_block > 0);
     319                 :   11204600 :   if (more)
     320                 :            :     {
     321                 :       1482 :       obs->left_in_block = 0;
     322                 :       1482 :       lto_append_block (obs);
     323                 :       1482 :       current_pointer = obs->current_pointer;
     324                 :       1482 :       left_in_block = obs->left_in_block;
     325                 :       7644 :       do
     326                 :            :         {
     327                 :       3822 :           unsigned int byte = (work & 0x7f);
     328                 :       3822 :           work >>= 6;
     329                 :       3822 :           more = !(work == 0 || work == -1);
     330                 :       3822 :           if (more)
     331                 :            :             {
     332                 :       2340 :               work >>= 1;
     333                 :       2340 :               byte |= 0x80;
     334                 :            :             }
     335                 :            : 
     336                 :       3822 :           *(current_pointer++) = byte;
     337                 :       3822 :           left_in_block--;
     338                 :       3822 :           size++;
     339                 :            :         }
     340                 :            :       while (more);
     341                 :            :     }
     342                 :   11204600 :   obs->current_pointer = current_pointer;
     343                 :   11204600 :   obs->left_in_block = left_in_block;
     344                 :   11204600 :   obs->total_size += size;
     345                 :   11204600 : }
     346                 :            : 
     347                 :            : /* Write a GCOV counter value WORK to OBS.  */
     348                 :            : 
     349                 :            : void
     350                 :    1379560 : streamer_write_gcov_count_stream (struct lto_output_stream *obs, gcov_type work)
     351                 :            : {
     352                 :    1379560 :   gcc_assert ((HOST_WIDE_INT) work == work);
     353                 :    1379560 :   streamer_write_hwi_stream (obs, work);
     354                 :    1379560 : }
     355                 :            : 
     356                 :            : /* Write raw DATA of length LEN to the output block OB.  */
     357                 :            : 
     358                 :            : void
     359                 :    2845080 : streamer_write_data_stream (struct lto_output_stream *obs, const void *data,
     360                 :            :                             size_t len)
     361                 :            : {
     362                 :    5692030 :   while (len)
     363                 :            :     {
     364                 :    2846950 :       size_t copy;
     365                 :            : 
     366                 :            :       /* No space left.  */
     367                 :    2846950 :       if (obs->left_in_block == 0)
     368                 :       2067 :         lto_append_block (obs);
     369                 :            : 
     370                 :            :       /* Determine how many bytes to copy in this loop.  */
     371                 :    2846950 :       if (len <= obs->left_in_block)
     372                 :            :         copy = len;
     373                 :            :       else
     374                 :            :         copy = obs->left_in_block;
     375                 :            : 
     376                 :            :       /* Copy the data and do bookkeeping.  */
     377                 :    2846950 :       memcpy (obs->current_pointer, data, copy);
     378                 :    2846950 :       obs->current_pointer += copy;
     379                 :    2846950 :       obs->total_size += copy;
     380                 :    2846950 :       obs->left_in_block -= copy;
     381                 :    2846950 :       data = (const char *) data + copy;
     382                 :    2846950 :       len -= copy;
     383                 :            :     }
     384                 :    2845080 : }
     385                 :            : 
     386                 :            : /* Emit the physical representation of wide_int VAL to output block OB.  */
     387                 :            : 
     388                 :            : void
     389                 :      19896 : streamer_write_wide_int (struct output_block *ob, const wide_int &val)
     390                 :            : {
     391                 :      19896 :   int len = val.get_len ();
     392                 :            : 
     393                 :      19896 :   streamer_write_uhwi (ob, val.get_precision ());
     394                 :      19896 :   streamer_write_uhwi (ob, len);
     395                 :      40373 :   for (int i = 0; i < len; i++)
     396                 :      40954 :     streamer_write_hwi (ob, val.elt (i));
     397                 :      19896 : }
     398                 :            : 
     399                 :            : /* Emit the physical representation of widest_int W to output block OB.  */
     400                 :            : 
     401                 :            : void
     402                 :     413961 : streamer_write_widest_int (struct output_block *ob,
     403                 :            :                            const widest_int &w)
     404                 :            : {
     405                 :     413961 :   int len = w.get_len ();
     406                 :            : 
     407                 :     413961 :   streamer_write_uhwi (ob, w.get_precision ());
     408                 :     413961 :   streamer_write_uhwi (ob, len);
     409                 :     916340 :   for (int i = 0; i < len; i++)
     410                 :    1004760 :     streamer_write_hwi (ob, w.elt (i));
     411                 :     413961 : }
     412                 :            : 

Generated by: LCOV version 1.0

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 --enable-host-shared. GCC test suite is run with the built compiler.