MLIR  20.0.0git
Public Types | Public Member Functions | List of all members
mlir::CyclicAttrTypeReplacer Class Reference

This is an attribute/type replacer that supports custom handling of cycles in the replacer logic. More...

#include "mlir/IR/AttrTypeSubElements.h"

+ Inheritance diagram for mlir::CyclicAttrTypeReplacer:

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)
 

Detailed Description

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.

Member Typedef Documentation

◆ CycleBreakerFn

template<typename T >
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.

Constructor & Destructor Documentation

◆ CyclicAttrTypeReplacer()

CyclicAttrTypeReplacer::CyclicAttrTypeReplacer ( )

Definition at line 263 of file AttrTypeSubElements.cpp.

Member Function Documentation

◆ addCycleBreaker() [1/3]

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().

◆ addCycleBreaker() [2/3]

void CyclicAttrTypeReplacer::addCycleBreaker ( CycleBreakerFn< Type fn)

Definition at line 270 of file AttrTypeSubElements.cpp.

◆ addCycleBreaker() [3/3]

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> > mlir::CyclicAttrTypeReplacer::addCycleBreaker ( FnT &&  callback)
inline

Register a cycle-breaking function that doesn't match the default signature.

Definition at line 292 of file AttrTypeSubElements.h.

References addCycleBreaker().

◆ replace() [1/2]

Attribute CyclicAttrTypeReplacer::replace ( Attribute  attr)

Definition at line 288 of file AttrTypeSubElements.cpp.

◆ replace() [2/2]

Type CyclicAttrTypeReplacer::replace ( Type  type)

Definition at line 292 of file AttrTypeSubElements.cpp.


The documentation for this class was generated from the following files: