LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/arrays - array_info.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 15 15 100.0 %
Date: 2026-04-22 10:35:54 Functions: 2 2 100.0 %
Branches: 9 20 45.0 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * This file is part of the cvc5 project.
       3                 :            :  *
       4                 :            :  * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS
       5                 :            :  * in the top-level source directory and their institutional affiliations.
       6                 :            :  * All rights reserved.  See the file COPYING in the top-level source
       7                 :            :  * directory for licensing information.
       8                 :            :  * ****************************************************************************
       9                 :            :  *
      10                 :            :  * Contains additional classes to store context dependent information
      11                 :            :  * for each term of type array.
      12                 :            :  */
      13                 :            : 
      14                 :            : #include "cvc5_private.h"
      15                 :            : 
      16                 :            : #ifndef CVC5__THEORY__ARRAYS__ARRAY_INFO_H
      17                 :            : #define CVC5__THEORY__ARRAYS__ARRAY_INFO_H
      18                 :            : 
      19                 :            : #include <tuple>
      20                 :            : #include <unordered_map>
      21                 :            : 
      22                 :            : #include "context/cdlist.h"
      23                 :            : #include "context/cdo.h"
      24                 :            : #include "expr/node.h"
      25                 :            : #include "util/statistics_stats.h"
      26                 :            : 
      27                 :            : namespace cvc5::internal {
      28                 :            : namespace theory {
      29                 :            : namespace arrays {
      30                 :            : 
      31                 :            : typedef context::CDList<TNode> CTNodeList;
      32                 :            : using RowLemmaType = std::tuple<TNode, TNode, TNode, TNode>;
      33                 :            : 
      34                 :            : struct RowLemmaTypeHashFunction
      35                 :            : {
      36                 :     234836 :   size_t operator()(const RowLemmaType& q) const
      37                 :            :   {
      38                 :     234836 :     TNode n1, n2, n3, n4;
      39                 :     234836 :     std::tie(n1, n2, n3, n4) = q;
      40                 :     234836 :     return (size_t)(n1.getId() * 0x9e3779b9 + n2.getId() * 0x30000059
      41                 :     469672 :                     + n3.getId() * 0x60000005 + n4.getId() * 0x07FFFFFF);
      42                 :     234836 :   }
      43                 :            : }; /* struct RowLemmaTypeHashFunction */
      44                 :            : 
      45                 :            : void printList(CTNodeList* list);
      46                 :            : 
      47                 :            : bool inList(const CTNodeList* l, const TNode el);
      48                 :            : 
      49                 :            : /**
      50                 :            :  * Small class encapsulating the information
      51                 :            :  * in the map. It's a class and not a struct to
      52                 :            :  * call the destructor.
      53                 :            :  */
      54                 :            : 
      55                 :            : class Info
      56                 :            : {
      57                 :            :  public:
      58                 :            :   context::CDO<bool> isNonLinear;
      59                 :            :   context::CDO<bool> rIntro1Applied;
      60                 :            :   context::CDO<TNode> modelRep;
      61                 :            :   context::CDO<TNode> constArr;
      62                 :            :   context::CDO<TNode> weakEquivPointer;
      63                 :            :   context::CDO<TNode> weakEquivIndex;
      64                 :            :   context::CDO<TNode> weakEquivSecondary;
      65                 :            :   context::CDO<TNode> weakEquivSecondaryReason;
      66                 :            :   CTNodeList* indices;
      67                 :            :   CTNodeList* stores;
      68                 :            :   CTNodeList* in_stores;
      69                 :            : 
      70                 :            :   Info(context::Context* c);
      71                 :            :   ~Info();
      72                 :            : 
      73                 :            :   /**
      74                 :            :    * prints the information
      75                 :            :    */
      76                 :        304 :   void print() const
      77                 :            :   {
      78 [ +  - ][ +  - ]:        304 :     Assert(indices != nullptr && stores != nullptr && in_stores != nullptr);
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
                 [ -  - ]
      79         [ +  - ]:        304 :     Trace("arrays-info") << "  indices   ";
      80                 :        304 :     printList(indices);
      81         [ +  - ]:        304 :     Trace("arrays-info") << "  stores ";
      82                 :        304 :     printList(stores);
      83         [ +  - ]:        304 :     Trace("arrays-info") << "  in_stores ";
      84                 :        304 :     printList(in_stores);
      85                 :        304 :   }
      86                 :            : }; /* class Info */
      87                 :            : 
      88                 :            : typedef std::unordered_map<Node, Info*> CNodeInfoMap;
      89                 :            : 
      90                 :            : /**
      91                 :            :  * Class keeping track of the following information for canonical
      92                 :            :  * representatives of type array [a] :
      93                 :            :  *    indices at which it is being read (all i for which there is a
      94                 :            :  *            term of the form SELECT a i)
      95                 :            :  *    all store terms in the congruence class
      96                 :            :  *    stores in which it appears (terms of the form STORE a _ _ )
      97                 :            :  *
      98                 :            :  */
      99                 :            : class ArrayInfo
     100                 :            : {
     101                 :            :  private:
     102                 :            :   context::Context* ct;
     103                 :            :   CNodeInfoMap info_map;
     104                 :            : 
     105                 :            :   CTNodeList* emptyList;
     106                 :            : 
     107                 :            :   /* == STATISTICS == */
     108                 :            : 
     109                 :            :   /** time spent in preregisterTerm() */
     110                 :            :   TimerStat d_mergeInfoTimer;
     111                 :            :   AverageStat d_avgIndexListLength;
     112                 :            :   AverageStat d_avgStoresListLength;
     113                 :            :   AverageStat d_avgInStoresListLength;
     114                 :            :   IntStat d_listsCount;
     115                 :            :   IntStat d_callsMergeInfo;
     116                 :            :   IntStat d_maxList;
     117                 :            :   SizeStat<CNodeInfoMap> d_tableSize;
     118                 :            : 
     119                 :            :   /**
     120                 :            :    * checks if a certain element is in the list l
     121                 :            :    * FIXME: better way to check for duplicates?
     122                 :            :    */
     123                 :            : 
     124                 :            :   /**
     125                 :            :    * helper method that merges two lists into the first
     126                 :            :    * without adding duplicates
     127                 :            :    */
     128                 :            :   void mergeLists(CTNodeList* la, const CTNodeList* lb) const;
     129                 :            : 
     130                 :            :  public:
     131                 :            :   const Info* emptyInfo;
     132                 :            : 
     133                 :            :   ArrayInfo(StatisticsRegistry& sr,
     134                 :            :             context::Context* c,
     135                 :            :             std::string statisticsPrefix = "");
     136                 :            : 
     137                 :            :   ~ArrayInfo();
     138                 :            : 
     139                 :            :   /**
     140                 :            :    * adds the node a to the map if it does not exist
     141                 :            :    * and it initializes the info. checks for duplicate i's
     142                 :            :    */
     143                 :            :   void addIndex(const Node a, const TNode i);
     144                 :            :   void addStore(const Node a, const TNode st);
     145                 :            :   void addInStore(const TNode a, const TNode st);
     146                 :            : 
     147                 :            :   void setNonLinear(const TNode a);
     148                 :            :   void setRIntro1Applied(const TNode a);
     149                 :            :   void setModelRep(const TNode a, const TNode rep);
     150                 :            : 
     151                 :            :   void setConstArr(const TNode a, const TNode constArr);
     152                 :            :   void setWeakEquivPointer(const TNode a, const TNode pointer);
     153                 :            :   void setWeakEquivIndex(const TNode a, const TNode index);
     154                 :            :   void setWeakEquivSecondary(const TNode a, const TNode secondary);
     155                 :            :   void setWeakEquivSecondaryReason(const TNode a, const TNode reason);
     156                 :            :   /**
     157                 :            :    * Returns the information associated with TNode a
     158                 :            :    */
     159                 :            : 
     160                 :            :   const Info* getInfo(const TNode a) const;
     161                 :            : 
     162                 :            :   bool isNonLinear(const TNode a) const;
     163                 :            : 
     164                 :            :   bool rIntro1Applied(const TNode a) const;
     165                 :            : 
     166                 :            :   const TNode getModelRep(const TNode a) const;
     167                 :            : 
     168                 :            :   const TNode getConstArr(const TNode a) const;
     169                 :            :   const TNode getWeakEquivPointer(const TNode a) const;
     170                 :            :   const TNode getWeakEquivIndex(const TNode a) const;
     171                 :            :   const TNode getWeakEquivSecondary(const TNode a) const;
     172                 :            :   const TNode getWeakEquivSecondaryReason(const TNode a) const;
     173                 :            : 
     174                 :            :   const CTNodeList* getIndices(const TNode a) const;
     175                 :            : 
     176                 :            :   const CTNodeList* getStores(const TNode a) const;
     177                 :            : 
     178                 :            :   const CTNodeList* getInStores(const TNode a) const;
     179                 :            : 
     180                 :            :   /**
     181                 :            :    * merges the information of  nodes a and b
     182                 :            :    * the nodes do not have to actually be in the map.
     183                 :            :    * pre-condition
     184                 :            :    *  a should be the canonical representative of b
     185                 :            :    */
     186                 :            :   void mergeInfo(const TNode a, const TNode b);
     187                 :            : }; /* class ArrayInfo */
     188                 :            : 
     189                 :            : }  // namespace arrays
     190                 :            : }  // namespace theory
     191                 :            : }  // namespace cvc5::internal
     192                 :            : 
     193                 :            : #endif /* CVC5__THEORY__ARRAYS__ARRAY_INFO_H */

Generated by: LCOV version 1.14