llvm / llvm/llvm-project

[mlir] `memref` rejects unregistered dialects' memory space attributes

Open
#200,150 2 comments 0 reactions 0 assignees View on GitHub
mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Consider the following MLIR snippet:

```mlir
func.func private @memrefs_nomap_opaquespace(memref<5x6x7xf32, #my_dialect.attr<>>)
```

Assuming that `my_dialect` is registered and has some `attr`, `memref` will accept it as a memory space because it does not belong to the `builtin` dialect. However, if `my_dialect` is _not_ registered, then the attribute actually becomes an `OpaqueAttr` from the `builtin` dialect at parse time, which is rejected by the `memref` verifier. The relevant code is in [`BuiltinTypes.cpp`](https://github.com/llvm/llvm-project/blob/66ee43ce9d66f80cc311e5653478ae83372afb89/mlir/lib/IR/BuiltinTypes.cpp#L610).

To me, this is clearly a bug, as it breaks parsing an MLIR module with unregistered dialects that was exported in the generic form. While it could be argued that unregistered dialects are a special case that verifiers generally do not account for, I believe that the `builtin` dialect should be held to a higher standard in that regard.

I'll open a PR that adds `OpaqueAttr` to the list of allowed attributes, as well as adds a test to the LIT test suite to verify this works.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.