Halide  17.0.2
Halide compiler and libraries
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 
14 namespace Halide {
15 
16 namespace Internal {
17 struct DefinitionContents;
18 struct FunctionContents;
19 class ReductionDomain;
20 } // namespace Internal
21 
22 namespace Internal {
23 
24 class IRVisitor;
25 class IRMutator;
26 struct 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  */
38 class Definition {
39 
41 
42 public:
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, const std::string &source_location);
53 
54  /** Construct an undefined Definition object. */
55  Definition();
56 
57  /** Return a copy of this Definition. */
58  Definition get_copy() const;
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. */
77  void mutate(IRMutator *);
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;
104  Expr &predicate();
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();
124  const Specialization &add_specialization(Expr condition);
125  // @}
126 
127  /** Attempt to get the source file and line where this definition
128  * was made using DWARF introspection. Returns an empty string if
129  * no debug symbols were found or the debug symbols were not
130  * understood. Works on OS X and Linux only. */
131  std::string source_location() const;
132 };
133 
137  std::string failure_message; // If non-empty, this specialization always assert-fails with this message.
138 };
139 
140 } // namespace Internal
141 } // namespace Halide
142 
143 #endif
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the definition.
A base class for algorithms that need to recursively walk over the IR.
Definition: IRVisitor.h:19
A schedule for a single stage of a Halide pipeline.
Definition: Schedule.h:695
A fragment of Halide syntax.
Definition: Expr.h:258
bool same_as(const Definition &other) const
Equality of identity.
Definition: Definition.h:61
const Expr & predicate() const
Get the predicate on the definition.
Definition()
Construct an undefined Definition object.
const std::vector< Expr > & args() const
Get the default (no-specialization) arguments (left-hand-side) of the definition. ...
This file defines the class FunctionDAG, which is our representation of a Halide pipeline, and contains methods to using Halide&#39;s bounds tools to query properties of it.
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the definition.
bool is_init() const
Is this an init definition; otherwise it&#39;s an update definition.
const std::vector< Specialization > & specializations() const
You may create several specialized versions of a func with different stage-specific schedules...
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt) ...
std::vector< Expr > split_predicate() const
Split predicate into vector of ANDs.
Not visible externally, similar to &#39;static&#39; linkage in C.
Support classes for reference-counting via intrusive shared pointers.
Defines the internal representation of the schedule for a function.
bool defined() const
Definition objects are nullable.
const StageSchedule & schedule() const
Get the default (no-specialization) stage-specific schedule associated with this definition.
std::string source_location() const
Attempt to get the source file and line where this definition was made using DWARF introspection...
HALIDE_ALWAYS_INLINE bool same_as(const IntrusivePtr &other) const
Definition: IntrusivePtr.h:168
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition: Reduction.h:33
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.
Definition get_copy() const
Return a copy of this Definition.
A base class for passes over the IR which modify it (e.g.
Definition: IRMutator.h:26
const Specialization & add_specialization(Expr condition)
You may create several specialized versions of a func with different stage-specific schedules...