Halide  12.0.1
Halide compiler and libraries
Interval.h
Go to the documentation of this file.
1 #ifndef HALIDE_INTERVAL_H
2 #define HALIDE_INTERVAL_H
3 
4 /** \file
5  * Defines the Interval class
6  */
7 
8 #include "Expr.h"
9 
10 namespace Halide {
11 namespace Internal {
12 
13 /** A class to represent ranges of Exprs. Can be unbounded above or below. */
14 struct Interval {
15 
16  /** Exprs to represent positive and negative infinity */
17 #ifdef COMPILING_HALIDE
19  return pos_inf_expr;
20  }
22  return neg_inf_expr;
23  }
24 #else
25  static Expr pos_inf() {
26  return pos_inf_noinline();
27  }
28  static Expr neg_inf() {
29  return neg_inf_noinline();
30  }
31 #endif
32 
33  /** The lower and upper bound of the interval. They are included
34  * in the interval. */
36 
37  /** A default-constructed Interval is everything */
39  : min(neg_inf()), max(pos_inf()) {
40  }
41 
42  /** Construct an interval from a lower and upper bound. */
43  Interval(const Expr &min, const Expr &max)
44  : min(min), max(max) {
46  }
47 
48  /** The interval representing everything. */
49  static Interval everything();
50 
51  /** The interval representing nothing. */
52  static Interval nothing();
53 
54  /** Construct an interval representing a single point */
55  static Interval single_point(const Expr &e);
56 
57  /** Is the interval the empty set */
58  bool is_empty() const;
59 
60  /** Is the interval the entire range */
61  bool is_everything() const;
62 
63  /** Is the interval just a single value (min == max) */
64  bool is_single_point() const;
65 
66  /** Is the interval a particular single value */
67  bool is_single_point(const Expr &e) const;
68 
69  /** Does the interval have a finite least upper bound */
70  bool has_upper_bound() const;
71 
72  /** Does the interval have a finite greatest lower bound */
73  bool has_lower_bound() const;
74 
75  /** Does the interval have a finite upper and lower bound */
76  bool is_bounded() const;
77 
78  /** Is the interval the same as another interval */
79  bool same_as(const Interval &other) const;
80 
81  /** Expand the interval to include another Interval */
82  void include(const Interval &i);
83 
84  /** Expand the interval to include an Expr */
85  void include(const Expr &e);
86 
87  /** Construct the smallest interval containing two intervals. */
88  static Interval make_union(const Interval &a, const Interval &b);
89 
90  /** Construct the largest interval contained within two intervals. */
91  static Interval make_intersection(const Interval &a, const Interval &b);
92 
93  /** An eagerly-simplifying max of two Exprs that respects infinities. */
94  static Expr make_max(const Expr &a, const Expr &b);
95 
96  /** An eagerly-simplifying min of two Exprs that respects infinities. */
97  static Expr make_min(const Expr &a, const Expr &b);
98 
99  /** Equivalent to same_as. Exists so that the autoscheduler can
100  * compare two map<string, Interval> for equality in order to
101  * cache computations. */
102  bool operator==(const Interval &other) const;
103 
104 private:
105  static Expr neg_inf_expr, pos_inf_expr;
106 
107  // Never used inside libHalide; provided for Halide tests, to avoid needing to export
108  // data fields in some build environments.
109  static Expr pos_inf_noinline();
110  static Expr neg_inf_noinline();
111 };
112 
113 /** A class to represent ranges of integers. Can be unbounded above or below, but
114  * they cannot be empty. */
116  /** The lower and upper bound of the interval. They are included
117  * in the interval. */
118  int64_t min = 0, max = 0;
119  bool min_defined = false, max_defined = false;
120 
121  /* A default-constructed Interval is everything */
123 
124  /** Construct an interval from a lower and upper bound. */
126 
127  /** The interval representing everything. */
129 
130  /** Construct an interval representing a single point. */
132 
133  /** Construct intervals bounded above or below. */
136 
137  /** Is the interval the entire range */
138  bool is_everything() const;
139 
140  /** Is the interval just a single value (min == max) */
141  bool is_single_point() const;
142 
143  /** Is the interval a particular single value */
144  bool is_single_point(int64_t x) const;
145 
146  /** Does the interval have a finite least upper bound */
147  bool has_upper_bound() const;
148 
149  /** Does the interval have a finite greatest lower bound */
150  bool has_lower_bound() const;
151 
152  /** Does the interval have a finite upper and lower bound */
153  bool is_bounded() const;
154 
155  /** Expand the interval to include another Interval */
156  void include(const ConstantInterval &i);
157 
158  /** Expand the interval to include a point */
159  void include(int64_t x);
160 
161  /** Construct the smallest interval containing two intervals. */
163 
164  /** Equivalent to same_as. Exists so that the autoscheduler can
165  * compare two map<string, Interval> for equality in order to
166  * cache computations. */
167  bool operator==(const ConstantInterval &other) const;
168 };
169 
170 } // namespace Internal
171 } // namespace Halide
172 
173 #endif
#define internal_assert(c)
Definition: Errors.h:19
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
#define HALIDE_ALWAYS_INLINE
Definition: HalideRuntime.h:38
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
signed __INT64_TYPE__ int64_t
A fragment of Halide syntax.
Definition: Expr.h:256
A class to represent ranges of integers.
Definition: Interval.h:115
int64_t min
The lower and upper bound of the interval.
Definition: Interval.h:118
static ConstantInterval bounded_above(int64_t max)
bool is_bounded() const
Does the interval have a finite upper and lower bound.
ConstantInterval(int64_t min, int64_t max)
Construct an interval from a lower and upper bound.
bool has_upper_bound() const
Does the interval have a finite least upper bound.
bool operator==(const ConstantInterval &other) const
Equivalent to same_as.
static ConstantInterval make_union(const ConstantInterval &a, const ConstantInterval &b)
Construct the smallest interval containing two intervals.
static ConstantInterval bounded_below(int64_t min)
Construct intervals bounded above or below.
bool has_lower_bound() const
Does the interval have a finite greatest lower bound.
bool is_single_point() const
Is the interval just a single value (min == max)
bool is_everything() const
Is the interval the entire range.
void include(const ConstantInterval &i)
Expand the interval to include another Interval.
void include(int64_t x)
Expand the interval to include a point.
static ConstantInterval everything()
The interval representing everything.
bool is_single_point(int64_t x) const
Is the interval a particular single value.
static ConstantInterval single_point(int64_t x)
Construct an interval representing a single point.
A class to represent ranges of Exprs.
Definition: Interval.h:14
static Interval single_point(const Expr &e)
Construct an interval representing a single point.
void include(const Interval &i)
Expand the interval to include another Interval.
bool operator==(const Interval &other) const
Equivalent to same_as.
static Interval make_union(const Interval &a, const Interval &b)
Construct the smallest interval containing two intervals.
static Interval make_intersection(const Interval &a, const Interval &b)
Construct the largest interval contained within two intervals.
Expr min
The lower and upper bound of the interval.
Definition: Interval.h:35
Interval(const Expr &min, const Expr &max)
Construct an interval from a lower and upper bound.
Definition: Interval.h:43
static Interval nothing()
The interval representing nothing.
static Interval everything()
The interval representing everything.
bool has_lower_bound() const
Does the interval have a finite greatest lower bound.
static Expr pos_inf()
Exprs to represent positive and negative infinity.
Definition: Interval.h:25
bool same_as(const Interval &other) const
Is the interval the same as another interval.
bool is_single_point(const Expr &e) const
Is the interval a particular single value.
void include(const Expr &e)
Expand the interval to include an Expr.
bool is_empty() const
Is the interval the empty set.
bool is_everything() const
Is the interval the entire range.
static Expr neg_inf()
Definition: Interval.h:28
static Expr make_min(const Expr &a, const Expr &b)
An eagerly-simplifying min of two Exprs that respects infinities.
static Expr make_max(const Expr &a, const Expr &b)
An eagerly-simplifying max of two Exprs that respects infinities.
bool has_upper_bound() const
Does the interval have a finite least upper bound.
bool is_single_point() const
Is the interval just a single value (min == max)
bool is_bounded() const
Does the interval have a finite upper and lower bound.
Interval()
A default-constructed Interval is everything.
Definition: Interval.h:38
HALIDE_ALWAYS_INLINE bool defined() const
Definition: IntrusivePtr.h:161