1 #ifndef HALIDE_SIMPLIFY_VISITORS_H
2 #define HALIDE_SIMPLIFY_VISITORS_H
18 #define LOG_EXPR_MUTATIONS 0
19 #define LOG_STMT_MUTATIONS 0
26 #define EVAL_IN_LAMBDA(x) (([&]() HALIDE_NEVER_INLINE { return (x); })())
33 if ((a > 0) == (b > 0)) {
106 #if (LOG_EXPR_MUTATORIONS || LOG_STMT_MUTATIONS)
107 static int debug_indent;
110 #if LOG_EXPR_MUTATIONS
112 const std::string spaces(debug_indent,
' ');
113 debug(1) << spaces <<
"Simplifying Expr: " << e <<
"\n";
119 << spaces <<
"Before: " << e <<
"\n"
120 << spaces <<
"After: " << new_e <<
"\n";
134 #if LOG_STMT_MUTATIONS
136 const std::string spaces(debug_indent,
' ');
137 debug(1) << spaces <<
"Simplifying Stmt: " << s <<
"\n";
143 << spaces <<
"Before: " << s <<
"\n"
144 << spaces <<
"After: " << new_s <<
"\n";
236 return va->
name.compare(vb->name) > 0;
296 template<
typename T,
typename Body>
Methods for computing the upper and lower bounds of an expression, and the regions of a function read...
#define internal_assert(c)
#define HALIDE_ALWAYS_INLINE
Defines a method to match a fragment of IR against a pattern containing wildcards.
Defines the base class for things that recursively walk over the IR.
Defines the Scope class, which is used for keeping track of names in a scope while traversing IR.
A common pattern when traversing Halide IR is that you need to keep track of stuff when you find a Le...
Expr visit(const Min *op, ExprInfo *bounds)
Stmt visit(const ProducerConsumer *op)
HALIDE_ALWAYS_INLINE Expr mutate(const Expr &e, ExprInfo *b)
Scope< ExprInfo > bounds_and_alignment_info
bool const_uint(const Expr &e, uint64_t *u)
IRMatcher::WildConst< 5 > c5
void found_buffer_reference(const std::string &name, size_t dimensions=0)
Expr visit(const Cast *op, ExprInfo *bounds)
Expr visit(const LT *op, ExprInfo *bounds)
Stmt visit(const Block *op)
Expr visit(const VectorReduce *op, ExprInfo *bounds)
Stmt visit(const AssertStmt *op)
Expr visit(const UIntImm *op, ExprInfo *bounds)
Stmt mutate(const Stmt &s)
Expr visit(const Load *op, ExprInfo *bounds)
Stmt visit(const Evaluate *op)
Expr visit(const Not *op, ExprInfo *bounds)
Body simplify_let(const T *op, ExprInfo *bounds)
Simplify(bool r, const Scope< Interval > *bi, const Scope< ModulusRemainder > *ai)
Stmt visit(const Prefetch *op)
HALIDE_ALWAYS_INLINE bool no_overflow(Type t)
Expr visit(const Div *op, ExprInfo *bounds)
IRMatcher::WildConst< 1 > c1
Expr visit(const Let *op, ExprInfo *bounds)
Expr hoist_slice_vector(Expr e)
Expr visit(const And *op, ExprInfo *bounds)
Stmt visit(const IfThenElse *op)
Expr visit(const NE *op, ExprInfo *bounds)
Expr visit(const FloatImm *op, ExprInfo *bounds)
Expr visit(const Shuffle *op, ExprInfo *bounds)
Expr visit(const Add *op, ExprInfo *bounds)
IRMatcher::WildConst< 0 > c0
ScopedFact scoped_truth(const Expr &fact)
IRMatcher::WildConst< 3 > c3
IRMatcher::WildConst< 2 > c2
Scope< VarInfo > var_info
Expr visit(const Ramp *op, ExprInfo *bounds)
Expr visit(const IntImm *op, ExprInfo *bounds)
Expr visit(const Max *op, ExprInfo *bounds)
Expr visit(const Variable *op, ExprInfo *bounds)
HALIDE_ALWAYS_INLINE bool may_simplify(const Type &t) const
Stmt visit(const For *op)
Stmt visit(const Atomic *op)
bool const_float(const Expr &e, double *f)
Expr visit(const GT *op, ExprInfo *bounds)
Stmt visit(const Provide *op)
Expr visit(const Sub *op, ExprInfo *bounds)
Expr visit(const LE *op, ExprInfo *bounds)
Expr visit(const Call *op, ExprInfo *bounds)
Stmt mutate_let_body(const Stmt &s, ExprInfo *)
Stmt visit(const Acquire *op)
Expr visit(const Broadcast *op, ExprInfo *bounds)
Stmt visit(const Fork *op)
HALIDE_ALWAYS_INLINE bool no_overflow_int(Type t)
Expr visit(const StringImm *op, ExprInfo *bounds)
std::set< Expr, IRDeepCompare > truths
Expr visit(const Select *op, ExprInfo *bounds)
ScopedFact scoped_falsehood(const Expr &fact)
HALIDE_ALWAYS_INLINE bool should_commute(const Expr &a, const Expr &b)
Expr visit(const Or *op, ExprInfo *bounds)
Expr visit(const Mul *op, ExprInfo *bounds)
Expr mutate_let_body(const Expr &e, ExprInfo *bounds)
Stmt visit(const Store *op)
Expr visit(const Mod *op, ExprInfo *bounds)
HALIDE_ALWAYS_INLINE bool no_overflow_scalar_int(Type t)
bool const_int(const Expr &e, int64_t *i)
Stmt visit(const Free *op)
IRMatcher::WildConst< 4 > c4
Stmt visit(const Allocate *op)
Stmt visit(const Realize *op)
Stmt visit(const LetStmt *op)
std::set< Expr, IRDeepCompare > falsehoods
Expr visit(const EQ *op, ExprInfo *bounds)
Expr visit(const GE *op, ExprInfo *bounds)
A visitor/mutator capable of passing arbitrary arguments to the visit methods using CRTP and returnin...
HALIDE_ALWAYS_INLINE Stmt dispatch(const Stmt &s, Args &&...args)
For optional debugging during codegen, use the debug class as follows:
T mod_imp(T a, T b)
Implementations of division and mod that are specific to Halide.
bool mul_would_overflow(int bits, int64_t a, int64_t b)
int64_t saturating_mul(int64_t a, int64_t b)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Expr min(const FuncRef &a, const FuncRef &b)
Explicit overloads of min and max for FuncRef.
Expr max(const FuncRef &a, const FuncRef &b)
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
A fragment of Halide syntax.
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
The sum of two expressions.
Allocate a scratch area called with the given name, type, and size.
Logical and - are both expressions true.
If the 'condition' is false, then evaluate and return the message, which should be a call to an error...
Lock all the Store nodes in the body statement.
A sequence of statements to be executed in-order.
A vector with 'lanes' elements, in which every element is 'value'.
The actual IR nodes begin here.
The ratio of two expressions.
Is the first expression equal to the second.
Evaluate and discard an expression, presumably because it has some side-effect.
Floating point constants.
A pair of statements executed concurrently.
Free the resources associated with the given buffer.
Is the first expression greater than or equal to the second.
Is the first expression greater than the second.
IRNodeType node_type() const
const T * as() const
Downcast this ir node to its actual type (e.g.
HALIDE_ALWAYS_INLINE bool same_as(const IntrusivePtr &other) const
Is the first expression less than or equal to the second.
Is the first expression less than the second.
A let expression, like you might find in a functional language.
The statement form of a let node.
Load a value from a named symbol if predicate is true.
The greater of two values.
The lesser of two values.
The result of modulus_remainder analysis.
static ModulusRemainder intersect(const ModulusRemainder &a, const ModulusRemainder &b)
The product of two expressions.
Is the first expression not equal to the second.
Logical not - true if the expression false.
Logical or - is at least one of the expression true.
Represent a multi-dimensional region of a Func or an ImageParam that needs to be prefetched.
This node is a helpful annotation to do with permissions.
This defines the value of a function at a multi-dimensional location.
A linear ramp vector node.
Allocate a multi-dimensional buffer of the given type and size.
Construct a new vector by taking elements from another sequence of vectors.
void intersect(const ExprInfo &other)
void trim_bounds_using_alignment()
ModulusRemainder alignment
ScopedFact(ScopedFact &&that)=default
void learn_true(const Expr &fact)
void learn_false(const Expr &fact)
std::vector< const Variable * > bounds_pop_list
ScopedFact(const ScopedFact &that)=delete
std::vector< Expr > truths
std::vector< const Variable * > pop_list
void learn_lower_bound(const Variable *v, int64_t val)
Expr substitute_facts(const Expr &e)
std::vector< Expr > falsehoods
Stmt substitute_facts(const Stmt &s)
void learn_upper_bound(const Variable *v, int64_t val)
A reference-counted handle to a statement node.
Store a 'value' to the buffer called 'name' at a given 'index' if 'predicate' is true.
The difference of two expressions.
Unsigned integer constants.
Horizontally reduce a vector to a scalar or narrower vector using the given commutative and associati...
Types in the halide type system.
HALIDE_ALWAYS_INLINE bool is_int() const
Is this type a signed integer type?
HALIDE_ALWAYS_INLINE int bits() const
Return the bit size of a single element of this type.
HALIDE_ALWAYS_INLINE bool is_scalar() const
Is this type a scalar type? (lanes() == 1).
HALIDE_ALWAYS_INLINE bool is_float() const
Is this type a floating point type (float or double).