LCOV - code coverage report
Current view: top level - gcc - gimple-range.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 65.4 % 601 393
Test Date: 2024-04-20 14:03:02 Functions: 67.5 % 40 27
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Code for GIMPLE range related routines.
       2                 :             :    Copyright (C) 2019-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Andrew MacLeod <amacleod@redhat.com>
       4                 :             :    and Aldy Hernandez <aldyh@redhat.com>.
       5                 :             : 
       6                 :             : This file is part of GCC.
       7                 :             : 
       8                 :             : GCC is free software; you can redistribute it and/or modify
       9                 :             : it under the terms of the GNU General Public License as published by
      10                 :             : the Free Software Foundation; either version 3, or (at your option)
      11                 :             : any later version.
      12                 :             : 
      13                 :             : GCC is distributed in the hope that it will be useful,
      14                 :             : but WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16                 :             : GNU General Public License 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-pretty-print.h"
      30                 :             : #include "gimple-iterator.h"
      31                 :             : #include "tree-cfg.h"
      32                 :             : #include "fold-const.h"
      33                 :             : #include "tree-cfg.h"
      34                 :             : #include "cfgloop.h"
      35                 :             : #include "tree-scalar-evolution.h"
      36                 :             : #include "gimple-range.h"
      37                 :             : #include "gimple-fold.h"
      38                 :             : #include "gimple-walk.h"
      39                 :             : 
      40                 :    24313375 : gimple_ranger::gimple_ranger (bool use_imm_uses) :
      41                 :    48626750 :         non_executable_edge_flag (cfun),
      42                 :    24313375 :         m_cache (non_executable_edge_flag, use_imm_uses),
      43                 :    24313375 :         tracer (""),
      44                 :    24313375 :         current_bb (NULL)
      45                 :             : {
      46                 :             :   // If the cache has a relation oracle, use it.
      47                 :    24313375 :   m_oracle = m_cache.oracle ();
      48                 :    24313375 :   if (dump_file && (param_ranger_debug & RANGER_DEBUG_TRACE))
      49                 :           0 :     tracer.enable_trace ();
      50                 :    24313375 :   m_stmt_list.create (0);
      51                 :    48626750 :   m_stmt_list.safe_grow (num_ssa_names);
      52                 :    24313375 :   m_stmt_list.truncate (0);
      53                 :             : 
      54                 :             :   // Ensure the not_executable flag is clear everywhere.
      55                 :    24313375 :   if (flag_checking)
      56                 :             :     {
      57                 :    24312937 :       basic_block bb;
      58                 :   278237347 :       FOR_ALL_BB_FN (bb, cfun)
      59                 :             :         {
      60                 :   253924410 :           edge_iterator ei;
      61                 :   253924410 :           edge e;
      62                 :   564711962 :           FOR_EACH_EDGE (e, ei, bb->succs)
      63                 :   310787552 :             gcc_checking_assert ((e->flags & non_executable_edge_flag) == 0);
      64                 :             :         }
      65                 :             :     }
      66                 :    24313375 : }
      67                 :             : 
      68                 :    47577449 : gimple_ranger::~gimple_ranger ()
      69                 :             : {
      70                 :    24313375 :   m_stmt_list.release ();
      71                 :    47577449 : }
      72                 :             : 
      73                 :             : // Return a range_query which accesses just the known global values.
      74                 :             : 
      75                 :             : range_query &
      76                 :     3956227 : gimple_ranger::const_query ()
      77                 :             : {
      78                 :     3956227 :   return m_cache.const_query ();
      79                 :             : }
      80                 :             : 
      81                 :             : bool
      82                 :   499411317 : gimple_ranger::range_of_expr (vrange &r, tree expr, gimple *stmt)
      83                 :             : {
      84                 :   499411317 :   unsigned idx;
      85                 :   499411317 :   if (!gimple_range_ssa_p (expr))
      86                 :    69333493 :     return get_tree_range (r, expr, stmt);
      87                 :             : 
      88                 :   430077824 :   if ((idx = tracer.header ("range_of_expr(")))
      89                 :             :     {
      90                 :           0 :       print_generic_expr (dump_file, expr, TDF_SLIM);
      91                 :           0 :       fputs (")", dump_file);
      92                 :           0 :       if (stmt)
      93                 :             :         {
      94                 :           0 :           fputs (" at stmt ", dump_file);
      95                 :           0 :           print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
      96                 :             :         }
      97                 :             :       else
      98                 :           0 :         fputs ("\n", dump_file);
      99                 :             :     }
     100                 :             : 
     101                 :             :   // If there is no statement, just get the global value.
     102                 :   430077824 :   if (!stmt)
     103                 :             :     {
     104                 :    43543106 :       Value_Range tmp (TREE_TYPE (expr));
     105                 :    43543106 :       m_cache.get_global_range (r, expr);
     106                 :             :       // Pick up implied context information from the on-entry cache
     107                 :             :       // if current_bb is set.  Do not attempt any new calculations.
     108                 :    43543106 :       if (current_bb && m_cache.block_range (tmp, current_bb, expr, false))
     109                 :             :         {
     110                 :      928115 :           r.intersect (tmp);
     111                 :      928115 :           char str[80];
     112                 :      928115 :           sprintf (str, "picked up range from bb %d\n",current_bb->index);
     113                 :      928115 :           if (idx)
     114                 :           0 :             tracer.print (idx, str);
     115                 :             :         }
     116                 :    43543106 :     }
     117                 :             :   // For a debug stmt, pick the best value currently available, do not
     118                 :             :   // trigger new value calculations.  PR 100781.
     119                 :   386534718 :   else if (is_gimple_debug (stmt))
     120                 :    33349778 :     m_cache.range_of_expr (r, expr, stmt);
     121                 :             :   else
     122                 :             :     {
     123                 :   353184940 :       basic_block bb = gimple_bb (stmt);
     124                 :   353184940 :       gimple *def_stmt = SSA_NAME_DEF_STMT (expr);
     125                 :             : 
     126                 :             :       // If name is defined in this block, try to get an range from S.
     127                 :   353184940 :       if (def_stmt && gimple_bb (def_stmt) == bb)
     128                 :             :         {
     129                 :             :           // Declared in this block, if it has a global set, check for an
     130                 :             :           // override from a block walk, otherwise calculate it.
     131                 :   219823163 :           if (m_cache.get_global_range (r, expr))
     132                 :   189706693 :             m_cache.block_range (r, bb, expr, false);
     133                 :             :           else
     134                 :    30116470 :             range_of_stmt (r, def_stmt, expr);
     135                 :             :         }
     136                 :             :       // Otherwise OP comes from outside this block, use range on entry.
     137                 :             :       else
     138                 :   133361777 :         range_on_entry (r, bb, expr);
     139                 :             :     }
     140                 :   430077824 :   if (idx)
     141                 :           0 :     tracer.trailer (idx, "range_of_expr", true, expr, r);
     142                 :             :   return true;
     143                 :             : }
     144                 :             : 
     145                 :             : // Return the range of NAME on entry to block BB in R.
     146                 :             : 
     147                 :             : void
     148                 :   159895086 : gimple_ranger::range_on_entry (vrange &r, basic_block bb, tree name)
     149                 :             : {
     150                 :   159895086 :   Value_Range entry_range (TREE_TYPE (name));
     151                 :   159895086 :   gcc_checking_assert (gimple_range_ssa_p (name));
     152                 :             : 
     153                 :   159895086 :   unsigned idx;
     154                 :   159895086 :   if ((idx = tracer.header ("range_on_entry (")))
     155                 :             :     {
     156                 :           0 :       print_generic_expr (dump_file, name, TDF_SLIM);
     157                 :           0 :       fprintf (dump_file, ") to BB %d\n", bb->index);
     158                 :             :     }
     159                 :             : 
     160                 :             :   // Start with any known range
     161                 :   159895086 :   range_of_stmt (r, SSA_NAME_DEF_STMT (name), name);
     162                 :             : 
     163                 :             :   // Now see if there is any on_entry value which may refine it.
     164                 :   159895086 :   if (m_cache.block_range (entry_range, bb, name))
     165                 :   101078454 :     r.intersect (entry_range);
     166                 :             : 
     167                 :   159895086 :   if (idx)
     168                 :           0 :     tracer.trailer (idx, "range_on_entry", true, name, r);
     169                 :   159895086 : }
     170                 :             : 
     171                 :             : // Calculate the range for NAME at the end of block BB and return it in R.
     172                 :             : // Return false if no range can be calculated.
     173                 :             : 
     174                 :             : void
     175                 :    48738334 : gimple_ranger::range_on_exit (vrange &r, basic_block bb, tree name)
     176                 :             : {
     177                 :             :   // on-exit from the exit block?
     178                 :    48738334 :   gcc_checking_assert (gimple_range_ssa_p (name));
     179                 :             : 
     180                 :    48738334 :   unsigned idx;
     181                 :    48738334 :   if ((idx = tracer.header ("range_on_exit (")))
     182                 :             :     {
     183                 :           0 :       print_generic_expr (dump_file, name, TDF_SLIM);
     184                 :           0 :       fprintf (dump_file, ") from BB %d\n", bb->index);
     185                 :             :     }
     186                 :             : 
     187                 :    48738334 :   gimple *s = SSA_NAME_DEF_STMT (name);
     188                 :    48738334 :   basic_block def_bb = gimple_bb (s);
     189                 :             :   // If this is not the definition block, get the range on the last stmt in
     190                 :             :   // the block... if there is one.
     191                 :    48738334 :   if (def_bb != bb)
     192                 :    21553295 :     s = last_nondebug_stmt (bb);
     193                 :             :   // If there is no statement provided, get the range_on_entry for this block.
     194                 :    21553295 :   if (s)
     195                 :    39498346 :     range_of_expr (r, name, s);
     196                 :             :   else
     197                 :     9239988 :     range_on_entry (r, bb, name);
     198                 :    48738334 :   gcc_checking_assert (r.undefined_p ()
     199                 :             :                        || range_compatible_p (r.type (), TREE_TYPE (name)));
     200                 :             :   
     201                 :    48738334 :   if (idx)
     202                 :           0 :     tracer.trailer (idx, "range_on_exit", true, name, r);
     203                 :    48738334 : }
     204                 :             : 
     205                 :             : // Calculate a range for NAME on edge E and return it in R.
     206                 :             : 
     207                 :             : bool
     208                 :    58373510 : gimple_ranger::range_on_edge (vrange &r, edge e, tree name)
     209                 :             : {
     210                 :    58373510 :   Value_Range edge_range (TREE_TYPE (name));
     211                 :             : 
     212                 :    58373510 :   if (!r.supports_type_p (TREE_TYPE (name)))
     213                 :             :     return false;
     214                 :             : 
     215                 :             :   // Do not process values along abnormal edges.
     216                 :    58373510 :   if (e->flags & EDGE_ABNORMAL)
     217                 :           2 :     return get_tree_range (r, name, NULL);
     218                 :             : 
     219                 :    58373508 :   unsigned idx;
     220                 :    58373508 :   if ((idx = tracer.header ("range_on_edge (")))
     221                 :             :     {
     222                 :           0 :       print_generic_expr (dump_file, name, TDF_SLIM);
     223                 :           0 :       fprintf (dump_file, ") on edge %d->%d\n", e->src->index, e->dest->index);
     224                 :             :     }
     225                 :             : 
     226                 :             :   // Check to see if the edge is executable.
     227                 :    58373508 :   if ((e->flags & non_executable_edge_flag))
     228                 :             :     {
     229                 :      214854 :       r.set_undefined ();
     230                 :      214854 :       if (idx)
     231                 :           0 :         tracer.trailer (idx, "range_on_edge [Unexecutable] ", true,
     232                 :             :                         name, r);
     233                 :      214854 :       return true;
     234                 :             :     }
     235                 :             : 
     236                 :    58158654 :   bool res = true;
     237                 :    58158654 :   if (!gimple_range_ssa_p (name))
     238                 :     9420320 :     res = get_tree_range (r, name, NULL);
     239                 :             :   else
     240                 :             :     {
     241                 :    48738334 :       range_on_exit (r, e->src, name);
     242                 :             :       // If this is not an abnormal edge, check for a non-null exit .
     243                 :    48738334 :       if ((e->flags & (EDGE_EH | EDGE_ABNORMAL)) == 0)
     244                 :    48361531 :         m_cache.m_exit.maybe_adjust_range (r, name, e->src);
     245                 :    48738334 :       gcc_checking_assert  (r.undefined_p ()
     246                 :             :                             || range_compatible_p (r.type(), TREE_TYPE (name)));
     247                 :             : 
     248                 :             :       // Check to see if NAME is defined on edge e.
     249                 :    48738334 :       if (m_cache.range_on_edge (edge_range, e, name))
     250                 :    48738334 :         r.intersect (edge_range);
     251                 :             :     }
     252                 :             : 
     253                 :    58158654 :   if (idx)
     254                 :           0 :     tracer.trailer (idx, "range_on_edge", res, name, r);
     255                 :             :   return res;
     256                 :    58373510 : }
     257                 :             : 
     258                 :             : // fold_range wrapper for range_of_stmt to use as an internal client.
     259                 :             : 
     260                 :             : bool
     261                 :   129503645 : gimple_ranger::fold_range_internal (vrange &r, gimple *s, tree name)
     262                 :             : {
     263                 :   129503645 :   fold_using_range f;
     264                 :   129503645 :   fur_depend src (s, &(gori ()), this);
     265                 :   129503645 :   return f.fold_stmt (r, s, src, name);
     266                 :             : }
     267                 :             : 
     268                 :             : // Calculate a range for statement S and return it in R.  If NAME is
     269                 :             : // provided it represents the SSA_NAME on the LHS of the statement.
     270                 :             : // It is only required if there is more than one lhs/output.  Check
     271                 :             : // the global cache for NAME first to see if the evaluation can be
     272                 :             : // avoided.  If a range cannot be calculated, return false and UNDEFINED.
     273                 :             : 
     274                 :             : bool
     275                 :   330946687 : gimple_ranger::range_of_stmt (vrange &r, gimple *s, tree name)
     276                 :             : {
     277                 :   330946687 :   bool res;
     278                 :   330946687 :   r.set_undefined ();
     279                 :             : 
     280                 :   330946687 :   unsigned idx;
     281                 :   330946687 :   if ((idx = tracer.header ("range_of_stmt (")))
     282                 :             :     {
     283                 :           0 :       if (name)
     284                 :           0 :         print_generic_expr (dump_file, name, TDF_SLIM);
     285                 :           0 :       fputs (") at stmt ", dump_file);
     286                 :           0 :       print_gimple_stmt (dump_file, s, 0, TDF_SLIM);
     287                 :             :     }
     288                 :             : 
     289                 :   330946687 :   if (!name)
     290                 :    18395061 :     name = gimple_get_lhs (s);
     291                 :             : 
     292                 :             :   // If no name, simply call the base routine.
     293                 :    18395061 :   if (!name)
     294                 :             :     {
     295                 :    18395061 :       res = fold_range_internal (r, s, NULL_TREE);
     296                 :    18395061 :       if (res && is_a <gcond *> (s))
     297                 :             :         {
     298                 :             :           // Update any exports in the cache if this is a gimple cond statement.
     299                 :    18349778 :           tree exp;
     300                 :    18349778 :           basic_block bb = gimple_bb (s);
     301                 :    54375536 :           FOR_EACH_GORI_EXPORT_NAME (m_cache.m_gori, bb, exp)
     302                 :    36025758 :             m_cache.propagate_updated_value (exp, bb);
     303                 :             :         }
     304                 :             :     }
     305                 :   312551626 :   else if (!gimple_range_ssa_p (name))
     306                 :    31644861 :     res = get_tree_range (r, name, NULL);
     307                 :             :   else
     308                 :             :     {
     309                 :   280906765 :       bool current;
     310                 :             :       // Check if the stmt has already been processed.
     311                 :   280906765 :       if (m_cache.get_global_range (r, name, current))
     312                 :             :         {
     313                 :             :           // If it isn't stale, use this cached value.
     314                 :   190739893 :           if (current)
     315                 :             :             {
     316                 :   183328412 :               if (idx)
     317                 :           0 :                 tracer.trailer (idx, " cached", true, name, r);
     318                 :   183328412 :               return true;
     319                 :             :             }
     320                 :             :         }
     321                 :             :       else
     322                 :    90166872 :         prefill_stmt_dependencies (name);
     323                 :             : 
     324                 :             :       // Calculate a new value.
     325                 :    97578353 :       Value_Range tmp (TREE_TYPE (name));
     326                 :    97578353 :       fold_range_internal (tmp, s, name);
     327                 :             : 
     328                 :             :       // Combine the new value with the old value.  This is required because
     329                 :             :       // the way value propagation works, when the IL changes on the fly we
     330                 :             :       // can sometimes get different results.  See PR 97741.
     331                 :    97578353 :       bool changed = r.intersect (tmp);
     332                 :    97578353 :       m_cache.set_global_range (name, r, changed);
     333                 :    97578353 :       res = true;
     334                 :    97578353 :     }
     335                 :             : 
     336                 :   147618275 :   if (idx)
     337                 :           0 :     tracer.trailer (idx, "range_of_stmt", res, name, r);
     338                 :             :   return res;
     339                 :             : }
     340                 :             : 
     341                 :             : 
     342                 :             : // Check if NAME is a dependency that needs resolving, and push it on the
     343                 :             : // stack if so.  R is a scratch range.
     344                 :             : 
     345                 :             : inline void
     346                 :   103144394 : gimple_ranger::prefill_name (vrange &r, tree name)
     347                 :             : {
     348                 :   103144394 :   if (!gimple_range_ssa_p (name))
     349                 :             :     return;
     350                 :    76094917 :   gimple *stmt = SSA_NAME_DEF_STMT (name);
     351                 :    76094917 :   if (!gimple_range_op_handler::supported_p (stmt) && !is_a<gphi *> (stmt))
     352                 :             :     return;
     353                 :             : 
     354                 :             :   // If this op has not been processed yet, then push it on the stack
     355                 :    51961555 :   if (!m_cache.get_global_range (r, name))
     356                 :             :     {
     357                 :    13530231 :       bool current;
     358                 :             :       // Set the global cache value and mark as alway_current.
     359                 :    13530231 :       m_cache.get_global_range (r, name, current);
     360                 :    13530231 :       m_stmt_list.safe_push (name);
     361                 :             :     }
     362                 :             : }
     363                 :             : 
     364                 :             : // This routine will seed the global cache with most of the dependencies of
     365                 :             : // NAME.  This prevents excessive call depth through the normal API.
     366                 :             : 
     367                 :             : void
     368                 :    90166872 : gimple_ranger::prefill_stmt_dependencies (tree ssa)
     369                 :             : {
     370                 :    90166872 :   if (SSA_NAME_IS_DEFAULT_DEF (ssa))
     371                 :             :     return;
     372                 :             : 
     373                 :    80906857 :   unsigned idx;
     374                 :    80906857 :   gimple *stmt = SSA_NAME_DEF_STMT (ssa);
     375                 :    80906857 :   gcc_checking_assert (stmt && gimple_bb (stmt));
     376                 :             : 
     377                 :             :   // Only pre-process range-ops and phis.
     378                 :    80906857 :   if (!gimple_range_op_handler::supported_p (stmt) && !is_a<gphi *> (stmt))
     379                 :             :     return;
     380                 :             : 
     381                 :             :   // Mark where on the stack we are starting.
     382                 :    43932851 :   unsigned start = m_stmt_list.length ();
     383                 :    43932851 :   m_stmt_list.safe_push (ssa);
     384                 :             : 
     385                 :    43932851 :   idx = tracer.header ("ROS dependence fill\n");
     386                 :             : 
     387                 :             :   // Loop until back at the start point.
     388                 :   317718030 :   while (m_stmt_list.length () > start)
     389                 :             :     {
     390                 :   114926164 :       tree name = m_stmt_list.last ();
     391                 :             :       // NULL is a marker which indicates the next name in the stack has now
     392                 :             :       // been fully resolved, so we can fold it.
     393                 :   114926164 :       if (!name)
     394                 :             :         {
     395                 :             :           // Pop the NULL, then pop the name.
     396                 :    57463082 :           m_stmt_list.pop ();
     397                 :    57463082 :           name = m_stmt_list.pop ();
     398                 :             :           // Don't fold initial request, it will be calculated upon return.
     399                 :    57463082 :           if (m_stmt_list.length () > start)
     400                 :             :             {
     401                 :             :               // Fold and save the value for NAME.
     402                 :    13530231 :               stmt = SSA_NAME_DEF_STMT (name);
     403                 :    13530231 :               Value_Range r (TREE_TYPE (name));
     404                 :    13530231 :               fold_range_internal (r, stmt, name);
     405                 :             :               // Make sure we don't lose any current global info.
     406                 :    13530231 :               Value_Range tmp (TREE_TYPE (name));
     407                 :    13530231 :               m_cache.get_global_range (tmp, name);
     408                 :    13530231 :               bool changed = tmp.intersect (r);
     409                 :    13530231 :               m_cache.set_global_range (name, tmp, changed);
     410                 :    13530231 :             }
     411                 :    57463082 :           continue;
     412                 :    57463082 :         }
     413                 :             : 
     414                 :             :       // Add marker indicating previous NAME in list should be folded
     415                 :             :       // when we get to this NULL.
     416                 :    57463082 :       m_stmt_list.safe_push (NULL_TREE);
     417                 :    57463082 :       stmt = SSA_NAME_DEF_STMT (name);
     418                 :             : 
     419                 :    57463082 :       if (idx)
     420                 :             :         {
     421                 :           0 :           tracer.print (idx, "ROS dep fill (");
     422                 :           0 :           print_generic_expr (dump_file, name, TDF_SLIM);
     423                 :           0 :           fputs (") at stmt ", dump_file);
     424                 :           0 :           print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
     425                 :             :         }
     426                 :             : 
     427                 :    57463082 :       gphi *phi = dyn_cast <gphi *> (stmt);
     428                 :    57463082 :       if (phi)
     429                 :             :         {
     430                 :    13964972 :           Value_Range r (TREE_TYPE (gimple_phi_result (phi)));
     431                 :    45579176 :           for (unsigned x = 0; x < gimple_phi_num_args (phi); x++)
     432                 :    31614204 :             prefill_name (r, gimple_phi_arg_def (phi, x));
     433                 :    13964972 :         }
     434                 :             :       else
     435                 :             :         {
     436                 :    43498110 :           gimple_range_op_handler handler (stmt);
     437                 :    43498110 :           if (handler)
     438                 :             :             {
     439                 :    43406408 :               tree op = handler.operand2 ();
     440                 :    43406408 :               if (op)
     441                 :             :                 {
     442                 :    28124640 :                   Value_Range r (TREE_TYPE (op));
     443                 :    28124640 :                   prefill_name (r, op);
     444                 :    28124640 :                 }
     445                 :    43406408 :               op = handler.operand1 ();
     446                 :    43406408 :               if (op)
     447                 :             :                 {
     448                 :    43405550 :                   Value_Range r (TREE_TYPE (op));
     449                 :    43405550 :                   prefill_name (r, op);
     450                 :    43405550 :                 }
     451                 :             :             }
     452                 :             :         }
     453                 :             :     }
     454                 :    43932851 :   if (idx)
     455                 :             :     {
     456                 :           0 :       unsupported_range r;
     457                 :           0 :       tracer.trailer (idx, "ROS ", false, ssa, r);
     458                 :             :     }
     459                 :             : }
     460                 :             : 
     461                 :             : 
     462                 :             : // This routine will invoke the gimple fold_stmt routine, providing context to
     463                 :             : // range_of_expr calls via an private internal API.
     464                 :             : 
     465                 :             : bool
     466                 :   200162422 : gimple_ranger::fold_stmt (gimple_stmt_iterator *gsi, tree (*valueize) (tree))
     467                 :             : {
     468                 :   200162422 :   gimple *stmt = gsi_stmt (*gsi);
     469                 :   200162422 :   current_bb = gimple_bb (stmt);
     470                 :   200162422 :   bool ret = ::fold_stmt (gsi, valueize);
     471                 :   200162422 :   current_bb = NULL;
     472                 :   200162422 :   return ret;
     473                 :             : }
     474                 :             : 
     475                 :             : // Called during dominator walks to register any inferred ranges that take
     476                 :             : // effect from this point forward.  
     477                 :             : 
     478                 :             : void
     479                 :   214182174 : gimple_ranger::register_inferred_ranges (gimple *s)
     480                 :             : {
     481                 :             :   // First, export the LHS if it is a new global range.
     482                 :   214182174 :   tree lhs = gimple_get_lhs (s);
     483                 :   214182174 :   if (lhs)
     484                 :             :     {
     485                 :    80486367 :       Value_Range tmp (TREE_TYPE (lhs));
     486                 :   144401565 :       if (range_of_stmt (tmp, s, lhs) && !tmp.varying_p ()
     487                 :    96129103 :           && set_range_info (lhs, tmp) && dump_file)
     488                 :             :         {
     489                 :         769 :           fprintf (dump_file, "Global Exported: ");
     490                 :         769 :           print_generic_expr (dump_file, lhs, TDF_SLIM);
     491                 :         769 :           fprintf (dump_file, " = ");
     492                 :         769 :           tmp.dump (dump_file);
     493                 :         769 :           fputc ('\n', dump_file);
     494                 :             :         }
     495                 :    80486367 :     }
     496                 :   214182174 :   m_cache.apply_inferred_ranges (s);
     497                 :   214182174 : }
     498                 :             : 
     499                 :             : // This function will walk the statements in BB to determine if any
     500                 :             : // discovered inferred ranges in the block have any transitive effects,
     501                 :             : // and if so, register those effects in BB.
     502                 :             : 
     503                 :             : void
     504                 :    27753227 : gimple_ranger::register_transitive_inferred_ranges (basic_block bb)
     505                 :             : {
     506                 :             :   // Return if there are no inferred ranges in BB.
     507                 :    27753227 :   infer_range_manager &infer = m_cache.m_exit;
     508                 :    27753227 :   if (!infer.has_range_p (bb))
     509                 :             :     return;
     510                 :             : 
     511                 :     5802615 :   if (dump_file && (dump_flags & TDF_DETAILS))
     512                 :          34 :     fprintf (dump_file, "Checking for transitive inferred ranges in BB %d\n",
     513                 :             :              bb->index);
     514                 :             : 
     515                 :    92672419 :   for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si);
     516                 :    81067189 :        gsi_next (&si))
     517                 :             :     {
     518                 :    81067189 :       gimple *s = gsi_stmt (si);
     519                 :    81067189 :       tree lhs = gimple_get_lhs (s);
     520                 :             :       // If the LHS already has an inferred effect, leave it be.
     521                 :    81067189 :       if (!gimple_range_ssa_p (lhs) || infer.has_range_p (lhs, bb))
     522                 :    64005990 :         continue;
     523                 :             :       // Pick up global value.
     524                 :    17061199 :       Value_Range g (TREE_TYPE (lhs));
     525                 :    17061199 :       range_of_expr (g, lhs);
     526                 :             : 
     527                 :             :       // If either dependency has an inferred range, check if recalculating
     528                 :             :       // the LHS is different than the global value. If so, register it as
     529                 :             :       // an inferred range as well.
     530                 :    17061199 :       Value_Range r (TREE_TYPE (lhs));
     531                 :    17061199 :       r.set_undefined ();
     532                 :    17061199 :       tree name1 = gori ().depend1 (lhs);
     533                 :    17061199 :       tree name2 = gori ().depend2 (lhs);
     534                 :     7796039 :       if ((name1 && infer.has_range_p (name1, bb))
     535                 :    24165853 :           || (name2 && infer.has_range_p (name2, bb)))
     536                 :             :         {
     537                 :             :           // Check if folding S produces a different result.
     538                 :     1387588 :           if (fold_range (r, s, this) && g != r)
     539                 :             :             {
     540                 :       22143 :               infer.add_range (lhs, bb, r);
     541                 :       22143 :               m_cache.register_inferred_value (r, lhs, bb);
     542                 :             :             }
     543                 :             :         }
     544                 :    17061199 :     }
     545                 :             : }
     546                 :             : 
     547                 :             : // This routine will export whatever global ranges are known to GCC
     548                 :             : // SSA_RANGE_NAME_INFO and SSA_NAME_PTR_INFO fields.
     549                 :             : 
     550                 :             : void
     551                 :     1971160 : gimple_ranger::export_global_ranges ()
     552                 :             : {
     553                 :             :   /* Cleared after the table header has been printed.  */
     554                 :     1971160 :   bool print_header = true;
     555                 :   191008078 :   for (unsigned x = 1; x < num_ssa_names; x++)
     556                 :             :     {
     557                 :    93532879 :       tree name = ssa_name (x);
     558                 :    93532879 :       if (!name)
     559                 :    33957949 :         continue;
     560                 :    69764458 :       Value_Range r (TREE_TYPE (name));
     561                 :    69764458 :       if (name && !SSA_NAME_IN_FREE_LIST (name)
     562                 :    69764458 :           && gimple_range_ssa_p (name)
     563                 :    39468829 :           && m_cache.get_global_range (r, name)
     564                 :    35740141 :           && !r.varying_p())
     565                 :             :         {
     566                 :    10189737 :           bool updated = set_range_info (name, r);
     567                 :    10189737 :           if (!updated || !dump_file)
     568                 :    10189528 :             continue;
     569                 :             : 
     570                 :         209 :           if (print_header)
     571                 :             :             {
     572                 :             :               /* Print the header only when there's something else
     573                 :             :                  to print below.  */
     574                 :          69 :               fprintf (dump_file, "Exported global range table:\n");
     575                 :          69 :               fprintf (dump_file, "============================\n");
     576                 :          69 :               print_header = false;
     577                 :             :             }
     578                 :             : 
     579                 :         209 :           print_generic_expr (dump_file, name , TDF_SLIM);
     580                 :         209 :           fprintf (dump_file, "  : ");
     581                 :         209 :           r.dump (dump_file);
     582                 :         209 :           fprintf (dump_file, "\n");
     583                 :             :         }
     584                 :    69764458 :     }
     585                 :     1971160 : }
     586                 :             : 
     587                 :             : // Print the known table values to file F.
     588                 :             : 
     589                 :             : void
     590                 :         259 : gimple_ranger::dump_bb (FILE *f, basic_block bb)
     591                 :             : {
     592                 :         259 :   unsigned x;
     593                 :         259 :   edge_iterator ei;
     594                 :         259 :   edge e;
     595                 :         259 :   fprintf (f, "\n=========== BB %d ============\n", bb->index);
     596                 :         259 :   m_cache.dump_bb (f, bb);
     597                 :             : 
     598                 :         259 :   ::dump_bb (f, bb, 4, TDF_NONE);
     599                 :             : 
     600                 :             :   // Now find any globals defined in this block.
     601                 :       27492 :   for (x = 1; x < num_ssa_names; x++)
     602                 :             :     {
     603                 :       13487 :       tree name = ssa_name (x);
     604                 :       18957 :       if (!gimple_range_ssa_p (name) || !SSA_NAME_DEF_STMT (name))
     605                 :        8017 :         continue;
     606                 :        5470 :       Value_Range range (TREE_TYPE (name));
     607                 :        5470 :       if (gimple_bb (SSA_NAME_DEF_STMT (name)) == bb
     608                 :        5470 :           && m_cache.get_global_range (range, name))
     609                 :             :         {
     610                 :         290 :           if (!range.varying_p ())
     611                 :             :             {
     612                 :         153 :               print_generic_expr (f, name, TDF_SLIM);
     613                 :         153 :               fprintf (f, " : ");
     614                 :         153 :               range.dump (f);
     615                 :         153 :               fprintf (f, "\n");
     616                 :             :             }
     617                 :             : 
     618                 :             :         }
     619                 :        5470 :     }
     620                 :             : 
     621                 :             :   // And now outgoing edges, if they define anything.
     622                 :         633 :   FOR_EACH_EDGE (e, ei, bb->succs)
     623                 :             :     {
     624                 :       44450 :       for (x = 1; x < num_ssa_names; x++)
     625                 :             :         {
     626                 :       21851 :           tree name = gimple_range_ssa_p (ssa_name (x));
     627                 :       21851 :           if (!name || !gori ().has_edge_range_p (name, e))
     628                 :       21231 :             continue;
     629                 :             : 
     630                 :         620 :           Value_Range range (TREE_TYPE (name));
     631                 :         620 :           if (m_cache.range_on_edge (range, e, name))
     632                 :             :             {
     633                 :         620 :               gimple *s = SSA_NAME_DEF_STMT (name);
     634                 :         620 :               Value_Range tmp_range (TREE_TYPE (name));
     635                 :             :               // Only print the range if this is the def block, or
     636                 :             :               // the on entry cache for either end of the edge is
     637                 :             :               // set.
     638                 :         944 :               if ((s && bb == gimple_bb (s)) ||
     639                 :        1076 :                   m_cache.block_range (tmp_range, bb, name, false) ||
     640                 :         132 :                   m_cache.block_range (tmp_range, e->dest, name, false))
     641                 :             :                 {
     642                 :         488 :                   if (!range.varying_p ())
     643                 :             :                     {
     644                 :         422 :                       fprintf (f, "%d->%d ", e->src->index,
     645                 :         422 :                                e->dest->index);
     646                 :         422 :                       char c = ' ';
     647                 :         422 :                       if (e->flags & EDGE_TRUE_VALUE)
     648                 :         205 :                         fprintf (f, " (T)%c", c);
     649                 :         217 :                       else if (e->flags & EDGE_FALSE_VALUE)
     650                 :         217 :                         fprintf (f, " (F)%c", c);
     651                 :             :                       else
     652                 :           0 :                         fprintf (f, "     ");
     653                 :         422 :                       print_generic_expr (f, name, TDF_SLIM);
     654                 :         422 :                       fprintf(f, " : \t");
     655                 :         422 :                       range.dump(f);
     656                 :         422 :                       fprintf (f, "\n");
     657                 :             :                     }
     658                 :             :                 }
     659                 :         620 :             }
     660                 :         620 :         }
     661                 :             :     }
     662                 :         259 : }
     663                 :             : 
     664                 :             : // Print the known table values to file F.
     665                 :             : 
     666                 :             : void
     667                 :          46 : gimple_ranger::dump (FILE *f)
     668                 :             : {
     669                 :          46 :   basic_block bb;
     670                 :             : 
     671                 :         305 :   FOR_EACH_BB_FN (bb, cfun)
     672                 :         259 :     dump_bb (f, bb);
     673                 :             : 
     674                 :          46 :   m_cache.dump (f);
     675                 :          46 : }
     676                 :             : 
     677                 :             : void
     678                 :           0 : gimple_ranger::debug ()
     679                 :             : {
     680                 :           0 :   dump (stderr);
     681                 :           0 : }
     682                 :             : 
     683                 :             : /* Create a new ranger instance and associate it with function FUN.
     684                 :             :    Each call must be paired with a call to disable_ranger to release
     685                 :             :    resources.  */
     686                 :             : 
     687                 :             : gimple_ranger *
     688                 :    16971298 : enable_ranger (struct function *fun, bool use_imm_uses)
     689                 :             : {
     690                 :    16971298 :   gimple_ranger *r;
     691                 :             : 
     692                 :    16971298 :   bitmap_obstack_initialize (NULL);
     693                 :             : 
     694                 :    16971298 :   gcc_checking_assert (!fun->x_range_query);
     695                 :    16971298 :   r = new gimple_ranger (use_imm_uses);
     696                 :    16971298 :   fun->x_range_query = r;
     697                 :             : 
     698                 :    16971298 :   return r;
     699                 :             : }
     700                 :             : 
     701                 :             : /* Destroy and release the ranger instance associated with function FUN
     702                 :             :    and replace it the global ranger.  */
     703                 :             : 
     704                 :             : void
     705                 :    16971298 : disable_ranger (struct function *fun)
     706                 :             : {
     707                 :    16971298 :   gcc_checking_assert (fun->x_range_query);
     708                 :    16971298 :   delete fun->x_range_query;
     709                 :    16971298 :   fun->x_range_query = NULL;
     710                 :             : 
     711                 :    16971298 :   bitmap_obstack_release (NULL);
     712                 :    16971298 : }
     713                 :             : 
     714                 :             : // ------------------------------------------------------------------------
     715                 :             : 
     716                 :             : // If there is a non-varying value associated with NAME, return true and the
     717                 :             : // range in R.
     718                 :             : 
     719                 :             : bool
     720                 :         110 : assume_query::assume_range_p (vrange &r, tree name)
     721                 :             : {
     722                 :         110 :   if (global.get_range (r, name))
     723                 :          95 :     return !r.varying_p ();
     724                 :             :   return false;
     725                 :             : }
     726                 :             : 
     727                 :             : // Query used by GORI to pick up any known value on entry to a block.
     728                 :             : 
     729                 :             : bool
     730                 :         570 : assume_query::range_of_expr (vrange &r, tree expr, gimple *stmt)
     731                 :             : {
     732                 :         570 :   if (!gimple_range_ssa_p (expr))
     733                 :         191 :     return get_tree_range (r, expr, stmt);
     734                 :             : 
     735                 :         379 :   if (!global.get_range (r, expr))
     736                 :         228 :     r.set_varying (TREE_TYPE (expr));
     737                 :             :   return true;
     738                 :             : }
     739                 :             : 
     740                 :             : // If the current function returns an integral value, and has a single return
     741                 :             : // statement, it will calculate any SSA_NAMES it can determine ranges for
     742                 :             : // assuming the function returns 1.
     743                 :             : 
     744                 :         101 : assume_query::assume_query ()
     745                 :             : {
     746                 :         101 :   basic_block exit_bb = EXIT_BLOCK_PTR_FOR_FN (cfun);
     747                 :         101 :   if (single_pred_p (exit_bb))
     748                 :             :     {
     749                 :         101 :       basic_block bb = single_pred (exit_bb);
     750                 :         101 :       gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
     751                 :         101 :       if (gsi_end_p (gsi))
     752                 :          25 :         return;
     753                 :         101 :       gimple *s = gsi_stmt (gsi);
     754                 :         101 :       if (!is_a<greturn *> (s))
     755                 :             :         return;
     756                 :         101 :       greturn *gret = as_a<greturn *> (s);
     757                 :         101 :       tree op = gimple_return_retval (gret);
     758                 :         101 :       if (!gimple_range_ssa_p (op))
     759                 :             :         return;
     760                 :          76 :       tree lhs_type = TREE_TYPE (op);
     761                 :          76 :       if (!irange::supports_p (lhs_type))
     762                 :             :         return;
     763                 :             : 
     764                 :          76 :       unsigned prec = TYPE_PRECISION (lhs_type);
     765                 :          76 :       int_range<2> lhs_range (lhs_type, wi::one (prec), wi::one (prec));
     766                 :          76 :       global.set_range (op, lhs_range);
     767                 :             : 
     768                 :          76 :       gimple *def = SSA_NAME_DEF_STMT (op);
     769                 :          76 :       if (!def || gimple_get_lhs (def) != op)
     770                 :           0 :         return;
     771                 :          76 :       fur_stmt src (gret, this);
     772                 :          76 :       calculate_stmt (def, lhs_range, src);
     773                 :          76 :     }
     774                 :             : }
     775                 :             : 
     776                 :             : // Evaluate operand OP on statement S, using the provided LHS range.
     777                 :             : // If successful, set the range in the global table, then visit OP's def stmt.
     778                 :             : 
     779                 :             : void
     780                 :         307 : assume_query::calculate_op (tree op, gimple *s, vrange &lhs, fur_source &src)
     781                 :             : {
     782                 :         307 :   Value_Range op_range (TREE_TYPE (op));
     783                 :         307 :   if (m_gori.compute_operand_range (op_range, s, lhs, op, src)
     784                 :         307 :       && !op_range.varying_p ())
     785                 :             :     {
     786                 :             :       // Set the global range, merging if there is already a range.
     787                 :         301 :       global.merge_range (op, op_range);
     788                 :         301 :       gimple *def_stmt = SSA_NAME_DEF_STMT (op);
     789                 :         301 :       if (def_stmt && gimple_get_lhs (def_stmt) == op)
     790                 :         154 :         calculate_stmt (def_stmt, op_range, src);
     791                 :             :     }
     792                 :         307 : }
     793                 :             : 
     794                 :             : // Evaluate PHI statement, using the provided LHS range.
     795                 :             : // Check each constant argument predecessor if it can be taken
     796                 :             : // provide LHS to any symbolic arguments, and process their def statements.
     797                 :             : 
     798                 :             : void
     799                 :          25 : assume_query::calculate_phi (gphi *phi, vrange &lhs_range, fur_source &src)
     800                 :             : {
     801                 :          75 :   for (unsigned x= 0; x < gimple_phi_num_args (phi); x++)
     802                 :             :     {
     803                 :          50 :       tree arg = gimple_phi_arg_def (phi, x);
     804                 :          50 :       Value_Range arg_range (TREE_TYPE (arg));
     805                 :          50 :       if (gimple_range_ssa_p (arg))
     806                 :             :         {
     807                 :             :           // A symbol arg will be the LHS value.
     808                 :          34 :           arg_range = lhs_range;
     809                 :          34 :           range_cast (arg_range, TREE_TYPE (arg));
     810                 :          34 :           if (!global.get_range (arg_range, arg))
     811                 :             :             {
     812                 :          31 :               global.set_range (arg, arg_range);
     813                 :          31 :               gimple *def_stmt = SSA_NAME_DEF_STMT (arg);
     814                 :          31 :               if (def_stmt && gimple_get_lhs (def_stmt) == arg)
     815                 :          31 :                 calculate_stmt (def_stmt, arg_range, src);
     816                 :             :             }
     817                 :             :         }
     818                 :          16 :       else if (get_tree_range (arg_range, arg, NULL))
     819                 :             :         {
     820                 :             :           // If this is a constant value that differs from LHS, this
     821                 :             :           // edge cannot be taken.
     822                 :          16 :           arg_range.intersect (lhs_range);
     823                 :          16 :           if (arg_range.undefined_p ())
     824                 :          16 :             continue;
     825                 :             :           // Otherwise check the condition feeding this edge.
     826                 :           0 :           edge e = gimple_phi_arg_edge (phi, x);
     827                 :           0 :           check_taken_edge (e, src);
     828                 :             :         }
     829                 :          50 :     }
     830                 :          25 : }
     831                 :             : 
     832                 :             : // If an edge is known to be taken, examine the outgoing edge to see
     833                 :             : // if it carries any range information that can also be evaluated.
     834                 :             : 
     835                 :             : void
     836                 :         273 : assume_query::check_taken_edge (edge e, fur_source &src)
     837                 :             : {
     838                 :         273 :   gimple *stmt = gimple_outgoing_range_stmt_p (e->src);
     839                 :         273 :   if (stmt && is_a<gcond *> (stmt))
     840                 :             :     {
     841                 :          55 :       int_range<2> cond;
     842                 :          55 :       gcond_edge_range (cond, e);
     843                 :          55 :       calculate_stmt (stmt, cond, src);
     844                 :          55 :     }
     845                 :         273 : }
     846                 :             : 
     847                 :             : // Evaluate statement S which produces range LHS_RANGE.
     848                 :             : 
     849                 :             : void
     850                 :         316 : assume_query::calculate_stmt (gimple *s, vrange &lhs_range, fur_source &src)
     851                 :             : {
     852                 :         316 :   gimple_range_op_handler handler (s);
     853                 :         316 :   if (handler)
     854                 :             :     {
     855                 :         271 :       tree op = gimple_range_ssa_p (handler.operand1 ());
     856                 :         271 :       if (op)
     857                 :         271 :         calculate_op (op, s, lhs_range, src);
     858                 :         271 :       op = gimple_range_ssa_p (handler.operand2 ());
     859                 :         271 :       if (op)
     860                 :          36 :         calculate_op (op, s, lhs_range, src);
     861                 :             :     }
     862                 :          45 :   else if (is_a<gphi *> (s))
     863                 :             :     {
     864                 :          25 :       calculate_phi (as_a<gphi *> (s), lhs_range, src);
     865                 :             :       // Don't further check predecessors of blocks with PHIs.
     866                 :          25 :       return;
     867                 :             :     }
     868                 :             : 
     869                 :             :   // Even if the walk back terminates before the top, if this is a single
     870                 :             :   // predecessor block, see if the predecessor provided any ranges to get here.
     871                 :         564 :   if (single_pred_p (gimple_bb (s)))
     872                 :         273 :     check_taken_edge (single_pred_edge (gimple_bb (s)), src);
     873                 :             : }
     874                 :             : 
     875                 :             : // Show everything that was calculated.
     876                 :             : 
     877                 :             : void
     878                 :           0 : assume_query::dump (FILE *f)
     879                 :             : {
     880                 :           0 :   fprintf (f, "Assumption details calculated:\n");
     881                 :           0 :   for (unsigned i = 0; i < num_ssa_names; i++)
     882                 :             :     {
     883                 :           0 :       tree name = ssa_name (i);
     884                 :           0 :       if (!name || !gimple_range_ssa_p (name))
     885                 :           0 :         continue;
     886                 :           0 :       tree type = TREE_TYPE (name);
     887                 :           0 :       if (!Value_Range::supports_type_p (type))
     888                 :           0 :         continue;
     889                 :             : 
     890                 :           0 :       Value_Range assume_range (type);
     891                 :           0 :       if (assume_range_p (assume_range, name))
     892                 :             :         {
     893                 :           0 :           print_generic_expr (f, name, TDF_SLIM);
     894                 :           0 :           fprintf (f, " -> ");
     895                 :           0 :           assume_range.dump (f);
     896                 :           0 :           fputc ('\n', f);
     897                 :             :         }
     898                 :           0 :     }
     899                 :           0 :   fprintf (f, "------------------------------\n");
     900                 :           0 : }
     901                 :             : 
     902                 :             : // ---------------------------------------------------------------------------
     903                 :             : 
     904                 :             : 
     905                 :             : // Create a DOM based ranger for use by a DOM walk pass.
     906                 :             : 
     907                 :           0 : dom_ranger::dom_ranger () : m_global (), m_out ()
     908                 :             : {
     909                 :           0 :   m_freelist.create (0);
     910                 :           0 :   m_freelist.truncate (0);
     911                 :           0 :   m_e0.create (0);
     912                 :           0 :   m_e0.safe_grow_cleared (last_basic_block_for_fn (cfun));
     913                 :           0 :   m_e1.create (0);
     914                 :           0 :   m_e1.safe_grow_cleared (last_basic_block_for_fn (cfun));
     915                 :           0 :   m_pop_list = BITMAP_ALLOC (NULL);
     916                 :           0 :   if (dump_file && (param_ranger_debug & RANGER_DEBUG_TRACE))
     917                 :           0 :     tracer.enable_trace ();
     918                 :           0 : }
     919                 :             : 
     920                 :             : // Dispose of a DOM ranger.
     921                 :             : 
     922                 :           0 : dom_ranger::~dom_ranger ()
     923                 :             : {
     924                 :           0 :   if (dump_file && (dump_flags & TDF_DETAILS))
     925                 :             :     {
     926                 :           0 :       fprintf (dump_file, "Non-varying global ranges:\n");
     927                 :           0 :       fprintf (dump_file, "=========================:\n");
     928                 :           0 :       m_global.dump (dump_file);
     929                 :             :     }
     930                 :           0 :   BITMAP_FREE (m_pop_list);
     931                 :           0 :   m_e1.release ();
     932                 :           0 :   m_e0.release ();
     933                 :           0 :   m_freelist.release ();
     934                 :           0 : }
     935                 :             : 
     936                 :             : // Implement range of EXPR on stmt S, and return it in R.
     937                 :             : // Return false if no range can be calculated.
     938                 :             : 
     939                 :             : bool
     940                 :           0 : dom_ranger::range_of_expr (vrange &r, tree expr, gimple *s)
     941                 :             : {
     942                 :           0 :   unsigned idx;
     943                 :           0 :   if (!gimple_range_ssa_p (expr))
     944                 :           0 :     return get_tree_range (r, expr, s);
     945                 :             : 
     946                 :           0 :   if ((idx = tracer.header ("range_of_expr ")))
     947                 :             :     {
     948                 :           0 :       print_generic_expr (dump_file, expr, TDF_SLIM);
     949                 :           0 :       if (s)
     950                 :             :         {
     951                 :           0 :           fprintf (dump_file, " at ");
     952                 :           0 :           print_gimple_stmt (dump_file, s, 0, TDF_SLIM);
     953                 :             :         }
     954                 :             :       else
     955                 :           0 :           fprintf (dump_file, "\n");
     956                 :             :     }
     957                 :             : 
     958                 :           0 :   if (s)
     959                 :           0 :     range_in_bb (r, gimple_bb (s), expr);
     960                 :             :   else
     961                 :           0 :     m_global.range_of_expr (r, expr, s);
     962                 :             : 
     963                 :           0 :   if (idx)
     964                 :           0 :     tracer.trailer (idx, " ", true, expr, r);
     965                 :             :   return true;
     966                 :             : }
     967                 :             : 
     968                 :             : 
     969                 :             : // Return TRUE and the range if edge E has a range set for NAME in
     970                 :             : // block E->src.
     971                 :             : 
     972                 :             : bool
     973                 :           0 : dom_ranger::edge_range (vrange &r, edge e, tree name)
     974                 :             : {
     975                 :           0 :   bool ret = false;
     976                 :           0 :   basic_block bb = e->src;
     977                 :             : 
     978                 :             :   // Check if BB has any outgoing ranges on edge E.
     979                 :           0 :   ssa_lazy_cache *out = NULL;
     980                 :           0 :   if (EDGE_SUCC (bb, 0) == e)
     981                 :           0 :     out = m_e0[bb->index];
     982                 :           0 :   else if (EDGE_SUCC (bb, 1) == e)
     983                 :           0 :     out = m_e1[bb->index];
     984                 :             : 
     985                 :             :   // If there is an edge vector and it has a range, pick it up.
     986                 :           0 :   if (out && out->has_range (name))
     987                 :           0 :     ret = out->get_range (r, name);
     988                 :             : 
     989                 :           0 :   return ret;
     990                 :             : }
     991                 :             : 
     992                 :             : 
     993                 :             : // Return the range of EXPR on edge E in R.
     994                 :             : // Return false if no range can be calculated.
     995                 :             : 
     996                 :             : bool
     997                 :           0 : dom_ranger::range_on_edge (vrange &r, edge e, tree expr)
     998                 :             : {
     999                 :           0 :   basic_block bb = e->src;
    1000                 :           0 :   unsigned idx;
    1001                 :           0 :   if ((idx = tracer.header ("range_on_edge ")))
    1002                 :             :     {
    1003                 :           0 :       fprintf (dump_file, "%d->%d for ",e->src->index, e->dest->index);
    1004                 :           0 :       print_generic_expr (dump_file, expr, TDF_SLIM);
    1005                 :           0 :       fputc ('\n',dump_file);
    1006                 :             :     }
    1007                 :             : 
    1008                 :           0 :   if (!gimple_range_ssa_p (expr))
    1009                 :           0 :     return get_tree_range (r, expr, NULL);
    1010                 :             : 
    1011                 :           0 :   if (!edge_range (r, e, expr))
    1012                 :           0 :     range_in_bb (r, bb, expr);
    1013                 :             : 
    1014                 :           0 :   if (idx)
    1015                 :           0 :     tracer.trailer (idx, " ", true, expr, r);
    1016                 :             :   return true;
    1017                 :             : }
    1018                 :             : 
    1019                 :             : // Return the range of NAME as it exists at the end of block BB in R.
    1020                 :             : 
    1021                 :             : void
    1022                 :           0 : dom_ranger::range_in_bb (vrange &r, basic_block bb, tree name)
    1023                 :             : {
    1024                 :           0 :   basic_block def_bb = gimple_bb (SSA_NAME_DEF_STMT (name));
    1025                 :             :   // Loop through dominators until we get to the entry block, or we find
    1026                 :             :   // either the defintion block for NAME, or a single pred edge with a range.
    1027                 :           0 :   while (bb != ENTRY_BLOCK_PTR_FOR_FN (cfun))
    1028                 :             :     {
    1029                 :             :       // If we hit the deifntion block, pick up the global value.
    1030                 :           0 :       if (bb == def_bb)
    1031                 :             :         {
    1032                 :           0 :           m_global.range_of_expr (r, name);
    1033                 :           0 :           return;
    1034                 :             :         }
    1035                 :             :       // If its a single pred, check the outgoing range of the edge.
    1036                 :           0 :       if (EDGE_COUNT (bb->preds) == 1
    1037                 :           0 :           && edge_range (r, EDGE_PRED (bb, 0), name))
    1038                 :             :         return;
    1039                 :             :       // Otherwise move up to the dominator, and check again.
    1040                 :           0 :       bb = get_immediate_dominator (CDI_DOMINATORS, bb);
    1041                 :             :     }
    1042                 :           0 :   m_global.range_of_expr (r, name);
    1043                 :             : }
    1044                 :             : 
    1045                 :             : 
    1046                 :             : // Calculate the range of NAME, as the def of stmt S and return it in R.
    1047                 :             : // Return FALSE if no range cqn be calculated.
    1048                 :             : // Also set the global range for NAME as this should only be called within
    1049                 :             : // the def block during a DOM walk.
    1050                 :             : // Outgoing edges were pre-calculated, so when we establish a global defintion
    1051                 :             : // check if any outgoing edges hav ranges that can be combined with the
    1052                 :             : // global.
    1053                 :             : 
    1054                 :             : bool
    1055                 :           0 : dom_ranger::range_of_stmt (vrange &r, gimple *s, tree name)
    1056                 :             : {
    1057                 :           0 :   unsigned idx;
    1058                 :           0 :   bool ret;
    1059                 :           0 :   if (!name)
    1060                 :           0 :     name = gimple_range_ssa_p (gimple_get_lhs (s));
    1061                 :             : 
    1062                 :           0 :   gcc_checking_assert (!name || name == gimple_get_lhs (s));
    1063                 :             : 
    1064                 :           0 :   if ((idx = tracer.header ("range_of_stmt ")))
    1065                 :           0 :     print_gimple_stmt (dump_file, s, 0, TDF_SLIM);
    1066                 :             : 
    1067                 :             :   // Its already been calculated.
    1068                 :           0 :   if (name && m_global.has_range (name))
    1069                 :             :     {
    1070                 :           0 :       ret = m_global.range_of_expr (r, name, s);
    1071                 :           0 :       if (idx)
    1072                 :           0 :         tracer.trailer (idx, " Already had value ", ret, name, r);
    1073                 :           0 :       return ret;
    1074                 :             :     }
    1075                 :             : 
    1076                 :             :   // If there is a new calculated range and it is not varying, set
    1077                 :             :   // a global range.
    1078                 :           0 :   ret = fold_range (r, s, this);
    1079                 :           0 :   if (ret && name && m_global.merge_range (name, r) && !r.varying_p ())
    1080                 :             :     {
    1081                 :           0 :       if (set_range_info (name, r) && dump_file)
    1082                 :             :         {
    1083                 :           0 :           fprintf (dump_file, "Global Exported: ");
    1084                 :           0 :           print_generic_expr (dump_file, name, TDF_SLIM);
    1085                 :           0 :           fprintf (dump_file, " = ");
    1086                 :           0 :           r.dump (dump_file);
    1087                 :           0 :           fputc ('\n', dump_file);
    1088                 :             :         }
    1089                 :           0 :       basic_block bb = gimple_bb (s);
    1090                 :           0 :       unsigned bbi = bb->index;
    1091                 :           0 :       Value_Range vr (TREE_TYPE (name));
    1092                 :             :       // If there is a range on edge 0, update it.
    1093                 :           0 :       if (m_e0[bbi] && m_e0[bbi]->has_range (name))
    1094                 :             :         {
    1095                 :           0 :           if (m_e0[bbi]->merge_range (name, r) && dump_file
    1096                 :           0 :               && (dump_flags & TDF_DETAILS))
    1097                 :             :             {
    1098                 :           0 :               fprintf (dump_file, "Outgoing range for ");
    1099                 :           0 :               print_generic_expr (dump_file, name, TDF_SLIM);
    1100                 :           0 :               fprintf (dump_file, " updated on edge %d->%d : ", bbi,
    1101                 :           0 :                        EDGE_SUCC (bb, 0)->dest->index);
    1102                 :           0 :               if (m_e0[bbi]->get_range (vr, name))
    1103                 :           0 :                 vr.dump (dump_file);
    1104                 :           0 :               fputc ('\n', dump_file);
    1105                 :             :             }
    1106                 :             :         }
    1107                 :             :       // If there is a range on edge 1, update it.
    1108                 :           0 :       if (m_e1[bbi] && m_e1[bbi]->has_range (name))
    1109                 :             :         {
    1110                 :           0 :           if (m_e1[bbi]->merge_range (name, r) && dump_file
    1111                 :           0 :               && (dump_flags & TDF_DETAILS))
    1112                 :             :             {
    1113                 :           0 :               fprintf (dump_file, "Outgoing range for ");
    1114                 :           0 :               print_generic_expr (dump_file, name, TDF_SLIM);
    1115                 :           0 :               fprintf (dump_file, " updated on edge %d->%d : ", bbi,
    1116                 :           0 :                        EDGE_SUCC (bb, 1)->dest->index);
    1117                 :           0 :               if (m_e1[bbi]->get_range (vr, name))
    1118                 :           0 :                 vr.dump (dump_file);
    1119                 :           0 :               fputc ('\n', dump_file);
    1120                 :             :             }
    1121                 :             :         }
    1122                 :           0 :     }
    1123                 :           0 :   if (idx)
    1124                 :           0 :     tracer.trailer (idx, " ", ret, name, r);
    1125                 :             :   return ret;
    1126                 :             : }
    1127                 :             : 
    1128                 :             : // Check if GORI has an ranges on edge E.  If there re, store them in
    1129                 :             : // either the E0 or E1 vector based on EDGE_0.
    1130                 :             : // If there are no ranges, put the empty lazy_cache entry on the freelist
    1131                 :             : // for use next time.
    1132                 :             : 
    1133                 :             : void
    1134                 :           0 : dom_ranger::maybe_push_edge (edge e, bool edge_0)
    1135                 :             : {
    1136                 :           0 :   ssa_lazy_cache *e_cache;
    1137                 :           0 :   if (!m_freelist.is_empty ())
    1138                 :           0 :     e_cache = m_freelist.pop ();
    1139                 :             :   else
    1140                 :           0 :     e_cache = new ssa_lazy_cache;
    1141                 :           0 :   gori_on_edge (*e_cache, e, this, &m_out);
    1142                 :           0 :   if (e_cache->empty_p ())
    1143                 :           0 :     m_freelist.safe_push (e_cache);
    1144                 :             :   else
    1145                 :             :     {
    1146                 :           0 :       if (edge_0)
    1147                 :           0 :         m_e0[e->src->index] = e_cache;
    1148                 :             :       else
    1149                 :           0 :         m_e1[e->src->index] = e_cache;
    1150                 :             :     }
    1151                 :           0 : }
    1152                 :             : 
    1153                 :             : // Preprocess block BB.  If there are any outgoing edges, precalculate
    1154                 :             : // the outgoing ranges and store them.   Note these are done before
    1155                 :             : // we process the block, so global values have not been set yet.
    1156                 :             : // These are "pure" outgoing ranges inflicted by the condition.
    1157                 :             : 
    1158                 :             : void
    1159                 :           0 : dom_ranger::pre_bb (basic_block bb)
    1160                 :             : {
    1161                 :           0 :   if (dump_file && (dump_flags & TDF_DETAILS))
    1162                 :           0 :     fprintf (dump_file, "#FVRP entering BB %d\n", bb->index);
    1163                 :             : 
    1164                 :             :   // Next, see if this block needs outgoing edges calculated.
    1165                 :           0 :   gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
    1166                 :           0 :   if (!gsi_end_p (gsi))
    1167                 :             :     {
    1168                 :           0 :       gimple *s = gsi_stmt (gsi);
    1169                 :           0 :       if (is_a<gcond *> (s) && gimple_range_op_handler::supported_p (s))
    1170                 :             :         {
    1171                 :           0 :           maybe_push_edge (EDGE_SUCC (bb, 0), true);
    1172                 :           0 :           maybe_push_edge (EDGE_SUCC (bb, 1), false);
    1173                 :             : 
    1174                 :           0 :           if (dump_file && (dump_flags & TDF_DETAILS))
    1175                 :             :             {
    1176                 :           0 :               if (m_e0[bb->index])
    1177                 :             :                 {
    1178                 :           0 :                   fprintf (dump_file, "\nEdge ranges BB %d->%d\n",
    1179                 :           0 :                            bb->index, EDGE_SUCC (bb, 0)->dest->index);
    1180                 :           0 :                   m_e0[bb->index]->dump(dump_file);
    1181                 :             :                 }
    1182                 :           0 :               if (m_e1[bb->index])
    1183                 :             :                 {
    1184                 :           0 :                   fprintf (dump_file, "\nEdge ranges BB %d->%d\n",
    1185                 :           0 :                            bb->index, EDGE_SUCC (bb, 1)->dest->index);
    1186                 :           0 :                   m_e1[bb->index]->dump(dump_file);
    1187                 :             :                 }
    1188                 :             :             }
    1189                 :             :         }
    1190                 :             :     }
    1191                 :           0 :   if (dump_file && (dump_flags & TDF_DETAILS))
    1192                 :           0 :     fprintf (dump_file, "#FVRP DONE entering BB %d\n", bb->index);
    1193                 :           0 : }
    1194                 :             : 
    1195                 :             : // Perform any post block processing.
    1196                 :             : 
    1197                 :             : void
    1198                 :           0 : dom_ranger::post_bb (basic_block)
    1199                 :             : {
    1200                 :           0 : }
        

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.