LCOV - code coverage report
Current view: top level - gcc - value-range-storage.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 90.6 % 32 29
Test Date: 2026-11-14 16:39:50 Functions: 100.0 % 1 1
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Support routines for vrange storage.
       2              :    Copyright (C) 2022-2026 Free Software Foundation, Inc.
       3              :    Contributed by Aldy Hernandez <aldyh@redhat.com>.
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify
       8              : it under the terms of the GNU General Public License as published by
       9              : the Free Software Foundation; either version 3, or (at your option)
      10              : any later version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful,
      13              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15              : GNU General Public License for more details.
      16              : 
      17              : You should have received a copy of the GNU General Public License
      18              : along with GCC; see the file COPYING3.  If not see
      19              : <http://www.gnu.org/licenses/>.  */
      20              : 
      21              : #ifndef GCC_VALUE_RANGE_STORAGE_H
      22              : #define GCC_VALUE_RANGE_STORAGE_H
      23              : 
      24              : // This class is used to allocate chunks of memory that can store
      25              : // ranges as memory efficiently as possible.
      26              : 
      27              : class vrange_allocator
      28              : {
      29              : public:
      30              :   // Use GC memory when GC is true, otherwise use obstacks.
      31              :   vrange_allocator (bool gc = false);
      32              :   ~vrange_allocator ();
      33              :   class vrange_storage *clone (const vrange &r, bool shared_p = true);
      34              :   vrange_storage *clone_varying (tree type);
      35              :   vrange_storage *clone_undefined (tree type);
      36              :   void *alloc (size_t size);
      37              :   void free (void *);
      38              : private:
      39              :   DISABLE_COPY_AND_ASSIGN (vrange_allocator);
      40              :   class vrange_internal_alloc *m_alloc;
      41              : };
      42              : 
      43              : // Efficient memory storage for a vrange.
      44              : 
      45              : class GTY((desc ("%h.m_discriminator"), tag("VR_UNKNOWN"))) vrange_storage
      46              : {
      47              : public:
      48              :   static vrange_storage *alloc (vrange_internal_alloc &, const vrange &,
      49              :                                 bool shared_p = true);
      50              :   void get_vrange (vrange &r, tree type) const;
      51              :   void set_vrange (const vrange &r);
      52              :   bool fits_p (const vrange &r) const;
      53              :   bool equal_p (const vrange &r) const;
      54              : 
      55              :   class irange_storage *dyn_irange ();
      56              :   class prange_storage *dyn_prange ();
      57              :   class frange_storage *dyn_frange ();
      58              :   const irange_storage *dyn_irange () const;
      59              :   const prange_storage *dyn_prange () const;
      60              :   const frange_storage *dyn_frange () const;
      61              :   // Stack initialization disallowed.
      62    408898953 :   vrange_storage (enum value_range_discriminator d) : m_discriminator (d) { }
      63              :   const enum value_range_discriminator m_discriminator : 4;
      64              : };
      65              : 
      66              : // Efficient memory storage for an irange.
      67              : 
      68              : class GTY((tag ("VR_IRANGE"))) irange_storage: public vrange_storage
      69              : {
      70              : public:
      71              :   static irange_storage *alloc (vrange_internal_alloc &, const irange &);
      72              :   void set_irange (const irange &r);
      73              :   void get_irange (irange &r, tree type) const;
      74              :   bool equal_p (const irange &r) const;
      75              :   bool fits_p (const irange &r) const;
      76              :   void dump () const;
      77              : private:
      78              :   DISABLE_COPY_AND_ASSIGN (irange_storage);
      79              :   static size_t size (const irange &r);
      80              :   const unsigned short *lengths_address () const;
      81              :   unsigned short *write_lengths_address ();
      82              : 
      83              :   // The shared precision of each number.
      84              :   unsigned short m_precision;
      85              : 
      86              :   // The max number of sub-ranges that fit in this storage.
      87              :   const unsigned char m_max_ranges;
      88              : 
      89              :   // The number of stored sub-ranges.
      90              :   unsigned char m_num_ranges;
      91              : 
      92              :   enum value_range_kind m_kind : 3;
      93              : 
      94              :   // The length of this is m_num_ranges * 2 + 2 to accommodate the bitmask.
      95              :   HOST_WIDE_INT m_val[1];
      96              : 
      97              :   // Another variable-length part of the structure following the HWIs.
      98              :   // This is the length of each wide_int in m_val.
      99              :   //
     100              :   // unsigned short m_len[];
     101              : 
     102              :   irange_storage (const irange &r);
     103              : };
     104              : 
     105              : 
     106              : // A prange_kind summarizes some common variations for a prange, and is used
     107              : // in a prange_storage clas for efficiency.
     108              : 
     109              : enum prange_kind { PR_UNDEFINED,        // VR_UNDEFINED
     110              :                    PR_VARYING,          // VR_VARYING
     111              :                    PR_ZERO,             // [0, 0]
     112              :                    PR_NONZERO,          // [1, +INF] (May have bitmask)
     113              :                    PR_FULL,             // [0, +INF] (Must have bitmask)
     114              :                    PR_OTHER };          // [x, y]    (MAy have bitmask)
     115              : 
     116              : // Maximum number of words that may be allocated by a prange_storage class.
     117              : const unsigned int PRANGE_STORAGE_NINTS = 4;
     118              : 
     119              : // Efficient memory storage for a prange.
     120              : class GTY((tag ("VR_PRANGE"))) prange_storage : public vrange_storage
     121              : {
     122              : private:
     123              :   // vrange_storage ends after four bytes but the first pointer member below
     124              :   // needs eight-byte alignment, so there is a four-byte hole.
     125              :   enum prange_kind m_kind : 4;
     126              :   unsigned int m_has_bitmask : 1;
     127              :   unsigned int m_known_p : 1;
     128              : 
     129              : public:
     130              :   friend void gt_ggc_mx_vrange_storage(void *);
     131              :   friend void gt_pch_nx_vrange_storage(void *);
     132              :   friend void gt_pch_p_14vrange_storage(void *, void *, gt_pointer_operator,
     133              :                                         void *);
     134              :   static prange_storage *alloc (vrange_internal_alloc &, const prange &,
     135              :                                 bool shared_p = true);
     136              :   void set_prange (const prange &r);
     137              :   void get_prange (prange &r, tree type) const;
     138              :   bool equal_p (const prange &r) const;
     139              :   bool fits_p (const prange &r) const;
     140            0 :   bool undefined_p () const { return m_kind == PR_UNDEFINED; }
     141              :   irange_bitmask get_bitmask (tree type) const;
     142              :   bool nonnull_p (tree type) const;
     143              :   void set_nonnull (tree type);
     144              :   void dump () const;
     145              : 
     146              :   // The points-to solution for the SSA name is flow insensitive and is
     147              :   // reached only through ssa_name_pt_solution.
     148              :   struct pt_solution *pt;
     149              : 
     150              : private:
     151              :   DISABLE_COPY_AND_ASSIGN (prange_storage);
     152              :   prange_storage (const prange &r);
     153              :   static enum prange_kind prange_format (const prange &r, unsigned &num_words);
     154              : 
     155              :   tree m_addr;
     156              : 
     157              :   // We don't use TRAILING_WIDE_INT_ACCESSOR because the getters here
     158              :   // must be const.  Perhaps TRAILING_WIDE_INT_ACCESSOR could be made
     159              :   // const and return wide_int instead of trailing_wide_int.
     160     47861865 :   wide_int get_word (unsigned i, tree) const
     161     56063252 :     { return m_trailing_ints[i]; }
     162     12818908 :   template <typename T> void set_word (unsigned i, const T &x, tree)
     163     12818908 :     { m_trailing_ints[i] = x; }
     164              : 
     165              :   trailing_wide_ints<PRANGE_STORAGE_NINTS> m_trailing_ints;
     166              : };
     167              : 
     168              : // Return TRUE if this range of type TYPE does not contain zero.
     169              : 
     170              : inline bool
     171     36795832 : prange_storage::nonnull_p (tree type) const
     172              : {
     173     36795832 :   switch (m_kind)
     174              :     {
     175              :       case PR_UNDEFINED:
     176              :       case PR_VARYING:
     177              :       case PR_ZERO:
     178              :       case PR_FULL:
     179              :         return false;
     180      4258630 :       case PR_NONZERO:
     181      4258630 :         return true;
     182        27313 :       case PR_OTHER:
     183        27313 :         return (get_word (0, type) != 0);
     184            0 :       default:
     185            0 :         gcc_unreachable ();
     186              :     }
     187              : }
     188              : 
     189              : 
     190              : // Efficient memory storage for an frange.
     191              : 
     192              : class GTY((tag ("VR_FRANGE"))) frange_storage : public vrange_storage
     193              : {
     194              :  public:
     195              :   static frange_storage *alloc (vrange_internal_alloc &, const frange &r);
     196              :   void set_frange (const frange &r);
     197              :   void get_frange (frange &r, tree type) const;
     198              :   bool equal_p (const frange &r) const;
     199              :   bool fits_p (const frange &) const;
     200              :  private:
     201              :   frange_storage (const frange &r);
     202              :   DISABLE_COPY_AND_ASSIGN (frange_storage);
     203              :   static size_t size (const frange &r);
     204              : 
     205              :   enum value_range_kind m_kind;
     206              :   // The max number of sub-ranges that fit in this storage.
     207              :   const unsigned char m_max_ranges;
     208              :   unsigned char m_num_ranges;
     209              :   bool m_pos_nan;
     210              :   bool m_neg_nan;
     211              :   frange_pair m_pairs[1];
     212              : };
     213              : 
     214              : inline irange_storage *
     215     29124070 : vrange_storage::dyn_irange ()
     216              : {
     217     29124070 :   if (m_discriminator == VR_IRANGE)
     218     23765795 :     return static_cast <irange_storage *> (this);
     219              :   return NULL;
     220              : }
     221              : 
     222              : inline prange_storage *
     223   2006938864 : vrange_storage::dyn_prange ()
     224              : {
     225   2006938864 :   if (m_discriminator == VR_PRANGE)
     226      5278249 :     return static_cast <prange_storage *> (this);
     227              :   return NULL;
     228              : }
     229              : 
     230              : inline frange_storage *
     231       598448 : vrange_storage::dyn_frange ()
     232              : {
     233       598448 :   if (m_discriminator == VR_FRANGE)
     234       598448 :     return static_cast <frange_storage *> (this);
     235              :   return NULL;
     236              : }
     237              : 
     238              : inline const irange_storage *
     239   2154770946 : vrange_storage::dyn_irange () const
     240              : {
     241   2154770946 :   if (m_discriminator == VR_IRANGE)
     242   1580224707 :     return static_cast <const irange_storage *> (this);
     243              :   return NULL;
     244              : }
     245              : 
     246              : inline const prange_storage *
     247    574546239 : vrange_storage::dyn_prange () const
     248              : {
     249    574546239 :   if (m_discriminator == VR_PRANGE)
     250    525206906 :     return static_cast <const prange_storage *> (this);
     251              :   return NULL;
     252              : }
     253              : 
     254              : inline const frange_storage *
     255     49339333 : vrange_storage::dyn_frange () const
     256              : {
     257     49339333 :   if (m_discriminator == VR_FRANGE)
     258     49339333 :     return static_cast <const frange_storage *> (this);
     259              :   return NULL;
     260              : }
     261              : extern vrange_storage *ggc_alloc_vrange_storage (tree type);
     262              : extern vrange_storage *ggc_alloc_vrange_storage (const vrange &,
     263              :                                                  bool shared_p = true);
     264              : 
     265              : #endif // GCC_VALUE_RANGE_STORAGE_H
        

Generated by: LCOV version 2.5.0-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.