Halide
Halide::Internal::ExprWithCompareCache Struct Reference

A wrapper about Exprs so that they can be deeply compared with a cache for known-equal subexpressions. More...

#include <IREquality.h>

Public Member Functions

 ExprWithCompareCache ()=default
 
 ExprWithCompareCache (const Expr &e, IRCompareCache *c)
 
bool operator< (const ExprWithCompareCache &other) const
 The comparison uses (and updates) the cache. More...
 

Public Attributes

Expr expr
 
IRCompareCachecache = nullptr
 

Detailed Description

A wrapper about Exprs so that they can be deeply compared with a cache for known-equal subexpressions.

Useful for unsanitized Exprs coming in from the front-end, which may be horrible graphs with sub-expressions that are equal by value but not by identity. This isn't a comparison object like IRDeepCompare above, because libc++ requires that comparison objects be stateless (and constructs a new one for each comparison!), so they can't have a cache associated with them. However, by sneakily making the cache a mutable member of the objects being compared, we can dodge this issue.

Clunky example usage:

Expr a, b, c, query;
std::set<ExprWithCompareCache> s;
IRCompareCache cache(8);
s.insert(ExprWithCompareCache(a, &cache));
s.insert(ExprWithCompareCache(b, &cache));
s.insert(ExprWithCompareCache(c, &cache));
if (m.contains(ExprWithCompareCache(query, &cache))) {...}

Definition at line 95 of file IREquality.h.

Constructor & Destructor Documentation

◆ ExprWithCompareCache() [1/2]

Halide::Internal::ExprWithCompareCache::ExprWithCompareCache ( )
default

◆ ExprWithCompareCache() [2/2]

Halide::Internal::ExprWithCompareCache::ExprWithCompareCache ( const Expr e,
IRCompareCache c 
)
inline

Definition at line 100 of file IREquality.h.

Member Function Documentation

◆ operator<()

bool Halide::Internal::ExprWithCompareCache::operator< ( const ExprWithCompareCache other) const

The comparison uses (and updates) the cache.

Member Data Documentation

◆ expr

Expr Halide::Internal::ExprWithCompareCache::expr

Definition at line 96 of file IREquality.h.

◆ cache

IRCompareCache* Halide::Internal::ExprWithCompareCache::cache = nullptr
mutable

Definition at line 97 of file IREquality.h.


The documentation for this struct was generated from the following file:
Halide::Internal::ExprWithCompareCache::ExprWithCompareCache
ExprWithCompareCache()=default
Halide::Internal::ExprWithCompareCache::cache
IRCompareCache * cache
Definition: IREquality.h:97