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: 2024-04-20 14:03:02 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-2024 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 "config.h"
      22                 :             : #define INCLUDE_MEMORY
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "tree.h"
      26                 :             : #include "options.h"
      27                 :             : #include "cgraph.h"
      28                 :             : #include "timevar.h"
      29                 :             : #include "ipa-utils.h"
      30                 :             : #include "function.h"
      31                 :             : #include "analyzer/analyzer.h"
      32                 :             : #include "diagnostic-core.h"
      33                 :             : #include "analyzer/analyzer-logging.h"
      34                 :             : #include "analyzer/analysis-plan.h"
      35                 :             : #include "ordered-hash-map.h"
      36                 :             : #include "options.h"
      37                 :             : #include "cgraph.h"
      38                 :             : #include "cfg.h"
      39                 :             : #include "basic-block.h"
      40                 :             : #include "gimple.h"
      41                 :             : #include "gimple-iterator.h"
      42                 :             : #include "digraph.h"
      43                 :             : #include "analyzer/supergraph.h"
      44                 :             : 
      45                 :             : #if ENABLE_ANALYZER
      46                 :             : 
      47                 :             : /* class analysis_plan.  */
      48                 :             : 
      49                 :             : /* analysis_plan's ctor.  */
      50                 :             : 
      51                 :        3737 : analysis_plan::analysis_plan (const supergraph &sg, logger *logger)
      52                 :        3737 : : log_user (logger), m_sg (sg),
      53                 :        3737 :   m_cgraph_node_postorder (XCNEWVEC (struct cgraph_node *,
      54                 :             :                                      symtab->cgraph_count)),
      55                 :        7474 :   m_index_by_uid (symtab->cgraph_max_uid)
      56                 :             : {
      57                 :        3737 :   LOG_SCOPE (logger);
      58                 :        3737 :   auto_timevar time (TV_ANALYZER_PLAN);
      59                 :             : 
      60                 :        3737 :   m_num_cgraph_nodes = ipa_reverse_postorder (m_cgraph_node_postorder);
      61                 :        3737 :   gcc_assert (m_num_cgraph_nodes == symtab->cgraph_count);
      62                 :        3737 :   if (get_logger_file ())
      63                 :           2 :     ipa_print_order (get_logger_file (),
      64                 :             :                      "analysis_plan", m_cgraph_node_postorder,
      65                 :             :                      m_num_cgraph_nodes);
      66                 :             : 
      67                 :             :   /* Populate m_index_by_uid.  */
      68                 :       49567 :   for (int i = 0; i < symtab->cgraph_max_uid; i++)
      69                 :       45830 :     m_index_by_uid.quick_push (-1);
      70                 :       23541 :   for (int i = 0; i < m_num_cgraph_nodes; i++)
      71                 :             :     {
      72                 :       19804 :       gcc_assert (m_cgraph_node_postorder[i]->get_uid ()
      73                 :             :                   < symtab->cgraph_max_uid);
      74                 :       19804 :       m_index_by_uid[m_cgraph_node_postorder[i]->get_uid ()] = i;
      75                 :             :     }
      76                 :        3737 : }
      77                 :             : 
      78                 :             : /* analysis_plan's dtor.  */
      79                 :             : 
      80                 :        3737 : analysis_plan::~analysis_plan ()
      81                 :             : {
      82                 :        3737 :   free (m_cgraph_node_postorder);
      83                 :        3737 : }
      84                 :             : 
      85                 :             : /* Comparator for use by the exploded_graph's worklist, to order FUN_A
      86                 :             :    and FUN_B so that functions that are to be summarized are visited
      87                 :             :    before the summary is needed (based on a sort of the callgraph).  */
      88                 :             : 
      89                 :             : int
      90                 :      359218 : analysis_plan::cmp_function (function *fun_a, function *fun_b) const
      91                 :             : {
      92                 :      359218 :   cgraph_node *node_a = cgraph_node::get (fun_a->decl);
      93                 :      359218 :   cgraph_node *node_b = cgraph_node::get (fun_b->decl);
      94                 :             : 
      95                 :      359218 :   int idx_a = m_index_by_uid[node_a->get_uid ()];
      96                 :      359218 :   int idx_b = m_index_by_uid[node_b->get_uid ()];
      97                 :             : 
      98                 :      359218 :   return idx_b - idx_a;
      99                 :             : }
     100                 :             : 
     101                 :             : /* Return true if the call EDGE should be analyzed using a call summary.
     102                 :             :    Return false if it should be analyzed using a full call and return.  */
     103                 :             : 
     104                 :             : bool
     105                 :       27035 : analysis_plan::use_summary_p (const cgraph_edge *edge) const
     106                 :             : {
     107                 :             :   /* Don't use call summaries if -fno-analyzer-call-summaries.  */
     108                 :       27035 :   if (!flag_analyzer_call_summaries)
     109                 :             :     return false;
     110                 :             : 
     111                 :             :   /* Don't use call summaries if there is no callgraph edge */
     112                 :       20715 :   if (!edge || !edge->callee)
     113                 :             :     return false;
     114                 :             : 
     115                 :             :   /* TODO: don't count callsites each time.  */
     116                 :       19333 :   int num_call_sites = 0;
     117                 :       19333 :   const cgraph_node *callee = edge->callee;
     118                 :       71476 :   for (cgraph_edge *edge = callee->callers; edge; edge = edge->next_caller)
     119                 :       52143 :     ++num_call_sites;
     120                 :             : 
     121                 :             :   /* Don't use a call summary if there's only one call site.  */
     122                 :       19333 :   if (num_call_sites <= 1)
     123                 :             :     return false;
     124                 :             : 
     125                 :             :   /* Require the callee to be sufficiently complex to be worth
     126                 :             :      summarizing.  */
     127                 :        9708 :   const function *fun
     128                 :        9708 :     = const_cast <cgraph_node *> (callee)->ultimate_alias_target ()->get_fun ();
     129                 :             :   /* TODO(stage1): can ultimate_alias_target be made const?  */
     130                 :             : 
     131                 :        9708 :   if ((int)m_sg.get_num_snodes (fun)
     132                 :        9708 :       < param_analyzer_min_snodes_for_call_summary)
     133                 :             :     return false;
     134                 :             : 
     135                 :             :   return true;
     136                 :             : }
     137                 :             : 
     138                 :             : #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.