[all-commits] [llvm/llvm-project] 547113: [mlir][ODS] Add `ConstantEnumCase` (#78992)

Markus Böck via All-commits all-commits at lists.llvm.org
Tue Jan 30 01:05:16 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 547113fd1f52e2a3d08e3b71ddcd47505ca4a21a
      https://github.com/llvm/llvm-project/commit/547113fd1f52e2a3d08e3b71ddcd47505ca4a21a
  Author: Markus Böck <markus.boeck02 at gmail.com>
  Date:   2024-01-30 (Tue, 30 Jan 2024)

  Changed paths:
    M mlir/include/mlir/IR/EnumAttr.td
    M mlir/lib/Dialect/Arith/IR/ArithCanonicalization.td
    M mlir/lib/Dialect/Arith/IR/ArithOps.cpp
    M mlir/test/IR/enum-attr-roundtrip.mlir
    M mlir/test/lib/Dialect/Test/TestOps.td

  Log Message:
  -----------
  [mlir][ODS] Add `ConstantEnumCase` (#78992)

Specifying an enum case of an enum attr currently requires the use of
either `NativeCodeCall` or a `ConstantAttr` specifying the full C++ name
of the enum case. The disadvantages of both are less readable code due
to including C++ expressions and very few checks of any kind, creating
C++ code that does not compile instead.

This PR adds `ConstantEnumCase`, a kind of `ConstantAttr` which
automatically derives the correct value representation from a given enum
and the string representation of an enum case. It supports both
`EnumAttrInfo`s (enums wrapping `IntegerAttr`) and `EnumAttr` (proper
dialect attributes). It even supports bit-enums, allowing one to list
multiple enum cases and have them be combined. If an enum case is not
found, an assertion is triggered with a proper error message.

Besides the tests, it was also used to simplify DRR patterns in the
arith dialect.




More information about the All-commits mailing list