MLIR  19.0.0git
Public Types | Public Member Functions | List of all members
mlir::AttrTypeReplacer Class Reference

AttrTypeReplacer. More...

#include "mlir/IR/AttrTypeSubElements.h"

Public Types

template<typename T >
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...
 
template<typename T >
using ReplaceFn = std::function< ReplaceFnResult< T >(T)>
 

Public Member Functions

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...
 
Attribute replace (Attribute attr)
 Replace the given attribute/type, and recursively replace any sub elements. More...
 
Type replace (Type type)
 
void addReplacement (ReplaceFn< Attribute > fn)
 Register a replacement function for mapping a given attribute or type. More...
 
void addReplacement (ReplaceFn< 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>, typename ResultT = std::invoke_result_t<FnT, T>>
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...
 

Detailed Description

AttrTypeReplacer.

This class provides a utility for replacing attributes/types, and their sub elements. Multiple replacement functions may be registered.

Definition at line 121 of file AttrTypeSubElements.h.

Member Typedef Documentation

◆ ReplaceFn

template<typename T >
using mlir::AttrTypeReplacer::ReplaceFn = std::function<ReplaceFnResult<T>(T)>

Definition at line 158 of file AttrTypeSubElements.h.

◆ ReplaceFnResult

template<typename T >
using mlir::AttrTypeReplacer::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.

Definition at line 156 of file AttrTypeSubElements.h.

Member Function Documentation

◆ addReplacement() [1/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>, typename ResultT = std::invoke_result_t<FnT, T>>
std::enable_if_t<!std::is_same_v<T, BaseT> || !std::is_convertible_v<ResultT, ReplaceFnResult<BaseT> > > mlir::AttrTypeReplacer::addReplacement ( FnT &&  callback)
inline

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.

Definition at line 193 of file AttrTypeSubElements.h.

References addReplacement(), and mlir::WalkResult::advance().

◆ addReplacement() [2/3]

void AttrTypeReplacer::addReplacement ( ReplaceFn< Attribute fn)

Register a replacement function for mapping a given attribute or type.

AttrTypeReplacer.

A replacement function must be convertible to any of the following forms(where T is a class derived from Type or Attribute, and BaseT is either Type or Attribute respectively):

  • std::optional<BaseT>(T)
    • This either returns a valid Attribute/Type in the case of success, nullptr in the case of failure, or std::nullopt to signify that additional replacement functions may be applied (i.e. this function doesn't handle that instance).
  • std::optional<std::pair<BaseT, WalkResult>>(T)
    • Similar to the above, but also allows specifying a WalkResult to control the replacement of sub elements of a given attribute or type. Returning a skip result, for example, will not recursively process the resultant attribute or type value.

Note: When replacing, the mostly recently added replacement functions will be invoked first.

Definition at line 73 of file AttrTypeSubElements.cpp.

Referenced by addReplacement(), handleLoopAnnotations(), mlir::Attribute::replace(), mlir::Type::replace(), and replaceAllSymbolUsesImpl().

◆ addReplacement() [3/3]

void AttrTypeReplacer::addReplacement ( ReplaceFn< Type fn)

Definition at line 76 of file AttrTypeSubElements.cpp.

◆ recursivelyReplaceElementsIn()

void AttrTypeReplacer::recursivelyReplaceElementsIn ( Operation op,
bool  replaceAttrs = true,
bool  replaceLocs = false,
bool  replaceTypes = false 
)

Replace the elements within the given operation, and all nested operations.

Definition at line 130 of file AttrTypeSubElements.cpp.

◆ replace() [1/2]

Attribute AttrTypeReplacer::replace ( Attribute  attr)

Replace the given attribute/type, and recursively replace any sub elements.

Returns either the new attribute/type, or nullptr in the case of failure.

Definition at line 222 of file AttrTypeSubElements.cpp.

Referenced by mlir::Attribute::replace(), mlir::Type::replace(), and updateSubElementImpl().

◆ replace() [2/2]

Type AttrTypeReplacer::replace ( Type  type)

Definition at line 226 of file AttrTypeSubElements.cpp.

◆ replaceElementsIn()

void AttrTypeReplacer::replaceElementsIn ( Operation op,
bool  replaceAttrs = true,
bool  replaceLocs = false,
bool  replaceTypes = false 
)

Replace the elements within the given operation.

If replaceAttrs is true, this updates the attribute dictionary of the operation. If replaceLocs is true, this also updates its location, and the locations of any nested block arguments. If replaceTypes is true, this also updates the result types of the operation, and the types of any nested block arguments.

Definition at line 80 of file AttrTypeSubElements.cpp.


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