Halide 22.0.0 Halide compiler and libraries

Classes | Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Halide::Internal::Closure Class Reference

A helper class to manage closures. More...

`#include <Closure.h>`

Inheritance diagram for Halide::Internal::Closure:

## Classes
struct | Buffer
| Information about a buffer reference from a closure. More...

## Public Member Functions
| Closure ()=default
| Closure (const Closure &)=delete
Closure & | operator= (const Closure &)=delete
| Closure (Closure &&)=default
Closure & | operator= (Closure &&)=default
void | include (const Stmt &s, const std::string &loop_variable="")
| Traverse a statement and find all references to external symbols. More...
Expr | pack_into_struct () const
| Pack a closure into a struct. More...
Stmt | unpack_from_struct (const Expr &, const Stmt &) const
| Unpack a closure around a Stmt, putting all the names in scope. More...
Public Member Functions inherited from Halide::Internal::IRVisitor
| IRVisitor ()=default
virtual | ~IRVisitor ()=default

## Public Attributes
std::map< std::string, Type > | vars
| External variables referenced. More...
std::map< std::string, Buffer > | buffers
| External allocations referenced. More...

## Protected Member Functions
void | visit (const Let *op) override
void | visit (const LetStmt *op) override
void | visit (const For *op) override
void | visit (const Load *op) override
void | visit (const Store *op) override
void | visit (const Allocate *op) override
void | visit (const Variable *op) override
void | visit (const Atomic *op) override
void | found_buffer_ref (const std::string &name, Type type, bool read, bool written, const Halide::Buffer<> &image)
virtual void | visit (const IntImm *)
virtual void | visit (const UIntImm *)
virtual void | visit (const FloatImm *)
virtual void | visit (const StringImm *)
virtual void | visit (const Cast *)
virtual void | visit (const Reinterpret *)
virtual void | visit (const Add *)
virtual void | visit (const Sub *)
virtual void | visit (const Mul *)
virtual void | visit (const Div *)
virtual void | visit (const Mod *)
virtual void | visit (const Min *)
virtual void | visit (const Max *)
virtual void | visit (const EQ *)
virtual void | visit (const NE *)
virtual void | visit (const LT *)
virtual void | visit (const LE *)
virtual void | visit (const GT *)
virtual void | visit (const GE *)
virtual void | visit (const And *)
virtual void | visit (const Or *)
virtual void | visit (const Not *)
virtual void | visit (const Select *)
virtual void | visit (const Load *)
virtual void | visit (const Ramp *)
virtual void | visit (const Broadcast *)
virtual void | visit (const Let *)
virtual void | visit (const LetStmt *)
virtual void | visit (const AssertStmt *)
virtual void | visit (const ProducerConsumer *)
virtual void | visit (const Store *)
virtual void | visit (const Provide *)
virtual void | visit (const Allocate *)
virtual void | visit (const Free *)
virtual void | visit (const Realize *)
virtual void | visit (const Block *)
virtual void | visit (const Fork *)
virtual void | visit (const IfThenElse *)
virtual void | visit (const Evaluate *)
virtual void | visit (const Call *)
virtual void | visit (const Variable *)
virtual void | visit (const For *)
virtual void | visit (const Acquire *)
virtual void | visit (const Shuffle *)
virtual void | visit (const Prefetch *)
virtual void | visit (const HoistedStorage *)
virtual void | visit (const Atomic *)
virtual void | visit (const VectorReduce *)
virtual void | visit (const IntImm *)
virtual void | visit (const UIntImm *)
virtual void | visit (const FloatImm *)
virtual void | visit (const StringImm *)
virtual void | visit (const Cast *)
virtual void | visit (const Reinterpret *)
virtual void | visit (const Add *)
virtual void | visit (const Sub *)
virtual void | visit (const Mul *)
virtual void | visit (const Div *)
virtual void | visit (const Mod *)
virtual void | visit (const Min *)
virtual void | visit (const Max *)
virtual void | visit (const EQ *)
virtual void | visit (const NE *)
virtual void | visit (const LT *)
virtual void | visit (const LE *)
virtual void | visit (const GT *)
virtual void | visit (const GE *)
virtual void | visit (const And *)
virtual void | visit (const Or *)
virtual void | visit (const Not *)
virtual void | visit (const Select *)
virtual void | visit (const Load *)
virtual void | visit (const Ramp *)
virtual void | visit (const Broadcast *)
virtual void | visit (const Let *)
virtual void | visit (const LetStmt *)
virtual void | visit (const AssertStmt *)
virtual void | visit (const ProducerConsumer *)
virtual void | visit (const Store *)
virtual void | visit (const Provide *)
virtual void | visit (const Allocate *)
virtual void | visit (const Free *)
virtual void | visit (const Realize *)
virtual void | visit (const Block *)
virtual void | visit (const Fork *)
virtual void | visit (const IfThenElse *)
virtual void | visit (const Evaluate *)
virtual void | visit (const Call *)
virtual void | visit (const Variable *)
virtual void | visit (const For *)
virtual void | visit (const Acquire *)
virtual void | visit (const Shuffle *)
virtual void | visit (const Prefetch *)
virtual void | visit (const HoistedStorage *)
virtual void | visit (const Atomic *)
virtual void | visit (const VectorReduce *)

