MLIR
20.0.0git
|
This is an attribute/type replacer that supports custom handling of cycles in the replacer logic. More...
#include "mlir/IR/AttrTypeSubElements.h"
Public Types | |
template<typename T > | |
using | CycleBreakerFn = std::function< std::optional< T >(T)> |
A cycle-breaking function. More... | |
Public Types inherited from mlir::detail::AttrTypeReplacerBase< CyclicAttrTypeReplacer > | |
using | ReplaceFnResult = std::optional< std::pair< T, WalkResult > > |
A replacement mapping function, which returns either std::nullopt (to signal the element wasn't handled), or a pair of the replacement element and a WalkResult. More... | |
using | ReplaceFn = std::function< ReplaceFnResult< T >(T)> |
Public Member Functions | |
CyclicAttrTypeReplacer () | |
Attribute | replace (Attribute attr) |
Type | replace (Type type) |
void | addCycleBreaker (CycleBreakerFn< Attribute > fn) |
Register a cycle-breaking function. More... | |
void | addCycleBreaker (CycleBreakerFn< Type > fn) |
template<typename FnT , typename T = typename llvm::function_traits< std::decay_t<FnT>>::template arg_t<0>, typename BaseT = std::conditional_t<std::is_base_of_v<Attribute, T>, Attribute, Type>> | |
std::enable_if_t<!std::is_same_v< T, BaseT > > | addCycleBreaker (FnT &&callback) |
Register a cycle-breaking function that doesn't match the default signature. More... | |
Public Member Functions inherited from mlir::detail::AttrTypeReplacerBase< CyclicAttrTypeReplacer > | |
void | replaceElementsIn (Operation *op, bool replaceAttrs=true, bool replaceLocs=false, bool replaceTypes=false) |
Replace the elements within the given operation. More... | |
void | recursivelyReplaceElementsIn (Operation *op, bool replaceAttrs=true, bool replaceLocs=false, bool replaceTypes=false) |
Replace the elements within the given operation, and all nested operations. More... | |
void | addReplacement (ReplaceFn< Attribute > fn) |
Register a replacement function for mapping a given attribute or type. More... | |
void | addReplacement (ReplaceFn< Type > fn) |
std::enable_if_t<!std::is_same_v< T, BaseT >||!std::is_convertible_v< ResultT, ReplaceFnResult< BaseT > > > | addReplacement (FnT &&callback) |
Register a replacement function that doesn't match the default signature, either because it uses a derived parameter type, or it uses a simplified result type. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from mlir::detail::AttrTypeReplacerBase< CyclicAttrTypeReplacer > | |
Attribute | replaceBase (Attribute attr) |
Invokes the registered replacement functions from most recently registered to least recently registered until a successful replacement is returned. More... | |
Type | replaceBase (Type type) |
This is an attribute/type replacer that supports custom handling of cycles in the replacer logic.
In addition to registering replacer functions, it allows registering cycle-breaking functions in the same style.
Definition at line 253 of file AttrTypeSubElements.h.
using mlir::CyclicAttrTypeReplacer::CycleBreakerFn = std::function<std::optional<T>(T)> |
A cycle-breaking function.
This is invoked if the same element is asked to be replaced again when the first instance of it is still being replaced. This function must not perform any more recursive replace
calls. If it is able to break the cycle, it should return a replacement result. Otherwise, it can return std::nullopt to defer cycle breaking to the next repeated element. However, the user must guarantee that, in any possible cycle, there always exists at least one element that can break the cycle.
Definition at line 277 of file AttrTypeSubElements.h.
CyclicAttrTypeReplacer::CyclicAttrTypeReplacer | ( | ) |
Definition at line 263 of file AttrTypeSubElements.cpp.
void CyclicAttrTypeReplacer::addCycleBreaker | ( | CycleBreakerFn< Attribute > | fn | ) |
Register a cycle-breaking function.
When breaking cycles, the mostly recently added cycle-breaking functions will be invoked first.
Definition at line 266 of file AttrTypeSubElements.cpp.
Referenced by addCycleBreaker().
void CyclicAttrTypeReplacer::addCycleBreaker | ( | CycleBreakerFn< Type > | fn | ) |
Definition at line 270 of file AttrTypeSubElements.cpp.
|
inline |
Register a cycle-breaking function that doesn't match the default signature.
Definition at line 292 of file AttrTypeSubElements.h.
References addCycleBreaker().
Definition at line 288 of file AttrTypeSubElements.cpp.
Definition at line 292 of file AttrTypeSubElements.cpp.