Transform .mlir files but preserve indentation

Hello,
I have a custom MLIR dialect that I want to refactor in such a way that a pattern of 2 specific operations in the IR becomes 1 merged operation.

I have a lot of LIT tests (i.e. .mlir files) that target my dialect. The refactor requires to modify those tests. Ideally, I want to add a utility pass to mlir-opt that merges those 2 operations. But after applying it to the .mlir files all the variables get renamed and the indentation changes. Is there a way to run mlir-opt to preserve the names and indentation?

Thanks,
Kuba

There isn’t any I know of, sorry!

The closets is the formatting tool that was proposed, it doesn’t preserve indentation on purpose but would have names. You can look at the mlir-rewrite tool that does preserve it as it only operates on sub ranges (e.g., localized sed effectively).

I see, thanks.

Could also you have a look at Generate EBNF grammar from custom mlir-opt? It’s indirectly related. I could create my own parser+transformer that does preserve variable names and indentation but for that I would need the grammar of my custom dialect. I can write it manually but perhaps there is a way to generate it automatically?