TVM  0.9.4
RangeCounting.h
Go to the documentation of this file.
1 /* Copyright 2017-2020 CNRS-AIST JRL and CNRS-UM LIRMM */
2 
3 #pragma once
4 
5 #include <tvm/api.h>
6 
7 #include <tvm/Range.h>
8 
9 #include <list>
10 
11 namespace tvm::internal
12 {
55 {
56 public:
58  struct Limit
59  {
60  enum Type
61  {
62  Lower = -1,
63  Cut = 0,
64  Upper = 1
65  };
66 
67  Limit(int i, Type type) : i_(i), type_(type) {}
68 
69  int i_; // Value of the limit
70  Type type_; // The type of the limit
71 
72  bool operator==(const Limit & other) const { return (i_ == other.i_ && type_ == other.type_); }
73  bool operator<(const Limit & other) const { return i_ < other.i_ || (i_ == other.i_ && type_ < other.type_); }
74  bool operator<=(const Limit & other) const { return i_ < other.i_ || (i_ == other.i_ && type_ <= other.type_); }
75  bool operator>(const Limit & other) const { return i_ > other.i_ || (i_ == other.i_ && type_ > other.type_); }
76  bool operator>=(const Limit & other) const { return i_ > other.i_ || (i_ == other.i_ && type_ >= other.type_); }
77 
78  friend std::ostream & operator<<(std::ostream & os, const Limit & lim)
79  {
80  os << "(" << lim.i_ << ", " << ((lim.type_ == Lower) ? "+" : ((lim.type_ == Cut) ? "|" : "-")) << ")";
81  return os;
82  }
83  };
84 
88  bool add(const Range & r);
92  bool remove(const Range & r);
93 
94  bool empty() const { return limits_.size() == 0; }
95 
102  const std::vector<Range> & ranges(bool splitOncountDiff = false) const;
104  const std::list<Limit> & limits() const;
105 
107  int maxCount() const;
108 
109 private:
110  using It = std::list<Limit>::iterator;
111 
115  bool moveToFirstAfter(const Limit & val, It & it, int & depth, int depthCut = 0) const;
116 
121  void insert(const Limit & val, It & it, int & depth);
122 
124  bool recompute(bool change);
125 
126  bool isValid() const;
127 
137  std::list<Limit> limits_; // The representation of the current state.
138  mutable bool recompute_ = false; // Need to recompute intervals_ without split. Used for lazy evaluation.
139  mutable bool recomputeSplit_ = false; // Need to recompute intervals_ with split. Used for lazy evaluation.
140  mutable std::vector<Range> intervals_; // The range representation of the current state, reevaluated
141  // if necessary when accessed (lazy evaluation).
142 };
143 } // namespace tvm::internal
#define TVM_DLLAPI
Definition: api.h:35
Definition: Range.h:19
Definition: RangeCounting.h:55
bool remove(const Range &r)
bool add(const Range &r)
bool empty() const
Definition: RangeCounting.h:94
const std::list< Limit > & limits() const
const std::vector< Range > & ranges(bool splitOncountDiff=false) const
Definition: CallbackManager.h:12
Definition: RangeCounting.h:59
bool operator>(const Limit &other) const
Definition: RangeCounting.h:75
bool operator<=(const Limit &other) const
Definition: RangeCounting.h:74
Type
Definition: RangeCounting.h:61
friend std::ostream & operator<<(std::ostream &os, const Limit &lim)
Definition: RangeCounting.h:78
bool operator>=(const Limit &other) const
Definition: RangeCounting.h:76
Limit(int i, Type type)
Definition: RangeCounting.h:67
bool operator<(const Limit &other) const
Definition: RangeCounting.h:73
bool operator==(const Limit &other) const
Definition: RangeCounting.h:72
int i_
Definition: RangeCounting.h:69
Type type_
Definition: RangeCounting.h:70