Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
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
10namespace Halide {
11namespace Internal {
12
13/** A class to represent ranges of Exprs. Can be unbounded above or below. */
14struct 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) {
45 internal_assert(min.defined() && max.defined());
46 }
47
48 /** The interval representing 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 other 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
104private:
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
#define internal_assert(c)
Definition Errors.h:19
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
#define HALIDE_ALWAYS_INLINE
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
A fragment of Halide syntax.
Definition Expr.h:258
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 other 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