Halide
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 an undefined Definition object. */
51  Definition();
52 
53  /** Return a copy of this Definition. */
54  Definition get_copy() const;
55 
56  /** Equality of identity */
57  bool same_as(const Definition &other) const {
58  return contents.same_as(other.contents);
59  }
60 
61  /** Definition objects are nullable. Does this definition exist? */
62  bool defined() const;
63 
64  /** Is this an init definition; otherwise it's an update definition */
65  bool is_init() const;
66 
67  /** Pass an IRVisitor through to all Exprs referenced in the
68  * definition. */
69  void accept(IRVisitor *) const;
70 
71  /** Pass an IRMutator through to all Exprs referenced in the
72  * definition. */
73  void mutate(IRMutator *);
74 
75  /** Get the default (no-specialization) arguments (left-hand-side) of the definition */
76  // @{
77  const std::vector<Expr> &args() const;
78  std::vector<Expr> &args();
79  // @}
80 
81  /** Get the default (no-specialization) right-hand-side of the definition */
82  // @{
83  const std::vector<Expr> &values() const;
84  std::vector<Expr> &values();
85  // @}
86 
87  /** Get the predicate on the definition */
88  // @{
89  const Expr &predicate() const;
90  Expr &predicate();
91  // @}
92 
93  /** Split predicate into vector of ANDs. If there is no predicate (i.e. this
94  * definition is always valid), this returns an empty vector. */
95  std::vector<Expr> split_predicate() const;
96 
97  /** Get the default (no-specialization) stage-specific schedule associated
98  * with this definition. */
99  // @{
100  const StageSchedule &schedule() const;
102  // @}
103 
104  /** You may create several specialized versions of a func with
105  * different stage-specific schedules. They trigger when the condition is
106  * true. See \ref Func::specialize */
107  // @{
108  const std::vector<Specialization> &specializations() const;
109  std::vector<Specialization> &specializations();
110  const Specialization &add_specialization(Expr condition);
111  // @}
112 
113  /** Attempt to get the source file and line where this definition
114  * was made using DWARF introspection. Returns an empty string if
115  * no debug symbols were found or the debug symbols were not
116  * understood. Works on OS X and Linux only. */
117  std::string source_location() const;
118 };
119 
123  std::string failure_message; // If non-empty, this specialization always assert-fails with this message.
124 };
125 
126 } // namespace Internal
127 } // namespace Halide
128 
129 #endif
Halide::Internal::Definition::values
const std::vector< Expr > & values() const
Get the default (no-specialization) right-hand-side of the definition.
Halide::Internal::IRVisitor
A base class for algorithms that need to recursively walk over the IR.
Definition: IRVisitor.h:21
Halide::Internal::Specialization::definition
Definition definition
Definition: Definition.h:122
Halide::Internal::Specialization
Definition: Definition.h:120
Schedule.h
Halide::Internal::Definition
A Function definition which can either represent a init or an update definition.
Definition: Definition.h:38
Halide::Internal::IntrusivePtr< DefinitionContents >
Halide::Internal::Specialization::failure_message
std::string failure_message
Definition: Definition.h:123
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::Internal::Definition::split_predicate
std::vector< Expr > split_predicate() const
Split predicate into vector of ANDs.
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Internal::Definition::args
const std::vector< Expr > & args() const
Get the default (no-specialization) arguments (left-hand-side) of the definition.
Halide::Internal::Specialization::condition
Expr condition
Definition: Definition.h:121
Halide::Internal::Definition::source_location
std::string source_location() const
Attempt to get the source file and line where this definition was made using DWARF introspection.
Halide::Internal::Definition::defined
bool defined() const
Definition objects are nullable.
Halide::Internal::Definition::accept
void accept(IRVisitor *) const
Pass an IRVisitor through to all Exprs referenced in the definition.
Expr.h
Halide::Internal::IRMutator
A base class for passes over the IR which modify it (e.g.
Definition: IRMutator.h:24
Halide::Internal::Definition::is_init
bool is_init() const
Is this an init definition; otherwise it's an update definition.
Halide::Internal::Definition::specializations
const std::vector< Specialization > & specializations() const
You may create several specialized versions of a func with different stage-specific schedules.
Halide::Internal::Definition::schedule
const StageSchedule & schedule() const
Get the default (no-specialization) stage-specific schedule associated with this definition.
Halide::Internal::Definition::add_specialization
const Specialization & add_specialization(Expr condition)
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
Halide::Internal::Definition::Definition
Definition()
Construct an undefined Definition object.
Halide::Internal::Definition::mutate
void mutate(IRMutator *)
Pass an IRMutator through to all Exprs referenced in the definition.
Halide::Internal::StageSchedule
A schedule for a single stage of a Halide pipeline.
Definition: Schedule.h:604
Halide::Internal::ReductionDomain
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition: Reduction.h:33
IntrusivePtr.h
Halide::Internal::Definition::same_as
bool same_as(const Definition &other) const
Equality of identity.
Definition: Definition.h:57
Halide::Internal::Definition::predicate
const Expr & predicate() const
Get the predicate on the definition.
Halide::Internal::Definition::get_copy
Definition get_copy() const
Return a copy of this Definition.
Halide::Internal::IntrusivePtr::same_as
HALIDE_ALWAYS_INLINE bool same_as(const IntrusivePtr &other) const
Definition: IntrusivePtr.h:163