LCOV - code coverage report
Current view: top level - gcc - gimple-range-infer.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 66.7 % 12 8
Test Date: 2024-12-21 13:15:12 Functions: 42.9 % 7 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Header file for gimple range inference.
       2                 :             :    Copyright (C) 2022-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Andrew MacLeod <amacleod@redhat.com>.
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it under
       8                 :             : the terms of the GNU General Public License as published by the Free
       9                 :             : Software Foundation; either version 3, or (at your option) any later
      10                 :             : version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             :  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                 :             : #ifndef GCC_GIMPLE_RANGE_SIDE_H
      22                 :             : #define GCC_GIMPLE_RANGE_SIDE_H
      23                 :             : 
      24                 :             : // Inferred ranges are ranges which are applied to use operands as a by product
      25                 :             : // of executing an operation.
      26                 :             : 
      27                 :             : // This class manages an on-demand summary of inferred ranges for a statement.
      28                 :             : // It can be instantiated as required and provides a list of inferred ranges.
      29                 :             : // New inferred ranges should be added in the constructor of this class.
      30                 :             : //
      31                 :             : // There are 2 main instantiations.
      32                 :             : // gimple_range_infer (gimple *s, range_query *q, bool use_range_ops)
      33                 :             : //   S is the statement being queried.
      34                 :             : //   Q is a range-query object which is used to resolve any ranges that
      35                 :             : //      might be required.  This defaults to NULL which maps to the
      36                 :             : //      global_range_query, which is what most passes will want.
      37                 :             : //      Ranger internally will pass the cache's range-query which is a
      38                 :             : //      read-only query and prevents any additional lookup.
      39                 :             : //   USE_RANGEOPS is a boolean flag which defaults to false.  if TRUE,
      40                 :             : //      range-ops is invoked to see if any additional side effects are seen
      41                 :             : //      based on the stmt.  ie .x = y * 2 will reigster a side effect for Y
      42                 :             : //      which is [-INF/2 , +INF/2].  It is not on by default because it
      43                 :             : //      is a relatively expensive operation to do on every statement, and
      44                 :             : //      ranger will already incorporate that range for Y via GORI most of the
      45                 :             : //      time that it matters.  Individual passes may have use for it however.
      46                 :             : //      PR 113879 is an example where this can be of use.
      47                 :             : //
      48                 :             : // gimple_range_infer (tree name, vrange &r)
      49                 :             : // This instantiation simply create an inferred range record directly.
      50                 :             : //   NAME is the SSA_NAME to create the record for
      51                 :             : //   R is the range for NAME.
      52                 :             : //
      53                 :             : // Once a gimple_infer_range record has been created, the API is simple:
      54                 :             : //   num ()    - The number of inferred ranges in this record.
      55                 :             : //   name (i)  - The i'th SSA_NAME in this record.
      56                 :             : //   range (i) - The range of the i'th SSA_NAME.
      57                 :             : 
      58                 :  3299227415 : class gimple_infer_range
      59                 :             : {
      60                 :             : public:
      61                 :             :   gimple_infer_range (gimple *s, range_query *q = NULL,
      62                 :             :                       bool use_rangeops = false);
      63                 :             :   gimple_infer_range (tree name, vrange &r);
      64                 :   365787535 :   inline unsigned num () const { return num_args; }
      65                 :    36493309 :   inline tree name (unsigned index) const
      66                 :    36493309 :     { gcc_checking_assert (index < num_args); return m_names[index]; }
      67                 :    39841612 :   inline const vrange& range (unsigned index) const
      68                 :    39841612 :     { gcc_checking_assert (index < num_args); return m_ranges[index]; }
      69                 :             : private:
      70                 :             :   void add_range (tree name, vrange &range);
      71                 :             :   void add_nonzero (tree name);
      72                 :             :   void check_assume_func (gcall *call);
      73                 :             :   unsigned num_args;
      74                 :             :   static const int size_limit = 10;
      75                 :             :   tree m_names[size_limit];
      76                 :             :   value_range m_ranges[size_limit];
      77                 :             :   inline void bump_index () { if (num_args < size_limit - 1) num_args++; }
      78                 :             :   friend class non_null_wrapper;
      79                 :             : };
      80                 :             : 
      81                 :             : // This is the basic infer oracle API.  Default functionaility does nothing.
      82                 :             : 
      83                 :             : class infer_range_oracle
      84                 :             : {
      85                 :             : public:
      86                 :    24573651 :   infer_range_oracle () { }
      87                 :    25131775 :   virtual ~infer_range_oracle () { }
      88                 :           0 :   virtual void add_ranges (gimple *, gimple_infer_range &) { }
      89                 :           0 :   virtual bool has_range_p (basic_block, tree = NULL_TREE) { return false; }
      90                 :           0 :   virtual bool maybe_adjust_range (vrange &, tree, basic_block)
      91                 :           0 :       { return false; }
      92                 :             : };
      93                 :             : 
      94                 :             : // This class manages a list of inferred ranges for each basic block.
      95                 :             : // As inferences are made, they can be registered to a block and later
      96                 :             : // queried via a DOM search.
      97                 :             : // When DO_SEARCH is TRUE,  immediate uses chains are followed the first time
      98                 :             : // a name is referenced and block populated if there are any inferred ranges.
      99                 :             : // range_query Q is the range_query to use for any range lookups. It defaults
     100                 :             : // to NULL which maps to the global_range_query.  This is what most passes
     101                 :             : // will want to use. Ranger invokes it with the cache's internal query which
     102                 :             : // can provide better ranges during a DOM walk.
     103                 :             : //
     104                 :             : // add_ranges is used to add inferred range IR assocaited with stmt S.
     105                 :             : // has_range_p is used to check if NAME has an inferred range in block BB.
     106                 :             : // maybe_adjust_range will adjust the range R to incorporate any inferred
     107                 :             : //   range NAME may have in block BB.  If there are on inferred ranges in
     108                 :             : //   block BB, then R will be unchanged, otherwise the ranges are intersected.
     109                 :             : 
     110                 :             : class infer_range_manager : public infer_range_oracle
     111                 :             : {
     112                 :             : public:
     113                 :             :   infer_range_manager (bool do_search, range_query *q = NULL);
     114                 :             :   virtual ~infer_range_manager ();
     115                 :             :   virtual void add_ranges (gimple *s, gimple_infer_range &ir);
     116                 :             :   virtual bool has_range_p (basic_block bb, tree name = NULL_TREE);
     117                 :             :   virtual bool maybe_adjust_range (vrange &r, tree name, basic_block bb);
     118                 :             : private:
     119                 :             :   void add_range (tree name, gimple *s, const vrange &r);
     120                 :             :   void add_nonzero (tree name, gimple *s);
     121                 :             :   class exit_range_head
     122                 :             :   {
     123                 :             :   public:
     124                 :             :     bitmap m_names;             // list of names with an outgoing range.
     125                 :             :     class exit_range *head;
     126                 :             :     int m_num_ranges;
     127                 :             :     exit_range *find_ptr (tree name);
     128                 :             :   };
     129                 :             :   void register_all_uses (tree name);
     130                 :             :   vec <exit_range_head> m_on_exit;
     131                 :             :   const vrange &get_nonzero (tree name);
     132                 :             :   vec <vrange *> m_nonzero;
     133                 :             :   bitmap m_seen;
     134                 :             :   bitmap_obstack m_bitmaps;
     135                 :             :   struct obstack m_list_obstack;
     136                 :             :   class vrange_allocator *m_range_allocator;
     137                 :             :   range_query *m_query;
     138                 :             : };
     139                 :             : #endif // GCC_GIMPLE_RANGE_SIDE_H
        

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.