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
12namespace Halide {
13namespace 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 {
20public:
21 IRVisitor() = default;
22 virtual ~IRVisitor() = default;
23
24protected:
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. */
84template<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
96private:
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
108protected:
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
255template<typename... Lambdas>
256 void visit_with(const IRNode *ir, Lambdas &&...lambdas) {
257 LambdaVisitor visitor{std::forward<Lambdas>(lambdas)...};
258 constexpr bool all_take_two_args =
259 (std::is_invocable_v<Lambdas, decltype(&visitor), decltype(nullptr)> && ...);
260 static_assert(all_take_two_args);
261 ir->accept(&visitor);
262}
263
264template<typename... Lambdas>
265 void visit_with(const IRHandle &ir, Lambdas &&...lambdas) {
266 visit_with(ir.get(), std::forward<Lambdas>(lambdas)...);
267}
268
269/** A base class for algorithms that walk recursively over the IR
270 * without visiting the same node twice. This is for passes that are
271 * capable of interpreting the IR as a DAG instead of a tree. */
272 class IRGraphVisitor : public IRVisitor {
273protected:
274 /** By default these methods add the node to the visited set, and
275 * return whether or not it was already there. If it wasn't there,
276 * it delegates to the appropriate visit method. You can override
277 * them if you like. */
278 // @{
279 virtual void include(const Expr &);
280 virtual void include(const Stmt &);
281 // @}
282
283private:
284 /** The nodes visited so far. Only includes nodes with a ref count greater
285 * than one, because we know that nodes with a ref count of 1 will only be
286 * visited once if their parents are only visited once. */
287 std::set<const IRNode *> visited;
288
289protected:
290 /** These methods should call 'include' on the children to only
291 * visit them if they haven't been visited already. */
292 // @{
293 void visit(const IntImm *) override;
294 void visit(const UIntImm *) override;
295 void visit(const FloatImm *) override;
296 void visit(const StringImm *) override;
297 void visit(const Cast *) override;
298 void visit(const Reinterpret *) override;
299 void visit(const Add *) override;
300 void visit(const Sub *) override;
301 void visit(const Mul *) override;
302 void visit(const Div *) override;
303 void visit(const Mod *) override;
304 void visit(const Min *) override;
305 void visit(const Max *) override;
306 void visit(const EQ *) override;
307 void visit(const NE *) override;
308 void visit(const LT *) override;
309 void visit(const LE *) override;
310 void visit(const GT *) override;
311 void visit(const GE *) override;
312 void visit(const And *) override;
313 void visit(const Or *) override;
314 void visit(const Not *) override;
315 void visit(const Select *) override;
316 void visit(const Load *) override;
317 void visit(const Ramp *) override;
318 void visit(const Broadcast *) override;
319 void visit(const Let *) override;
320 void visit(const LetStmt *) override;
321 void visit(const AssertStmt *) override;
322 void visit(const ProducerConsumer *) override;
323 void visit(const Store *) override;
324 void visit(const Provide *) override;
325 void visit(const Allocate *) override;
326 void visit(const Free *) override;
327 void visit(const Realize *) override;
328 void visit(const Block *) override;
329 void visit(const Fork *) override;
330 void visit(const IfThenElse *) override;
331 void visit(const Evaluate *) override;
332 void visit(const Call *) override;
333 void visit(const Variable *) override;
334 void visit(const For *) override;
335 void visit(const Acquire *) override;
336 void visit(const Shuffle *) override;
337 void visit(const Prefetch *) override;
338 void visit(const HoistedStorage *) override;
339 void visit(const Atomic *) override;
340 void visit(const VectorReduce *) override;
341 // @}
342};
343
344/** A visitor/mutator capable of passing arbitrary arguments to the
345 * visit methods using CRTP and returning any types from them. All
346 * Expr visitors must have the same signature, and all Stmt visitors
347 * must have the same signature. Does not have default implementations
348 * of the visit methods. */
349template<typename T, typename ExprRet, typename StmtRet>
350 class VariadicVisitor {
351private:
352 template<typename... Args>
353 ExprRet dispatch_expr(const BaseExprNode *node, Args &&...args) {
354 if (node == nullptr) {
355 return ExprRet{};
356 }
357 switch (node->node_type) {
358 case IRNodeType::IntImm:
359 return ((T *)this)->visit((const IntImm *)node, std::forward<Args>(args)...);
360 case IRNodeType::UIntImm:
361 return ((T *)this)->visit((const UIntImm *)node, std::forward<Args>(args)...);
362 case IRNodeType::FloatImm:
363 return ((T *)this)->visit((const FloatImm *)node, std::forward<Args>(args)...);
364 case IRNodeType::StringImm:
365 return ((T *)this)->visit((const StringImm *)node, std::forward<Args>(args)...);
366 case IRNodeType::Broadcast:
367 return ((T *)this)->visit((const Broadcast *)node, std::forward<Args>(args)...);
368 case IRNodeType::Cast:
369 return ((T *)this)->visit((const Cast *)node, std::forward<Args>(args)...);
370 case IRNodeType::Reinterpret:
371 return ((T *)this)->visit((const Reinterpret *)node, std::forward<Args>(args)...);
372 case IRNodeType::Variable:
373 return ((T *)this)->visit((const Variable *)node, std::forward<Args>(args)...);
374 case IRNodeType::Add:
375 return ((T *)this)->visit((const Add *)node, std::forward<Args>(args)...);
376 case IRNodeType::Sub:
377 return ((T *)this)->visit((const Sub *)node, std::forward<Args>(args)...);
378 case IRNodeType::Mod:
379 return ((T *)this)->visit((const Mod *)node, std::forward<Args>(args)...);
380 case IRNodeType::Mul:
381 return ((T *)this)->visit((const Mul *)node, std::forward<Args>(args)...);
382 case IRNodeType::Div:
383 return ((T *)this)->visit((const Div *)node, std::forward<Args>(args)...);
384 case IRNodeType::Min:
385 return ((T *)this)->visit((const Min *)node, std::forward<Args>(args)...);
386 case IRNodeType::Max:
387 return ((T *)this)->visit((const Max *)node, std::forward<Args>(args)...);
388 case IRNodeType::EQ:
389 return ((T *)this)->visit((const EQ *)node, std::forward<Args>(args)...);
390 case IRNodeType::NE:
391 return ((T *)this)->visit((const NE *)node, std::forward<Args>(args)...);
392 case IRNodeType::LT:
393 return ((T *)this)->visit((const LT *)node, std::forward<Args>(args)...);
394 case IRNodeType::LE:
395 return ((T *)this)->visit((const LE *)node, std::forward<Args>(args)...);
396 case IRNodeType::GT:
397 return ((T *)this)->visit((const GT *)node, std::forward<Args>(args)...);
398 case IRNodeType::GE:
399 return ((T *)this)->visit((const GE *)node, std::forward<Args>(args)...);
400 case IRNodeType::And:
401 return ((T *)this)->visit((const And *)node, std::forward<Args>(args)...);
402 case IRNodeType::Or:
403 return ((T *)this)->visit((const Or *)node, std::forward<Args>(args)...);
404 case IRNodeType::Not:
405 return ((T *)this)->visit((const Not *)node, std::forward<Args>(args)...);
406 case IRNodeType::Select:
407 return ((T *)this)->visit((const Select *)node, std::forward<Args>(args)...);
408 case IRNodeType::Load:
409 return ((T *)this)->visit((const Load *)node, std::forward<Args>(args)...);
410 case IRNodeType::Ramp:
411 return ((T *)this)->visit((const Ramp *)node, std::forward<Args>(args)...);
412 case IRNodeType::Call:
413 return ((T *)this)->visit((const Call *)node, std::forward<Args>(args)...);
414 case IRNodeType::Let:
415 return ((T *)this)->visit((const Let *)node, std::forward<Args>(args)...);
416 case IRNodeType::Shuffle:
417 return ((T *)this)->visit((const Shuffle *)node, std::forward<Args>(args)...);
418 case IRNodeType::VectorReduce:
419 return ((T *)this)->visit((const VectorReduce *)node, std::forward<Args>(args)...);
420 // Explicitly list the Stmt types rather than using a
421 // default case so that when new IR nodes are added we
422 // don't miss them here.
423 case IRNodeType::LetStmt:
424 case IRNodeType::AssertStmt:
425 case IRNodeType::ProducerConsumer:
426 case IRNodeType::For:
427 case IRNodeType::Acquire:
428 case IRNodeType::Store:
429 case IRNodeType::Provide:
430 case IRNodeType::Allocate:
431 case IRNodeType::Free:
432 case IRNodeType::Realize:
433 case IRNodeType::Block:
434 case IRNodeType::Fork:
435 case IRNodeType::IfThenElse:
436 case IRNodeType::Evaluate:
437 case IRNodeType::Prefetch:
438 case IRNodeType::Atomic:
439 case IRNodeType::HoistedStorage:
440 internal_error << "Unreachable";
441 }
442 return ExprRet{};
443 }
444
445 template<typename... Args>
446 StmtRet dispatch_stmt(const BaseStmtNode *node, Args &&...args) {
447 if (node == nullptr) {
448 return StmtRet{};
449 }
450 switch (node->node_type) {
451 case IRNodeType::IntImm:
452 case IRNodeType::UIntImm:
453 case IRNodeType::FloatImm:
454 case IRNodeType::StringImm:
455 case IRNodeType::Broadcast:
456 case IRNodeType::Cast:
457 case IRNodeType::Reinterpret:
458 case IRNodeType::Variable:
459 case IRNodeType::Add:
460 case IRNodeType::Sub:
461 case IRNodeType::Mod:
462 case IRNodeType::Mul:
463 case IRNodeType::Div:
464 case IRNodeType::Min:
465 case IRNodeType::Max:
466 case IRNodeType::EQ:
467 case IRNodeType::NE:
468 case IRNodeType::LT:
469 case IRNodeType::LE:
470 case IRNodeType::GT:
471 case IRNodeType::GE:
472 case IRNodeType::And:
473 case IRNodeType::Or:
474 case IRNodeType::Not:
475 case IRNodeType::Select:
476 case IRNodeType::Load:
477 case IRNodeType::Ramp:
478 case IRNodeType::Call:
479 case IRNodeType::Let:
480 case IRNodeType::Shuffle:
481 case IRNodeType::VectorReduce:
482 internal_error << "Unreachable";
483 break;
484 case IRNodeType::LetStmt:
485 return ((T *)this)->visit((const LetStmt *)node, std::forward<Args>(args)...);
486 case IRNodeType::AssertStmt:
487 return ((T *)this)->visit((const AssertStmt *)node, std::forward<Args>(args)...);
488 case IRNodeType::ProducerConsumer:
489 return ((T *)this)->visit((const ProducerConsumer *)node, std::forward<Args>(args)...);
490 case IRNodeType::For:
491 return ((T *)this)->visit((const For *)node, std::forward<Args>(args)...);
492 case IRNodeType::Acquire:
493 return ((T *)this)->visit((const Acquire *)node, std::forward<Args>(args)...);
494 case IRNodeType::Store:
495 return ((T *)this)->visit((const Store *)node, std::forward<Args>(args)...);
496 case IRNodeType::Provide:
497 return ((T *)this)->visit((const Provide *)node, std::forward<Args>(args)...);
498 case IRNodeType::Allocate:
499 return ((T *)this)->visit((const Allocate *)node, std::forward<Args>(args)...);
500 case IRNodeType::Free:
501 return ((T *)this)->visit((const Free *)node, std::forward<Args>(args)...);
502 case IRNodeType::Realize:
503 return ((T *)this)->visit((const Realize *)node, std::forward<Args>(args)...);
504 case IRNodeType::Block:
505 return ((T *)this)->visit((const Block *)node, std::forward<Args>(args)...);
506 case IRNodeType::Fork:
507 return ((T *)this)->visit((const Fork *)node, std::forward<Args>(args)...);
508 case IRNodeType::IfThenElse:
509 return ((T *)this)->visit((const IfThenElse *)node, std::forward<Args>(args)...);
510 case IRNodeType::Evaluate:
511 return ((T *)this)->visit((const Evaluate *)node, std::forward<Args>(args)...);
512 case IRNodeType::Prefetch:
513 return ((T *)this)->visit((const Prefetch *)node, std::forward<Args>(args)...);
514 case IRNodeType::Atomic:
515 return ((T *)this)->visit((const Atomic *)node, std::forward<Args>(args)...);
516 case IRNodeType::HoistedStorage:
517 return ((T *)this)->visit((const HoistedStorage *)node, std::forward<Args>(args)...);
518 }
519 return StmtRet{};
520 }
521
522public:
523 template<typename... Args>
524 HALIDE_ALWAYS_INLINE StmtRet dispatch(const Stmt &s, Args &&...args) {
525 return dispatch_stmt(s.get(), std::forward<Args>(args)...);
526 }
527
528 template<typename... Args>
529 HALIDE_ALWAYS_INLINE StmtRet dispatch(Stmt &&s, Args &&...args) {
530 return dispatch_stmt(s.get(), std::forward<Args>(args)...);
531 }
532
533 template<typename... Args>
534 HALIDE_ALWAYS_INLINE ExprRet dispatch(const Expr &e, Args &&...args) {
535 return dispatch_expr(e.get(), std::forward<Args>(args)...);
536 }
537
538 template<typename... Args>
539 HALIDE_ALWAYS_INLINE ExprRet dispatch(Expr &&e, Args &&...args) {
540 return dispatch_expr(e.get(), std::forward<Args>(args)...);
541 }
542};
543
544} // namespace Internal
545} // namespace Halide
546
547#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:272
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:350
Halide::Internal::VariadicVisitor::dispatch
HALIDE_ALWAYS_INLINE StmtRet dispatch(const Stmt &s, Args &&...args)
Definition: IRVisitor.h:524
Halide::Internal::VariadicVisitor::dispatch
HALIDE_ALWAYS_INLINE ExprRet dispatch(Expr &&e, Args &&...args)
Definition: IRVisitor.h:539
Halide::Internal::VariadicVisitor::dispatch
HALIDE_ALWAYS_INLINE StmtRet dispatch(Stmt &&s, Args &&...args)
Definition: IRVisitor.h:529
Halide::Internal::VariadicVisitor::dispatch
HALIDE_ALWAYS_INLINE ExprRet dispatch(const Expr &e, Args &&...args)
Definition: IRVisitor.h:534
Halide::Internal::visit_with
void visit_with(const IRNode *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:886
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:1008
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:992
Halide::Internal::IRHandle
IR nodes are passed around opaque handles to them.
Definition: Expr.h:180
Halide::Internal::IRNode
The abstract base classes for a node in the Halide IR.
Definition: Expr.h:84
Halide::Internal::IRNode::accept
virtual void accept(IRVisitor *v) const =0
We use the visitor pattern to traverse IR nodes throughout the compiler, so we have a virtual accept ...
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::IntrusivePtr::get
T * get() const
Access the raw pointer in a variety of ways.
Definition: IntrusivePtr.h:102
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:970
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:898
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:813
Halide::Internal::VectorReduce
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
Definition: IR.h:1026