[all-commits] [llvm/llvm-project] b121c2: [mlir] Add helper method to print and parse cyclic...

Markus Böck via All-commits all-commits at lists.llvm.org
Mon Sep 4 09:19:31 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b121c266744d030120c59e6256559cbccacd3c6f
      https://github.com/llvm/llvm-project/commit/b121c266744d030120c59e6256559cbccacd3c6f
  Author: Markus Böck <markus.boeck02 at gmail.com>
  Date:   2023-09-04 (Mon, 04 Sep 2023)

  Changed paths:
    M mlir/include/mlir/IR/OpImplementation.h
    M mlir/lib/AsmParser/AsmParserImpl.h
    M mlir/lib/AsmParser/ParserState.h
    M mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
    M mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
    M mlir/lib/IR/AsmPrinter.cpp
    M mlir/test/Dialect/LLVMIR/types-invalid.mlir
    M mlir/test/lib/Dialect/Test/TestDialect.td
    M mlir/test/lib/Dialect/Test/TestTypes.cpp

  Log Message:
  -----------
  [mlir] Add helper method to print and parse cyclic attributes and types (#65210)

Printing cyclic attributes and types currently has no first-class
support within the AsmPrinter and AsmParser. The workaround for this
issue used in all mutable attributes and types upstream has been to
create a `thread_local static SetVector` keeping track of currently
parsed and printed attributes.

This solution is not ideal readability wise due to the use of globals
and keeping track of state. Worst of all, this pattern had to be
reimplemented for every mutable attribute and type.

This patch therefore adds support for this pattern in `AsmPrinter` and
`AsmParser` replacing the use of this pattern. By calling
`tryStartCyclingPrint/Parse`, the mutable attribute or type are
registered in an internal stack. All subsequent calls to the function
with the same attribute or type will lead to returning failure. This way
the nesting can be detected and a short form printed or parsed instead.
Through the resetter returned by the call, the cyclic printing or
parsing region automatically ends on return.




More information about the All-commits mailing list