MLIR
20.0.0git
|
A cache for replacer-like functions that map values between two domains. More...
#include "mlir/Support/CyclicReplacerCache.h"
Classes | |
struct | CacheEntry |
A possibly unresolved cache entry. More... | |
Public Types | |
using | CycleBreakerFn = std::function< std::optional< OutT >(InT)> |
User-provided replacement function & cycle-breaking functions. More... | |
Public Member Functions | |
CyclicReplacerCache ()=delete | |
CyclicReplacerCache (CycleBreakerFn cycleBreaker) | |
CacheEntry | lookupOrInit (InT element) |
Lookup the cache for a pre-calculated replacement for element . More... | |
A cache for replacer-like functions that map values between two domains.
The difference compared to just using a map to cache in-out pairs is that this class is able to handle replacer logic that is self-recursive (and thus may cause infinite recursion in the naive case).
This class provides a hook for the user to perform cycle pruning when a cycle is identified, and is able to perform context-sensitive caching so that the replacement result for an input that is part of a pruned cycle can be distinct from the replacement result for the same input when it is not part of a cycle.
In addition, this class allows deferring cycle pruning until specific inputs are repeated. This is useful for cases where not all elements in a cycle can perform pruning. The user still must guarantee that at least one element in any given cycle can perform pruning. Even if not, an assertion will eventually be tripped instead of infinite recursion (the run-time is linearly bounded by the maximum cycle length of its input).
WARNING: This class works best with InT & OutT that are trivial scalar types. The input/output elements will be frequently copied and hashed.
Definition at line 52 of file CyclicReplacerCache.h.
using mlir::CyclicReplacerCache< InT, OutT >::CycleBreakerFn = std::function<std::optional<OutT>(InT)> |
User-provided replacement function & cycle-breaking functions.
The cycle-breaking function must not make any more recursive invocations to this cached replacer.
Definition at line 57 of file CyclicReplacerCache.h.
|
delete |
|
inline |
Definition at line 60 of file CyclicReplacerCache.h.
CyclicReplacerCache< InT, OutT >::CacheEntry mlir::CyclicReplacerCache< InT, OutT >::lookupOrInit | ( | InT | element | ) |
Lookup the cache for a pre-calculated replacement for element
.
If one exists, a resolved CacheEntry will be returned. Otherwise, an unresolved CacheEntry will be returned, and the caller must resolve it with the calculated replacement so it can be registered in the cache for future use. Multiple unresolved CacheEntries may be retrieved. However, any unresolved CacheEntries that are returned must be resolved in reverse order of retrieval, i.e. the last retrieved CacheEntry must be resolved first, and the first retrieved CacheEntry must be resolved last. This should be natural when used as a stack / inside recursion.
Definition at line 153 of file CyclicReplacerCache.h.