Formating MLIR tablegen code?


Until now, for formatting the MLIR tablegen files, we have used clang-format. The result is not convincing, for instance for the arguments definition, the description statement.

In your opinion, what is the best approach for formating MLIR tablegen files ? Are there some custom clang-format rules defined somewhere for MLIR ?


Hi tlepley,
I don’t think today there is a clang-format for Tablegen, but I know that there is some interest, see for example TableGen Formatter

1 Like

Yes indeed this is on the wishlist only still (but quite high on it for many folks). I have not found clang-format to do too good a job, but also haven’t tried much. We should probably also differentiate between the ODS and DRR TableGen files - for the latter I’ve even tried a couple of lisp formatters without luck. Contributions here very much welcome :slight_smile:

clang-format already works fine for pass td files. For ODS, it works fine only here and there – for eg. between angular brackets (breaks lines fine but the indentation isn’t right), right indentation after semi-colons, etc. If you use vim, you can use GitHub - rhysd/vim-clang-format: Vim plugin for clang-format, a formatter for C, C++, Obj-C, Java, JavaScript, and so on. with visual range formating in vim to limit where you apply clang-format. I agree the end result here isn’t satisfactory.

1 Like

I have a script running clang-format on my td files. Biggest functional issue seems to be that it doesn’t recognize the multi-line strings [{ }] and C++ code contained within. That’s the only thing I’ve seen that breaks compilation. I just put // clang-format off and // clang-format on around those and live with stylistic issues mentioned above.

Thanks for your answers. What I understand is that there’s no good solution today for ODS. I’ll then continue to investigate.