Halide
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. */
128  static ConstantInterval 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
Halide::Internal::ConstantInterval::bounded_above
static ConstantInterval bounded_above(int64_t max)
internal_assert
#define internal_assert(c)
Definition: Errors.h:19
Halide::Internal::Interval::max
Expr max
Definition: Interval.h:35
Halide::Internal::ConstantInterval::single_point
static ConstantInterval single_point(int64_t x)
Construct an interval representing a single point.
Halide::Internal::Interval::Interval
Interval(const Expr &min, const Expr &max)
Construct an interval from a lower and upper bound.
Definition: Interval.h:43
Halide::Internal::Interval::pos_inf
static Expr pos_inf()
Exprs to represent positive and negative infinity.
Definition: Interval.h:25
Halide::Internal::Interval::is_everything
bool is_everything() const
Is the interval the entire range.
Halide::Internal::ConstantInterval::bounded_below
static ConstantInterval bounded_below(int64_t min)
Construct intervals bounded above or below.
Halide::Internal::ConstantInterval::max
int64_t max
Definition: Interval.h:118
Halide::Internal::ConstantInterval::has_lower_bound
bool has_lower_bound() const
Does the interval have a finite greatest lower bound.
Halide::Internal::Interval::same_as
bool same_as(const Interval &other) const
Is the interval the same as another interval.
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Internal::ConstantInterval::is_single_point
bool is_single_point() const
Is the interval just a single value (min == max)
Halide::Internal::Interval::make_min
static Expr make_min(const Expr &a, const Expr &b)
An eagerly-simplifying min of two Exprs that respects infinities.
Halide::Internal::Interval::is_empty
bool is_empty() const
Is the interval the empty set.
Halide::Internal::Interval::make_union
static Interval make_union(const Interval &a, const Interval &b)
Construct the smallest interval containing two intervals.
Halide::Internal::Interval::is_single_point
bool is_single_point() const
Is the interval just a single value (min == max)
Halide::Internal::ConstantInterval::make_union
static ConstantInterval make_union(const ConstantInterval &a, const ConstantInterval &b)
Construct the smallest interval containing two intervals.
Halide::Internal::ConstantInterval::has_upper_bound
bool has_upper_bound() const
Does the interval have a finite least upper bound.
HALIDE_ALWAYS_INLINE
#define HALIDE_ALWAYS_INLINE
Definition: HalideRuntime.h:40
Halide::Internal::Interval::include
void include(const Interval &i)
Expand the interval to include another Interval.
Halide::Internal::Interval::Interval
Interval()
A default-constructed Interval is everything.
Definition: Interval.h:38
Halide::Internal::Interval::is_bounded
bool is_bounded() const
Does the interval have a finite upper and lower bound.
Halide::Internal::ConstantInterval::max_defined
bool max_defined
Definition: Interval.h:119
int64_t
signed __INT64_TYPE__ int64_t
Definition: runtime_internal.h:22
Halide::Internal::Interval::has_upper_bound
bool has_upper_bound() const
Does the interval have a finite least upper bound.
Halide::Internal::ConstantInterval::operator==
bool operator==(const ConstantInterval &other) const
Equivalent to same_as.
Expr.h
Halide::Internal::Interval
A class to represent ranges of Exprs.
Definition: Interval.h:14
Halide::Internal::Interval::single_point
static Interval single_point(const Expr &e)
Construct an interval representing a single point.
Halide::Internal::ConstantInterval::is_everything
bool is_everything() const
Is the interval the entire range.
Halide::Internal::Interval::make_intersection
static Interval make_intersection(const Interval &a, const Interval &b)
Construct the largest interval contained within two intervals.
Halide::Internal::Interval::min
Expr min
The lower and upper bound of the interval.
Definition: Interval.h:35
Halide::Internal::ConstantInterval::include
void include(const ConstantInterval &i)
Expand the interval to include another Interval.
Halide::Internal::Interval::neg_inf
static Expr neg_inf()
Definition: Interval.h:28
Halide::Internal::ConstantInterval::min
int64_t min
The lower and upper bound of the interval.
Definition: Interval.h:118
Halide::Internal::ConstantInterval
A class to represent ranges of integers.
Definition: Interval.h:115
Halide::Internal::IntrusivePtr::defined
HALIDE_ALWAYS_INLINE bool defined() const
Definition: IntrusivePtr.h:161
Halide::Internal::Interval::everything
static Interval everything()
The interval representing everything.
Halide::Internal::Interval::has_lower_bound
bool has_lower_bound() const
Does the interval have a finite greatest lower bound.
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:257
Halide::Internal::ConstantInterval::min_defined
bool min_defined
Definition: Interval.h:119
Halide::Internal::ConstantInterval::is_bounded
bool is_bounded() const
Does the interval have a finite upper and lower bound.
Halide::Internal::Interval::operator==
bool operator==(const Interval &other) const
Equivalent to same_as.
Halide::Internal::Interval::nothing
static Interval nothing()
The interval representing nothing.
Halide::Internal::ConstantInterval::ConstantInterval
ConstantInterval()
Halide::Internal::Interval::make_max
static Expr make_max(const Expr &a, const Expr &b)
An eagerly-simplifying max of two Exprs that respects infinities.
Halide::Internal::ConstantInterval::everything
static ConstantInterval everything()
The interval representing everything.