Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
Definition.h
Go to the documentation of this file.
1#ifndef HALIDE_DEFINITION_H
2#define HALIDE_DEFINITION_H
3
4/** \file
5 * Defines the internal representation of a halide function's definition and related classes
6 */
7
8#include "Expr.h"
9#include "IntrusivePtr.h"
10#include "Schedule.h"
11
12#include <map>
13
14namespace Halide {
15
16namespace Internal {
17struct DefinitionContents;
18struct FunctionContents;
19class ReductionDomain;
20} // namespace Internal
21
22namespace Internal {
23
24class IRVisitor;
25class IRMutator;
26struct Specialization;
27
28/** A Function definition which can either represent a init or an update
29 * definition. A function may have different definitions due to specialization,
30 * which are stored in 'specializations' (Not possible from the front-end, but
31 * some scheduling directives may potentially cause this divergence to occur).
32 * Although init definition may have multiple values (RHS) per specialization, it
33 * must have the same LHS (i.e. same pure dimension variables). The update
34 * definition, on the other hand, may have different LHS/RHS per specialization.
35 * Note that, while the Expr in LHS/RHS may be different across specializations,
36 * they must have the same number of dimensions and the same pure dimensions.
37 */
39
41
42public:
43 /** Construct a Definition from an existing DefinitionContents pointer. Must be non-null */
45
46 /** Construct a Definition with the supplied args, values, and reduction domain. */
47 Definition(const std::vector<Expr> &args, const std::vector<Expr> &values,
48 const ReductionDomain &rdom, bool is_init);
49
50 /** Construct a Definition with deserialized data. */
51 Definition(bool is_init, const Expr &predicate, const std::vector<Expr> &args, const std::vector<Expr> &values,
52 const StageSchedule &schedule, const std::vector<Specialization> &specializations);
53
54 /** Construct an undefined Definition object. */
56
57 /** Return a copy of this Definition. */
59
60 /** Equality of identity */
61 bool same_as(const Definition &other) const {
62 return contents.same_as(other.contents);
63 }
64
65 /** Definition objects are nullable. Does this definition exist? */
66 bool defined() const;
67
68 /** Is this an init definition; otherwise it's an update definition */
69 bool is_init() const;
70
71 /** Pass an IRVisitor through to all Exprs referenced in the
72 * definition. */
73 void accept(IRVisitor *) const;
74
75 /** Pass an IRMutator through to all Exprs referenced in the
76 * definition. */
78
79 /** Get the default (no-specialization) arguments (left-hand-side) of the definition.
80 *
81 * Warning: Any Vars in the Exprs are not qualified with the Func name, so
82 * the Exprs may contain names which collide with names provided by
83 * unique_name.
84 */
85 // @{
86 const std::vector<Expr> &args() const;
87 std::vector<Expr> &args();
88 // @}
89
90 /** Get the default (no-specialization) right-hand-side of the definition.
91 *
92 * Warning: Any Vars in the Exprs are not qualified with the Func name, so
93 * the Exprs may contain names which collide with names provided by
94 * unique_name.
95 */
96 // @{
97 const std::vector<Expr> &values() const;
98 std::vector<Expr> &values();
99 // @}
100
101 /** Get the predicate on the definition */
102 // @{
103 const Expr &predicate() const;
105 // @}
106
107 /** Split predicate into vector of ANDs. If there is no predicate (i.e. this
108 * definition is always valid), this returns an empty vector. */
109 std::vector<Expr> split_predicate() const;
110
111 /** Get the default (no-specialization) stage-specific schedule associated
112 * with this definition. */
113 // @{
114 const StageSchedule &schedule() const;
116 // @}
117
118 /** You may create several specialized versions of a func with
119 * different stage-specific schedules. They trigger when the condition is
120 * true. See \ref Func::specialize */
121 // @{
122 const std::vector<Specialization> &specializations() const;
123 std::vector<Specialization> &specializations();
125 // @}
126};
127
131 std::string failure_message; // If non-empty, this specialization always assert-fails with this message.
132};
133
134} // namespace Internal
135} // namespace Halide
136
137#endif
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Support classes for reference-counting via intrusive shared pointers.
Defines the internal representation of the schedule for a function.
A Function definition which can either represent a init or an update definition.
Definition Definition.h:38
const std::vector< Expr > & values() const
Get the default (no-specialization) right-hand-side of the definition.
bool same_as(const Definition &other) const
Equality of identity.
Definition Definition.h:61
std::vector< Expr > split_predicate() const
Split predicate into vector of ANDs.
std::vector< Expr > & args()
Definition(bool is_init, const Expr &predicate, const std::vector< Expr > &args, const std::vector< Expr > &values, const StageSchedule &schedule, const std::vector< Specialization > &specializations)
Construct a Definition with deserialized data.
Definition(const IntrusivePtr< DefinitionContents > &)
Construct a Definition from an existing DefinitionContents pointer.
const Expr & predicate() const
Get the predicate on the definition.
const Specialization & add_specialization(Expr condition)
Definition()
Construct an undefined Definition object.
std::vector< Expr > & values()
StageSchedule & schedule()
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the definition.
const std::vector< Expr > & args() const
Get the default (no-specialization) arguments (left-hand-side) of the definition.
bool is_init() const
Is this an init definition; otherwise it's an update definition.
const std::vector< Specialization > & specializations() const
You may create several specialized versions of a func with different stage-specific schedules.
const StageSchedule & schedule() const
Get the default (no-specialization) stage-specific schedule associated with this definition.
bool defined() const
Definition objects are nullable.
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the definition.
Definition get_copy() const
Return a copy of this Definition.
std::vector< Specialization > & specializations()
Definition(const std::vector< Expr > &args, const std::vector< Expr > &values, const ReductionDomain &rdom, bool is_init)
Construct a Definition with the supplied args, values, and reduction domain.
A base class for passes over the IR which modify it (e.g.
Definition IRMutator.h:26
A base class for algorithms that need to recursively walk over the IR.
Definition IRVisitor.h:19
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition Reduction.h:33
A schedule for a single stage of a Halide pipeline.
Definition Schedule.h:698
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
Intrusive shared pointers have a reference count (a RefCount object) stored in the class itself.
HALIDE_ALWAYS_INLINE bool same_as(const IntrusivePtr &other) const