[all-commits] [llvm/llvm-project] 06e25d: [mlir][IR] Refactor the `getChecked` and `verifyCo...

River Riddle via All-commits all-commits at lists.llvm.org
Mon Feb 22 17:38:22 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 06e25d56451977ef5b7052282faacfe3d42acb65
      https://github.com/llvm/llvm-project/commit/06e25d56451977ef5b7052282faacfe3d42acb65
  Author: River Riddle <riddleriver at gmail.com>
  Date:   2021-02-22 (Mon, 22 Feb 2021)

  Changed paths:
    M flang/include/flang/Optimizer/Dialect/FIRType.h
    M flang/include/flang/Optimizer/Dialect/FIRTypes.td
    M flang/lib/Optimizer/Dialect/FIRType.cpp
    M mlir/docs/OpDefinitions.md
    M mlir/docs/Tutorials/DefiningAttributesAndTypes.md
    M mlir/include/mlir-c/BuiltinAttributes.h
    M mlir/include/mlir-c/BuiltinTypes.h
    M mlir/include/mlir/Dialect/Async/IR/AsyncTypes.td
    M mlir/include/mlir/Dialect/LLVMIR/LLVMTypes.h
    M mlir/include/mlir/Dialect/Quant/QuantTypes.h
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVAttributes.h
    M mlir/include/mlir/Dialect/SPIRV/IR/SPIRVTypes.h
    M mlir/include/mlir/IR/BuiltinAttributes.h
    M mlir/include/mlir/IR/BuiltinTypes.h
    M mlir/include/mlir/IR/BuiltinTypes.td
    M mlir/include/mlir/IR/OpBase.td
    M mlir/include/mlir/IR/StorageUniquerSupport.h
    M mlir/include/mlir/IR/Types.h
    M mlir/include/mlir/TableGen/TypeDef.h
    M mlir/lib/Bindings/Python/IRModules.cpp
    M mlir/lib/CAPI/IR/BuiltinAttributes.cpp
    M mlir/lib/CAPI/IR/BuiltinTypes.cpp
    M mlir/lib/Dialect/LLVMIR/IR/LLVMTypeSyntax.cpp
    M mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
    M mlir/lib/Dialect/Quant/IR/QuantTypes.cpp
    M mlir/lib/Dialect/Quant/IR/TypeParser.cpp
    M mlir/lib/Dialect/Quant/Utils/FakeQuantSupport.cpp
    M mlir/lib/Dialect/SPIRV/IR/SPIRVAttributes.cpp
    M mlir/lib/Dialect/SPIRV/IR/SPIRVTypes.cpp
    M mlir/lib/IR/BuiltinAttributes.cpp
    M mlir/lib/IR/BuiltinTypes.cpp
    M mlir/lib/IR/MLIRContext.cpp
    M mlir/lib/Parser/DialectSymbolParser.cpp
    M mlir/lib/TableGen/TypeDef.cpp
    M mlir/test/lib/Dialect/Test/TestTypeDefs.td
    M mlir/test/lib/Dialect/Test/TestTypes.cpp
    M mlir/test/mlir-tblgen/typedefs.td
    M mlir/tools/mlir-tblgen/TypeDefGen.cpp

  Log Message:
  -----------
  [mlir][IR] Refactor the `getChecked` and `verifyConstructionInvariants` methods on Attributes/Types

`verifyConstructionInvariants` is intended to allow for verifying the invariants of an attribute/type on construction, and `getChecked` is intended to enable more graceful error handling aside from an assert. There are a few problems with the current implementation of these methods:
* `verifyConstructionInvariants` requires an mlir::Location for emitting errors, which is prohibitively costly in the situations that would most likely use them, e.g. the parser.
This creates an unfortunate code duplication between the verifier code and the parser code, given that the parser operates on llvm::SMLoc and it is an undesirable overhead to pre-emptively convert from that to an mlir::Location.
* `getChecked` effectively requires duplicating the definition of the `get` method, creating a quite clunky workflow due to the subtle different in its signature.

This revision aims to talk the above problems by refactoring the implementation to use a callback for error emission. Using a callback allows for deferring the costly part of error emission until it is actually necessary.

Due to the necessary signature change in each instance of these methods, this revision also takes this opportunity to cleanup the definition of these methods by:
* restructuring the signature of `getChecked` such that it can be generated from the same code block as the `get` method.
* renaming `verifyConstructionInvariants` to `verify` to match the naming scheme of the rest of the compiler.

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




More information about the All-commits mailing list