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 } // namespace Internal
114 } // namespace Halide
115 
116 #endif
internal_assert
#define internal_assert(c)
Definition: Errors.h:19
Halide::Internal::Interval::max
Expr max
Definition: Interval.h:35
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::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: AddAtomicMutex.h:21
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
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_ALWAYS_INLINE
#define HALIDE_ALWAYS_INLINE
Definition: HalideRuntime.h:32
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::Interval::has_upper_bound
bool has_upper_bound() const
Does the interval have a finite least upper bound.
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::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::Interval::neg_inf
static Expr neg_inf()
Definition: Interval.h:28
Halide::Internal::IntrusivePtr::defined
HALIDE_ALWAYS_INLINE bool defined() const
Definition: IntrusivePtr.h:156
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:256
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::Interval::make_max
static Expr make_max(const Expr &a, const Expr &b)
An eagerly-simplifying max of two Exprs that respects infinities.