I am trying to update my dialect to llvm 17.
In llvm 16 all i had to do to be able to the SubElements interface from cpp defined types was to implement a couple of methods.
void T::walkImmediateSubElements(
function_ref<void(Attribute)> walkAttrsFn,
function_ref<void(Type)> walkTypesFn) const
mlir::Type T::replaceImmediateSubElements(
ArrayRef<Attribute> replAttrs, ArrayRef<Type> replTypes) const
from what i understand this has now changed, and looking at LLVMStructType it seems that one has to implement a handler that has a similar behaviour
// from mlir/lib/Dialect/LLVMIR/IR/TypeDetail.h
/// Allow walking and replacing the subelements of a LLVMStructTypeStorage key.
template <>
struct AttrTypeSubElementHandler<LLVM::detail::LLVMStructTypeStorage::Key> {
static void walk(const LLVM::detail::LLVMStructTypeStorage::Key ¶m,
AttrTypeImmediateSubElementWalker &walker) {
if (param.isIdentified())
walker.walkRange(param.getIdentifiedStructBody());
else
walker.walkRange(param.getTypeList());
}
static FailureOr<LLVM::detail::LLVMStructTypeStorage::Key>
replace(const LLVM::detail::LLVMStructTypeStorage::Key ¶m,
AttrSubElementReplacements &attrRepls,
TypeSubElementReplacements &typeRepls) {
// TODO: It's not clear how we support replacing sub-elements of mutable
// types.
if (param.isIdentified())
return failure();
return LLVM::detail::LLVMStructTypeStorage::Key(
typeRepls.take_front(param.getTypeList().size()), param.isPacked());
}
};
unfortunately this new pattern is not equivalent to the old one, because not all my sub types are in the key, and therefore implementing the handler for the key only would not suffice. I tried implementing the handler for the derived type, but that was not invoked.
I understand that this is a limitation related to the fact that is not very clear what would mean to mutate a type while leaving the key unchanged, but i think that changing non key sub types should be allowed when the user takes ownership of the semantic of non key sub types by implementing a custom type in cpp.
Is there a intended way to specify a custom walk and replace function for a arbitrary mlir type, or is this limitation by design?
Thank you in advance.