Loading...
Searching...
No Matches
IREquality.h
Go to the documentation of this file.
#ifndef HALIDE_IR_EQUALITY_H
#define HALIDE_IR_EQUALITY_H
/** \file
* Methods to test Exprs and Stmts for equality of value.
*
* These methods traverse the entire IR tree. For equality of reference, use
* Expr::same_as. If you're comparing non-CSE'd Exprs, use graph_equal or
* graph_less_than, which is safe for nasty graphs of IR nodes.
*/
#include "Expr.h"
namespace Halide {
namespace Internal {
// We want to inline a few quick checks into the caller. These are the actual
// implementations that get called after those quick checks.
bool equal_impl(const IRNode &a, const IRNode &b);
bool graph_equal_impl(const IRNode &a, const IRNode &b);
bool less_than_impl(const IRNode &a, const IRNode &b);
bool graph_less_than_impl(const IRNode &a, const IRNode &b);
/** Compare an Expr to an int literal. This is a somewhat common use of equal in
* tests. Making this separate avoids constructing an Expr out of the int
* literal just to check if it's equal to a. */
HALIDE_ALWAYS_INLINE
bool equal(const Expr &a, int b) {
if (const IntImm *i = a.as<IntImm>()) {
return (a.type() == Int(32) && i->value == b);
} else {
return false;
}
}
/** Check if two defined Stmts or Exprs are equal. */
HALIDE_ALWAYS_INLINE
bool equal(const IRNode &a, const IRNode &b) {
if (&a == &b) {
return true;
} else if (a.node_type != b.node_type) {
return false;
} else {
return equal_impl(a, b);
}
}
/** Check if two possible-undefined Stmts or Exprs are equal. */
HALIDE_ALWAYS_INLINE
bool equal(const IRHandle &a, const IRHandle &b) {
if (!a.defined()) {
return !b.defined();
} else if (!b.defined()) {
return false;
} else {
return equal(*(a.get()), *(b.get()));
}
}
/** Check if two defined Stmts or Exprs are equal. Safe to call on Exprs that
* haven't been passed to common_subexpression_elimination. */
HALIDE_ALWAYS_INLINE
bool graph_equal(const IRNode &a, const IRNode &b) {
if (&a == &b) {
return true;
} else if (a.node_type != b.node_type) {
return false;
} else {
return graph_equal_impl(a, b);
}
}
/** Check if two possibly-undefined Stmts or Exprs are equal. Safe to call on
* Exprs that haven't been passed to common_subexpression_elimination. */
HALIDE_ALWAYS_INLINE
bool graph_equal(const IRHandle &a, const IRHandle &b) {
if (!a.defined()) {
return !b.defined();
} else if (!b.defined()) {
return false;
} else {
return graph_equal(*(a.get()), *(b.get()));
}
}
/** Check if two defined Stmts or Exprs are in a lexicographic order. For use in
* map keys. */
HALIDE_ALWAYS_INLINE
bool less_than(const IRNode &a, const IRNode &b) {
if (&a == &b) {
return false;
} else if (a.node_type < b.node_type) {
return true;
} else {
return less_than_impl(a, b);
}
}
/** Check if two possibly-undefined Stmts or Exprs are in a lexicographic
* order. For use in map keys. */
HALIDE_ALWAYS_INLINE
bool less_than(const IRHandle &a, const IRHandle &b) {
if (a.get() == b.get()) {
return false;
} else if (!a.defined()) {
return true;
} else if (!b.defined()) {
return false;
} else {
return less_than(*(a.get()), *(b.get()));
}
}
/** Check if two defined Stmts or Exprs are in a lexicographic order. For use in
* map keys. Safe to use on Exprs that haven't been passed to
* common_subexpression_elimination. */
HALIDE_ALWAYS_INLINE
bool graph_less_than(const IRNode &a, const IRNode &b) {
if (&a == &b) {
return false;
} else if (a.node_type < b.node_type) {
return true;
} else {
return graph_less_than_impl(a, b);
}
}
/** Check if two possibly-undefined Stmts or Exprs are in a lexicographic
* order. For use in map keys. Safe to use on Exprs that haven't been passed to
* common_subexpression_elimination. */
HALIDE_ALWAYS_INLINE
bool graph_less_than(const IRHandle &a, const IRHandle &b) {
if (a.get() == b.get()) {
return false;
} else if (!a.defined()) {
return true;
} else if (!b.defined()) {
return false;
} else {
return graph_less_than(*(a.get()), *(b.get()));
}
}
/** A compare struct built around less_than, for use as the comparison
* object in a std::map or std::set. */
struct IRDeepCompare {
bool operator()(const IRHandle &a, const IRHandle &b) const {
return less_than(a, b);
}
};
/** A compare struct built around graph_less_than, for use as the comparison
* object in a std::map or std::set. */
struct IRGraphDeepCompare {
bool operator()(const IRHandle &a, const IRHandle &b) const {
return graph_less_than(a, b);
}
};
void ir_equality_test();
} // namespace Internal
} // namespace Halide
#endif
Expr.h
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt).
HALIDE_ALWAYS_INLINE
#define HALIDE_ALWAYS_INLINE
Definition HalideRuntime.h:49
Halide::Internal
Definition AbstractGenerator.h:24
Halide::Internal::equal
bool equal(const RDom &bounds0, const RDom &bounds1)
Return true if bounds0 and bounds1 represent the same bounds.
Halide::Internal::graph_less_than
HALIDE_ALWAYS_INLINE bool graph_less_than(const IRNode &a, const IRNode &b)
Check if two defined Stmts or Exprs are in a lexicographic order.
Definition IREquality.h:118
Halide::Internal::graph_less_than_impl
bool graph_less_than_impl(const IRNode &a, const IRNode &b)
Halide::Internal::equal_impl
bool equal_impl(const IRNode &a, const IRNode &b)
Halide::Internal::less_than_impl
bool less_than_impl(const IRNode &a, const IRNode &b)
Halide::Internal::graph_equal_impl
bool graph_equal_impl(const IRNode &a, const IRNode &b)
Halide::Internal::less_than
HALIDE_ALWAYS_INLINE bool less_than(const IRNode &a, const IRNode &b)
Check if two defined Stmts or Exprs are in a lexicographic order.
Definition IREquality.h:89
Halide::Internal::graph_equal
HALIDE_ALWAYS_INLINE bool graph_equal(const IRNode &a, const IRNode &b)
Check if two defined Stmts or Exprs are equal.
Definition IREquality.h:63
Halide::Internal::ir_equality_test
void ir_equality_test()
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19
Halide::Int
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Definition Type.h:541
Halide::Expr
A fragment of Halide syntax.
Definition Expr.h:258
Halide::Expr::type
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Definition Expr.h:327
Halide::Internal::IRDeepCompare
A compare struct built around less_than, for use as the comparison object in a std::map or std::set.
Definition IREquality.h:146
Halide::Internal::IRDeepCompare::operator()
bool operator()(const IRHandle &a, const IRHandle &b) const
Definition IREquality.h:147
Halide::Internal::IRGraphDeepCompare
A compare struct built around graph_less_than, for use as the comparison object in a std::map or std:...
Definition IREquality.h:154
Halide::Internal::IRGraphDeepCompare::operator()
bool operator()(const IRHandle &a, const IRHandle &b) const
Definition IREquality.h:155
Halide::Internal::IRHandle
IR nodes are passed around opaque handles to them.
Definition Expr.h:180
Halide::Internal::IRHandle::as
const T * as() const
Downcast this ir node to its actual type (e.g.
Definition Expr.h:205
Halide::Internal::IRNode
The abstract base classes for a node in the Halide IR.
Definition Expr.h:84
Halide::Internal::IRNode::node_type
IRNodeType node_type
Each IR node subclass has a unique identifier.
Definition Expr.h:113
Halide::Internal::IntImm
Integer constants.
Definition Expr.h:218
Halide::Internal::IntrusivePtr::defined
HALIDE_ALWAYS_INLINE bool defined() const
Definition IntrusivePtr.h:164
Halide::Internal::IntrusivePtr::get
T * get() const
Access the raw pointer in a variety of ways.
Definition IntrusivePtr.h:102