[all-commits] [llvm/llvm-project] 86d68e: [mlir] Gen removeAttr methods with tablegen

Felipe de Azevedo Piovezan via All-commits all-commits at lists.llvm.org
Tue Jan 5 10:53:24 PST 2021


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 86d68e288585964546d6382ecf71dcce10d018b7
      https://github.com/llvm/llvm-project/commit/86d68e288585964546d6382ecf71dcce10d018b7
  Author: Felipe de Azevedo Piovezan <piovezan.fpi at gmail.com>
  Date:   2021-01-05 (Tue, 05 Jan 2021)

  Changed paths:
    M mlir/test/mlir-tblgen/op-attribute.td
    M mlir/test/mlir-tblgen/op-decl.td
    M mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

  Log Message:
  -----------
  [mlir] Gen removeAttr methods with tablegen

If an operation defines an optional attribute (OptionalAttr or
UnitAttr), transformations may wish to remove these attributes while
maintaining invariants established by the operation. Currently, the only
way to do this is by calling `Operation::removeAttr("attrName")`, which
requires developers to know the exact name of the attribute used by
table-gen. Furthermore, if the attribute name changes, this won't be
detected at compile time. Instead, `removeAttr` would return an empty
attribute and no errors would be raised, unless the caller checks for
the returned value.

This patch adds table gen support for generating `remove<AttrName>Attr`
methods for OptionalAttributes defined by operations.

Implementation choice: to preserve camelCase for the method's name, the
first character of an attribute called `myAttr` is changed to upper case
in order to preserve the coding style, so the final method would be
called `removeMyAttr`.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D93903




More information about the All-commits mailing list