## Protected Attributes
Scope | ignore

## Detailed Description

A helper class to manage closures.

Walks over a statement and retrieves all the references within it to external symbols (variables and allocations). It then helps you build a struct containing the current values of these symbols that you can use as a closure if you want to migrate the body of the statement to its own function (e.g. because it's the body of a parallel for loop.

Definition at line 26 of file Closure.h.

## Constructor & Destructor Documentation

## ◆ Closure() [1/3]

Halide::Internal::Closure::Closure | ( |  | ) |
| default

## ◆ Closure() [2/3]

Halide::Internal::Closure::Closure | ( | const Closure & |  | ) |
| delete

## ◆ Closure() [3/3]

Halide::Internal::Closure::Closure | ( | Closure && |  | ) |
| default

## Member Function Documentation

## ◆ visit() [1/56]

void Halide::Internal::Closure::visit | ( | const Let * | op | ) |
| override protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [2/56]

void Halide::Internal::Closure::visit | ( | const LetStmt * | op | ) |
| override protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [3/56]

void Halide::Internal::Closure::visit | ( | const For * | op | ) |
| override protected virtual

Reimplemented from Halide::Internal::IRVisitor.

Reimplemented in Halide::Internal::HostClosure.

## ◆ visit() [4/56]

void Halide::Internal::Closure::visit | ( | const Load * | op | ) |
| override protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [5/56]

void Halide::Internal::Closure::visit | ( | const Store * | op | ) |
| override protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [6/56]

void Halide::Internal::Closure::visit | ( | const Allocate * | op | ) |
| override protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [7/56]

void Halide::Internal::Closure::visit | ( | const Variable * | op | ) |
| override protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [8/56]

void Halide::Internal::Closure::visit | ( | const Atomic * | op | ) |
| override protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ found_buffer_ref()

void Halide::Internal::Closure::found_buffer_ref | ( | const std::string & | name,
|  | Type | type,
|  | bool | read,
|  | bool | written,
|  | const Halide::Buffer<> & | image
| ) |  |
| protected

## ◆ operator=() [1/2]

Closure & Halide::Internal::Closure::operator= | ( | const Closure & |  | ) |
| delete

## ◆ operator=() [2/2]

Closure & Halide::Internal::Closure::operator= | ( | Closure && |  | ) |
| default

## ◆ include()

void Halide::Internal::Closure::include | ( | const Stmt & | s,
|  | const std::string & | loop_variable = `""`
| ) |  |

Traverse a statement and find all references to external symbols.

When the closure encounters a read or write to 'foo', it assumes that the host pointer is found in the symbol table as 'foo.host', and any halide_buffer_t pointer is found under 'foo.buffer'.

Calling this multiple times (on multiple statements) is legal (and will produce a unified closure).

## ◆ pack_into_struct()

Expr Halide::Internal::Closure::pack_into_struct | ( |  | ) | const

Pack a closure into a struct.

## ◆ unpack_from_struct()

Stmt Halide::Internal::Closure::unpack_from_struct | ( | const Expr & | ,
|  | const Stmt & |
| ) |  | const

Unpack a closure around a Stmt, putting all the names in scope.

## ◆ visit() [9/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const IntImm * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [10/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const UIntImm * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [11/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const FloatImm * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [12/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const StringImm * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [13/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Cast * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [14/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Reinterpret * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [15/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Add * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [16/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Sub * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [17/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Mul * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [18/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Div * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [19/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Mod * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [20/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Min * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [21/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Max * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [22/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const EQ * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [23/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const NE * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [24/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const LT * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [25/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const LE * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [26/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const GT * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [27/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const GE * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [28/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const And * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [29/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Or * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [30/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Not * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [31/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Select * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [32/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Load * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [33/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Ramp * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [34/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Broadcast * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [35/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Let * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [36/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const LetStmt * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [37/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const AssertStmt * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [38/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const ProducerConsumer * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [39/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Store * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [40/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Provide * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [41/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Allocate * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [42/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Free * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [43/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Realize * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [44/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Block * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [45/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Fork * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [46/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const IfThenElse * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [47/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Evaluate * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [48/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Call * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [49/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Variable * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [50/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const For * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [51/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Acquire * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [52/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Shuffle * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [53/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Prefetch * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [54/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const HoistedStorage * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [55/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const Atomic * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## ◆ visit() [56/56]

virtual void Halide::Internal::IRVisitor::visit | ( | const VectorReduce * |  | ) |
| protected virtual

Reimplemented from Halide::Internal::IRVisitor.

## Member Data Documentation

## ◆ ignore

Scope Halide::Internal::Closure::ignore
| protected

Definition at line 28 of file Closure.h.

## ◆ vars

std::map<std::string, Type> Halide::Internal::Closure::vars

External variables referenced.

There's code that assumes iterating over this repeatedly gives a consistent order, so don't swap out the data type for something non-deterministic.

Definition at line 94 of file Closure.h.

## ◆ buffers

std::map<std::string, Buffer> Halide::Internal::Closure::buffers

External allocations referenced.

Definition at line 97 of file Closure.h.

The documentation for this class was generated from the following file:

- src/Closure.h