Halide 22.0.0 Halide compiler and libraries

IRVisitor.h
Go to the documentation of this file.
1#ifndef HALIDE_IR_VISITOR_H
2#define HALIDE_IR_VISITOR_H
3
4#include <set>
5
6#include "IR.h"
7
8/** \file
9 * Defines the base class for things that recursively walk over the IR
10 */
11
12 namespace Halide {
13 namespace Internal {
14
15/** A base class for algorithms that need to recursively walk over the
16 * IR. The default implementations just recursively walk over the
17 * children. Override the ones you care about.
18 */
19 class IRVisitor {
20 public:
21 IRVisitor() = default;
22 virtual ~IRVisitor() = default;
23
24 protected:
25 // ExprNode<> and StmtNode<> are allowed to call visit (to implement accept())
26 template<typename T>
27 friend struct ExprNode;
28
29 template<typename T>
30 friend struct StmtNode;
31
32 virtual void visit(const IntImm *);
33 virtual void visit(const UIntImm *);
34 virtual void visit(const FloatImm *);
35 virtual void visit(const StringImm *);
36 virtual void visit(const Cast *);
37 virtual void visit(const Reinterpret *);
38 virtual void visit(const Add *);
39 virtual void visit(const Sub *);
40 virtual void visit(const Mul *);
41 virtual void visit(const Div *);
42 virtual void visit(const Mod *);
43 virtual void visit(const Min *);
44 virtual void visit(const Max *);
45 virtual void visit(const EQ *);
46 virtual void visit(const NE *);
47 virtual void visit(const LT *);
48 virtual void visit(const LE *);
49 virtual void visit(const GT *);
50 virtual void visit(const GE *);
51 virtual void visit(const And *);
52 virtual void visit(const Or *);
53 virtual void visit(const Not *);
54 virtual void visit(const Select *);
55 virtual void visit(const Load *);
56 virtual void visit(const Ramp *);
57 virtual void visit(const Broadcast *);
58 virtual void visit(const Let *);
59 virtual void visit(const LetStmt *);
60 virtual void visit(const AssertStmt *);
61 virtual void visit(const ProducerConsumer *);
62 virtual void visit(const Store *);
63 virtual void visit(const Provide *);
64 virtual void visit(const Allocate *);
65 virtual void visit(const Free *);
66 virtual void visit(const Realize *);
67 virtual void visit(const Block *);
68 virtual void visit(const Fork *);
69 virtual void visit(const IfThenElse *);
70 virtual void visit(const Evaluate *);
71 virtual void visit(const Call *);
72 virtual void visit(const Variable *);
73 virtual void visit(const For *);
74 virtual void visit(const Acquire *);
75 virtual void visit(const Shuffle *);
76 virtual void visit(const Prefetch *);
77 virtual void visit(const HoistedStorage *);
78 virtual void visit(const Atomic *);
79 virtual void visit(const VectorReduce *);
80};
81
82/** A lambda-based IR visitor that accepts multiple lambdas for different
83 * node types. */
84 template<typename... Lambdas>
85 struct LambdaVisitor final : IRVisitor {
86 explicit LambdaVisitor(Lambdas... lambdas)
87 : handlers(std::move(lambdas)...) {
88 }
89
90 /** Public helper to call the base visitor from lambdas. */
91 template<typename T>
92 void visit_base(const T *op) {
93 IRVisitor::visit(op);
94 }
95
96 private:
97 LambdaOverloads<Lambdas...> handlers;
98
99 template<typename T>
100 auto visit_impl(const T *op) {
101 if constexpr (std::is_invocable_v<decltype(handlers), LambdaVisitor *, const T *>) {
102 return handlers(this, op);
103 } else {
104 return this->visit_base(op);
105 }
106 }
107
108 protected:
109 void visit(const IntImm *op) override {
110 this->visit_impl(op);
111 }
112 void visit(const UIntImm *op) override {
113 this->visit_impl(op);
114 }
115 void visit(const FloatImm *op) override {
116 this->visit_impl(op);
117 }
118 void visit(const StringImm *op) override {
119 this->visit_impl(op);
120 }
121 void visit(const Cast *op) override {
122 this->visit_impl(op);
123 }
124 void visit(const Reinterpret *op) override {
125 this->visit_impl(op);
126 }
127 void visit(const Add *op) override {
128 this->visit_impl(op);
129 }
130 void visit(const Sub *op) override {
131 this->visit_impl(op);
132 }
133 void visit(const Mul *op) override {
134 this->visit_impl(op);
135 }
136 void visit(const Div *op) override {
137 this->visit_impl(op);
138 }
139 void visit(const Mod *op) override {
140 this->visit_impl(op);
141 }
142 void visit(const Min *op) override {
143 this->visit_impl(op);
144 }
145 void visit(const Max *op) override {
146 this->visit_impl(op);
147 }
148 void visit(const EQ *op) override {
149 this->visit_impl(op);
150 }
151 void visit(const NE *op) override {
152 this->visit_impl(op);
153 }
154 void visit(const LT *op) override {
155 this->visit_impl(op);
156 }
157 void visit(const LE *op) override {
158 this->visit_impl(op);
159 }
160 void visit(const GT *op) override {
161 this->visit_impl(op);
162 }
163 void visit(const GE *op) override {
164 this->visit_impl(op);
165 }
166 void visit(const And *op) override {
167 this->visit_impl(op);
168 }
169 void visit(const Or *op) override {
170 this->visit_impl(op);
171 }
172 void visit(const Not *op) override {
173 this->visit_impl(op);
174 }
175 void visit(const Select *op) override {
176 this->visit_impl(op);
177 }
178 void visit(const Load *op) override {
179 this->visit_impl(op);
180 }
181 void visit(const Ramp *op) override {
182 this->visit_impl(op);
183 }
184 void visit(const Broadcast *op) override {
185 this->visit_impl(op);
186 }
187 void visit(const Let *op) override {
188 this->visit_impl(op);
189 }
190 void visit(const LetStmt *op) override {
191 this->visit_impl(op);
192 }
193 void visit(const AssertStmt *op) override {
194 this->visit_impl(op);
195 }
196 void visit(const ProducerConsumer *op) override {
197 this->visit_impl(op);
198 }
199 void visit(const Store *op) override {
200 this->visit_impl(op);
201 }
202 void visit(const Provide *op) override {
203 this->visit_impl(op);
204 }
205 void visit(const Allocate *op) override {
206 this->visit_impl(op);
207 }
208 void visit(const Free *op) override {
209 this->visit_impl(op);
210 }
211 void visit(const Realize *op) override {
212 this->visit_impl(op);
213 }
214 void visit(const Block *op) override {
215 this->visit_impl(op);
216 }
217 void visit(const Fork *op) override {
218 this->visit_impl(op);
219 }
220 void visit(const IfThenElse *op) override {
221 this->visit_impl(op);
222 }
223 void visit(const Evaluate *op) override {
224 this->visit_impl(op);
225 }
226 void visit(const Call *op) override {
227 this->visit_impl(op);
228 }
229 void visit(const Variable *op) override {
230 this->visit_impl(op);
231 }
232 void visit(const For *op) override {
233 this->visit_impl(op);
234 }
235 void visit(const Acquire *op) override {
236 this->visit_impl(op);
237 }
238 void visit(const Shuffle *op) override {
239 this->visit_impl(op);
240 }
241 void visit(const Prefetch *op) override {
242 this->visit_impl(op);
243 }
244 void visit(const HoistedStorage *op) override {
245 this->visit_impl(op);
246 }
247 void visit(const Atomic *op) override {
248 this->visit_impl(op);
249 }
250 void visit(const VectorReduce *op) override {
251 this->visit_impl(op);
252 }
253};
254
255 template<typename T, typename... Lambdas>
256 void visit_with(const T &ir, Lambdas &&...lambdas) {
257 LambdaVisitor visitor{std::forward<Lambdas>(lambdas)...};
258 ir.accept(&visitor);
259}
260
261/** A base class for algorithms that walk recursively over the IR
262 * without visiting the same node twice. This is for passes that are
263 * capable of interpreting the IR as a DAG instead of a tree. */
264 class IRGraphVisitor : public IRVisitor {
265 protected:
266 /** By default these methods add the node to the visited set, and
267 * return whether or not it was already there. If it wasn't there,
268 * it delegates to the appropriate visit method. You can override
269 * them if you like. */
270 // @{
271 virtual void include(const Expr &);
272 virtual void include(const Stmt &);
273 // @}
274
275 private:
276 /** The nodes visited so far. Only includes nodes with a ref count greater
277 * than one, because we know that nodes with a ref count of 1 will only be
278 * visited once if their parents are only visited once. */
279 std::set<const IRNode *> visited;
280
281 protected:
282 /** These methods should call 'include' on the children to only
283 * visit them if they haven't been visited already. */
284 // @{
285 void visit(const IntImm *) override;
286 void visit(const UIntImm *) override;
287 void visit(const FloatImm *) override;
288 void visit(const StringImm *) override;
289 void visit(const Cast *) override;
290 void visit(const Reinterpret *) override;
291 void visit(const Add *) override;
292 void visit(const Sub *) override;
293 void visit(const Mul *) override;
294 void visit(const Div *) override;
295 void visit(const Mod *) override;
296 void visit(const Min *) override;
297 void visit(const Max *) override;
298 void visit(const EQ *) override;
299 void visit(const NE *) override;
300 void visit(const LT *) override;
301 void visit(const LE *) override;
302 void visit(const GT *) override;
303 void visit(const GE *) override;
304 void visit(const And *) override;
305 void visit(const Or *) override;
306 void visit(const Not *) override;
307 void visit(const Select *) override;
308 void visit(const Load *) override;
309 void visit(const Ramp *) override;
310 void visit(const Broadcast *) override;
311 void visit(const Let *) override;
312 void visit(const LetStmt *) override;
313 void visit(const AssertStmt *) override;
314 void visit(const ProducerConsumer *) override;
315 void visit(const Store *) override;
316 void visit(const Provide *) override;
317 void visit(const Allocate *) override;
318 void visit(const Free *) override;
319 void visit(const Realize *) override;
320 void visit(const Block *) override;
321 void visit(const Fork *) override;
322 void visit(const IfThenElse *) override;
323 void visit(const Evaluate *) override;
324 void visit(const Call *) override;
325 void visit(const Variable *) override;
326 void visit(const For *) override;
327 void visit(const Acquire *) override;
328 void visit(const Shuffle *) override;
329 void visit(const Prefetch *) override;
330 void visit(const HoistedStorage *) override;
331 void visit(const Atomic *) override;
332 void visit(const VectorReduce *) override;
333 // @}
334};
335
336/** A visitor/mutator capable of passing arbitrary arguments to the
337 * visit methods using CRTP and returning any types from them. All
338 * Expr visitors must have the same signature, and all Stmt visitors
339 * must have the same signature. Does not have default implementations
340 * of the visit methods. */
341 template<typename T, typename ExprRet, typename StmtRet>
342 class VariadicVisitor {
343 private:
344 template<typename... Args>
345 ExprRet dispatch_expr(const BaseExprNode *node, Args &&...args) {
346 if (node == nullptr) {
347 return ExprRet{};
348 }
349 switch (node->node_type) {
350 case IRNodeType::IntImm:
351 return ((T *)this)->visit((const IntImm *)node, std::forward<Args>(args)...);
352 case IRNodeType::UIntImm:
353 return ((T *)this)->visit((const UIntImm *)node, std::forward<Args>(args)...);
354 case IRNodeType::FloatImm:
355 return ((T *)this)->visit((const FloatImm *)node, std::forward<Args>(args)...);
356 case IRNodeType::StringImm:
357 return ((T *)this)->visit((const StringImm *)node, std::forward<Args>(args)...);
358 case IRNodeType::Broadcast:
359 return ((T *)this)->visit((const Broadcast *)node, std::forward<Args>(args)...);
360 case IRNodeType::Cast:
361 return ((T *)this)->visit((const Cast *)node, std::forward<Args>(args)...);
362 case IRNodeType::Reinterpret:
363 return ((T *)this)->visit((const Reinterpret *)node, std::forward<Args>(args)...);
364 case IRNodeType::Variable:
365 return ((T *)this)->visit((const Variable *)node, std::forward<Args>(args)...);
366 case IRNodeType::Add:
367 return ((T *)this)->visit((const Add *)node, std::forward<Args>(args)...);
368 case IRNodeType::Sub:
369 return ((T *)this)->visit((const Sub *)node, std::forward<Args>(args)...);
370 case IRNodeType::Mod:
371 return ((T *)this)->visit((const Mod *)node, std::forward<Args>(args)...);
372 case IRNodeType::Mul:
373 return ((T *)this)->visit((const Mul *)node, std::forward<Args>(args)...);
374 case IRNodeType::Div:
375 return ((T *)this)->visit((const Div *)node, std::forward<Args>(args)...);
376 case IRNodeType::Min:
377 return ((T *)this)->visit((const Min *)node, std::forward<Args>(args)...);
378 case IRNodeType::Max:
379 return ((T *)this)->visit((const Max *)node, std::forward<Args>(args)...);
380 case IRNodeType::EQ:
381 return ((T *)this)->visit((const EQ *)node, std::forward<Args>(args)...);
382 case IRNodeType::NE:
383 return ((T *)this)->visit((const NE *)node, std::forward<Args>(args)...);
384 case IRNodeType::LT:
385 return ((T *)this)->visit((const LT *)node, std::forward<Args>(args)...);
386 case IRNodeType::LE:
387 return ((T *)this)->visit((const LE *)node, std::forward<Args>(args)...);
388 case IRNodeType::GT:
389 return ((T *)this)->visit((const GT *)node, std::forward<Args>(args)...);
390 case IRNodeType::GE:
391 return ((T *)this)->visit((const GE *)node, std::forward<Args>(args)...);
392 case IRNodeType::And:
393 return ((T *)this)->visit((const And *)node, std::forward<Args>(args)...);
394 case IRNodeType::Or:
395 return ((T *)this)->visit((const Or *)node, std::forward<Args>(args)...);
396 case IRNodeType::Not:
397 return ((T *)this)->visit((const Not *)node, std::forward<Args>(args)...);
398 case IRNodeType::Select:
399 return ((T *)this)->visit((const Select *)node, std::forward<Args>(args)...);
400 case IRNodeType::Load:
401 return ((T *)this)->visit((const Load *)node, std::forward<Args>(args)...);
402 case IRNodeType::Ramp:
403 return ((T *)this)->visit((const Ramp *)node, std::forward<Args>(args)...);
404 case IRNodeType::Call:
405 return ((T *)this)->visit((const Call *)node, std::forward<Args>(args)...);
406 case IRNodeType::Let:
407 return ((T *)this)->visit((const Let *)node, std::forward<Args>(args)...);
408 case IRNodeType::Shuffle:
409 return ((T *)this)->visit((const Shuffle *)node, std::forward<Args>(args)...);
410 case IRNodeType::VectorReduce:
411 return ((T *)this)->visit((const VectorReduce *)node, std::forward<Args>(args)...);
412 // Explicitly list the Stmt types rather than using a
413 // default case so that when new IR nodes are added we
414 // don't miss them here.
415 case IRNodeType::LetStmt:
416 case IRNodeType::AssertStmt:
417 case IRNodeType::ProducerConsumer:
418 case IRNodeType::For:
419 case IRNodeType::Acquire:
420 case IRNodeType::Store:
421 case IRNodeType::Provide:
422 case IRNodeType::Allocate:
423 case IRNodeType::Free:
424 case IRNodeType::Realize:
425 case IRNodeType::Block:
426 case IRNodeType::Fork:
427 case IRNodeType::IfThenElse:
428 case IRNodeType::Evaluate:
429 case IRNodeType::Prefetch:
430 case IRNodeType::Atomic:
431 case IRNodeType::HoistedStorage:
432 internal_error << "Unreachable";
433 }
434 return ExprRet{};
435 }
436
437 template<typename... Args>
438 StmtRet dispatch_stmt(const BaseStmtNode *node, Args &&...args) {
439 if (node == nullptr) {
440 return StmtRet{};
441 }
442 switch (node->node_type) {
443 case IRNodeType::IntImm:
444 case IRNodeType::UIntImm:
445 case IRNodeType::FloatImm:
446 case IRNodeType::StringImm:
447 case IRNodeType::Broadcast:
448 case IRNodeType::Cast:
449 case IRNodeType::Reinterpret:
450 case IRNodeType::Variable:
451 case IRNodeType::Add:
452 case IRNodeType::Sub:
453 case IRNodeType::Mod:
454 case IRNodeType::Mul:
455 case IRNodeType::Div:
456 case IRNodeType::Min:
457 case IRNodeType::Max:
458 case IRNodeType::EQ:
459 case IRNodeType::NE:
460 case IRNodeType::LT:
461 case IRNodeType::LE:
462 case IRNodeType::GT:
463 case IRNodeType::GE:
464 case IRNodeType::And:
465 case IRNodeType::Or:
466 case IRNodeType::Not:
467 case IRNodeType::Select:
468 case IRNodeType::Load:
469 case IRNodeType::Ramp:
470 case IRNodeType::Call:
471 case IRNodeType::Let:
472 case IRNodeType::Shuffle:
473 case IRNodeType::VectorReduce:
474 internal_error << "Unreachable";
475 break;
476 case IRNodeType::LetStmt:
477 return ((T *)this)->visit((const LetStmt *)node, std::forward<Args>(args)...);
478 case IRNodeType::AssertStmt:
479 return ((T *)this)->visit((const AssertStmt *)node, std::forward<Args>(args)...);
480 case IRNodeType::ProducerConsumer:
481 return ((T *)this)->visit((const ProducerConsumer *)node, std::forward<Args>(args)...);
482 case IRNodeType::For:
483 return ((T *)this)->visit((const For *)node, std::forward<Args>(args)...);
484 case IRNodeType::Acquire:
485 return ((T *)this)->visit((const Acquire *)node, std::forward<Args>(args)...);
486 case IRNodeType::Store:
487 return ((T *)this)->visit((const Store *)node, std::forward<Args>(args)...);
488 case IRNodeType::Provide:
489 return ((T *)this)->visit((const Provide *)node, std::forward<Args>(args)...);
490 case IRNodeType::Allocate:
491 return ((T *)this)->visit((const Allocate *)node, std::forward<Args>(args)...);
492 case IRNodeType::Free:
493 return ((T *)this)->visit((const Free *)node, std::forward<Args>(args)...);
494 case IRNodeType::Realize:
495 return ((T *)this)->visit((const Realize *)node, std::forward<Args>(args)...);
496 case IRNodeType::Block:
497 return ((T *)this)->visit((const Block *)node, std::forward<Args>(args)...);
498 case IRNodeType::Fork:
499 return ((T *)this)->visit((const Fork *)node, std::forward<Args>(args)...);
500 case IRNodeType::IfThenElse:
501 return ((T *)this)->visit((const IfThenElse *)node, std::forward<Args>(args)...);
502 case IRNodeType::Evaluate:
503 return ((T *)this)->visit((const Evaluate *)node, std::forward<Args>(args)...);
504 case IRNodeType::Prefetch:
505 return ((T *)this)->visit((const Prefetch *)node, std::forward<Args>(args)...);
506 case IRNodeType::Atomic:
507 return ((T *)this)->visit((const Atomic *)node, std::forward<Args>(args)...);
508 case IRNodeType::HoistedStorage:
509 return ((T *)this)->visit((const HoistedStorage *)node, std::forward<Args>(args)...);
510 }
511 return StmtRet{};
512 }
513
514 public:
515 template<typename... Args>
516 HALIDE_ALWAYS_INLINE StmtRet dispatch(const Stmt &s, Args &&...args) {
517 return dispatch_stmt(s.get(), std::forward<Args>(args)...);
518 }
519
520 template<typename... Args>
521 HALIDE_ALWAYS_INLINE StmtRet dispatch(Stmt &&s, Args &&...args) {
522 return dispatch_stmt(s.get(), std::forward<Args>(args)...);
523 }
524
525 template<typename... Args>
526 HALIDE_ALWAYS_INLINE ExprRet dispatch(const Expr &e, Args &&...args) {
527 return dispatch_expr(e.get(), std::forward<Args>(args)...);
528 }
529
530 template<typename... Args>
531 HALIDE_ALWAYS_INLINE ExprRet dispatch(Expr &&e, Args &&...args) {
532 return dispatch_expr(e.get(), std::forward<Args>(args)...);
533 }
534};
535
536} // namespace Internal
537} // namespace Halide
538
539#endif
internal_error
#define internal_error
Definition: Error.h:229
HALIDE_ALWAYS_INLINE
#define HALIDE_ALWAYS_INLINE
Definition: HalideRuntime.h:49
IR.h
Subtypes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Halide::Internal::IRGraphVisitor
A base class for algorithms that walk recursively over the IR without visiting the same node twice.
Definition: IRVisitor.h:264
Halide::Internal::IRGraphVisitor::visit
void visit(const Div *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Shuffle *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const NE *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Block *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const EQ *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Let *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Provide *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const StringImm *) override
Halide::Internal::IRGraphVisitor::include
virtual void include(const Expr &)
By default these methods add the node to the visited set, and return whether or not it was already th...
Halide::Internal::IRGraphVisitor::visit
void visit(const For *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const HoistedStorage *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Ramp *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Or *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const UIntImm *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Mul *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const AssertStmt *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const GE *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Min *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Free *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Add *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Acquire *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Store *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Max *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const IntImm *) override
These methods should call 'include' on the children to only visit them if they haven't been visited a...
Halide::Internal::IRGraphVisitor::visit
void visit(const IfThenElse *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const LT *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const VectorReduce *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Atomic *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Sub *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Not *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Mod *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const ProducerConsumer *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const LetStmt *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const LE *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Allocate *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Load *) override
Halide::Internal::IRGraphVisitor::include
virtual void include(const Stmt &)
Halide::Internal::IRGraphVisitor::visit
void visit(const Realize *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Prefetch *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const FloatImm *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Fork *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Call *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Reinterpret *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const And *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Variable *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Evaluate *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Broadcast *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const GT *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Cast *) override
Halide::Internal::IRGraphVisitor::visit
void visit(const Select *) override
Halide::Internal::IRVisitor
A base class for algorithms that need to recursively walk over the IR.
Definition: IRVisitor.h:19
Halide::Internal::IRVisitor::visit
virtual void visit(const NE *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Mul *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Max *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Select *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Load *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Div *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Fork *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Sub *)
Halide::Internal::IRVisitor::visit
virtual void visit(const LE *)
Halide::Internal::IRVisitor::~IRVisitor
virtual ~IRVisitor()=default
Halide::Internal::IRVisitor::visit
virtual void visit(const ProducerConsumer *)
Halide::Internal::IRVisitor::visit
virtual void visit(const VectorReduce *)
Halide::Internal::IRVisitor::visit
virtual void visit(const GE *)
Halide::Internal::IRVisitor::visit
virtual void visit(const StringImm *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Allocate *)
Halide::Internal::IRVisitor::visit
virtual void visit(const IfThenElse *)
Halide::Internal::IRVisitor::visit
virtual void visit(const For *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Prefetch *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Block *)
Halide::Internal::IRVisitor::visit
virtual void visit(const UIntImm *)
Halide::Internal::IRVisitor::visit
virtual void visit(const HoistedStorage *)
Halide::Internal::IRVisitor::visit
virtual void visit(const FloatImm *)
Halide::Internal::IRVisitor::visit
virtual void visit(const GT *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Mod *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Acquire *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Atomic *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Ramp *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Free *)
Halide::Internal::IRVisitor::visit
virtual void visit(const IntImm *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Or *)
Halide::Internal::IRVisitor::visit
virtual void visit(const EQ *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Broadcast *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Call *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Min *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Variable *)
Halide::Internal::IRVisitor::IRVisitor
IRVisitor()=default
Halide::Internal::IRVisitor::visit
virtual void visit(const Realize *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Add *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Shuffle *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Reinterpret *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Evaluate *)
Halide::Internal::IRVisitor::visit
virtual void visit(const AssertStmt *)
Halide::Internal::IRVisitor::visit
virtual void visit(const And *)
Halide::Internal::IRVisitor::visit
virtual void visit(const LetStmt *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Store *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Provide *)
Halide::Internal::IRVisitor::visit
virtual void visit(const LT *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Cast *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Not *)
Halide::Internal::IRVisitor::visit
virtual void visit(const Let *)
Halide::Internal::VariadicVisitor
A visitor/mutator capable of passing arbitrary arguments to the visit methods using CRTP and returnin...
Definition: IRVisitor.h:342
Halide::Internal::VariadicVisitor::dispatch
HALIDE_ALWAYS_INLINE StmtRet dispatch(const Stmt &s, Args &&...args)
Definition: IRVisitor.h:516
Halide::Internal::VariadicVisitor::dispatch
HALIDE_ALWAYS_INLINE ExprRet dispatch(Expr &&e, Args &&...args)
Definition: IRVisitor.h:531
Halide::Internal::VariadicVisitor::dispatch
HALIDE_ALWAYS_INLINE StmtRet dispatch(Stmt &&s, Args &&...args)
Definition: IRVisitor.h:521
Halide::Internal::VariadicVisitor::dispatch
HALIDE_ALWAYS_INLINE ExprRet dispatch(const Expr &e, Args &&...args)
Definition: IRVisitor.h:526
Halide::Internal::visit_with
void visit_with(const T &ir, Lambdas &&...lambdas)
Definition: IRVisitor.h:256
Halide::Internal::IRNodeType::VectorReduce
@ VectorReduce
Halide::Internal::IRNodeType::UIntImm
@ UIntImm
Halide::Internal::IRNodeType::Prefetch
@ Prefetch
Halide::Internal::IRNodeType::Reinterpret
@ Reinterpret
Halide::Internal::IRNodeType::ProducerConsumer
@ ProducerConsumer
Halide::Internal::IRNodeType::EQ
@ EQ
Halide::Internal::IRNodeType::Provide
@ Provide
Halide::Internal::IRNodeType::Fork
@ Fork
Halide::Internal::IRNodeType::For
@ For
Halide::Internal::IRNodeType::Or
@ Or
Halide::Internal::IRNodeType::FloatImm
@ FloatImm
Halide::Internal::IRNodeType::Div
@ Div
Halide::Internal::IRNodeType::Variable
@ Variable
Halide::Internal::IRNodeType::Cast
@ Cast
Halide::Internal::IRNodeType::Atomic
@ Atomic
Halide::Internal::IRNodeType::AssertStmt
@ AssertStmt
Halide::Internal::IRNodeType::Mul
@ Mul
Halide::Internal::IRNodeType::Max
@ Max
Halide::Internal::IRNodeType::StringImm
@ StringImm
Halide::Internal::IRNodeType::Min
@ Min
Halide::Internal::IRNodeType::Mod
@ Mod
Halide::Internal::IRNodeType::Acquire
@ Acquire
Halide::Internal::IRNodeType::Ramp
@ Ramp
Halide::Internal::IRNodeType::LetStmt
@ LetStmt
Halide::Internal::IRNodeType::Not
@ Not
Halide::Internal::IRNodeType::IfThenElse
@ IfThenElse
Halide::Internal::IRNodeType::Evaluate
@ Evaluate
Halide::Internal::IRNodeType::Free
@ Free
Halide::Internal::IRNodeType::HoistedStorage
@ HoistedStorage
Halide::Internal::IRNodeType::Broadcast
@ Broadcast
Halide::Internal::IRNodeType::And
@ And
Halide::Internal::IRNodeType::Call
@ Call
Halide::Internal::IRNodeType::LT
@ LT
Halide::Internal::IRNodeType::Allocate
@ Allocate
Halide::Internal::IRNodeType::Let
@ Let
Halide::Internal::IRNodeType::Realize
@ Realize
Halide::Internal::IRNodeType::GT
@ GT
Halide::Internal::IRNodeType::LE
@ LE
Halide::Internal::IRNodeType::IntImm
@ IntImm
Halide::Internal::IRNodeType::NE
@ NE
Halide::Internal::IRNodeType::Select
@ Select
Halide::Internal::IRNodeType::Block
@ Block
Halide::Internal::IRNodeType::Sub
@ Sub
Halide::Internal::IRNodeType::Shuffle
@ Shuffle
Halide::Internal::IRNodeType::Add
@ Add
Halide::Internal::IRNodeType::Load
@ Load
Halide::Internal::IRNodeType::GE
@ GE
Halide::Internal::IRNodeType::Store
@ Store
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:258
Halide::Expr::get
HALIDE_ALWAYS_INLINE const Internal::BaseExprNode * get() const
Override get() to return a BaseExprNode * instead of an IRNode *.
Definition: Expr.h:321
Halide::Internal::Acquire
Definition: IR.h:882
Halide::Internal::Add
The sum of two expressions.
Definition: IR.h:66
Halide::Internal::Allocate
Allocate a scratch area called with the given name, type, and size.
Definition: IR.h:381
Halide::Internal::And
Logical and - are both expressions true.
Definition: IR.h:185
Halide::Internal::AssertStmt
If the 'condition' is false, then evaluate and return the message, which should be a call to an error...
Definition: IR.h:304
Halide::Internal::Atomic
Lock all the Store nodes in the body statement.
Definition: IR.h:1004
Halide::Internal::BaseExprNode
A base class for expression nodes.
Definition: Expr.h:143
Halide::Internal::Block
A sequence of statements to be executed in-order.
Definition: IR.h:452
Halide::Internal::Broadcast
A vector with 'lanes' elements, in which every element is 'value'.
Definition: IR.h:269
Halide::Internal::Call
A function call.
Definition: IR.h:500
Halide::Internal::Cast
The actual IR nodes begin here.
Definition: IR.h:40
Halide::Internal::Div
The ratio of two expressions.
Definition: IR.h:93
Halide::Internal::EQ
Is the first expression equal to the second.
Definition: IR.h:131
Halide::Internal::Evaluate
Evaluate and discard an expression, presumably because it has some side-effect.
Definition: IR.h:486
Halide::Internal::ExprNode
We use the "curiously recurring template pattern" to avoid duplicated code in the IR Nodes.
Definition: Expr.h:158
Halide::Internal::FloatImm
Floating point constants.
Definition: Expr.h:236
Halide::Internal::For
A for loop.
Definition: IR.h:858
Halide::Internal::Fork
A pair of statements executed concurrently.
Definition: IR.h:467
Halide::Internal::Free
Free the resources associated with the given buffer.
Definition: IR.h:423
Halide::Internal::GE
Is the first expression greater than or equal to the second.
Definition: IR.h:176
Halide::Internal::GT
Is the first expression greater than the second.
Definition: IR.h:167
Halide::Internal::HoistedStorage
Represents a location where storage will be hoisted to for a Func / Realize node with a given name.
Definition: IR.h:988
Halide::Internal::IRNode::node_type
IRNodeType node_type
Each IR node subclass has a unique identifier.
Definition: Expr.h:113
Halide::Internal::IfThenElse
An if-then-else block.
Definition: IR.h:476
Halide::Internal::IntImm
Integer constants.
Definition: Expr.h:218
Halide::Internal::LE
Is the first expression less than or equal to the second.
Definition: IR.h:158
Halide::Internal::LT
Is the first expression less than the second.
Definition: IR.h:149
Halide::Internal::LambdaOverloads
Definition: IR.h:29
Halide::Internal::LambdaVisitor
A lambda-based IR visitor that accepts multiple lambdas for different node types.
Definition: IRVisitor.h:85
Halide::Internal::LambdaVisitor::visit
void visit(const Atomic *op) override
Definition: IRVisitor.h:247
Halide::Internal::LambdaVisitor::visit
void visit(const IntImm *op) override
Definition: IRVisitor.h:109
Halide::Internal::LambdaVisitor::visit
void visit(const Mod *op) override
Definition: IRVisitor.h:139
Halide::Internal::LambdaVisitor::visit
void visit(const HoistedStorage *op) override
Definition: IRVisitor.h:244
Halide::Internal::LambdaVisitor::visit
void visit(const Min *op) override
Definition: IRVisitor.h:142
Halide::Internal::LambdaVisitor::visit
void visit(const Max *op) override
Definition: IRVisitor.h:145
Halide::Internal::LambdaVisitor::visit
void visit(const GE *op) override
Definition: IRVisitor.h:163
Halide::Internal::LambdaVisitor::visit
void visit(const Variable *op) override
Definition: IRVisitor.h:229
Halide::Internal::LambdaVisitor::visit
void visit(const Not *op) override
Definition: IRVisitor.h:172
Halide::Internal::LambdaVisitor::visit
void visit(const Realize *op) override
Definition: IRVisitor.h:211
Halide::Internal::LambdaVisitor::visit
void visit(const LT *op) override
Definition: IRVisitor.h:154
Halide::Internal::LambdaVisitor::visit
void visit(const Reinterpret *op) override
Definition: IRVisitor.h:124
Halide::Internal::LambdaVisitor::visit
void visit(const Prefetch *op) override
Definition: IRVisitor.h:241
Halide::Internal::LambdaVisitor::LambdaVisitor
LambdaVisitor(Lambdas... lambdas)
Definition: IRVisitor.h:86
Halide::Internal::LambdaVisitor::visit
void visit(const Fork *op) override
Definition: IRVisitor.h:217
Halide::Internal::LambdaVisitor::visit
void visit(const Mul *op) override
Definition: IRVisitor.h:133
Halide::Internal::LambdaVisitor::visit
void visit(const EQ *op) override
Definition: IRVisitor.h:148
Halide::Internal::LambdaVisitor::visit
void visit(const Div *op) override
Definition: IRVisitor.h:136
Halide::Internal::LambdaVisitor::visit
void visit(const Sub *op) override
Definition: IRVisitor.h:130
Halide::Internal::LambdaVisitor::visit
void visit(const StringImm *op) override
Definition: IRVisitor.h:118
Halide::Internal::LambdaVisitor::visit_base
void visit_base(const T *op)
Public helper to call the base visitor from lambdas.
Definition: IRVisitor.h:92
Halide::Internal::LambdaVisitor::visit
void visit(const NE *op) override
Definition: IRVisitor.h:151
Halide::Internal::LambdaVisitor::visit
void visit(const IfThenElse *op) override
Definition: IRVisitor.h:220
Halide::Internal::LambdaVisitor::visit
void visit(const Provide *op) override
Definition: IRVisitor.h:202
Halide::Internal::LambdaVisitor::visit
void visit(const Or *op) override
Definition: IRVisitor.h:169
Halide::Internal::LambdaVisitor::visit
void visit(const LetStmt *op) override
Definition: IRVisitor.h:190
Halide::Internal::LambdaVisitor::visit
void visit(const VectorReduce *op) override
Definition: IRVisitor.h:250
Halide::Internal::LambdaVisitor::visit
void visit(const Free *op) override
Definition: IRVisitor.h:208
Halide::Internal::LambdaVisitor::visit
void visit(const And *op) override
Definition: IRVisitor.h:166
Halide::Internal::LambdaVisitor::visit
void visit(const Acquire *op) override
Definition: IRVisitor.h:235
Halide::Internal::LambdaVisitor::visit
void visit(const Let *op) override
Definition: IRVisitor.h:187
Halide::Internal::LambdaVisitor::visit
void visit(const For *op) override
Definition: IRVisitor.h:232
Halide::Internal::LambdaVisitor::visit
void visit(const Allocate *op) override
Definition: IRVisitor.h:205
Halide::Internal::LambdaVisitor::visit
void visit(const Shuffle *op) override
Definition: IRVisitor.h:238
Halide::Internal::LambdaVisitor::visit
void visit(const ProducerConsumer *op) override
Definition: IRVisitor.h:196
Halide::Internal::LambdaVisitor::visit
void visit(const LE *op) override
Definition: IRVisitor.h:157
Halide::Internal::LambdaVisitor::visit
void visit(const Ramp *op) override
Definition: IRVisitor.h:181
Halide::Internal::LambdaVisitor::visit
void visit(const Store *op) override
Definition: IRVisitor.h:199
Halide::Internal::LambdaVisitor::visit
void visit(const Load *op) override
Definition: IRVisitor.h:178
Halide::Internal::LambdaVisitor::visit
void visit(const AssertStmt *op) override
Definition: IRVisitor.h:193
Halide::Internal::LambdaVisitor::visit
void visit(const GT *op) override
Definition: IRVisitor.h:160
Halide::Internal::LambdaVisitor::visit
void visit(const FloatImm *op) override
Definition: IRVisitor.h:115
Halide::Internal::LambdaVisitor::visit
void visit(const Evaluate *op) override
Definition: IRVisitor.h:223
Halide::Internal::LambdaVisitor::visit
void visit(const Add *op) override
Definition: IRVisitor.h:127
Halide::Internal::LambdaVisitor::visit
void visit(const Call *op) override
Definition: IRVisitor.h:226
Halide::Internal::LambdaVisitor::visit
void visit(const Cast *op) override
Definition: IRVisitor.h:121
Halide::Internal::LambdaVisitor::visit
void visit(const Select *op) override
Definition: IRVisitor.h:175
Halide::Internal::LambdaVisitor::visit
void visit(const UIntImm *op) override
Definition: IRVisitor.h:112
Halide::Internal::LambdaVisitor::visit
void visit(const Broadcast *op) override
Definition: IRVisitor.h:184
Halide::Internal::LambdaVisitor::visit
void visit(const Block *op) override
Definition: IRVisitor.h:214
Halide::Internal::Let
A let expression, like you might find in a functional language.
Definition: IR.h:281
Halide::Internal::LetStmt
The statement form of a let node.
Definition: IR.h:292
Halide::Internal::Load
Load a value from a named symbol if predicate is true.
Definition: IR.h:227
Halide::Internal::Max
The greater of two values.
Definition: IR.h:122
Halide::Internal::Min
The lesser of two values.
Definition: IR.h:113
Halide::Internal::Mod
The remainder of a / b.
Definition: IR.h:104
Halide::Internal::Mul
The product of two expressions.
Definition: IR.h:84
Halide::Internal::NE
Is the first expression not equal to the second.
Definition: IR.h:140
Halide::Internal::Not
Logical not - true if the expression false.
Definition: IR.h:203
Halide::Internal::Or
Logical or - is at least one of the expression true.
Definition: IR.h:194
Halide::Internal::Prefetch
Represent a multi-dimensional region of a Func or an ImageParam that needs to be prefetched.
Definition: IR.h:966
Halide::Internal::ProducerConsumer
This node is a helpful annotation to do with permissions.
Definition: IR.h:325
Halide::Internal::Provide
This defines the value of a function at a multi-dimensional location.
Definition: IR.h:364
Halide::Internal::Ramp
A linear ramp vector node.
Definition: IR.h:257
Halide::Internal::Realize
Allocate a multi-dimensional buffer of the given type and size.
Definition: IR.h:437
Halide::Internal::Reinterpret
Reinterpret value as another type, without affecting any of the bits (on little-endian systems).
Definition: IR.h:57
Halide::Internal::Select
A ternary operator.
Definition: IR.h:214
Halide::Internal::Shuffle
Construct a new vector by taking elements from another sequence of vectors.
Definition: IR.h:894
Halide::Internal::Stmt
A reference-counted handle to a statement node.
Definition: Expr.h:427
Halide::Internal::Stmt::get
HALIDE_ALWAYS_INLINE const BaseStmtNode * get() const
Override get() to return a BaseStmtNode * instead of an IRNode *.
Definition: Expr.h:435
Halide::Internal::StmtNode
Definition: Expr.h:168
Halide::Internal::Store
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
Definition: IR.h:343
Halide::Internal::StringImm
String constants.
Definition: Expr.h:245
Halide::Internal::Sub
The difference of two expressions.
Definition: IR.h:75
Halide::Internal::UIntImm
Unsigned integer constants.
Definition: Expr.h:227
Halide::Internal::Variable
A named variable.
Definition: IR.h:811
Halide::Internal::VectorReduce
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
Definition: IR.h:1022