[all-commits] [llvm/llvm-project] 500735: [mlir] Start moving some builtin type formats to t...

Markus Böck via All-commits all-commits at lists.llvm.org
Fri Feb 2 04:06:42 PST 2024


  Branch: refs/heads/users/zero9178/simplify-builtin-parsing
  Home:   https://github.com/llvm/llvm-project
  Commit: 5007356799376ecc2b0ef554d7308baf36e8e69c
      https://github.com/llvm/llvm-project/commit/5007356799376ecc2b0ef554d7308baf36e8e69c
  Author: Markus Böck <markus.boeck02 at gmail.com>
  Date:   2024-02-02 (Fri, 02 Feb 2024)

  Changed paths:
    M mlir/include/mlir/IR/BuiltinDialect.td
    M mlir/include/mlir/IR/BuiltinTypes.td
    M mlir/include/mlir/IR/OpImplementation.h
    M mlir/lib/AsmParser/DialectSymbolParser.cpp
    M mlir/lib/AsmParser/Parser.h
    M mlir/lib/AsmParser/TypeParser.cpp
    M mlir/lib/IR/AsmPrinter.cpp
    M mlir/lib/IR/BuiltinTypes.cpp
    M mlir/test/IR/invalid-builtin-types.mlir
    M mlir/test/IR/invalid.mlir
    A mlir/test/IR/qualified-builtin.mlir

  Log Message:
  -----------
  [mlir] Start moving some builtin type formats to the dialect

Most types and attributes in the builtin dialect are parsed and printed using special-purpose printers and parsers for that type. They also use the low-level `Printer` rather than the `AsmPrinter`, making the implementations inconsistent compared to all other dialects in MLIR.

This PR starts moving some builtin types to be parsed using the usual `print` and `parse` methods like all other MLIR dialects. This has the following advantages:
* The implementation now looks like any other dialect's types
* It is now possible to use `assemblyFormat` for builtin types and attributes
* The code can be easily moved to other dialects if desired
* Arguably better layering and less code
* As a side-effect, it is now also possible to write `!builtin.<type>` for any types moved

A future benefit would include being able to print types and attributes in stripped format as well (e.g. `<f32>` vs `complex<f32>`), just like all other dialect types and attributes. This is currently explicitly disabled as it causes a LOT of changes in IR syntax and I believe some ambiguities in the parser.

For the purpose of reviewing and incremental development, this PR only moves `tuple`, `tensor`, `none`, `memref` and `complex`. The plan is to eventually move all attributes and types where the current syntax can be implemented within the dialect.

For backwards compatibility with the existing syntax, the builtin dialect is special-cased in the printer where the `builtin.` prefix is omitted.




More information about the All-commits mailing list