[all-commits] [llvm/llvm-project] b0774e: [mlir][ods] ODS ops get an `extraClassDefinition`

Jeff Niu via All-commits all-commits at lists.llvm.org
Wed Jan 5 17:43:39 PST 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b0774e5f500b5bb68451ee3f0590035d0f6e4e54
  Author: Mogball <jeffniu22 at gmail.com>
  Date:   2022-01-06 (Thu, 06 Jan 2022)

  Changed paths:
    M mlir/docs/OpDefinitions.md
    M mlir/include/mlir/IR/OpBase.td
    M mlir/include/mlir/TableGen/Class.h
    M mlir/include/mlir/TableGen/Operator.h
    M mlir/lib/TableGen/Class.cpp
    M mlir/lib/TableGen/Operator.cpp
    M mlir/test/lib/Dialect/Test/TestOps.td
    M mlir/tools/mlir-tblgen/OpClass.cpp
    M mlir/tools/mlir-tblgen/OpClass.h
    M mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp

  Log Message:
  [mlir][ods] ODS ops get an `extraClassDefinition`

Extra definitions are placed in the generated source file for each op class. The substitution `$cppClass` is replaced by the op's C++ class name.

This is useful when declaring but not defining methods in TableGen base classes:

class BaseOp<string mnemonic>
    : Op<MyDialect, mnemonic, [DeclareOpInterfaceMethods<SomeInterface>] {
  let extraClassDeclaration = [{
    // ZOp is declared at at the bottom of the file and is incomplete here
    ZOp getParent();
  let extraClassDefinition = [{
    int $cppClass::someInterfaceMethod() {
      return someUtilityFunction(*this);
    ZOp $cppClass::getParent() {
      return dyn_cast<ZOp>(this->getParentOp());

Certain things may prevent defining these functions inline, in the declaration. In this example, `ZOp` in the same dialect is incomplete at the function declaration because ops classes are declared in alphabetical order. Alternatively, functions may be too big to be desired as inlined, or they may require dependencies that create cyclic includes, or they may be calling a templated utility function that one may not want to expose in a header. If the functions are not inlined, then inheriting from the base class N times means that each function will need to be defined N times. With `extraClassDefinitions`, they only need to be defined once.

Reviewed By: rriddle

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

More information about the All-commits mailing list