Halide  12.0.1
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;
340 
341  static Stmt make(const std::string &name, const std::vector<Expr> &values, const std::vector<Expr> &args);
342 
344 };
345 
346 /** Allocate a scratch area called with the given name, type, and
347  * size. The buffer lives for at most the duration of the body
348  * statement, within which it may or may not be freed explicitly with
349  * a Free node with a matching name. Allocation only occurs if the
350  * condition evaluates to true. Within the body of the allocation,
351  * defines a symbol with the given name and the type Handle(). */
352 struct Allocate : public StmtNode<Allocate> {
353  std::string name;
356  std::vector<Expr> extents;
358 
359  // These override the code generator dependent malloc and free
360  // equivalents if provided. If the new_expr succeeds, that is it
361  // returns non-nullptr, the function named be free_function is
362  // guaranteed to be called. The free function signature must match
363  // that of the code generator dependent free (typically
364  // halide_free). If free_function is left empty, code generator
365  // default will be called.
367  std::string free_function;
368 
370 
371  static Stmt make(const std::string &name, Type type, MemoryType memory_type,
372  const std::vector<Expr> &extents,
374  Expr new_expr = Expr(), const std::string &free_function = std::string());
375 
376  /** A routine to check if the extents are all constants, and if so verify
377  * the total size is less than 2^31 - 1. If the result is constant, but
378  * overflows, this routine asserts. This returns 0 if the extents are
379  * not all constants; otherwise, it returns the total constant allocation
380  * size. */
381  static int32_t constant_allocation_size(const std::vector<Expr> &extents, const std::string &name);
383 
385 };
386 
387 /** Free the resources associated with the given buffer. */
388 struct Free : public StmtNode<Free> {
389  std::string name;
390 
391  static Stmt make(const std::string &name);
392 
394 };
395 
396 /** Allocate a multi-dimensional buffer of the given type and
397  * size. Create some scratch memory that will back the function 'name'
398  * over the range specified in 'bounds'. The bounds are a vector of
399  * (min, extent) pairs for each dimension. Allocation only occurs if
400  * the condition evaluates to true.
401  */
402 struct Realize : public StmtNode<Realize> {
403  std::string name;
404  std::vector<Type> types;
409 
410  static Stmt make(const std::string &name, const std::vector<Type> &types, MemoryType memory_type, const Region &bounds, Expr condition, Stmt body);
411 
413 };
414 
415 /** A sequence of statements to be executed in-order. 'rest' may be
416  * undefined. Used rest.defined() to find out. */
417 struct Block : public StmtNode<Block> {
419 
421  /** Construct zero or more Blocks to invoke a list of statements in order.
422  * This method may not return a Block statement if stmts.size() <= 1. */
423  static Stmt make(const std::vector<Stmt> &stmts);
424 
426 };
427 
428 /** A pair of statements executed concurrently. Both statements are
429  * joined before the Stmt ends. This is the parallel equivalent to
430  * Block. */
431 struct Fork : public StmtNode<Fork> {
433 
435 
437 };
438 
439 /** An if-then-else block. 'else' may be undefined. */
440 struct IfThenElse : public StmtNode<IfThenElse> {
443 
445 
447 };
448 
449 /** Evaluate and discard an expression, presumably because it has some side-effect. */
450 struct Evaluate : public StmtNode<Evaluate> {
452 
453  static Stmt make(Expr v);
454 
456 };
457 
458 /** A function call. This can represent a call to some extern function
459  * (like sin), but it's also our multi-dimensional version of a Load,
460  * so it can be a load from an input image, or a call to another
461  * halide function. These two types of call nodes don't survive all
462  * the way down to code generation - the lowering process converts
463  * them to Load nodes. */
464 struct Call : public ExprNode<Call> {
465  std::string name;
466  std::vector<Expr> args;
467  typedef enum { Image, ///< A load from an input image
468  Extern, ///< A call to an external C-ABI function, possibly with side-effects
469  ExternCPlusPlus, ///< A call to an external C-ABI function, possibly with side-effects
470  PureExtern, ///< A call to a guaranteed-side-effect-free external function
471  Halide, ///< A call to a Func
472  Intrinsic, ///< A possibly-side-effecty compiler intrinsic, which has special handling during codegen
473  PureIntrinsic ///< A side-effect-free version of the above.
476 
477  // Halide uses calls internally to represent certain operations
478  // (instead of IR nodes). These are matched by name. Note that
479  // these are deliberately char* (rather than std::string) so that
480  // they can be referenced at static-initialization time without
481  // risking ambiguous initalization order; we use a typedef to simplify
482  // declaration.
483  typedef const char *const ConstString;
484 
485  // enums for various well-known intrinsics. (It is not *required* that all
486  // intrinsics have an enum entry here, but as a matter of style, it is recommended.)
487  // Note that these are only used in the API; inside the node, they are translated
488  // into a name. (To recover the name, call get_intrinsic_name().)
489  //
490  // Please keep this list sorted alphabetically; the specific enum values
491  // are *not* guaranteed to be stable across time.
492  enum IntrinsicOp {
502  bundle, // Bundle multiple exprs together temporarily for analysis (e.g. CSE)
555  sorted_avg, // Compute (arg[0] + arg[1]) / 2, assuming arg[0] < arg[1].
566  IntrinsicOpCount // Sentinel: keep last.
567  };
568 
569  static const char *get_intrinsic_name(IntrinsicOp op);
570 
571  // We also declare some symbolic names for some of the runtime
572  // functions that we want to construct Call nodes to here to avoid
573  // magic string constants and the potential risk of typos.
595 
596  // If it's a call to another halide function, this call node holds
597  // a possibly-weak reference to that function.
599 
600  // If that function has multiple values, which value does this
601  // call node refer to?
603 
604  // If it's a call to an image, this call nodes hold a
605  // pointer to that image's buffer
607 
608  // If it's a call to an image parameter, this call node holds a
609  // pointer to that
611 
612  static Expr make(Type type, IntrinsicOp op, const std::vector<Expr> &args, CallType call_type,
614  const Buffer<> &image = Buffer<>(), Parameter param = Parameter());
615 
616  static Expr make(Type type, const std::string &name, const std::vector<Expr> &args, CallType call_type,
619 
620  /** Convenience constructor for calls to other halide functions */
621  static Expr make(const Function &func, const std::vector<Expr> &args, int idx = 0);
622 
623  /** Convenience constructor for loads from concrete images */
624  static Expr make(const Buffer<> &image, const std::vector<Expr> &args) {
625  return make(image.type(), image.name(), args, Image, FunctionPtr(), 0, image, Parameter());
626  }
627 
628  /** Convenience constructor for loads from images parameters */
629  static Expr make(const Parameter &param, const std::vector<Expr> &args) {
630  return make(param.type(), param.name(), args, Image, FunctionPtr(), 0, Buffer<>(), param);
631  }
632 
633  /** Check if a call node is pure within a pipeline, meaning that
634  * the same args always give the same result, and the calls can be
635  * reordered, duplicated, unified, etc without changing the
636  * meaning of anything. Not transitive - doesn't guarantee the
637  * args themselves are pure. An example of a pure Call node is
638  * sqrt. If in doubt, don't mark a Call node as pure. */
639  bool is_pure() const {
640  return (call_type == PureExtern ||
641  call_type == Image ||
643  }
644 
645  bool is_intrinsic() const {
646  return (call_type == Intrinsic ||
648  }
649 
650  bool is_intrinsic(IntrinsicOp op) const {
651  return is_intrinsic() && this->name == get_intrinsic_name(op);
652  }
653 
654  /** Returns a pointer to a call node if the expression is a call to
655  * one of the requested intrinsics. */
656  static const Call *as_intrinsic(const Expr &e, std::initializer_list<IntrinsicOp> intrinsics) {
657  if (const Call *c = e.as<Call>()) {
658  for (IntrinsicOp i : intrinsics) {
659  if (c->is_intrinsic(i)) {
660  return c;
661  }
662  }
663  }
664  return nullptr;
665  }
666 
667  static const Call *as_tag(const Expr &e) {
669  }
670 
671  bool is_extern() const {
672  return (call_type == Extern ||
674  call_type == PureExtern);
675  }
676 
678 };
679 
680 /** A named variable. Might be a loop variable, function argument,
681  * parameter, reduction variable, or something defined by a Let or
682  * LetStmt node. */
683 struct Variable : public ExprNode<Variable> {
684  std::string name;
685 
686  /** References to scalar parameters, or to the dimensions of buffer
687  * parameters hang onto those expressions. */
689 
690  /** References to properties of literal image parameters. */
692 
693  /** Reduction variables hang onto their domains */
695 
696  static Expr make(Type type, const std::string &name) {
697  return make(type, name, Buffer<>(), Parameter(), ReductionDomain());
698  }
699 
700  static Expr make(Type type, const std::string &name, Parameter param) {
701  return make(type, name, Buffer<>(), std::move(param), ReductionDomain());
702  }
703 
704  static Expr make(Type type, const std::string &name, const Buffer<> &image) {
705  return make(type, name, image, Parameter(), ReductionDomain());
706  }
707 
708  static Expr make(Type type, const std::string &name, ReductionDomain reduction_domain) {
709  return make(type, name, Buffer<>(), Parameter(), std::move(reduction_domain));
710  }
711 
712  static Expr make(Type type, const std::string &name, Buffer<> image,
714 
716 };
717 
718 /** A for loop. Execute the 'body' statement for all values of the
719  * variable 'name' from 'min' to 'min + extent'. There are four
720  * types of For nodes. A 'Serial' for loop is a conventional
721  * one. In a 'Parallel' for loop, each iteration of the loop
722  * happens in parallel or in some unspecified order. In a
723  * 'Vectorized' for loop, each iteration maps to one SIMD lane,
724  * and the whole loop is executed in one shot. For this case,
725  * 'extent' must be some small integer constant (probably 4, 8, or
726  * 16). An 'Unrolled' for loop compiles to a completely unrolled
727  * version of the loop. Each iteration becomes its own
728  * statement. Again in this case, 'extent' should be a small
729  * integer constant. */
730 struct For : public StmtNode<For> {
731  std::string name;
736 
738 
739  bool is_unordered_parallel() const {
741  }
742  bool is_parallel() const {
744  }
745 
747 };
748 
749 struct Acquire : public StmtNode<Acquire> {
753 
755 
757 };
758 
759 /** Construct a new vector by taking elements from another sequence of
760  * vectors. */
761 struct Shuffle : public ExprNode<Shuffle> {
762  std::vector<Expr> vectors;
763 
764  /** Indices indicating which vector element to place into the
765  * result. The elements are numbered by their position in the
766  * concatenation of the vector arguments. */
767  std::vector<int> indices;
768 
769  static Expr make(const std::vector<Expr> &vectors,
770  const std::vector<int> &indices);
771 
772  /** Convenience constructor for making a shuffle representing an
773  * interleaving of vectors of the same length. */
774  static Expr make_interleave(const std::vector<Expr> &vectors);
775 
776  /** Convenience constructor for making a shuffle representing a
777  * concatenation of the vectors. */
778  static Expr make_concat(const std::vector<Expr> &vectors);
779 
780  /** Convenience constructor for making a shuffle representing a
781  * broadcast of a vector. */
782  static Expr make_broadcast(Expr vector, int factor);
783 
784  /** Convenience constructor for making a shuffle representing a
785  * contiguous subset of a vector. */
786  static Expr make_slice(Expr vector, int begin, int stride, int size);
787 
788  /** Convenience constructor for making a shuffle representing
789  * extracting a single element. */
790  static Expr make_extract_element(Expr vector, int i);
791 
792  /** Check if this shuffle is an interleaving of the vector
793  * arguments. */
794  bool is_interleave() const;
795 
796  /** Check if this shuffle can be represented as a broadcast.
797  * For example:
798  * A uint8 shuffle of with 4*n lanes and indices:
799  * 0, 1, 2, 3, 0, 1, 2, 3, ....., 0, 1, 2, 3
800  * can be represented as a uint32 broadcast with n lanes (factor = 4). */
801  bool is_broadcast() const;
802  int broadcast_factor() const;
803 
804  /** Check if this shuffle is a concatenation of the vector
805  * arguments. */
806  bool is_concat() const;
807 
808  /** Check if this shuffle is a contiguous strict subset of the
809  * vector arguments, and if so, the offset and stride of the
810  * slice. */
811  ///@{
812  bool is_slice() const;
813  int slice_begin() const {
814  return indices[0];
815  }
816  int slice_stride() const {
817  return indices.size() >= 2 ? indices[1] - indices[0] : 1;
818  }
819  ///@}
820 
821  /** Check if this shuffle is extracting a scalar from the vector
822  * arguments. */
823  bool is_extract_element() const;
824 
826 };
827 
828 /** Represent a multi-dimensional region of a Func or an ImageParam that
829  * needs to be prefetched. */
830 struct Prefetch : public StmtNode<Prefetch> {
831  std::string name;
832  std::vector<Type> types;
836 
838 
839  static Stmt make(const std::string &name, const std::vector<Type> &types,
840  const Region &bounds,
843 
845 };
846 
847 /** Lock all the Store nodes in the body statement.
848  * Typically the lock is implemented by an atomic operation
849  * (e.g. atomic add or atomic compare-and-swap).
850  * However, if necessary, the node can access a mutex buffer through
851  * mutex_name and mutex_args, by lowering this node into
852  * calls to acquire and release the lock. */
853 struct Atomic : public StmtNode<Atomic> {
854  std::string producer_name;
855  std::string mutex_name; // empty string if not using mutex
857 
858  static Stmt make(const std::string &producer_name,
859  const std::string &mutex_name,
860  Stmt body);
861 
863 };
864 
865 /** Horizontally reduce a vector to a scalar or narrower vector using
866  * the given commutative and associative binary operator. The reduction
867  * factor is dictated by the number of lanes in the input and output
868  * types. Groups of adjacent lanes are combined. The number of lanes
869  * in the input type must be a divisor of the number of lanes of the
870  * output type. */
871 struct VectorReduce : public ExprNode<VectorReduce> {
872  // 99.9% of the time people will use this for horizontal addition,
873  // but these are all of our commutative and associative primitive
874  // operators.
875  typedef enum {
882  Or,
883  } Operator;
884 
887 
888  static Expr make(Operator op, Expr vec, int lanes);
889 
891 };
892 
893 } // namespace Internal
894 } // namespace Halide
895 
896 #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:115
Type type() const
Definition: Buffer.h:520
const std::string & name() const
Definition: Buffer.h:360
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:29
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:395
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:756
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:352
std::string name
Definition: IR.h:353
std::vector< Expr > extents
Definition: IR.h:356
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:384
int32_t constant_allocation_size() const
MemoryType memory_type
Definition: IR.h:355
std::string free_function
Definition: IR.h:367
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:853
static const IRNodeType _node_type
Definition: IR.h:862
static Stmt make(const std::string &producer_name, const std::string &mutex_name, Stmt body)
std::string mutex_name
Definition: IR.h:855
std::string producer_name
Definition: IR.h:854
A sequence of statements to be executed in-order.
Definition: IR.h:417
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:425
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:464
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:579
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:584
static HALIDE_EXPORT ConstString buffer_set_bounds
Definition: IR.h:593
const char *const ConstString
Definition: IR.h:483
@ call_cached_indirect_function
Definition: IR.h:503
@ signed_integer_overflow
Definition: IR.h:553
@ unsafe_promise_clamped
Definition: IR.h:560
@ add_image_checks_marker
Definition: IR.h:495
@ rounding_mul_shift_right
Definition: IR.h:544
@ size_of_halide_buffer_t
Definition: IR.h:554
bool is_extern() const
Definition: IR.h:671
@ Extern
A call to an external C-ABI function, possibly with side-effects.
Definition: IR.h:468
@ ExternCPlusPlus
A call to an external C-ABI function, possibly with side-effects.
Definition: IR.h:469
@ Image
A load from an input image.
Definition: IR.h:467
@ Halide
A call to a Func.
Definition: IR.h:471
@ Intrinsic
A possibly-side-effecty compiler intrinsic, which has special handling during codegen.
Definition: IR.h:472
@ PureExtern
A call to a guaranteed-side-effect-free external function.
Definition: IR.h:470
@ PureIntrinsic
A side-effect-free version of the above.
Definition: IR.h:473
std::string name
Definition: IR.h:465
static HALIDE_EXPORT ConstString buffer_get_min
Definition: IR.h:576
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:656
bool is_intrinsic() const
Definition: IR.h:645
static HALIDE_EXPORT ConstString buffer_get_device_interface
Definition: IR.h:582
static HALIDE_EXPORT ConstString buffer_get_dimensions
Definition: IR.h:575
static HALIDE_EXPORT ConstString buffer_get_device_dirty
Definition: IR.h:585
static HALIDE_EXPORT ConstString buffer_crop
Definition: IR.h:592
FunctionPtr func
Definition: IR.h:598
CallType call_type
Definition: IR.h:475
static HALIDE_EXPORT ConstString buffer_get_host
Definition: IR.h:580
static Expr make(const Buffer<> &image, const std::vector< Expr > &args)
Convenience constructor for loads from concrete images.
Definition: IR.h:624
static HALIDE_EXPORT ConstString buffer_get_device
Definition: IR.h:581
static HALIDE_EXPORT ConstString buffer_init
Definition: IR.h:590
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:639
static HALIDE_EXPORT ConstString buffer_get_stride
Definition: IR.h:578
static HALIDE_EXPORT ConstString buffer_get_extent
Definition: IR.h:577
bool is_intrinsic(IntrinsicOp op) const
Definition: IR.h:650
static Expr make(const Parameter &param, const std::vector< Expr > &args)
Convenience constructor for loads from images parameters.
Definition: IR.h:629
static const IRNodeType _node_type
Definition: IR.h:677
static const char * get_intrinsic_name(IntrinsicOp op)
static HALIDE_EXPORT ConstString trace
Definition: IR.h:594
std::vector< Expr > args
Definition: IR.h:466
static HALIDE_EXPORT ConstString buffer_get_shape
Definition: IR.h:583
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:610
static const Call * as_tag(const Expr &e)
Definition: IR.h:667
static HALIDE_EXPORT ConstString buffer_is_bounds_query
Definition: IR.h:589
static HALIDE_EXPORT ConstString buffer_get_type
Definition: IR.h:586
static HALIDE_EXPORT ConstString buffer_set_device_dirty
Definition: IR.h:588
static HALIDE_EXPORT ConstString buffer_set_host_dirty
Definition: IR.h:587
static HALIDE_EXPORT ConstString buffer_init_from_buffer
Definition: IR.h:591
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:450
static Stmt make(Expr v)
static const IRNodeType _node_type
Definition: IR.h:455
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:730
std::string name
Definition: IR.h:731
DeviceAPI device_api
Definition: IR.h:734
ForType for_type
Definition: IR.h:733
bool is_parallel() const
Definition: IR.h:742
bool is_unordered_parallel() const
Definition: IR.h:739
static const IRNodeType _node_type
Definition: IR.h:746
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:431
static Stmt make(Stmt first, Stmt rest)
static const IRNodeType _node_type
Definition: IR.h:436
Free the resources associated with the given buffer.
Definition: IR.h:388
static const IRNodeType _node_type
Definition: IR.h:393
static Stmt make(const std::string &name)
std::string name
Definition: IR.h:389
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:440
static const IRNodeType _node_type
Definition: IR.h:446
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:830
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:844
PrefetchDirective prefetch
Definition: IR.h:834
std::vector< Type > types
Definition: IR.h:832
std::string name
Definition: IR.h:831
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:343
std::string name
Definition: IR.h:337
static Stmt make(const std::string &name, const std::vector< Expr > &values, const std::vector< Expr > &args)
std::vector< Expr > values
Definition: IR.h:338
std::vector< Expr > args
Definition: IR.h:339
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:402
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:405
std::vector< Type > types
Definition: IR.h:404
static const IRNodeType _node_type
Definition: IR.h:412
std::string name
Definition: IR.h:403
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:761
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:825
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:762
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:767
int slice_stride() const
Check if this shuffle is a contiguous strict subset of the vector arguments, and if so,...
Definition: IR.h:816
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:813
A reference-counted handle to a statement node.
Definition: Expr.h:413
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:683
static Expr make(Type type, const std::string &name, const Buffer<> &image)
Definition: IR.h:704
static Expr make(Type type, const std::string &name, Parameter param)
Definition: IR.h:700
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:691
ReductionDomain reduction_domain
Reduction variables hang onto their domains.
Definition: IR.h:694
static Expr make(Type type, const std::string &name)
Definition: IR.h:696
Parameter param
References to scalar parameters, or to the dimensions of buffer parameters hang onto those expression...
Definition: IR.h:688
static Expr make(Type type, const std::string &name, ReductionDomain reduction_domain)
Definition: IR.h:708
std::string name
Definition: IR.h:684
static const IRNodeType _node_type
Definition: IR.h:715
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
Definition: IR.h:871
static const IRNodeType _node_type
Definition: IR.h:890
static Expr make(Operator op, Expr vec, int lanes)
Types in the halide type system.
Definition: Type.h:269