Halide  14.0.0
Halide compiler and libraries
IR.h
Go to the documentation of this file.
1 #ifndef HALIDE_IR_H
2 #define HALIDE_IR_H
3 
4 /** \file
5  * Subtypes for Halide expressions (\ref Halide::Expr) and statements (\ref Halide::Internal::Stmt)
6  */
7 
8 #include <string>
9 #include <vector>
10 
11 #include "Buffer.h"
12 #include "Expr.h"
13 #include "FunctionPtr.h"
14 #include "ModulusRemainder.h"
15 #include "Parameter.h"
16 #include "PrefetchDirective.h"
17 #include "Reduction.h"
18 #include "Type.h"
19 
20 namespace Halide {
21 namespace Internal {
22 
23 class Function;
24 
25 /** The actual IR nodes begin here. Remember that all the Expr
26  * nodes also have a public "type" property */
27 
28 /** Cast a node from one type to another. Can't change vector widths. */
29 struct Cast : public ExprNode<Cast> {
31 
32  static Expr make(Type t, Expr v);
33 
35 };
36 
37 /** The sum of two expressions */
38 struct Add : public ExprNode<Add> {
39  Expr a, b;
40 
41  static Expr make(Expr a, Expr b);
42 
44 };
45 
46 /** The difference of two expressions */
47 struct Sub : public ExprNode<Sub> {
48  Expr a, b;
49 
50  static Expr make(Expr a, Expr b);
51 
53 };
54 
55 /** The product of two expressions */
56 struct Mul : public ExprNode<Mul> {
57  Expr a, b;
58 
59  static Expr make(Expr a, Expr b);
60 
62 };
63 
64 /** The ratio of two expressions */
65 struct Div : public ExprNode<Div> {
66  Expr a, b;
67 
68  static Expr make(Expr a, Expr b);
69 
71 };
72 
73 /** The remainder of a / b. Mostly equivalent to '%' in C, except that
74  * the result here is always positive. For floats, this is equivalent
75  * to calling fmod. */
76 struct Mod : public ExprNode<Mod> {
77  Expr a, b;
78 
79  static Expr make(Expr a, Expr b);
80 
82 };
83 
84 /** The lesser of two values. */
85 struct Min : public ExprNode<Min> {
86  Expr a, b;
87 
88  static Expr make(Expr a, Expr b);
89 
91 };
92 
93 /** The greater of two values */
94 struct Max : public ExprNode<Max> {
95  Expr a, b;
96 
97  static Expr make(Expr a, Expr b);
98 
100 };
101 
102 /** Is the first expression equal to the second */
103 struct EQ : public ExprNode<EQ> {
104  Expr a, b;
105 
106  static Expr make(Expr a, Expr b);
107 
109 };
110 
111 /** Is the first expression not equal to the second */
112 struct NE : public ExprNode<NE> {
113  Expr a, b;
114 
115  static Expr make(Expr a, Expr b);
116 
118 };
119 
120 /** Is the first expression less than the second. */
121 struct LT : public ExprNode<LT> {
122  Expr a, b;
123 
124  static Expr make(Expr a, Expr b);
125 
127 };
128 
129 /** Is the first expression less than or equal to the second. */
130 struct LE : public ExprNode<LE> {
131  Expr a, b;
132 
133  static Expr make(Expr a, Expr b);
134 
136 };
137 
138 /** Is the first expression greater than the second. */
139 struct GT : public ExprNode<GT> {
140  Expr a, b;
141 
142  static Expr make(Expr a, Expr b);
143 
145 };
146 
147 /** Is the first expression greater than or equal to the second. */
148 struct GE : public ExprNode<GE> {
149  Expr a, b;
150 
151  static Expr make(Expr a, Expr b);
152 
154 };
155 
156 /** Logical and - are both expressions true */
157 struct And : public ExprNode<And> {
158  Expr a, b;
159 
160  static Expr make(Expr a, Expr b);
161 
163 };
164 
165 /** Logical or - is at least one of the expression true */
166 struct Or : public ExprNode<Or> {
167  Expr a, b;
168 
169  static Expr make(Expr a, Expr b);
170 
172 };
173 
174 /** Logical not - true if the expression false */
175 struct Not : public ExprNode<Not> {
177 
178  static Expr make(Expr a);
179 
181 };
182 
183 /** A ternary operator. Evalutes 'true_value' and 'false_value',
184  * then selects between them based on 'condition'. Equivalent to
185  * the ternary operator in C. */
186 struct Select : public ExprNode<Select> {
188 
190 
192 };
193 
194 /** Load a value from a named symbol if predicate is true. The buffer
195  * is treated as an array of the 'type' of this Load node. That is,
196  * the buffer has no inherent type. The name may be the name of an
197  * enclosing allocation, an input or output buffer, or any other
198  * symbol of type Handle(). */
199 struct Load : public ExprNode<Load> {
200  std::string name;
201 
203 
204  // If it's a load from an image argument or compiled-in constant
205  // image, this will point to that
207 
208  // If it's a load from an image parameter, this points to that
210 
211  // The alignment of the index. If the index is a vector, this is
212  // the alignment of the first lane.
214 
215  static Expr make(Type type, const std::string &name,
218  Expr predicate,
220 
222 };
223 
224 /** A linear ramp vector node. This is vector with 'lanes' elements,
225  * where element i is 'base' + i*'stride'. This is a convenient way to
226  * pass around vectors without busting them up into individual
227  * elements. E.g. a dense vector load from a buffer can use a ramp
228  * node with stride 1 as the index. */
229 struct Ramp : public ExprNode<Ramp> {
231  int lanes;
232 
233  static Expr make(Expr base, Expr stride, int lanes);
234 
236 };
237 
238 /** A vector with 'lanes' elements, in which every element is
239  * 'value'. This is a special case of the ramp node above, in which
240  * the stride is zero. */
241 struct Broadcast : public ExprNode<Broadcast> {
243  int lanes;
244 
245  static Expr make(Expr value, int lanes);
246 
248 };
249 
250 /** A let expression, like you might find in a functional
251  * language. Within the expression \ref Let::body, instances of the Var
252  * node \ref Let::name refer to \ref Let::value. */
253 struct Let : public ExprNode<Let> {
254  std::string name;
256 
257  static Expr make(const std::string &name, Expr value, Expr body);
258 
260 };
261 
262 /** The statement form of a let node. Within the statement 'body',
263  * instances of the Var named 'name' refer to 'value' */
264 struct LetStmt : public StmtNode<LetStmt> {
265  std::string name;
268 
269  static Stmt make(const std::string &name, Expr value, Stmt body);
270 
272 };
273 
274 /** If the 'condition' is false, then evaluate and return the message,
275  * which should be a call to an error function. */
276 struct AssertStmt : public StmtNode<AssertStmt> {
277  // if condition then val else error out with message
280 
282 
284 };
285 
286 /** This node is a helpful annotation to do with permissions. If 'is_produce' is
287  * set to true, this represents a producer node which may also contain updates;
288  * otherwise, this represents a consumer node. If the producer node contains
289  * updates, the body of the node will be a block of 'produce' and 'update'
290  * in that order. In a producer node, the access is read-write only (or write
291  * only if it doesn't have updates). In a consumer node, the access is read-only.
292  * None of this is actually enforced, the node is purely for informative purposes
293  * to help out our analysis during lowering. For every unique ProducerConsumer,
294  * there is an associated Realize node with the same name that creates the buffer
295  * being read from or written to in the body of the ProducerConsumer.
296  */
297 struct ProducerConsumer : public StmtNode<ProducerConsumer> {
298  std::string name;
301 
302  static Stmt make(const std::string &name, bool is_producer, Stmt body);
303 
304  static Stmt make_produce(const std::string &name, Stmt body);
305  static Stmt make_consume(const std::string &name, Stmt body);
306 
308 };
309 
310 /** Store a 'value' to the buffer called 'name' at a given 'index' if
311  * 'predicate' is true. The buffer is interpreted as an array of the
312  * same type as 'value'. The name may be the name of an enclosing
313  * Allocate node, an output buffer, or any other symbol of type
314  * Handle(). */
315 struct Store : public StmtNode<Store> {
316  std::string name;
318  // If it's a store to an output buffer, then this parameter points to it.
320 
321  // The alignment of the index. If the index is a vector, this is
322  // the alignment of the first lane.
324 
325  static Stmt make(const std::string &name, Expr value, Expr index,
327 
329 };
330 
331 /** This defines the value of a function at a multi-dimensional
332  * location. You should think of it as a store to a multi-dimensional
333  * array. It gets lowered to a conventional Store node. The name must
334  * correspond to an output buffer or the name of an enclosing Realize
335  * node. */
336 struct Provide : public StmtNode<Provide> {
337  std::string name;
338  std::vector<Expr> values;
339  std::vector<Expr> args;
341 
342  static Stmt make(const std::string &name, const std::vector<Expr> &values, const std::vector<Expr> &args, const Expr &predicate);
343 
345 };
346 
347 /** Allocate a scratch area called with the given name, type, and
348  * size. The buffer lives for at most the duration of the body
349  * statement, within which it may or may not be freed explicitly with
350  * a Free node with a matching name. Allocation only occurs if the
351  * condition evaluates to true. Within the body of the allocation,
352  * defines a symbol with the given name and the type Handle(). */
353 struct Allocate : public StmtNode<Allocate> {
354  std::string name;
357  std::vector<Expr> extents;
359 
360  // These override the code generator dependent malloc and free
361  // equivalents if provided. If the new_expr succeeds, that is it
362  // returns non-nullptr, the function named be free_function is
363  // guaranteed to be called. The free function signature must match
364  // that of the code generator dependent free (typically
365  // halide_free). If free_function is left empty, code generator
366  // default will be called.
368  std::string free_function;
369 
371 
372  static Stmt make(const std::string &name, Type type, MemoryType memory_type,
373  const std::vector<Expr> &extents,
375  Expr new_expr = Expr(), const std::string &free_function = std::string());
376 
377  /** A routine to check if the extents are all constants, and if so verify
378  * the total size is less than 2^31 - 1. If the result is constant, but
379  * overflows, this routine asserts. This returns 0 if the extents are
380  * not all constants; otherwise, it returns the total constant allocation
381  * size. */
382  static int32_t constant_allocation_size(const std::vector<Expr> &extents, const std::string &name);
384 
386 };
387 
388 /** Free the resources associated with the given buffer. */
389 struct Free : public StmtNode<Free> {
390  std::string name;
391 
392  static Stmt make(const std::string &name);
393 
395 };
396 
397 /** Allocate a multi-dimensional buffer of the given type and
398  * size. Create some scratch memory that will back the function 'name'
399  * over the range specified in 'bounds'. The bounds are a vector of
400  * (min, extent) pairs for each dimension. Allocation only occurs if
401  * the condition evaluates to true.
402  */
403 struct Realize : public StmtNode<Realize> {
404  std::string name;
405  std::vector<Type> types;
410 
411  static Stmt make(const std::string &name, const std::vector<Type> &types, MemoryType memory_type, const Region &bounds, Expr condition, Stmt body);
412 
414 };
415 
416 /** A sequence of statements to be executed in-order. 'first' is never
417  a Block, so this can be treated as a linked list. */
418 struct Block : public StmtNode<Block> {
420 
422 
423  /** Construct zero or more Blocks to invoke a list of statements in order.
424  * This method may not return a Block statement if stmts.size() <= 1. */
425  static Stmt make(const std::vector<Stmt> &stmts);
426 
428 };
429 
430 /** A pair of statements executed concurrently. Both statements are
431  * joined before the Stmt ends. This is the parallel equivalent to
432  * Block. */
433 struct Fork : public StmtNode<Fork> {
435 
437 
439 };
440 
441 /** An if-then-else block. 'else' may be undefined. */
442 struct IfThenElse : public StmtNode<IfThenElse> {
445 
447 
449 };
450 
451 /** Evaluate and discard an expression, presumably because it has some side-effect. */
452 struct Evaluate : public StmtNode<Evaluate> {
454 
455  static Stmt make(Expr v);
456 
458 };
459 
460 /** A function call. This can represent a call to some extern function
461  * (like sin), but it's also our multi-dimensional version of a Load,
462  * so it can be a load from an input image, or a call to another
463  * halide function. These two types of call nodes don't survive all
464  * the way down to code generation - the lowering process converts
465  * them to Load nodes. */
466 struct Call : public ExprNode<Call> {
467  std::string name;
468  std::vector<Expr> args;
469  typedef enum { Image, ///< A load from an input image
470  Extern, ///< A call to an external C-ABI function, possibly with side-effects
471  ExternCPlusPlus, ///< A call to an external C-ABI function, possibly with side-effects
472  PureExtern, ///< A call to a guaranteed-side-effect-free external function
473  Halide, ///< A call to a Func
474  Intrinsic, ///< A possibly-side-effecty compiler intrinsic, which has special handling during codegen
475  PureIntrinsic ///< A side-effect-free version of the above.
478 
479  // Halide uses calls internally to represent certain operations
480  // (instead of IR nodes). These are matched by name. Note that
481  // these are deliberately char* (rather than std::string) so that
482  // they can be referenced at static-initialization time without
483  // risking ambiguous initalization order; we use a typedef to simplify
484  // declaration.
485  typedef const char *const ConstString;
486 
487  // enums for various well-known intrinsics. (It is not *required* that all
488  // intrinsics have an enum entry here, but as a matter of style, it is recommended.)
489  // Note that these are only used in the API; inside the node, they are translated
490  // into a name. (To recover the name, call get_intrinsic_name().)
491  //
492  // Please keep this list sorted alphabetically; the specific enum values
493  // are *not* guaranteed to be stable across time.
494  enum IntrinsicOp {
504  bundle, // Bundle multiple exprs together temporarily for analysis (e.g. CSE)
558  sorted_avg, // Compute (arg[0] + arg[1]) / 2, assuming arg[0] < arg[1].
569 
570  IntrinsicOpCount // Sentinel: keep last.
571  };
572 
573  static const char *get_intrinsic_name(IntrinsicOp op);
574 
575  // We also declare some symbolic names for some of the runtime
576  // functions that we want to construct Call nodes to here to avoid
577  // magic string constants and the potential risk of typos.
599 
600  // If it's a call to another halide function, this call node holds
601  // a possibly-weak reference to that function.
603 
604  // If that function has multiple values, which value does this
605  // call node refer to?
607 
608  // If it's a call to an image, this call nodes hold a
609  // pointer to that image's buffer
611 
612  // If it's a call to an image parameter, this call node holds a
613  // pointer to that
615 
616  static Expr make(Type type, IntrinsicOp op, const std::vector<Expr> &args, CallType call_type,
618  const Buffer<> &image = Buffer<>(), Parameter param = Parameter());
619 
620  static Expr make(Type type, const std::string &name, const std::vector<Expr> &args, CallType call_type,
623 
624  /** Convenience constructor for calls to other halide functions */
625  static Expr make(const Function &func, const std::vector<Expr> &args, int idx = 0);
626 
627  /** Convenience constructor for loads from concrete images */
628  static Expr make(const Buffer<> &image, const std::vector<Expr> &args) {
629  return make(image.type(), image.name(), args, Image, FunctionPtr(), 0, image, Parameter());
630  }
631 
632  /** Convenience constructor for loads from images parameters */
633  static Expr make(const Parameter &param, const std::vector<Expr> &args) {
634  return make(param.type(), param.name(), args, Image, FunctionPtr(), 0, Buffer<>(), param);
635  }
636 
637  /** Check if a call node is pure within a pipeline, meaning that
638  * the same args always give the same result, and the calls can be
639  * reordered, duplicated, unified, etc without changing the
640  * meaning of anything. Not transitive - doesn't guarantee the
641  * args themselves are pure. An example of a pure Call node is
642  * sqrt. If in doubt, don't mark a Call node as pure. */
643  bool is_pure() const {
644  return (call_type == PureExtern ||
645  call_type == Image ||
647  }
648 
649  bool is_intrinsic() const {
650  return (call_type == Intrinsic ||
652  }
653 
654  bool is_intrinsic(IntrinsicOp op) const {
655  return is_intrinsic() && this->name == get_intrinsic_name(op);
656  }
657 
658  bool is_intrinsic(std::initializer_list<IntrinsicOp> intrinsics) const {
659  for (IntrinsicOp i : intrinsics) {
660  if (is_intrinsic(i)) {
661  return true;
662  }
663  }
664  return false;
665  }
666 
667  bool is_tag() const {
669  }
670 
671  /** Returns a pointer to a call node if the expression is a call to
672  * one of the requested intrinsics. */
673  static const Call *as_intrinsic(const Expr &e, std::initializer_list<IntrinsicOp> intrinsics) {
674  if (const Call *c = e.as<Call>()) {
675  for (IntrinsicOp i : intrinsics) {
676  if (c->is_intrinsic(i)) {
677  return c;
678  }
679  }
680  }
681  return nullptr;
682  }
683 
684  static const Call *as_tag(const Expr &e) {
686  }
687 
688  bool is_extern() const {
689  return (call_type == Extern ||
691  call_type == PureExtern);
692  }
693 
695 };
696 
697 /** A named variable. Might be a loop variable, function argument,
698  * parameter, reduction variable, or something defined by a Let or
699  * LetStmt node. */
700 struct Variable : public ExprNode<Variable> {
701  std::string name;
702 
703  /** References to scalar parameters, or to the dimensions of buffer
704  * parameters hang onto those expressions. */
706 
707  /** References to properties of literal image parameters. */
709 
710  /** Reduction variables hang onto their domains */
712 
713  static Expr make(Type type, const std::string &name) {
714  return make(type, name, Buffer<>(), Parameter(), ReductionDomain());
715  }
716 
717  static Expr make(Type type, const std::string &name, Parameter param) {
718  return make(type, name, Buffer<>(), std::move(param), ReductionDomain());
719  }
720 
721  static Expr make(Type type, const std::string &name, const Buffer<> &image) {
722  return make(type, name, image, Parameter(), ReductionDomain());
723  }
724 
725  static Expr make(Type type, const std::string &name, ReductionDomain reduction_domain) {
726  return make(type, name, Buffer<>(), Parameter(), std::move(reduction_domain));
727  }
728 
729  static Expr make(Type type, const std::string &name, Buffer<> image,
731 
733 };
734 
735 /** A for loop. Execute the 'body' statement for all values of the
736  * variable 'name' from 'min' to 'min + extent'. There are four
737  * types of For nodes. A 'Serial' for loop is a conventional
738  * one. In a 'Parallel' for loop, each iteration of the loop
739  * happens in parallel or in some unspecified order. In a
740  * 'Vectorized' for loop, each iteration maps to one SIMD lane,
741  * and the whole loop is executed in one shot. For this case,
742  * 'extent' must be some small integer constant (probably 4, 8, or
743  * 16). An 'Unrolled' for loop compiles to a completely unrolled
744  * version of the loop. Each iteration becomes its own
745  * statement. Again in this case, 'extent' should be a small
746  * integer constant. */
747 struct For : public StmtNode<For> {
748  std::string name;
753 
755 
756  bool is_unordered_parallel() const {
758  }
759  bool is_parallel() const {
761  }
762 
764 };
765 
766 struct Acquire : public StmtNode<Acquire> {
770 
772 
774 };
775 
776 /** Construct a new vector by taking elements from another sequence of
777  * vectors. */
778 struct Shuffle : public ExprNode<Shuffle> {
779  std::vector<Expr> vectors;
780 
781  /** Indices indicating which vector element to place into the
782  * result. The elements are numbered by their position in the
783  * concatenation of the vector arguments. */
784  std::vector<int> indices;
785 
786  static Expr make(const std::vector<Expr> &vectors,
787  const std::vector<int> &indices);
788 
789  /** Convenience constructor for making a shuffle representing an
790  * interleaving of vectors of the same length. */
791  static Expr make_interleave(const std::vector<Expr> &vectors);
792 
793  /** Convenience constructor for making a shuffle representing a
794  * concatenation of the vectors. */
795  static Expr make_concat(const std::vector<Expr> &vectors);
796 
797  /** Convenience constructor for making a shuffle representing a
798  * broadcast of a vector. */
799  static Expr make_broadcast(Expr vector, int factor);
800 
801  /** Convenience constructor for making a shuffle representing a
802  * contiguous subset of a vector. */
803  static Expr make_slice(Expr vector, int begin, int stride, int size);
804 
805  /** Convenience constructor for making a shuffle representing
806  * extracting a single element. */
807  static Expr make_extract_element(Expr vector, int i);
808 
809  /** Check if this shuffle is an interleaving of the vector
810  * arguments. */
811  bool is_interleave() const;
812 
813  /** Check if this shuffle can be represented as a broadcast.
814  * For example:
815  * A uint8 shuffle of with 4*n lanes and indices:
816  * 0, 1, 2, 3, 0, 1, 2, 3, ....., 0, 1, 2, 3
817  * can be represented as a uint32 broadcast with n lanes (factor = 4). */
818  bool is_broadcast() const;
819  int broadcast_factor() const;
820 
821  /** Check if this shuffle is a concatenation of the vector
822  * arguments. */
823  bool is_concat() const;
824 
825  /** Check if this shuffle is a contiguous strict subset of the
826  * vector arguments, and if so, the offset and stride of the
827  * slice. */
828  ///@{
829  bool is_slice() const;
830  int slice_begin() const {
831  return indices[0];
832  }
833  int slice_stride() const {
834  return indices.size() >= 2 ? indices[1] - indices[0] : 1;
835  }
836  ///@}
837 
838  /** Check if this shuffle is extracting a scalar from the vector
839  * arguments. */
840  bool is_extract_element() const;
841 
843 };
844 
845 /** Represent a multi-dimensional region of a Func or an ImageParam that
846  * needs to be prefetched. */
847 struct Prefetch : public StmtNode<Prefetch> {
848  std::string name;
849  std::vector<Type> types;
853 
855 
856  static Stmt make(const std::string &name, const std::vector<Type> &types,
857  const Region &bounds,
860 
862 };
863 
864 /** Lock all the Store nodes in the body statement.
865  * Typically the lock is implemented by an atomic operation
866  * (e.g. atomic add or atomic compare-and-swap).
867  * However, if necessary, the node can access a mutex buffer through
868  * mutex_name and mutex_args, by lowering this node into
869  * calls to acquire and release the lock. */
870 struct Atomic : public StmtNode<Atomic> {
871  std::string producer_name;
872  std::string mutex_name; // empty string if not using mutex
874 
875  static Stmt make(const std::string &producer_name,
876  const std::string &mutex_name,
877  Stmt body);
878 
880 };
881 
882 /** Horizontally reduce a vector to a scalar or narrower vector using
883  * the given commutative and associative binary operator. The reduction
884  * factor is dictated by the number of lanes in the input and output
885  * types. Groups of adjacent lanes are combined. The number of lanes
886  * in the input type must be a divisor of the number of lanes of the
887  * output type. */
888 struct VectorReduce : public ExprNode<VectorReduce> {
889  // 99.9% of the time people will use this for horizontal addition,
890  // but these are all of our commutative and associative primitive
891  // operators.
892  typedef enum {
899  Or,
900  } Operator;
901 
904 
905  static Expr make(Operator op, Expr vec, int lanes);
906 
908 };
909 
910 } // namespace Internal
911 } // namespace Halide
912 
913 #endif
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Routines for statically determining what expressions are divisible by.
Defines the internal representation of parameters to halide piplines.
Defines the PrefetchDirective struct.
Defines internal classes related to Reduction Domains.
Defines halide types.
#define HALIDE_EXPORT
Definition: Util.h:37
A Halide::Buffer is a named shared reference to a Halide::Runtime::Buffer.
Definition: Buffer.h:120
Type type() const
Definition: Buffer.h:531
const std::string & name() const
Definition: Buffer.h:365
A reference-counted handle to Halide's internal representation of a function.
Definition: Function.h:38
A reference-counted handle to a parameter to a halide pipeline.
Definition: Parameter.h:28
const std::string & name() const
Get the name of this parameter.
Type type() const
Get the type of this parameter.
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition: Reduction.h:33
ForType
An enum describing a type of loop traversal.
Definition: Expr.h:399
bool is_unordered_parallel(ForType for_type)
Check if for_type executes for loop iterations in parallel and unordered.
bool is_parallel(ForType for_type)
Returns true if for_type executes for loop iterations in parallel.
IRNodeType
All our IR node types get unique IDs for the purposes of RTTI.
Definition: Expr.h:25
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
DeviceAPI
An enum describing a type of device API.
Definition: DeviceAPI.h:15
std::vector< Range > Region
A multi-dimensional box.
Definition: Expr.h:343
MemoryType
An enum describing different address spaces to be used with Func::store_in.
Definition: Expr.h:346
signed __INT32_TYPE__ int32_t
A fragment of Halide syntax.
Definition: Expr.h:256
static const IRNodeType _node_type
Definition: IR.h:773
static Stmt make(Expr semaphore, Expr count, Stmt body)
The sum of two expressions.
Definition: IR.h:38
static Expr make(Expr a, Expr b)
static const IRNodeType _node_type
Definition: IR.h:43
Allocate a scratch area called with the given name, type, and size.
Definition: IR.h:353
std::string name
Definition: IR.h:354
std::vector< Expr > extents
Definition: IR.h:357
static int32_t constant_allocation_size(const std::vector< Expr > &extents, const std::string &name)
A routine to check if the extents are all constants, and if so verify the total size is less than 2^3...
static const IRNodeType _node_type
Definition: IR.h:385
int32_t constant_allocation_size() const
MemoryType memory_type
Definition: IR.h:356
std::string free_function
Definition: IR.h:368
static Stmt make(const std::string &name, Type type, MemoryType memory_type, const std::vector< Expr > &extents, Expr condition, Stmt body, Expr new_expr=Expr(), const std::string &free_function=std::string())
Logical and - are both expressions true.
Definition: IR.h:157
static const IRNodeType _node_type
Definition: IR.h:162
static Expr make(Expr a, Expr b)
If the 'condition' is false, then evaluate and return the message, which should be a call to an error...
Definition: IR.h:276
static const IRNodeType _node_type
Definition: IR.h:283
static Stmt make(Expr condition, Expr message)
Lock all the Store nodes in the body statement.
Definition: IR.h:870
static const IRNodeType _node_type
Definition: IR.h:879
static Stmt make(const std::string &producer_name, const std::string &mutex_name, Stmt body)
std::string mutex_name
Definition: IR.h:872
std::string producer_name
Definition: IR.h:871
A sequence of statements to be executed in-order.
Definition: IR.h:418
static Stmt make(const std::vector< Stmt > &stmts)
Construct zero or more Blocks to invoke a list of statements in order.
static Stmt make(Stmt first, Stmt rest)
static const IRNodeType _node_type
Definition: IR.h:427
A vector with 'lanes' elements, in which every element is 'value'.
Definition: IR.h:241
static Expr make(Expr value, int lanes)
static const IRNodeType _node_type
Definition: IR.h:247
A function call.
Definition: IR.h:466
static Expr make(Type type, const std::string &name, const std::vector< Expr > &args, CallType call_type, FunctionPtr func=FunctionPtr(), int value_index=0, Buffer<> image=Buffer<>(), Parameter param=Parameter())
static HALIDE_EXPORT ConstString buffer_get_max
Definition: IR.h:583
static Expr make(const Function &func, const std::vector< Expr > &args, int idx=0)
Convenience constructor for calls to other halide functions.
static HALIDE_EXPORT ConstString buffer_get_host_dirty
Definition: IR.h:588
static HALIDE_EXPORT ConstString buffer_set_bounds
Definition: IR.h:597
const char *const ConstString
Definition: IR.h:485
bool is_tag() const
Definition: IR.h:667
@ call_cached_indirect_function
Definition: IR.h:505
@ signed_integer_overflow
Definition: IR.h:556
@ unsafe_promise_clamped
Definition: IR.h:563
@ add_image_checks_marker
Definition: IR.h:497
@ rounding_mul_shift_right
Definition: IR.h:547
@ load_typed_struct_member
Definition: IR.h:529
@ size_of_halide_buffer_t
Definition: IR.h:557
bool is_extern() const
Definition: IR.h:688
@ Extern
A call to an external C-ABI function, possibly with side-effects.
Definition: IR.h:470
@ ExternCPlusPlus
A call to an external C-ABI function, possibly with side-effects.
Definition: IR.h:471
@ Image
A load from an input image.
Definition: IR.h:469
@ Halide
A call to a Func.
Definition: IR.h:473
@ Intrinsic
A possibly-side-effecty compiler intrinsic, which has special handling during codegen.
Definition: IR.h:474
@ PureExtern
A call to a guaranteed-side-effect-free external function.
Definition: IR.h:472
@ PureIntrinsic
A side-effect-free version of the above.
Definition: IR.h:475
std::string name
Definition: IR.h:467
static HALIDE_EXPORT ConstString buffer_get_min
Definition: IR.h:580
static const Call * as_intrinsic(const Expr &e, std::initializer_list< IntrinsicOp > intrinsics)
Returns a pointer to a call node if the expression is a call to one of the requested intrinsics.
Definition: IR.h:673
bool is_intrinsic() const
Definition: IR.h:649
static HALIDE_EXPORT ConstString buffer_get_device_interface
Definition: IR.h:586
static HALIDE_EXPORT ConstString buffer_get_dimensions
Definition: IR.h:579
static HALIDE_EXPORT ConstString buffer_get_device_dirty
Definition: IR.h:589
static HALIDE_EXPORT ConstString buffer_crop
Definition: IR.h:596
FunctionPtr func
Definition: IR.h:602
CallType call_type
Definition: IR.h:477
static HALIDE_EXPORT ConstString buffer_get_host
Definition: IR.h:584
static Expr make(const Buffer<> &image, const std::vector< Expr > &args)
Convenience constructor for loads from concrete images.
Definition: IR.h:628
static HALIDE_EXPORT ConstString buffer_get_device
Definition: IR.h:585
static HALIDE_EXPORT ConstString buffer_init
Definition: IR.h:594
bool is_pure() const
Check if a call node is pure within a pipeline, meaning that the same args always give the same resul...
Definition: IR.h:643
static HALIDE_EXPORT ConstString buffer_get_stride
Definition: IR.h:582
static HALIDE_EXPORT ConstString buffer_get_extent
Definition: IR.h:581
bool is_intrinsic(std::initializer_list< IntrinsicOp > intrinsics) const
Definition: IR.h:658
bool is_intrinsic(IntrinsicOp op) const
Definition: IR.h:654
static Expr make(const Parameter &param, const std::vector< Expr > &args)
Convenience constructor for loads from images parameters.
Definition: IR.h:633
static const IRNodeType _node_type
Definition: IR.h:694
static const char * get_intrinsic_name(IntrinsicOp op)
static HALIDE_EXPORT ConstString trace
Definition: IR.h:598
std::vector< Expr > args
Definition: IR.h:468
static HALIDE_EXPORT ConstString buffer_get_shape
Definition: IR.h:587
static Expr make(Type type, IntrinsicOp op, const std::vector< Expr > &args, CallType call_type, FunctionPtr func=FunctionPtr(), int value_index=0, const Buffer<> &image=Buffer<>(), Parameter param=Parameter())
Parameter param
Definition: IR.h:614
static const Call * as_tag(const Expr &e)
Definition: IR.h:684
static HALIDE_EXPORT ConstString buffer_is_bounds_query
Definition: IR.h:593
static HALIDE_EXPORT ConstString buffer_get_type
Definition: IR.h:590
static HALIDE_EXPORT ConstString buffer_set_device_dirty
Definition: IR.h:592
static HALIDE_EXPORT ConstString buffer_set_host_dirty
Definition: IR.h:591
static HALIDE_EXPORT ConstString buffer_init_from_buffer
Definition: IR.h:595
The actual IR nodes begin here.
Definition: IR.h:29
static const IRNodeType _node_type
Definition: IR.h:34
static Expr make(Type t, Expr v)
The ratio of two expressions.
Definition: IR.h:65
static const IRNodeType _node_type
Definition: IR.h:70
static Expr make(Expr a, Expr b)
Is the first expression equal to the second.
Definition: IR.h:103
static const IRNodeType _node_type
Definition: IR.h:108
static Expr make(Expr a, Expr b)
Evaluate and discard an expression, presumably because it has some side-effect.
Definition: IR.h:452
static Stmt make(Expr v)
static const IRNodeType _node_type
Definition: IR.h:457
We use the "curiously recurring template pattern" to avoid duplicated code in the IR Nodes.
Definition: Expr.h:156
A for loop.
Definition: IR.h:747
std::string name
Definition: IR.h:748
DeviceAPI device_api
Definition: IR.h:751
ForType for_type
Definition: IR.h:750
bool is_parallel() const
Definition: IR.h:759
bool is_unordered_parallel() const
Definition: IR.h:756
static const IRNodeType _node_type
Definition: IR.h:763
static Stmt make(const std::string &name, Expr min, Expr extent, ForType for_type, DeviceAPI device_api, Stmt body)
A pair of statements executed concurrently.
Definition: IR.h:433
static Stmt make(Stmt first, Stmt rest)
static const IRNodeType _node_type
Definition: IR.h:438
Free the resources associated with the given buffer.
Definition: IR.h:389
static const IRNodeType _node_type
Definition: IR.h:394
static Stmt make(const std::string &name)
std::string name
Definition: IR.h:390
A possibly-weak pointer to a Halide function.
Definition: FunctionPtr.h:27
Is the first expression greater than or equal to the second.
Definition: IR.h:148
static const IRNodeType _node_type
Definition: IR.h:153
static Expr make(Expr a, Expr b)
Is the first expression greater than the second.
Definition: IR.h:139
static const IRNodeType _node_type
Definition: IR.h:144
static Expr make(Expr a, Expr b)
const T * as() const
Downcast this ir node to its actual type (e.g.
Definition: Expr.h:203
An if-then-else block.
Definition: IR.h:442
static const IRNodeType _node_type
Definition: IR.h:448
static Stmt make(Expr condition, Stmt then_case, Stmt else_case=Stmt())
Is the first expression less than or equal to the second.
Definition: IR.h:130
static Expr make(Expr a, Expr b)
static const IRNodeType _node_type
Definition: IR.h:135
Is the first expression less than the second.
Definition: IR.h:121
static Expr make(Expr a, Expr b)
static const IRNodeType _node_type
Definition: IR.h:126
A let expression, like you might find in a functional language.
Definition: IR.h:253
std::string name
Definition: IR.h:254
static Expr make(const std::string &name, Expr value, Expr body)
static const IRNodeType _node_type
Definition: IR.h:259
The statement form of a let node.
Definition: IR.h:264
static Stmt make(const std::string &name, Expr value, Stmt body)
std::string name
Definition: IR.h:265
static const IRNodeType _node_type
Definition: IR.h:271
Load a value from a named symbol if predicate is true.
Definition: IR.h:199
std::string name
Definition: IR.h:200
static Expr make(Type type, const std::string &name, Expr index, Buffer<> image, Parameter param, Expr predicate, ModulusRemainder alignment)
Parameter param
Definition: IR.h:209
static const IRNodeType _node_type
Definition: IR.h:221
ModulusRemainder alignment
Definition: IR.h:213
The greater of two values.
Definition: IR.h:94
static const IRNodeType _node_type
Definition: IR.h:99
static Expr make(Expr a, Expr b)
The lesser of two values.
Definition: IR.h:85
static const IRNodeType _node_type
Definition: IR.h:90
static Expr make(Expr a, Expr b)
The remainder of a / b.
Definition: IR.h:76
static const IRNodeType _node_type
Definition: IR.h:81
static Expr make(Expr a, Expr b)
The result of modulus_remainder analysis.
The product of two expressions.
Definition: IR.h:56
static const IRNodeType _node_type
Definition: IR.h:61
static Expr make(Expr a, Expr b)
Is the first expression not equal to the second.
Definition: IR.h:112
static const IRNodeType _node_type
Definition: IR.h:117
static Expr make(Expr a, Expr b)
Logical not - true if the expression false.
Definition: IR.h:175
static Expr make(Expr a)
static const IRNodeType _node_type
Definition: IR.h:180
Logical or - is at least one of the expression true.
Definition: IR.h:166
static Expr make(Expr a, Expr b)
static const IRNodeType _node_type
Definition: IR.h:171
Represent a multi-dimensional region of a Func or an ImageParam that needs to be prefetched.
Definition: IR.h:847
static Stmt make(const std::string &name, const std::vector< Type > &types, const Region &bounds, const PrefetchDirective &prefetch, Expr condition, Stmt body)
static const IRNodeType _node_type
Definition: IR.h:861
PrefetchDirective prefetch
Definition: IR.h:851
std::vector< Type > types
Definition: IR.h:849
std::string name
Definition: IR.h:848
This node is a helpful annotation to do with permissions.
Definition: IR.h:297
static const IRNodeType _node_type
Definition: IR.h:307
static Stmt make_consume(const std::string &name, Stmt body)
static Stmt make_produce(const std::string &name, Stmt body)
static Stmt make(const std::string &name, bool is_producer, Stmt body)
This defines the value of a function at a multi-dimensional location.
Definition: IR.h:336
static const IRNodeType _node_type
Definition: IR.h:344
std::string name
Definition: IR.h:337
std::vector< Expr > values
Definition: IR.h:338
std::vector< Expr > args
Definition: IR.h:339
static Stmt make(const std::string &name, const std::vector< Expr > &values, const std::vector< Expr > &args, const Expr &predicate)
A linear ramp vector node.
Definition: IR.h:229
static const IRNodeType _node_type
Definition: IR.h:235
static Expr make(Expr base, Expr stride, int lanes)
Allocate a multi-dimensional buffer of the given type and size.
Definition: IR.h:403
static Stmt make(const std::string &name, const std::vector< Type > &types, MemoryType memory_type, const Region &bounds, Expr condition, Stmt body)
MemoryType memory_type
Definition: IR.h:406
std::vector< Type > types
Definition: IR.h:405
static const IRNodeType _node_type
Definition: IR.h:413
std::string name
Definition: IR.h:404
A ternary operator.
Definition: IR.h:186
static Expr make(Expr condition, Expr true_value, Expr false_value)
static const IRNodeType _node_type
Definition: IR.h:191
Construct a new vector by taking elements from another sequence of vectors.
Definition: IR.h:778
static Expr make_slice(Expr vector, int begin, int stride, int size)
Convenience constructor for making a shuffle representing a contiguous subset of a vector.
bool is_interleave() const
Check if this shuffle is an interleaving of the vector arguments.
static Expr make_extract_element(Expr vector, int i)
Convenience constructor for making a shuffle representing extracting a single element.
bool is_extract_element() const
Check if this shuffle is extracting a scalar from the vector arguments.
bool is_broadcast() const
Check if this shuffle can be represented as a broadcast.
static Expr make_concat(const std::vector< Expr > &vectors)
Convenience constructor for making a shuffle representing a concatenation of the vectors.
static Expr make(const std::vector< Expr > &vectors, const std::vector< int > &indices)
static const IRNodeType _node_type
Definition: IR.h:842
static Expr make_broadcast(Expr vector, int factor)
Convenience constructor for making a shuffle representing a broadcast of a vector.
std::vector< Expr > vectors
Definition: IR.h:779
bool is_concat() const
Check if this shuffle is a concatenation of the vector arguments.
bool is_slice() const
Check if this shuffle is a contiguous strict subset of the vector arguments, and if so,...
std::vector< int > indices
Indices indicating which vector element to place into the result.
Definition: IR.h:784
int slice_stride() const
Check if this shuffle is a contiguous strict subset of the vector arguments, and if so,...
Definition: IR.h:833
static Expr make_interleave(const std::vector< Expr > &vectors)
Convenience constructor for making a shuffle representing an interleaving of vectors of the same leng...
int slice_begin() const
Check if this shuffle is a contiguous strict subset of the vector arguments, and if so,...
Definition: IR.h:830
A reference-counted handle to a statement node.
Definition: Expr.h:417
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
Definition: IR.h:315
std::string name
Definition: IR.h:316
static const IRNodeType _node_type
Definition: IR.h:328
Parameter param
Definition: IR.h:319
ModulusRemainder alignment
Definition: IR.h:323
static Stmt make(const std::string &name, Expr value, Expr index, Parameter param, Expr predicate, ModulusRemainder alignment)
The difference of two expressions.
Definition: IR.h:47
static const IRNodeType _node_type
Definition: IR.h:52
static Expr make(Expr a, Expr b)
A named variable.
Definition: IR.h:700
static Expr make(Type type, const std::string &name, const Buffer<> &image)
Definition: IR.h:721
static Expr make(Type type, const std::string &name, Parameter param)
Definition: IR.h:717
static Expr make(Type type, const std::string &name, Buffer<> image, Parameter param, ReductionDomain reduction_domain)
Buffer image
References to properties of literal image parameters.
Definition: IR.h:708
ReductionDomain reduction_domain
Reduction variables hang onto their domains.
Definition: IR.h:711
static Expr make(Type type, const std::string &name)
Definition: IR.h:713
Parameter param
References to scalar parameters, or to the dimensions of buffer parameters hang onto those expression...
Definition: IR.h:705
static Expr make(Type type, const std::string &name, ReductionDomain reduction_domain)
Definition: IR.h:725
std::string name
Definition: IR.h:701
static const IRNodeType _node_type
Definition: IR.h:732
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
Definition: IR.h:888
static const IRNodeType _node_type
Definition: IR.h:907
static Expr make(Operator op, Expr vec, int lanes)
Types in the halide type system.
Definition: Type.h:266