Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
Substitute.h
Go to the documentation of this file.
1#ifndef HALIDE_SUBSTITUTE_H
2#define HALIDE_SUBSTITUTE_H
3
4/** \file
5 *
6 * Defines methods for substituting out variables in expressions and
7 * statements. */
8
9#include <map>
10
11#include "Expr.h"
12
13namespace Halide {
14namespace Internal {
15
16/** Substitute variables with the given name with the replacement
17 * expression within expr. This is a dangerous thing to do if variable
18 * names have not been uniquified. While it won't traverse inside let
19 * statements with the same name as the first argument, moving a piece
20 * of syntax around can change its meaning, because it can cross lets
21 * that redefine variable names that it includes references to. */
22Expr substitute(const std::string &name, const Expr &replacement, const Expr &expr);
23
24/** Substitute variables with the given name with the replacement
25 * expression within stmt. */
26Stmt substitute(const std::string &name, const Expr &replacement, const Stmt &stmt);
27
28/** Substitute variables with names in the map. */
29// @{
30Expr substitute(const std::map<std::string, Expr> &replacements, const Expr &expr);
31Stmt substitute(const std::map<std::string, Expr> &replacements, const Stmt &stmt);
32// @}
33
34/** Substitute expressions for other expressions. */
35// @{
36Expr substitute(const Expr &find, const Expr &replacement, const Expr &expr);
37Stmt substitute(const Expr &find, const Expr &replacement, const Stmt &stmt);
38// @}
39
40/** Substitutions where the IR may be a general graph (and not just a
41 * DAG). */
42// @{
43Expr graph_substitute(const std::string &name, const Expr &replacement, const Expr &expr);
44Stmt graph_substitute(const std::string &name, const Expr &replacement, const Stmt &stmt);
45Expr graph_substitute(const Expr &find, const Expr &replacement, const Expr &expr);
46Stmt graph_substitute(const Expr &find, const Expr &replacement, const Stmt &stmt);
47// @}
48
49/** Substitute in all let Exprs in a piece of IR. Doesn't substitute
50 * in let stmts, as this may change the meaning of the IR (e.g. by
51 * moving a load after a store). Produces graphs of IR, so don't use
52 * non-graph-aware visitors or mutators on it until you've CSE'd the
53 * result. */
54// @{
57// @}
58
59} // namespace Internal
60} // namespace Halide
61
62#endif
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Expr graph_substitute(const std::string &name, const Expr &replacement, const Expr &expr)
Substitutions where the IR may be a general graph (and not just a DAG).
Expr substitute_in_all_lets(const Expr &expr)
Substitute in all let Exprs in a piece of IR.
Expr substitute(const std::string &name, const Expr &replacement, const Expr &expr)
Substitute variables with the given name with the replacement expression within expr.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
A fragment of Halide syntax.
Definition Expr.h:258
A reference-counted handle to a statement node.
Definition Expr.h:427