LCOV - code coverage report
Current view: top level - gcc - gimple-streamer-in.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 137 144 95.1 %
Date: 2020-03-28 11:57:23 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Routines for reading GIMPLE from a file stream.
       2                 :            : 
       3                 :            :    Copyright (C) 2011-2020 Free Software Foundation, Inc.
       4                 :            :    Contributed by Diego Novillo <dnovillo@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 "tree.h"
      27                 :            : #include "gimple.h"
      28                 :            : #include "ssa.h"
      29                 :            : #include "gimple-streamer.h"
      30                 :            : #include "tree-eh.h"
      31                 :            : #include "gimple-iterator.h"
      32                 :            : #include "cgraph.h"
      33                 :            : #include "value-prof.h"
      34                 :            : 
      35                 :            : /* Read a PHI function for basic block BB in function FN.  DATA_IN is
      36                 :            :    the file being read.  IB is the input block to use for reading.  */
      37                 :            : 
      38                 :            : static gphi *
      39                 :      28763 : input_phi (class lto_input_block *ib, basic_block bb, class data_in *data_in,
      40                 :            :            struct function *fn)
      41                 :            : {
      42                 :      28763 :   unsigned HOST_WIDE_INT ix;
      43                 :      28763 :   tree phi_result;
      44                 :      28763 :   int i, len;
      45                 :      28763 :   gphi *result;
      46                 :            : 
      47                 :      28763 :   ix = streamer_read_uhwi (ib);
      48                 :      28763 :   phi_result = (*SSANAMES (fn))[ix];
      49                 :      28763 :   len = EDGE_COUNT (bb->preds);
      50                 :      28763 :   result = create_phi_node (phi_result, bb);
      51                 :            : 
      52                 :            :   /* We have to go through a lookup process here because the preds in the
      53                 :            :      reconstructed graph are generally in a different order than they
      54                 :            :      were in the original program.  */
      55                 :      84445 :   for (i = 0; i < len; i++)
      56                 :            :     {
      57                 :      55682 :       tree def = stream_read_tree (ib, data_in);
      58                 :      55682 :       int src_index = streamer_read_uhwi (ib);
      59                 :      55682 :       bitpack_d bp = streamer_read_bitpack (ib);
      60                 :            :       /* Do not cache a location - we do not have API to get pointer to the
      61                 :            :          location in PHI statement and we may trigger reallocation.  */
      62                 :      55682 :       location_t arg_loc = stream_input_location_now (&bp, data_in);
      63                 :      55682 :       basic_block sbb = BASIC_BLOCK_FOR_FN (fn, src_index);
      64                 :            : 
      65                 :      55682 :       edge e = NULL;
      66                 :      55682 :       int j;
      67                 :            : 
      68                 :     108247 :       for (j = 0; j < len; j++)
      69                 :     108247 :         if (EDGE_PRED (bb, j)->src == sbb)
      70                 :            :           {
      71                 :      55682 :             e = EDGE_PRED (bb, j);
      72                 :            :             break;
      73                 :            :           }
      74                 :            : 
      75                 :      55682 :       add_phi_arg (result, def, e, arg_loc);
      76                 :            :     }
      77                 :            : 
      78                 :      28763 :   return result;
      79                 :            : }
      80                 :            : 
      81                 :            : 
      82                 :            : /* Read a statement with tag TAG in function FN from block IB using
      83                 :            :    descriptors in DATA_IN.  */
      84                 :            : 
      85                 :            : static gimple *
      86                 :     967861 : input_gimple_stmt (class lto_input_block *ib, class data_in *data_in,
      87                 :            :                    enum LTO_tags tag)
      88                 :            : {
      89                 :     967861 :   gimple *stmt;
      90                 :     967861 :   enum gimple_code code;
      91                 :     967861 :   unsigned HOST_WIDE_INT num_ops;
      92                 :     967861 :   size_t i;
      93                 :     967861 :   struct bitpack_d bp;
      94                 :     967861 :   bool has_hist;
      95                 :            : 
      96                 :     967861 :   code = lto_tag_to_gimple_code (tag);
      97                 :            : 
      98                 :            :   /* Read the tuple header.  */
      99                 :     967861 :   bp = streamer_read_bitpack (ib);
     100                 :     967861 :   num_ops = bp_unpack_var_len_unsigned (&bp);
     101                 :     967861 :   stmt = gimple_alloc (code, num_ops);
     102                 :     967861 :   stmt->no_warning = bp_unpack_value (&bp, 1);
     103                 :     967861 :   if (is_gimple_assign (stmt))
     104                 :     469030 :     stmt->nontemporal_move = bp_unpack_value (&bp, 1);
     105                 :     967861 :   stmt->has_volatile_ops = bp_unpack_value (&bp, 1);
     106                 :     967861 :   has_hist = bp_unpack_value (&bp, 1);
     107                 :     967861 :   stmt->subcode = bp_unpack_var_len_unsigned (&bp);
     108                 :            : 
     109                 :            :   /* Read location information.  Caching here makes no sense until streamer
     110                 :            :      cache can handle the following gimple_set_block.  */
     111                 :     967861 :   gimple_set_location (stmt, stream_input_location_now (&bp, data_in));
     112                 :            : 
     113                 :            :   /* Read lexical block reference.  */
     114                 :     967861 :   gimple_set_block (stmt, stream_read_tree (ib, data_in));
     115                 :            : 
     116                 :            :   /* Read in all the operands.  */
     117                 :     967861 :   switch (code)
     118                 :            :     {
     119                 :       1736 :     case GIMPLE_RESX:
     120                 :       1736 :       gimple_resx_set_region (as_a <gresx *> (stmt),
     121                 :       1736 :                               streamer_read_hwi (ib));
     122                 :            :       break;
     123                 :            : 
     124                 :          0 :     case GIMPLE_EH_MUST_NOT_THROW:
     125                 :          0 :       gimple_eh_must_not_throw_set_fndecl (
     126                 :            :         as_a <geh_mnt *> (stmt),
     127                 :          0 :         stream_read_tree (ib, data_in));
     128                 :            :       break;
     129                 :            : 
     130                 :        186 :     case GIMPLE_EH_DISPATCH:
     131                 :        186 :       gimple_eh_dispatch_set_region (as_a <geh_dispatch *> (stmt),
     132                 :        186 :                                      streamer_read_hwi (ib));
     133                 :            :       break;
     134                 :            : 
     135                 :       5459 :     case GIMPLE_ASM:
     136                 :       5459 :       {
     137                 :            :         /* FIXME lto.  Move most of this into a new gimple_asm_set_string().  */
     138                 :       5459 :         gasm *asm_stmt = as_a <gasm *> (stmt);
     139                 :       5459 :         tree str;
     140                 :       5459 :         asm_stmt->ni = streamer_read_uhwi (ib);
     141                 :       5459 :         asm_stmt->no = streamer_read_uhwi (ib);
     142                 :       5459 :         asm_stmt->nc = streamer_read_uhwi (ib);
     143                 :       5459 :         asm_stmt->nl = streamer_read_uhwi (ib);
     144                 :       5459 :         str = streamer_read_string_cst (data_in, ib);
     145                 :       5459 :         asm_stmt->string = TREE_STRING_POINTER (str);
     146                 :            :       }
     147                 :            :       /* Fallthru  */
     148                 :            : 
     149                 :            :     case GIMPLE_ASSIGN:
     150                 :            :     case GIMPLE_CALL:
     151                 :            :     case GIMPLE_RETURN:
     152                 :            :     case GIMPLE_SWITCH:
     153                 :            :     case GIMPLE_LABEL:
     154                 :            :     case GIMPLE_COND:
     155                 :            :     case GIMPLE_GOTO:
     156                 :            :     case GIMPLE_DEBUG:
     157                 :    3795010 :       for (i = 0; i < num_ops; i++)
     158                 :            :         {
     159                 :    2829940 :           tree *opp, op = stream_read_tree (ib, data_in);
     160                 :    2829940 :           gimple_set_op (stmt, i, op);
     161                 :    2829940 :           if (!op)
     162                 :     843271 :             continue;
     163                 :            : 
     164                 :    1986670 :           opp = gimple_op_ptr (stmt, i);
     165                 :    1986670 :           if (TREE_CODE (*opp) == ADDR_EXPR)
     166                 :     266832 :             opp = &TREE_OPERAND (*opp, 0);
     167                 :    2130670 :           while (handled_component_p (*opp))
     168                 :     143999 :             opp = &TREE_OPERAND (*opp, 0);
     169                 :            :           /* At LTO output time we wrap all global decls in MEM_REFs to
     170                 :            :              allow seamless replacement with prevailing decls.  Undo this
     171                 :            :              here if the prevailing decl allows for this.
     172                 :            :              ???  Maybe we should simply fold all stmts.  */
     173                 :    1986670 :           if (TREE_CODE (*opp) == MEM_REF
     174                 :     172368 :               && TREE_CODE (TREE_OPERAND (*opp, 0)) == ADDR_EXPR
     175                 :     130281 :               && integer_zerop (TREE_OPERAND (*opp, 1))
     176                 :     252534 :               && (TREE_THIS_VOLATILE (*opp)
     177                 :     126267 :                   == TREE_THIS_VOLATILE
     178                 :            :                        (TREE_OPERAND (TREE_OPERAND (*opp, 0), 0)))
     179                 :     126302 :               && !TYPE_REF_CAN_ALIAS_ALL (TREE_TYPE (TREE_OPERAND (*opp, 1)))
     180                 :     125946 :               && (TREE_TYPE (*opp)
     181                 :     125946 :                   == TREE_TYPE (TREE_TYPE (TREE_OPERAND (*opp, 1))))
     182                 :    2112220 :               && (TREE_TYPE (*opp)
     183                 :     125556 :                   == TREE_TYPE (TREE_OPERAND (TREE_OPERAND (*opp, 0), 0))))
     184                 :     124106 :             *opp = TREE_OPERAND (TREE_OPERAND (*opp, 0), 0);
     185                 :            :         }
     186                 :     965070 :       if (gcall *call_stmt = dyn_cast <gcall *> (stmt))
     187                 :            :         {
     188                 :     243850 :           if (gimple_call_internal_p (call_stmt))
     189                 :      37342 :             gimple_call_set_internal_fn
     190                 :      37342 :               (call_stmt, streamer_read_enum (ib, internal_fn, IFN_LAST));
     191                 :            :           else
     192                 :     206508 :             gimple_call_set_fntype (call_stmt, stream_read_tree (ib, data_in));
     193                 :            :         }
     194                 :            :       break;
     195                 :            : 
     196                 :            :     case GIMPLE_NOP:
     197                 :            :     case GIMPLE_PREDICT:
     198                 :            :       break;
     199                 :            : 
     200                 :          1 :     case GIMPLE_TRANSACTION:
     201                 :          1 :       gimple_transaction_set_label_norm (as_a <gtransaction *> (stmt),
     202                 :          1 :                                          stream_read_tree (ib, data_in));
     203                 :          1 :       gimple_transaction_set_label_uninst (as_a <gtransaction *> (stmt),
     204                 :          1 :                                            stream_read_tree (ib, data_in));
     205                 :          1 :       gimple_transaction_set_label_over (as_a <gtransaction *> (stmt),
     206                 :          1 :                                          stream_read_tree (ib, data_in));
     207                 :            :       break;
     208                 :            : 
     209                 :          0 :     default:
     210                 :          0 :       internal_error ("bytecode stream: unknown GIMPLE statement tag %s",
     211                 :            :                       lto_tag_name (tag));
     212                 :            :     }
     213                 :            : 
     214                 :            :   /* Update the properties of symbols, SSA names and labels associated
     215                 :            :      with STMT.  */
     216                 :     967861 :   if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
     217                 :            :     {
     218                 :     712880 :       tree lhs = gimple_get_lhs (stmt);
     219                 :     712880 :       if (lhs && TREE_CODE (lhs) == SSA_NAME)
     220                 :     464330 :         SSA_NAME_DEF_STMT (lhs) = stmt;
     221                 :            :     }
     222                 :     254981 :   else if (code == GIMPLE_ASM)
     223                 :            :     {
     224                 :       5459 :       gasm *asm_stmt = as_a <gasm *> (stmt);
     225                 :            :       unsigned i;
     226                 :            : 
     227                 :      14183 :       for (i = 0; i < gimple_asm_noutputs (asm_stmt); i++)
     228                 :            :         {
     229                 :       8724 :           tree op = TREE_VALUE (gimple_asm_output_op (asm_stmt, i));
     230                 :       8724 :           if (TREE_CODE (op) == SSA_NAME)
     231                 :       8574 :             SSA_NAME_DEF_STMT (op) = stmt;
     232                 :            :         }
     233                 :            :     }
     234                 :            : 
     235                 :            :   /* Reset alias information.  */
     236                 :     967861 :   if (code == GIMPLE_CALL)
     237                 :     243850 :     gimple_call_reset_alias_info (as_a <gcall *> (stmt));
     238                 :            : 
     239                 :            :   /* Mark the statement modified so its operand vectors can be filled in.  */
     240                 :     967861 :   gimple_set_modified (stmt, true);
     241                 :     967861 :   if (has_hist)
     242                 :          1 :     stream_in_histogram_value (ib, stmt);
     243                 :            : 
     244                 :     967861 :   return stmt;
     245                 :            : }
     246                 :            : 
     247                 :            : 
     248                 :            : /* Read a basic block with tag TAG from DATA_IN using input block IB.
     249                 :            :    FN is the function being processed.  */
     250                 :            : 
     251                 :            : void
     252                 :     503585 : input_bb (class lto_input_block *ib, enum LTO_tags tag,
     253                 :            :           class data_in *data_in, struct function *fn,
     254                 :            :           int count_materialization_scale)
     255                 :            : {
     256                 :     503585 :   unsigned int index;
     257                 :     503585 :   basic_block bb;
     258                 :     503585 :   gimple_stmt_iterator bsi;
     259                 :            : 
     260                 :            :   /* This routine assumes that CFUN is set to FN, as it needs to call
     261                 :            :      basic GIMPLE routines that use CFUN.  */
     262                 :     503585 :   gcc_assert (cfun == fn);
     263                 :            : 
     264                 :     503585 :   index = streamer_read_uhwi (ib);
     265                 :     503585 :   bb = BASIC_BLOCK_FOR_FN (fn, index);
     266                 :            : 
     267                 :     503585 :   bb->count = profile_count::stream_in (ib);
     268                 :     503585 :   if (count_materialization_scale != REG_BR_PROB_BASE
     269                 :     503585 :       && bb->count.ipa ().nonzero_p ())
     270                 :          0 :     bb->count
     271                 :          0 :       = bb->count.apply_scale (count_materialization_scale, REG_BR_PROB_BASE);
     272                 :     503585 :   bb->flags = streamer_read_hwi (ib);
     273                 :     503585 :   bb->discriminator = streamer_read_hwi (ib);
     274                 :            : 
     275                 :            :   /* LTO_bb1 has statements.  LTO_bb0 does not.  */
     276                 :     503585 :   if (tag == LTO_bb0)
     277                 :     159869 :     return;
     278                 :            : 
     279                 :     343716 :   bsi = gsi_start_bb (bb);
     280                 :     343716 :   tag = streamer_read_record_start (ib);
     281                 :    1311580 :   while (tag)
     282                 :            :     {
     283                 :     967861 :       gimple *stmt = input_gimple_stmt (ib, data_in, tag);
     284                 :     967861 :       gsi_insert_after (&bsi, stmt, GSI_NEW_STMT);
     285                 :            : 
     286                 :            :       /* After the statement, expect a 0 delimiter or the EH region
     287                 :            :          that the previous statement belongs to.  */
     288                 :     967861 :       tag = streamer_read_record_start (ib);
     289                 :     967861 :       lto_tag_check_set (tag, 2, LTO_eh_region, LTO_null);
     290                 :            : 
     291                 :     967861 :       if (tag == LTO_eh_region)
     292                 :            :         {
     293                 :       3997 :           HOST_WIDE_INT region = streamer_read_hwi (ib);
     294                 :       3997 :           gcc_assert (region == (int) region);
     295                 :       3997 :           add_stmt_to_eh_lp (stmt, region);
     296                 :            :         }
     297                 :            : 
     298                 :     967861 :       tag = streamer_read_record_start (ib);
     299                 :            :     }
     300                 :            : 
     301                 :     343716 :   tag = streamer_read_record_start (ib);
     302                 :     372479 :   while (tag)
     303                 :            :     {
     304                 :      28763 :       input_phi (ib, bb, data_in, fn);
     305                 :      28763 :       tag = streamer_read_record_start (ib);
     306                 :            :     }
     307                 :            : }

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.