Clang-format or some other auto-format for .mlir files

That’s the hard part, when dialects have custom parsers/printers.

tpp-opt doesn’t quite know what the canonical form is, it just parses and prints back out “in canonical form” because of the parser/printer.

Exactly! But again, having a completely separate clang-format for MLIR would require us to teach syntax and semantics of MLIR to it, which changes wildly (more so than spec-based languages like C++ and Python), so we’d end up with an arms race of sorts.

We do have a similar problem locally (when writing test variations, for example) and what I do is just write some IR, pass it through mlir-opt -canonicalize and work with the textual result in an editor. That loses a lot of stuff, unfortunately.

Trying to hook that up in an IDE would require some external text parsing, which could be more tractable than re-writing the entire MLIR semantics (including custom dialects) in clang-format.