Halide
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 
13 namespace Halide {
14 namespace 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. */
22 Expr 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. */
26 Stmt substitute(const std::string &name, const Expr &replacement, const Stmt &stmt);
27 
28 /** Substitute variables with names in the map. */
29 // @{
30 Expr substitute(const std::map<std::string, Expr> &replacements, const Expr &expr);
31 Stmt substitute(const std::map<std::string, Expr> &replacements, const Stmt &stmt);
32 // @}
33 
34 /** Substitute expressions for other expressions. */
35 // @{
36 Expr substitute(const Expr &find, const Expr &replacement, const Expr &expr);
37 Stmt 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 // @{
43 Expr graph_substitute(const std::string &name, const Expr &replacement, const Expr &expr);
44 Stmt graph_substitute(const std::string &name, const Expr &replacement, const Stmt &stmt);
45 Expr graph_substitute(const Expr &find, const Expr &replacement, const Expr &expr);
46 Stmt 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 // @{
55 Expr substitute_in_all_lets(const Expr &expr);
56 Stmt substitute_in_all_lets(const Stmt &stmt);
57 // @}
58 
59 } // namespace Internal
60 } // namespace Halide
61 
62 #endif
Halide::Internal::substitute
Expr substitute(const std::string &name, const Expr &replacement, const Expr &expr)
Substitute variables with the given name with the replacement expression within expr.
Halide::Internal::substitute_in_all_lets
Expr substitute_in_all_lets(const Expr &expr)
Substitute in all let Exprs in a piece of IR.
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Expr.h
Halide::Internal::graph_substitute
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).