Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
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"
15#include "ModulusRemainder.h"
16#include "Parameter.h"
17#include "PrefetchDirective.h"
18#include "Reduction.h"
19#include "Type.h"
20
21namespace Halide {
22namespace Internal {
23
24class Function;
25
26/** The actual IR nodes begin here. Remember that all the Expr
27 * nodes also have a public "type" property */
28
29/** Cast a node from one type to another. Can't change vector widths. */
30struct Cast : public ExprNode<Cast> {
32
33 static Expr make(Type t, Expr v);
34
36
37 /** Check if the cast is equivalent to a reinterpret. */
38 bool is_reinterpret() const {
39 return (type.is_int_or_uint() &&
41 type.bits() == value.type().bits());
42 }
43};
44
45/** Reinterpret value as another type, without affecting any of the bits
46 * (on little-endian systems). */
47struct Reinterpret : public ExprNode<Reinterpret> {
49
50 static Expr make(Type t, Expr v);
51
53};
54
55/** The sum of two expressions */
56struct Add : public ExprNode<Add> {
58
59 static Expr make(Expr a, Expr b);
60
62};
63
64/** The difference of two expressions */
65struct Sub : public ExprNode<Sub> {
67
68 static Expr make(Expr a, Expr b);
69
71};
72
73/** The product of two expressions */
74struct Mul : public ExprNode<Mul> {
76
77 static Expr make(Expr a, Expr b);
78
80};
81
82/** The ratio of two expressions */
83struct Div : public ExprNode<Div> {
85
86 static Expr make(Expr a, Expr b);
87
89};
90
91/** The remainder of a / b. Mostly equivalent to '%' in C, except that
92 * the result here is always positive. For floats, this is equivalent
93 * to calling fmod. */
94struct Mod : public ExprNode<Mod> {
96
97 static Expr make(Expr a, Expr b);
98
100};
101
102/** The lesser of two values. */
103struct Min : public ExprNode<Min> {
105
106 static Expr make(Expr a, Expr b);
107
109};
110
111/** The greater of two values */
112struct Max : public ExprNode<Max> {
114
115 static Expr make(Expr a, Expr b);
116
118};
119
120/** Is the first expression equal to the second */
121struct EQ : public ExprNode<EQ> {
123
124 static Expr make(Expr a, Expr b);
125
127};
128
129/** Is the first expression not equal to the second */
130struct NE : public ExprNode<NE> {
132
133 static Expr make(Expr a, Expr b);
134
136};
137
138/** Is the first expression less than the second. */
139struct LT : public ExprNode<LT> {
141
142 static Expr make(Expr a, Expr b);
143
145};
146
147/** Is the first expression less than or equal to the second. */
148struct LE : public ExprNode<LE> {
150
151 static Expr make(Expr a, Expr b);
152
154};
155
156/** Is the first expression greater than the second. */
157struct GT : public ExprNode<GT> {
159
160 static Expr make(Expr a, Expr b);
161
163};
164
165/** Is the first expression greater than or equal to the second. */
166struct GE : public ExprNode<GE> {
168
169 static Expr make(Expr a, Expr b);
170
172};
173
174/** Logical and - are both expressions true */
175struct And : public ExprNode<And> {
177
178 static Expr make(Expr a, Expr b);
179
181};
182
183/** Logical or - is at least one of the expression true */
184struct Or : public ExprNode<Or> {
186
187 static Expr make(Expr a, Expr b);
188
190};
191
192/** Logical not - true if the expression false */
193struct Not : public ExprNode<Not> {
195
196 static Expr make(Expr a);
197
199};
200
201/** A ternary operator. Evalutes 'true_value' and 'false_value',
202 * then selects between them based on 'condition'. Equivalent to
203 * the ternary operator in C. */
211
212/** Load a value from a named symbol if predicate is true. The buffer
213 * is treated as an array of the 'type' of this Load node. That is,
214 * the buffer has no inherent type. The name may be the name of an
215 * enclosing allocation, an input or output buffer, or any other
216 * symbol of type Handle(). */
217struct Load : public ExprNode<Load> {
218 std::string name;
219
221
222 // If it's a load from an image argument or compiled-in constant
223 // image, this will point to that
225
226 // If it's a load from an image parameter, this points to that
228
229 // The alignment of the index. If the index is a vector, this is
230 // the alignment of the first lane.
232
233 static Expr make(Type type, const std::string &name,
238
240};
241
242/** A linear ramp vector node. This is vector with 'lanes' elements,
243 * where element i is 'base' + i*'stride'. This is a convenient way to
244 * pass around vectors without busting them up into individual
245 * elements. E.g. a dense vector load from a buffer can use a ramp
246 * node with stride 1 as the index. */
247struct Ramp : public ExprNode<Ramp> {
249 int lanes;
250
252
254};
255
256/** A vector with 'lanes' elements, in which every element is
257 * 'value'. This is a special case of the ramp node above, in which
258 * the stride is zero. */
259struct Broadcast : public ExprNode<Broadcast> {
261 int lanes;
262
263 static Expr make(Expr value, int lanes);
264
266};
267
268/** A let expression, like you might find in a functional
269 * language. Within the expression \ref Let::body, instances of the Var
270 * node \ref Let::name refer to \ref Let::value. */
271struct Let : public ExprNode<Let> {
272 std::string name;
274
275 static Expr make(const std::string &name, Expr value, Expr body);
276
278};
279
280/** The statement form of a let node. Within the statement 'body',
281 * instances of the Var named 'name' refer to 'value' */
282struct LetStmt : public StmtNode<LetStmt> {
283 std::string name;
286
287 static Stmt make(const std::string &name, Expr value, Stmt body);
288
290};
291
292/** If the 'condition' is false, then evaluate and return the message,
293 * which should be a call to an error function. */
294struct AssertStmt : public StmtNode<AssertStmt> {
295 // if condition then val else error out with message
298
300
302};
303
304/** This node is a helpful annotation to do with permissions. If 'is_produce' is
305 * set to true, this represents a producer node which may also contain updates;
306 * otherwise, this represents a consumer node. If the producer node contains
307 * updates, the body of the node will be a block of 'produce' and 'update'
308 * in that order. In a producer node, the access is read-write only (or write
309 * only if it doesn't have updates). In a consumer node, the access is read-only.
310 * None of this is actually enforced, the node is purely for informative purposes
311 * to help out our analysis during lowering. For every unique ProducerConsumer,
312 * there is an associated Realize node with the same name that creates the buffer
313 * being read from or written to in the body of the ProducerConsumer.
314 */
315struct ProducerConsumer : public StmtNode<ProducerConsumer> {
316 std::string name;
319
320 static Stmt make(const std::string &name, bool is_producer, Stmt body);
321
322 static Stmt make_produce(const std::string &name, Stmt body);
323 static Stmt make_consume(const std::string &name, Stmt body);
324
326};
327
328/** Store a 'value' to the buffer called 'name' at a given 'index' if
329 * 'predicate' is true. The buffer is interpreted as an array of the
330 * same type as 'value'. The name may be the name of an enclosing
331 * Allocate node, an output buffer, or any other symbol of type
332 * Handle(). */
333struct Store : public StmtNode<Store> {
334 std::string name;
336 // If it's a store to an output buffer, then this parameter points to it.
338
339 // The alignment of the index. If the index is a vector, this is
340 // the alignment of the first lane.
342
343 static Stmt make(const std::string &name, Expr value, Expr index,
345
347};
348
349/** This defines the value of a function at a multi-dimensional
350 * location. You should think of it as a store to a multi-dimensional
351 * array. It gets lowered to a conventional Store node. The name must
352 * correspond to an output buffer or the name of an enclosing Realize
353 * node. */
354struct Provide : public StmtNode<Provide> {
355 std::string name;
356 std::vector<Expr> values;
357 std::vector<Expr> args;
359
360 static Stmt make(const std::string &name, const std::vector<Expr> &values, const std::vector<Expr> &args, const Expr &predicate);
361
363};
364
365/** Allocate a scratch area called with the given name, type, and
366 * size. The buffer lives for at most the duration of the body
367 * statement, within which it may or may not be freed explicitly with
368 * a Free node with a matching name. Allocation only occurs if the
369 * condition evaluates to true. Within the body of the allocation,
370 * defines a symbol with the given name and the type Handle(). */
371struct Allocate : public StmtNode<Allocate> {
372 std::string name;
375 std::vector<Expr> extents;
376
377 // A boolean condition that determines if the allocation needs to be made at all.
379
380 // These override the code generator dependent malloc and free
381 // equivalents if provided. If the new_expr succeeds, that is it
382 // returns non-nullptr, the function named be free_function is
383 // guaranteed to be called. The free function signature must match
384 // that of the code generator dependent free (typically
385 // halide_free). If free_function is left empty, code generator
386 // default will be called.
388 std::string free_function;
389
390 // Extra padding elements to allow for overreads. Elements in the padding
391 // have undetermined values, but are guaranteed safe to load.
393
395
396 static Stmt make(const std::string &name, Type type, MemoryType memory_type,
397 const std::vector<Expr> &extents,
399 Expr new_expr = Expr(), const std::string &free_function = std::string(), int padding = 0);
400
401 /** A routine to check if the extents are all constants, and if so verify
402 * the total size is less than 2^31 - 1. If the result is constant, but
403 * overflows, this routine asserts. This returns 0 if the extents are
404 * not all constants; otherwise, it returns the total constant allocation
405 * size. Does not include any padding bytes. */
406 static int32_t constant_allocation_size(const std::vector<Expr> &extents, const std::string &name);
408
410};
411
412/** Free the resources associated with the given buffer. */
413struct Free : public StmtNode<Free> {
414 std::string name;
415
416 static Stmt make(const std::string &name);
417
419};
420
421/** Allocate a multi-dimensional buffer of the given type and
422 * size. Create some scratch memory that will back the function 'name'
423 * over the range specified in 'bounds'. The bounds are a vector of
424 * (min, extent) pairs for each dimension. Allocation only occurs if
425 * the condition evaluates to true.
426 */
427struct Realize : public StmtNode<Realize> {
428 std::string name;
429 std::vector<Type> types;
434
435 static Stmt make(const std::string &name, const std::vector<Type> &types, MemoryType memory_type, const Region &bounds, Expr condition, Stmt body);
436
438};
439
440/** A sequence of statements to be executed in-order. 'first' is never
441 a Block, so this can be treated as a linked list. */
442struct Block : public StmtNode<Block> {
444
446
447 /** Construct zero or more Blocks to invoke a list of statements in order.
448 * This method may not return a Block statement if stmts.size() <= 1. */
449 static Stmt make(const std::vector<Stmt> &stmts);
450
452};
453
454/** A pair of statements executed concurrently. Both statements are
455 * joined before the Stmt ends. This is the parallel equivalent to
456 * Block. */
457struct Fork : public StmtNode<Fork> {
459
461
463};
464
465/** An if-then-else block. 'else' may be undefined. */
474
475/** Evaluate and discard an expression, presumably because it has some side-effect. */
476struct Evaluate : public StmtNode<Evaluate> {
478
479 static Stmt make(Expr v);
480
482};
483
484/** A function call. This can represent a call to some extern function
485 * (like sin), but it's also our multi-dimensional version of a Load,
486 * so it can be a load from an input image, or a call to another
487 * halide function. These two types of call nodes don't survive all
488 * the way down to code generation - the lowering process converts
489 * them to Load nodes. */
490struct Call : public ExprNode<Call> {
491 std::string name;
492 std::vector<Expr> args;
493 typedef enum { Image, ///< A load from an input image
494 Extern, ///< A call to an external C-ABI function, possibly with side-effects
495 ExternCPlusPlus, ///< A call to an external C-ABI function, possibly with side-effects
496 PureExtern, ///< A call to a guaranteed-side-effect-free external function
497 Halide, ///< A call to a Func
498 Intrinsic, ///< A possibly-side-effecty compiler intrinsic, which has special handling during codegen
499 PureIntrinsic ///< A side-effect-free version of the above.
502
503 // Halide uses calls internally to represent certain operations
504 // (instead of IR nodes). These are matched by name. Note that
505 // these are deliberately char* (rather than std::string) so that
506 // they can be referenced at static-initialization time without
507 // risking ambiguous initalization order; we use a typedef to simplify
508 // declaration.
509 typedef const char *const ConstString;
510
511 // enums for various well-known intrinsics. (It is not *required* that all
512 // intrinsics have an enum entry here, but as a matter of style, it is recommended.)
513 // Note that these are only used in the API; inside the node, they are translated
514 // into a name. (To recover the name, call get_intrinsic_name().)
515 //
516 // Please keep this list sorted alphabetically; the specific enum values
517 // are *not* guaranteed to be stable across time.
528
529 // Bundle multiple exprs together temporarily for analysis (e.g. CSE)
533
534 // Concatenate bits of the args, with least significant bits as the
535 // first arg (i.e. little-endian)
543
544 // Extract some contiguous slice of bits from the argument starting at
545 // the nth bit, counting from the least significant bit, with the number
546 // of bits determined by the return type.
580
581 // Round a floating point value to nearest integer, with ties going to even
583
597
598 // Marks the point in lowering where the outermost skip stages checks
599 // should be introduced.
601
602 // Takes a realization name and a loop variable. Declares that values of
603 // the realization that were stored on earlier loop iterations of the
604 // given loop are potentially loaded in this loop iteration somewhere
605 // after this point. Must occur inside a Realize node and For node of
606 // the given names but outside any corresponding ProducerConsumer
607 // nodes. Communicates to storage folding that sliding window took
608 // place.
610
611 // Compute (arg[0] + arg[1]) / 2, assuming arg[0] < arg[1].
615
621
625
626 // One-sided variants of widening_add, widening_mul, and widening_sub.
627 // arg[0] + widen(arg[1])
629 // arg[0] * widen(arg[1])
631 // arg[0] - widen(arg[1])
633
639
641
642 IntrinsicOpCount // Sentinel: keep last.
643 };
644
645 static const char *get_intrinsic_name(IntrinsicOp op);
646
647 // We also declare some symbolic names for some of the runtime
648 // functions that we want to construct Call nodes to here to avoid
649 // magic string constants and the potential risk of typos.
671
672 // If it's a call to another halide function, this call node holds
673 // a possibly-weak reference to that function.
675
676 // If that function has multiple values, which value does this
677 // call node refer to?
679
680 // If it's a call to an image, this call nodes hold a
681 // pointer to that image's buffer
683
684 // If it's a call to an image parameter, this call node holds a
685 // pointer to that
687
688 static Expr make(Type type, IntrinsicOp op, const std::vector<Expr> &args, CallType call_type,
691
692 static Expr make(Type type, const std::string &name, const std::vector<Expr> &args, CallType call_type,
695
696 /** Convenience constructor for calls to other halide functions */
697 static Expr make(const Function &func, const std::vector<Expr> &args, int idx = 0);
698
699 /** Convenience constructor for loads from concrete images */
700 static Expr make(const Buffer<> &image, const std::vector<Expr> &args) {
701 return make(image.type(), image.name(), args, Image, FunctionPtr(), 0, image, Parameter());
702 }
703
704 /** Convenience constructor for loads from images parameters */
705 static Expr make(const Parameter &param, const std::vector<Expr> &args) {
706 return make(param.type(), param.name(), args, Image, FunctionPtr(), 0, Buffer<>(), param);
707 }
708
709 /** Check if a call node is pure within a pipeline, meaning that
710 * the same args always give the same result, and the calls can be
711 * reordered, duplicated, unified, etc without changing the
712 * meaning of anything. Not transitive - doesn't guarantee the
713 * args themselves are pure. An example of a pure Call node is
714 * sqrt. If in doubt, don't mark a Call node as pure. */
715 bool is_pure() const {
716 return (call_type == PureExtern ||
717 call_type == Image ||
719 }
720
721 bool is_intrinsic() const {
722 return (call_type == Intrinsic ||
724 }
725
726 bool is_intrinsic(IntrinsicOp op) const {
727 return is_intrinsic() && this->name == get_intrinsic_name(op);
728 }
729
730 bool is_intrinsic(std::initializer_list<IntrinsicOp> intrinsics) const {
731 for (IntrinsicOp i : intrinsics) {
732 if (is_intrinsic(i)) {
733 return true;
734 }
735 }
736 return false;
737 }
738
742
743 /** Returns a pointer to a call node if the expression is a call to
744 * one of the requested intrinsics. */
745 static const Call *as_intrinsic(const Expr &e, std::initializer_list<IntrinsicOp> intrinsics) {
746 if (const Call *c = e.as<Call>()) {
747 for (IntrinsicOp i : intrinsics) {
748 if (c->is_intrinsic(i)) {
749 return c;
750 }
751 }
752 }
753 return nullptr;
754 }
755
756 static const Call *as_tag(const Expr &e) {
758 }
759
760 bool is_extern() const {
761 return (call_type == Extern ||
764 }
765
767};
768
769/** A named variable. Might be a loop variable, function argument,
770 * parameter, reduction variable, or something defined by a Let or
771 * LetStmt node. */
772struct Variable : public ExprNode<Variable> {
773 std::string name;
774
775 /** References to scalar parameters, or to the dimensions of buffer
776 * parameters hang onto those expressions. */
778
779 /** References to properties of literal image parameters. */
781
782 /** Reduction variables hang onto their domains */
784
785 static Expr make(Type type, const std::string &name) {
787 }
788
789 static Expr make(Type type, const std::string &name, Parameter param) {
790 return make(type, name, Buffer<>(), std::move(param), ReductionDomain());
791 }
792
793 static Expr make(Type type, const std::string &name, const Buffer<> &image) {
795 }
796
797 static Expr make(Type type, const std::string &name, ReductionDomain reduction_domain) {
798 return make(type, name, Buffer<>(), Parameter(), std::move(reduction_domain));
799 }
800
801 static Expr make(Type type, const std::string &name, Buffer<> image,
803
805};
806
807/** A for loop. Execute the 'body' statement for all values of the
808 * variable 'name' from 'min' to 'min + extent'. There are four
809 * types of For nodes. A 'Serial' for loop is a conventional
810 * one. In a 'Parallel' for loop, each iteration of the loop
811 * happens in parallel or in some unspecified order. In a
812 * 'Vectorized' for loop, each iteration maps to one SIMD lane,
813 * and the whole loop is executed in one shot. For this case,
814 * 'extent' must be some small integer constant (probably 4, 8, or
815 * 16). An 'Unrolled' for loop compiles to a completely unrolled
816 * version of the loop. Each iteration becomes its own
817 * statement. Again in this case, 'extent' should be a small
818 * integer constant. */
842
852
853/** Construct a new vector by taking elements from another sequence of
854 * vectors. */
855struct Shuffle : public ExprNode<Shuffle> {
856 std::vector<Expr> vectors;
857
858 /** Indices indicating which vector element to place into the
859 * result. The elements are numbered by their position in the
860 * concatenation of the vector arguments. */
861 std::vector<int> indices;
862
863 static Expr make(const std::vector<Expr> &vectors,
864 const std::vector<int> &indices);
865
866 /** Convenience constructor for making a shuffle representing an
867 * interleaving of vectors of the same length. */
868 static Expr make_interleave(const std::vector<Expr> &vectors);
869
870 /** Convenience constructor for making a shuffle representing a
871 * concatenation of the vectors. */
872 static Expr make_concat(const std::vector<Expr> &vectors);
873
874 /** Convenience constructor for making a shuffle representing a
875 * broadcast of a vector. */
876 static Expr make_broadcast(Expr vector, int factor);
877
878 /** Convenience constructor for making a shuffle representing a
879 * contiguous subset of a vector. */
880 static Expr make_slice(Expr vector, int begin, int stride, int size);
881
882 /** Convenience constructor for making a shuffle representing
883 * extracting a single element. */
884 static Expr make_extract_element(Expr vector, int i);
885
886 /** Check if this shuffle is an interleaving of the vector
887 * arguments. */
888 bool is_interleave() const;
889
890 /** Check if this shuffle can be represented as a repeating pattern that
891 * repeats the same shuffle of the single input vector some number of times.
892 * For example: 0, 3, 1, 1, 0, 3, 1, 1, ....., 0, 3, 1, 1
893 */
894 bool is_broadcast() const;
895 int broadcast_factor() const;
896
897 /** Check if this shuffle is a concatenation of the vector
898 * arguments. */
899 bool is_concat() const;
900
901 /** Check if this shuffle is a contiguous strict subset of the
902 * vector arguments, and if so, the offset and stride of the
903 * slice. */
904 ///@{
905 bool is_slice() const;
906 int slice_begin() const {
907 return indices[0];
908 }
909 int slice_stride() const {
910 return indices.size() >= 2 ? indices[1] - indices[0] : 1;
911 }
912 ///@}
913
914 /** Check if this shuffle is extracting a scalar from the vector
915 * arguments. */
916 bool is_extract_element() const;
917
919};
920
921/** Represent a multi-dimensional region of a Func or an ImageParam that
922 * needs to be prefetched. */
923struct Prefetch : public StmtNode<Prefetch> {
924 std::string name;
925 std::vector<Type> types;
929
931
932 static Stmt make(const std::string &name, const std::vector<Type> &types,
933 const Region &bounds,
936
938};
939
940/**
941 * Represents a location where storage will be hoisted to for a Func / Realize
942 * node with a given name.
943 *
944 */
945struct HoistedStorage : public StmtNode<HoistedStorage> {
946 std::string name;
948
949 static Stmt make(const std::string &name,
950 Stmt body);
951
953};
954
955/** Lock all the Store nodes in the body statement.
956 * Typically the lock is implemented by an atomic operation
957 * (e.g. atomic add or atomic compare-and-swap).
958 * However, if necessary, the node can access a mutex buffer through
959 * mutex_name and mutex_args, by lowering this node into
960 * calls to acquire and release the lock. */
961struct Atomic : public StmtNode<Atomic> {
962 std::string producer_name;
963 std::string mutex_name; // empty string if not using mutex
965
966 static Stmt make(const std::string &producer_name,
967 const std::string &mutex_name,
968 Stmt body);
969
971};
972
973/** Horizontally reduce a vector to a scalar or narrower vector using
974 * the given commutative and associative binary operator. The reduction
975 * factor is dictated by the number of lanes in the input and output
976 * types. Groups of adjacent lanes are combined. The number of lanes
977 * in the input type must be a divisor of the number of lanes of the
978 * output type. */
979struct VectorReduce : public ExprNode<VectorReduce> {
980 // 99.9% of the time people will use this for horizontal addition,
981 // but these are all of our commutative and associative primitive
982 // operators.
992
995
996 static Expr make(Operator op, Expr vec, int lanes);
997
999};
1000
1001} // namespace Internal
1002} // namespace Halide
1003
1004#endif
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Defines the Partition enum.
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:39
Type type() const
Definition Buffer.h:533
const std::string & name() const
Definition Buffer.h:367
A reference-counted handle to Halide's internal representation of a function.
Definition Function.h:39
A reference-counted handle on a reduction domain, which is just a vector of ReductionVariable.
Definition Reduction.h:33
A reference-counted handle to a parameter to a halide pipeline.
Definition Parameter.h:40
const std::string & name() const
Get the name of this parameter.
Type type() const
Get the type of this parameter.
ForType
An enum describing a type of loop traversal.
Definition Expr.h:406
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:350
MemoryType
An enum describing different address spaces to be used with Func::store_in.
Definition Expr.h:353
Partition
Different ways to handle loops with a potentially optimizable boundary conditions.
signed __INT32_TYPE__ int32_t
A fragment of Halide syntax.
Definition Expr.h:258
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Definition Expr.h:327
static const IRNodeType _node_type
Definition IR.h:850
static Stmt make(Expr semaphore, Expr count, Stmt body)
The sum of two expressions.
Definition IR.h:56
static Expr make(Expr a, Expr b)
static const IRNodeType _node_type
Definition IR.h:61
Allocate a scratch area called with the given name, type, and size.
Definition IR.h:371
std::string name
Definition IR.h:372
std::vector< Expr > extents
Definition IR.h:375
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:409
int32_t constant_allocation_size() const
MemoryType memory_type
Definition IR.h:374
std::string free_function
Definition IR.h:388
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(), int padding=0)
Logical and - are both expressions true.
Definition IR.h:175
static const IRNodeType _node_type
Definition IR.h:180
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:294
static const IRNodeType _node_type
Definition IR.h:301
static Stmt make(Expr condition, Expr message)
Lock all the Store nodes in the body statement.
Definition IR.h:961
static const IRNodeType _node_type
Definition IR.h:970
static Stmt make(const std::string &producer_name, const std::string &mutex_name, Stmt body)
std::string mutex_name
Definition IR.h:963
std::string producer_name
Definition IR.h:962
A sequence of statements to be executed in-order.
Definition IR.h:442
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:451
A vector with 'lanes' elements, in which every element is 'value'.
Definition IR.h:259
static Expr make(Expr value, int lanes)
static const IRNodeType _node_type
Definition IR.h:265
A function call.
Definition IR.h:490
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:655
static const Call * as_tag(const Expr &e)
Definition IR.h:756
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:660
static HALIDE_EXPORT ConstString buffer_set_bounds
Definition IR.h:669
bool is_tag() const
Definition IR.h:739
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:745
const char *const ConstString
Definition IR.h:509
@ call_cached_indirect_function
Definition IR.h:531
@ profiling_enable_instance_marker
Definition IR.h:572
@ target_natural_vector_size
Definition IR.h:619
bool is_extern() const
Definition IR.h:760
@ Extern
A call to an external C-ABI function, possibly with side-effects.
Definition IR.h:494
@ ExternCPlusPlus
A call to an external C-ABI function, possibly with side-effects.
Definition IR.h:495
@ Image
A load from an input image.
Definition IR.h:493
@ Halide
A call to a Func.
Definition IR.h:497
@ Intrinsic
A possibly-side-effecty compiler intrinsic, which has special handling during codegen.
Definition IR.h:498
@ PureExtern
A call to a guaranteed-side-effect-free external function.
Definition IR.h:496
@ PureIntrinsic
A side-effect-free version of the above.
Definition IR.h:499
std::string name
Definition IR.h:491
static HALIDE_EXPORT ConstString buffer_get_min
Definition IR.h:652
bool is_intrinsic() const
Definition IR.h:721
static HALIDE_EXPORT ConstString buffer_get_device_interface
Definition IR.h:658
static HALIDE_EXPORT ConstString buffer_get_dimensions
Definition IR.h:651
static HALIDE_EXPORT ConstString buffer_get_device_dirty
Definition IR.h:661
static HALIDE_EXPORT ConstString buffer_crop
Definition IR.h:668
FunctionPtr func
Definition IR.h:674
CallType call_type
Definition IR.h:501
static HALIDE_EXPORT ConstString buffer_get_host
Definition IR.h:656
static Expr make(const Buffer<> &image, const std::vector< Expr > &args)
Convenience constructor for loads from concrete images.
Definition IR.h:700
static HALIDE_EXPORT ConstString buffer_get_device
Definition IR.h:657
static HALIDE_EXPORT ConstString buffer_init
Definition IR.h:666
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:715
static HALIDE_EXPORT ConstString buffer_get_stride
Definition IR.h:654
static HALIDE_EXPORT ConstString buffer_get_extent
Definition IR.h:653
bool is_intrinsic(std::initializer_list< IntrinsicOp > intrinsics) const
Definition IR.h:730
static const char * get_intrinsic_name(IntrinsicOp op)
bool is_intrinsic(IntrinsicOp op) const
Definition IR.h:726
static Expr make(const Parameter &param, const std::vector< Expr > &args)
Convenience constructor for loads from images parameters.
Definition IR.h:705
static const IRNodeType _node_type
Definition IR.h:766
static HALIDE_EXPORT ConstString trace
Definition IR.h:670
std::vector< Expr > args
Definition IR.h:492
static HALIDE_EXPORT ConstString buffer_get_shape
Definition IR.h:659
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:686
static HALIDE_EXPORT ConstString buffer_is_bounds_query
Definition IR.h:665
static HALIDE_EXPORT ConstString buffer_get_type
Definition IR.h:662
static HALIDE_EXPORT ConstString buffer_set_device_dirty
Definition IR.h:664
static HALIDE_EXPORT ConstString buffer_set_host_dirty
Definition IR.h:663
static HALIDE_EXPORT ConstString buffer_init_from_buffer
Definition IR.h:667
The actual IR nodes begin here.
Definition IR.h:30
static const IRNodeType _node_type
Definition IR.h:35
static Expr make(Type t, Expr v)
bool is_reinterpret() const
Check if the cast is equivalent to a reinterpret.
Definition IR.h:38
The ratio of two expressions.
Definition IR.h:83
static const IRNodeType _node_type
Definition IR.h:88
static Expr make(Expr a, Expr b)
Is the first expression equal to the second.
Definition IR.h:121
static const IRNodeType _node_type
Definition IR.h:126
static Expr make(Expr a, Expr b)
Evaluate and discard an expression, presumably because it has some side-effect.
Definition IR.h:476
static Stmt make(Expr v)
static const IRNodeType _node_type
Definition IR.h:481
We use the "curiously recurring template pattern" to avoid duplicated code in the IR Nodes.
Definition Expr.h:158
A for loop.
Definition IR.h:819
Partition partition_policy
Definition IR.h:825
std::string name
Definition IR.h:820
DeviceAPI device_api
Definition IR.h:823
ForType for_type
Definition IR.h:822
bool is_parallel() const
Definition IR.h:836
bool is_unordered_parallel() const
Definition IR.h:833
static const IRNodeType _node_type
Definition IR.h:840
static Stmt make(const std::string &name, Expr min, Expr extent, ForType for_type, Partition partition_policy, DeviceAPI device_api, Stmt body)
A pair of statements executed concurrently.
Definition IR.h:457
static Stmt make(Stmt first, Stmt rest)
static const IRNodeType _node_type
Definition IR.h:462
Free the resources associated with the given buffer.
Definition IR.h:413
static const IRNodeType _node_type
Definition IR.h:418
static Stmt make(const std::string &name)
std::string name
Definition IR.h:414
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:166
static const IRNodeType _node_type
Definition IR.h:171
static Expr make(Expr a, Expr b)
Is the first expression greater than the second.
Definition IR.h:157
static const IRNodeType _node_type
Definition IR.h:162
static Expr make(Expr a, Expr b)
Represents a location where storage will be hoisted to for a Func / Realize node with a given name.
Definition IR.h:945
static Stmt make(const std::string &name, Stmt body)
static const IRNodeType _node_type
Definition IR.h:952
const T * as() const
Downcast this ir node to its actual type (e.g.
Definition Expr.h:205
An if-then-else block.
Definition IR.h:466
static const IRNodeType _node_type
Definition IR.h:472
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:148
static Expr make(Expr a, Expr b)
static const IRNodeType _node_type
Definition IR.h:153
Is the first expression less than the second.
Definition IR.h:139
static Expr make(Expr a, Expr b)
static const IRNodeType _node_type
Definition IR.h:144
A let expression, like you might find in a functional language.
Definition IR.h:271
std::string name
Definition IR.h:272
static Expr make(const std::string &name, Expr value, Expr body)
static const IRNodeType _node_type
Definition IR.h:277
The statement form of a let node.
Definition IR.h:282
static Stmt make(const std::string &name, Expr value, Stmt body)
std::string name
Definition IR.h:283
static const IRNodeType _node_type
Definition IR.h:289
Load a value from a named symbol if predicate is true.
Definition IR.h:217
std::string name
Definition IR.h:218
static Expr make(Type type, const std::string &name, Expr index, Buffer<> image, Parameter param, Expr predicate, ModulusRemainder alignment)
Parameter param
Definition IR.h:227
static const IRNodeType _node_type
Definition IR.h:239
ModulusRemainder alignment
Definition IR.h:231
The greater of two values.
Definition IR.h:112
static const IRNodeType _node_type
Definition IR.h:117
static Expr make(Expr a, Expr b)
The lesser of two values.
Definition IR.h:103
static const IRNodeType _node_type
Definition IR.h:108
static Expr make(Expr a, Expr b)
The remainder of a / b.
Definition IR.h:94
static const IRNodeType _node_type
Definition IR.h:99
static Expr make(Expr a, Expr b)
The result of modulus_remainder analysis.
The product of two expressions.
Definition IR.h:74
static const IRNodeType _node_type
Definition IR.h:79
static Expr make(Expr a, Expr b)
Is the first expression not equal to the second.
Definition IR.h:130
static const IRNodeType _node_type
Definition IR.h:135
static Expr make(Expr a, Expr b)
Logical not - true if the expression false.
Definition IR.h:193
static Expr make(Expr a)
static const IRNodeType _node_type
Definition IR.h:198
Logical or - is at least one of the expression true.
Definition IR.h:184
static Expr make(Expr a, Expr b)
static const IRNodeType _node_type
Definition IR.h:189
Represent a multi-dimensional region of a Func or an ImageParam that needs to be prefetched.
Definition IR.h:923
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:937
PrefetchDirective prefetch
Definition IR.h:927
std::vector< Type > types
Definition IR.h:925
std::string name
Definition IR.h:924
This node is a helpful annotation to do with permissions.
Definition IR.h:315
static const IRNodeType _node_type
Definition IR.h:325
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:354
static const IRNodeType _node_type
Definition IR.h:362
std::string name
Definition IR.h:355
std::vector< Expr > values
Definition IR.h:356
std::vector< Expr > args
Definition IR.h:357
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:247
static const IRNodeType _node_type
Definition IR.h:253
static Expr make(Expr base, Expr stride, int lanes)
Allocate a multi-dimensional buffer of the given type and size.
Definition IR.h:427
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:430
std::vector< Type > types
Definition IR.h:429
static const IRNodeType _node_type
Definition IR.h:437
std::string name
Definition IR.h:428
Reinterpret value as another type, without affecting any of the bits (on little-endian systems).
Definition IR.h:47
static const IRNodeType _node_type
Definition IR.h:52
static Expr make(Type t, Expr v)
A ternary operator.
Definition IR.h:204
static Expr make(Expr condition, Expr true_value, Expr false_value)
static const IRNodeType _node_type
Definition IR.h:209
Construct a new vector by taking elements from another sequence of vectors.
Definition IR.h:855
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 repeating pattern that repeats the same shuffle of the ...
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:918
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:856
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:861
int slice_stride() const
Check if this shuffle is a contiguous strict subset of the vector arguments, and if so,...
Definition IR.h:909
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:906
A reference-counted handle to a statement node.
Definition Expr.h:427
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
Definition IR.h:333
std::string name
Definition IR.h:334
static const IRNodeType _node_type
Definition IR.h:346
Parameter param
Definition IR.h:337
ModulusRemainder alignment
Definition IR.h:341
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:65
static const IRNodeType _node_type
Definition IR.h:70
static Expr make(Expr a, Expr b)
A named variable.
Definition IR.h:772
static Expr make(Type type, const std::string &name, const Buffer<> &image)
Definition IR.h:793
static Expr make(Type type, const std::string &name, Parameter param)
Definition IR.h:789
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:780
ReductionDomain reduction_domain
Reduction variables hang onto their domains.
Definition IR.h:783
static Expr make(Type type, const std::string &name)
Definition IR.h:785
Parameter param
References to scalar parameters, or to the dimensions of buffer parameters hang onto those expression...
Definition IR.h:777
static Expr make(Type type, const std::string &name, ReductionDomain reduction_domain)
Definition IR.h:797
std::string name
Definition IR.h:773
static const IRNodeType _node_type
Definition IR.h:804
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
Definition IR.h:979
static const IRNodeType _node_type
Definition IR.h:998
static Expr make(Operator op, Expr vec, int lanes)
Types in the halide type system.
Definition Type.h:283
HALIDE_ALWAYS_INLINE int bits() const
Return the bit size of a single element of this type.
Definition Type.h:349
HALIDE_ALWAYS_INLINE bool is_int_or_uint() const
Is this type an integer type of any sort?
Definition Type.h:447