LCOV - code coverage report
Current view: top level - gcc/analyzer - analysis-plan.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 37 37
Test Date: 2025-06-21 16:26:05 Functions: 100.0 % 4 4
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* A class to encapsulate decisions about how the analysis should happen.
       2                 :             :    Copyright (C) 2019-2025 Free Software Foundation, Inc.
       3                 :             :    Contributed by David Malcolm <dmalcolm@redhat.com>.
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it
       8                 :             : under the terms of the GNU General Public License as published by
       9                 :             : the Free Software Foundation; either version 3, or (at your option)
      10                 :             : any later version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but
      13                 :             : WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15                 :             : General Public License 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                 :             : #include "analyzer/common.h"
      22                 :             : 
      23                 :             : #include "timevar.h"
      24                 :             : #include "ordered-hash-map.h"
      25                 :             : #include "options.h"
      26                 :             : #include "cgraph.h"
      27                 :             : #include "cfg.h"
      28                 :             : #include "gimple-iterator.h"
      29                 :             : #include "digraph.h"
      30                 :             : #include "ipa-utils.h"
      31                 :             : 
      32                 :             : #include "analyzer/analyzer-logging.h"
      33                 :             : #include "analyzer/analysis-plan.h"
      34                 :             : #include "analyzer/supergraph.h"
      35                 :             : 
      36                 :             : #if ENABLE_ANALYZER
      37                 :             : 
      38                 :             : /* class analysis_plan.  */
      39                 :             : 
      40                 :             : /* analysis_plan's ctor.  */
      41                 :             : 
      42                 :        3313 : analysis_plan::analysis_plan (const supergraph &sg, logger *logger)
      43                 :        3313 : : log_user (logger), m_sg (sg),
      44                 :        3313 :   m_cgraph_node_postorder (XCNEWVEC (struct cgraph_node *,
      45                 :             :                                      symtab->cgraph_count)),
      46                 :        6626 :   m_index_by_uid (symtab->cgraph_max_uid)
      47                 :             : {
      48                 :        3313 :   LOG_SCOPE (logger);
      49                 :        3313 :   auto_timevar time (TV_ANALYZER_PLAN);
      50                 :             : 
      51                 :        3313 :   m_num_cgraph_nodes = ipa_reverse_postorder (m_cgraph_node_postorder);
      52                 :        3313 :   gcc_assert (m_num_cgraph_nodes == symtab->cgraph_count);
      53                 :        3313 :   if (get_logger_file ())
      54                 :           2 :     ipa_print_order (get_logger_file (),
      55                 :             :                      "analysis_plan", m_cgraph_node_postorder,
      56                 :             :                      m_num_cgraph_nodes);
      57                 :             : 
      58                 :             :   /* Populate m_index_by_uid.  */
      59                 :       62010 :   for (int i = 0; i < symtab->cgraph_max_uid; i++)
      60                 :       58697 :     m_index_by_uid.quick_push (-1);
      61                 :       21004 :   for (int i = 0; i < m_num_cgraph_nodes; i++)
      62                 :             :     {
      63                 :       17691 :       gcc_assert (m_cgraph_node_postorder[i]->get_uid ()
      64                 :             :                   < symtab->cgraph_max_uid);
      65                 :       17691 :       m_index_by_uid[m_cgraph_node_postorder[i]->get_uid ()] = i;
      66                 :             :     }
      67                 :        3313 : }
      68                 :             : 
      69                 :             : /* analysis_plan's dtor.  */
      70                 :             : 
      71                 :        3313 : analysis_plan::~analysis_plan ()
      72                 :             : {
      73                 :        3313 :   free (m_cgraph_node_postorder);
      74                 :        3313 : }
      75                 :             : 
      76                 :             : /* Comparator for use by the exploded_graph's worklist, to order FUN_A
      77                 :             :    and FUN_B so that functions that are to be summarized are visited
      78                 :             :    before the summary is needed (based on a sort of the callgraph).  */
      79                 :             : 
      80                 :             : int
      81                 :      338648 : analysis_plan::cmp_function (function *fun_a, function *fun_b) const
      82                 :             : {
      83                 :      338648 :   cgraph_node *node_a = cgraph_node::get (fun_a->decl);
      84                 :      338648 :   cgraph_node *node_b = cgraph_node::get (fun_b->decl);
      85                 :             : 
      86                 :      338648 :   int idx_a = m_index_by_uid[node_a->get_uid ()];
      87                 :      338648 :   int idx_b = m_index_by_uid[node_b->get_uid ()];
      88                 :             : 
      89                 :      338648 :   return idx_b - idx_a;
      90                 :             : }
      91                 :             : 
      92                 :             : /* Return true if the call EDGE should be analyzed using a call summary.
      93                 :             :    Return false if it should be analyzed using a full call and return.  */
      94                 :             : 
      95                 :             : bool
      96                 :       24403 : analysis_plan::use_summary_p (const cgraph_edge *edge) const
      97                 :             : {
      98                 :             :   /* Don't use call summaries if -fno-analyzer-call-summaries.  */
      99                 :       24403 :   if (!flag_analyzer_call_summaries)
     100                 :             :     return false;
     101                 :             : 
     102                 :             :   /* Don't use call summaries if there is no callgraph edge */
     103                 :       19364 :   if (!edge || !edge->callee)
     104                 :             :     return false;
     105                 :             : 
     106                 :             :   /* TODO: don't count callsites each time.  */
     107                 :       18149 :   int num_call_sites = 0;
     108                 :       18149 :   const cgraph_node *callee = edge->callee;
     109                 :       65268 :   for (cgraph_edge *edge = callee->callers; edge; edge = edge->next_caller)
     110                 :       47119 :     ++num_call_sites;
     111                 :             : 
     112                 :             :   /* Don't use a call summary if there's only one call site.  */
     113                 :       18149 :   if (num_call_sites <= 1)
     114                 :             :     return false;
     115                 :             : 
     116                 :             :   /* Require the callee to be sufficiently complex to be worth
     117                 :             :      summarizing.  */
     118                 :        8365 :   const function *fun
     119                 :        8365 :     = const_cast <cgraph_node *> (callee)->ultimate_alias_target ()->get_fun ();
     120                 :             :   /* TODO(stage1): can ultimate_alias_target be made const?  */
     121                 :             : 
     122                 :        8365 :   if ((int)m_sg.get_num_snodes (fun)
     123                 :        8365 :       < param_analyzer_min_snodes_for_call_summary)
     124                 :             :     return false;
     125                 :             : 
     126                 :             :   return true;
     127                 :             : }
     128                 :             : 
     129                 :             : #endif /* #if ENABLE_ANALYZER */
        

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.