Halide  13.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;
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)
556  sorted_avg, // Compute (arg[0] + arg[1]) / 2, assuming arg[0] < arg[1].
567  IntrinsicOpCount // Sentinel: keep last.
568  };
569 
570  static const char *get_intrinsic_name(IntrinsicOp op);
571 
572  // We also declare some symbolic names for some of the runtime
573  // functions that we want to construct Call nodes to here to avoid
574  // magic string constants and the potential risk of typos.
596 
597  // If it's a call to another halide function, this call node holds
598  // a possibly-weak reference to that function.
600 
601  // If that function has multiple values, which value does this
602  // call node refer to?
604 
605  // If it's a call to an image, this call nodes hold a
606  // pointer to that image's buffer
608 
609  // If it's a call to an image parameter, this call node holds a
610  // pointer to that
612 
613  static Expr make(Type type, IntrinsicOp op, const std::vector<Expr> &args, CallType call_type,
615  const Buffer<> &image = Buffer<>(), Parameter param = Parameter());
616 
617  static Expr make(Type type, const std::string &name, const std::vector<Expr> &args, CallType call_type,
620 
621  /** Convenience constructor for calls to other halide functions */
622  static Expr make(const Function &func, const std::vector<Expr> &args, int idx = 0);
623 
624  /** Convenience constructor for loads from concrete images */
625  static Expr make(const Buffer<> &image, const std::vector<Expr> &args) {
626  return make(image.type(), image.name(), args, Image, FunctionPtr(), 0, image, Parameter());
627  }
628 
629  /** Convenience constructor for loads from images parameters */
630  static Expr make(const Parameter &param, const std::vector<Expr> &args) {
631  return make(param.type(), param.name(), args, Image, FunctionPtr(), 0, Buffer<>(), param);
632  }
633 
634  /** Check if a call node is pure within a pipeline, meaning that
635  * the same args always give the same result, and the calls can be
636  * reordered, duplicated, unified, etc without changing the
637  * meaning of anything. Not transitive - doesn't guarantee the
638  * args themselves are pure. An example of a pure Call node is
639  * sqrt. If in doubt, don't mark a Call node as pure. */
640  bool is_pure() const {
641  return (call_type == PureExtern ||
642  call_type == Image ||
644  }
645 
646  bool is_intrinsic() const {
647  return (call_type == Intrinsic ||
649  }
650 
651  bool is_intrinsic(IntrinsicOp op) const {
652  return is_intrinsic() && this->name == get_intrinsic_name(op);
653  }
654 
655  bool is_intrinsic(std::initializer_list<IntrinsicOp> intrinsics) const {
656  for (IntrinsicOp i : intrinsics) {
657  if (is_intrinsic(i)) {
658  return true;
659  }
660  }
661  return false;
662  }
663 
664  bool is_tag() const {
666  }
667 
668  /** Returns a pointer to a call node if the expression is a call to
669  * one of the requested intrinsics. */
670  static const Call *as_intrinsic(const Expr &e, std::initializer_list<IntrinsicOp> intrinsics) {
671  if (const Call *c = e.as<Call>()) {
672  for (IntrinsicOp i : intrinsics) {
673  if (c->is_intrinsic(i)) {
674  return c;
675  }
676  }
677  }
678  return nullptr;
679  }
680 
681  static const Call *as_tag(const Expr &e) {
683  }
684 
685  bool is_extern() const {
686  return (call_type == Extern ||
688  call_type == PureExtern);
689  }
690 
692 };
693 
694 /** A named variable. Might be a loop variable, function argument,
695  * parameter, reduction variable, or something defined by a Let or
696  * LetStmt node. */
697 struct Variable : public ExprNode<Variable> {
698  std::string name;
699 
700  /** References to scalar parameters, or to the dimensions of buffer
701  * parameters hang onto those expressions. */
703 
704  /** References to properties of literal image parameters. */
706 
707  /** Reduction variables hang onto their domains */
709 
710  static Expr make(Type type, const std::string &name) {
711  return make(type, name, Buffer<>(), Parameter(), ReductionDomain());
712  }
713 
714  static Expr make(Type type, const std::string &name, Parameter param) {
715  return make(type, name, Buffer<>(), std::move(param), ReductionDomain());
716  }
717 
718  static Expr make(Type type, const std::string &name, const Buffer<> &image) {
719  return make(type, name, image, Parameter(), ReductionDomain());
720  }
721 
722  static Expr make(Type type, const std::string &name, ReductionDomain reduction_domain) {
723  return make(type, name, Buffer<>(), Parameter(), std::move(reduction_domain));
724  }
725 
726  static Expr make(Type type, const std::string &name, Buffer<> image,
728 
730 };
731 
732 /** A for loop. Execute the 'body' statement for all values of the
733  * variable 'name' from 'min' to 'min + extent'. There are four
734  * types of For nodes. A 'Serial' for loop is a conventional
735  * one. In a 'Parallel' for loop, each iteration of the loop
736  * happens in parallel or in some unspecified order. In a
737  * 'Vectorized' for loop, each iteration maps to one SIMD lane,
738  * and the whole loop is executed in one shot. For this case,
739  * 'extent' must be some small integer constant (probably 4, 8, or
740  * 16). An 'Unrolled' for loop compiles to a completely unrolled
741  * version of the loop. Each iteration becomes its own
742  * statement. Again in this case, 'extent' should be a small
743  * integer constant. */
744 struct For : public StmtNode<For> {
745  std::string name;
750 
752 
753  bool is_unordered_parallel() const {
755  }
756  bool is_parallel() const {
758  }
759 
761 };
762 
763 struct Acquire : public StmtNode<Acquire> {
767 
769 
771 };
772 
773 /** Construct a new vector by taking elements from another sequence of
774  * vectors. */
775 struct Shuffle : public ExprNode<Shuffle> {
776  std::vector<Expr> vectors;
777 
778  /** Indices indicating which vector element to place into the
779  * result. The elements are numbered by their position in the
780  * concatenation of the vector arguments. */
781  std::vector<int> indices;
782 
783  static Expr make(const std::vector<Expr> &vectors,
784  const std::vector<int> &indices);
785 
786  /** Convenience constructor for making a shuffle representing an
787  * interleaving of vectors of the same length. */
788  static Expr make_interleave(const std::vector<Expr> &vectors);
789 
790  /** Convenience constructor for making a shuffle representing a
791  * concatenation of the vectors. */
792  static Expr make_concat(const std::vector<Expr> &vectors);
793 
794  /** Convenience constructor for making a shuffle representing a
795  * broadcast of a vector. */
796  static Expr make_broadcast(Expr vector, int factor);
797 
798  /** Convenience constructor for making a shuffle representing a
799  * contiguous subset of a vector. */
800  static Expr make_slice(Expr vector, int begin, int stride, int size);
801 
802  /** Convenience constructor for making a shuffle representing
803  * extracting a single element. */
804  static Expr make_extract_element(Expr vector, int i);
805 
806  /** Check if this shuffle is an interleaving of the vector
807  * arguments. */
808  bool is_interleave() const;
809 
810  /** Check if this shuffle can be represented as a broadcast.
811  * For example:
812  * A uint8 shuffle of with 4*n lanes and indices:
813  * 0, 1, 2, 3, 0, 1, 2, 3, ....., 0, 1, 2, 3
814  * can be represented as a uint32 broadcast with n lanes (factor = 4). */
815  bool is_broadcast() const;
816  int broadcast_factor() const;
817 
818  /** Check if this shuffle is a concatenation of the vector
819  * arguments. */
820  bool is_concat() const;
821 
822  /** Check if this shuffle is a contiguous strict subset of the
823  * vector arguments, and if so, the offset and stride of the
824  * slice. */
825  ///@{
826  bool is_slice() const;
827  int slice_begin() const {
828  return indices[0];
829  }
830  int slice_stride() const {
831  return indices.size() >= 2 ? indices[1] - indices[0] : 1;
832  }
833  ///@}
834 
835  /** Check if this shuffle is extracting a scalar from the vector
836  * arguments. */
837  bool is_extract_element() const;
838 
840 };
841 
842 /** Represent a multi-dimensional region of a Func or an ImageParam that
843  * needs to be prefetched. */
844 struct Prefetch : public StmtNode<Prefetch> {
845  std::string name;
846  std::vector<Type> types;
850 
852 
853  static Stmt make(const std::string &name, const std::vector<Type> &types,
854  const Region &bounds,
857 
859 };
860 
861 /** Lock all the Store nodes in the body statement.
862  * Typically the lock is implemented by an atomic operation
863  * (e.g. atomic add or atomic compare-and-swap).
864  * However, if necessary, the node can access a mutex buffer through
865  * mutex_name and mutex_args, by lowering this node into
866  * calls to acquire and release the lock. */
867 struct Atomic : public StmtNode<Atomic> {
868  std::string producer_name;
869  std::string mutex_name; // empty string if not using mutex
871 
872  static Stmt make(const std::string &producer_name,
873  const std::string &mutex_name,
874  Stmt body);
875 
877 };
878 
879 /** Horizontally reduce a vector to a scalar or narrower vector using
880  * the given commutative and associative binary operator. The reduction
881  * factor is dictated by the number of lanes in the input and output
882  * types. Groups of adjacent lanes are combined. The number of lanes
883  * in the input type must be a divisor of the number of lanes of the
884  * output type. */
885 struct VectorReduce : public ExprNode<VectorReduce> {
886  // 99.9% of the time people will use this for horizontal addition,
887  // but these are all of our commutative and associative primitive
888  // operators.
889  typedef enum {
896  Or,
897  } Operator;
898 
901 
902  static Expr make(Operator op, Expr vec, int lanes);
903 
905 };
906 
907 } // namespace Internal
908 } // namespace Halide
909 
910 #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:770
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:867
static const IRNodeType _node_type
Definition: IR.h:876
static Stmt make(const std::string &producer_name, const std::string &mutex_name, Stmt body)
std::string mutex_name
Definition: IR.h:869
std::string producer_name
Definition: IR.h:868
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:580
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:585
static HALIDE_EXPORT ConstString buffer_set_bounds
Definition: IR.h:594
const char *const ConstString
Definition: IR.h:485
bool is_tag() const
Definition: IR.h:664
@ call_cached_indirect_function
Definition: IR.h:505
@ signed_integer_overflow
Definition: IR.h:554
@ unsafe_promise_clamped
Definition: IR.h:561
@ add_image_checks_marker
Definition: IR.h:497
@ rounding_mul_shift_right
Definition: IR.h:545
@ size_of_halide_buffer_t
Definition: IR.h:555
bool is_extern() const
Definition: IR.h:685
@ 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:577
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:670
bool is_intrinsic() const
Definition: IR.h:646
static HALIDE_EXPORT ConstString buffer_get_device_interface
Definition: IR.h:583
static HALIDE_EXPORT ConstString buffer_get_dimensions
Definition: IR.h:576
static HALIDE_EXPORT ConstString buffer_get_device_dirty
Definition: IR.h:586
static HALIDE_EXPORT ConstString buffer_crop
Definition: IR.h:593
FunctionPtr func
Definition: IR.h:599
CallType call_type
Definition: IR.h:477
static HALIDE_EXPORT ConstString buffer_get_host
Definition: IR.h:581
static Expr make(const Buffer<> &image, const std::vector< Expr > &args)
Convenience constructor for loads from concrete images.
Definition: IR.h:625
static HALIDE_EXPORT ConstString buffer_get_device
Definition: IR.h:582
static HALIDE_EXPORT ConstString buffer_init
Definition: IR.h:591
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:640
static HALIDE_EXPORT ConstString buffer_get_stride
Definition: IR.h:579
static HALIDE_EXPORT ConstString buffer_get_extent
Definition: IR.h:578
bool is_intrinsic(std::initializer_list< IntrinsicOp > intrinsics) const
Definition: IR.h:655
bool is_intrinsic(IntrinsicOp op) const
Definition: IR.h:651
static Expr make(const Parameter &param, const std::vector< Expr > &args)
Convenience constructor for loads from images parameters.
Definition: IR.h:630
static const IRNodeType _node_type
Definition: IR.h:691
static const char * get_intrinsic_name(IntrinsicOp op)
static HALIDE_EXPORT ConstString trace
Definition: IR.h:595
std::vector< Expr > args
Definition: IR.h:468
static HALIDE_EXPORT ConstString buffer_get_shape
Definition: IR.h:584
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:611
static const Call * as_tag(const Expr &e)
Definition: IR.h:681
static HALIDE_EXPORT ConstString buffer_is_bounds_query
Definition: IR.h:590
static HALIDE_EXPORT ConstString buffer_get_type
Definition: IR.h:587
static HALIDE_EXPORT ConstString buffer_set_device_dirty
Definition: IR.h:589
static HALIDE_EXPORT ConstString buffer_set_host_dirty
Definition: IR.h:588
static HALIDE_EXPORT ConstString buffer_init_from_buffer
Definition: IR.h:592
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:744
std::string name
Definition: IR.h:745
DeviceAPI device_api
Definition: IR.h:748
ForType for_type
Definition: IR.h:747
bool is_parallel() const
Definition: IR.h:756
bool is_unordered_parallel() const
Definition: IR.h:753
static const IRNodeType _node_type
Definition: IR.h:760
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:844
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:858
PrefetchDirective prefetch
Definition: IR.h:848
std::vector< Type > types
Definition: IR.h:846
std::string name
Definition: IR.h:845
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:775
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:839
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:776
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:781
int slice_stride() const
Check if this shuffle is a contiguous strict subset of the vector arguments, and if so,...
Definition: IR.h:830
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:827
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:697
static Expr make(Type type, const std::string &name, const Buffer<> &image)
Definition: IR.h:718
static Expr make(Type type, const std::string &name, Parameter param)
Definition: IR.h:714
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:705
ReductionDomain reduction_domain
Reduction variables hang onto their domains.
Definition: IR.h:708
static Expr make(Type type, const std::string &name)
Definition: IR.h:710
Parameter param
References to scalar parameters, or to the dimensions of buffer parameters hang onto those expression...
Definition: IR.h:702
static Expr make(Type type, const std::string &name, ReductionDomain reduction_domain)
Definition: IR.h:722
std::string name
Definition: IR.h:698
static const IRNodeType _node_type
Definition: IR.h:729
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
Definition: IR.h:885
static const IRNodeType _node_type
Definition: IR.h:904
static Expr make(Operator op, Expr vec, int lanes)
Types in the halide type system.
Definition: Type.h:265