[mlir] Add verify method to adaptor
authorJacques Pienaar <jpienaar@google.com>
Fri, 5 Jun 2020 16:47:37 +0000 (09:47 -0700)
committerJacques Pienaar <jpienaar@google.com>
Fri, 5 Jun 2020 16:47:37 +0000 (09:47 -0700)
commitb0921f68e1eeb3ac0cf4e178014237e14c20be03
tree49c7753752226808ba30b00c7fdd68d7e5aee93c
parentf57dd41562340b0d5d9931b3f1becca761a54d26
[mlir] Add verify method to adaptor

This allows verifying op-indepent attributes (e.g., attributes that do not require the op to have been created) before constructing an operation. These include checking whether required attributes are defined or constraints on attributes (such as I32 attribute). This is not perfect (e.g., if one had a disjunctive constraint where one part relied on the op and the other doesn't, then this would not try and extract the op independent from the op dependent).

The next step is to move these out to a trait that could be verified earlier than in the generated method. The first use case is for inferring the return type while constructing the op. At that point you don't have an Operation yet and that ends up in one having to duplicate the same checks, e.g., verify that attribute A is defined before querying A in shape function which requires that duplication. Instead this allows one to invoke a method to verify all the traits and, if this is checked first during verification, then all other traits could use attributes knowing they have been verified.

It is a little bit funny to have these on the adaptor, but I see the adaptor as a place to collect information about the op before the op is constructed (e.g., avoiding stringly typed accessors, verifying what is possible to verify before the op is constructed) while being cheap to use even with constructed op (so layer of indirection between the op constructed/being constructed). And from that point of view it made sense to me.

Differential Revision: https://reviews.llvm.org/D80842
mlir/docs/OpDefinitions.md
mlir/test/Dialect/GPU/invalid.mlir
mlir/test/Dialect/LLVMIR/global.mlir
mlir/test/Dialect/SPIRV/composite-ops.mlir
mlir/test/Dialect/Vector/invalid.mlir
mlir/test/IR/invalid-ops.mlir
mlir/test/mlir-tblgen/op-attribute.td
mlir/test/mlir-tblgen/predicate.td
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp