From 7c59120f6e4ca769ab2bfb26484eb8eaca2eadc0 Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Thu, 18 Jun 2020 12:51:51 -0700 Subject: [PATCH] [mlir][ods] Look through OpVariable for type constraint If one uses an OpVariable (such as via Res) then the result type constraint should be returned. Differential Revision: https://reviews.llvm.org/D82119 --- mlir/lib/TableGen/Constraint.cpp | 19 +++++++++++++------ mlir/test/mlir-tblgen/op-decl.td | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/mlir/lib/TableGen/Constraint.cpp b/mlir/lib/TableGen/Constraint.cpp index 98bb7d63d06d..b8e1b9f05acd 100644 --- a/mlir/lib/TableGen/Constraint.cpp +++ b/mlir/lib/TableGen/Constraint.cpp @@ -17,21 +17,28 @@ using namespace mlir::tblgen; Constraint::Constraint(const llvm::Record *record) : def(record), kind(CK_Uncategorized) { - if (record->isSubClassOf("TypeConstraint")) { + // Look through OpVariable's to their constraint. + if (def->isSubClassOf("OpVariable")) + def = def->getValueAsDef("constraint"); + if (def->isSubClassOf("TypeConstraint")) { kind = CK_Type; - } else if (record->isSubClassOf("AttrConstraint")) { + } else if (def->isSubClassOf("AttrConstraint")) { kind = CK_Attr; - } else if (record->isSubClassOf("RegionConstraint")) { + } else if (def->isSubClassOf("RegionConstraint")) { kind = CK_Region; - } else if (record->isSubClassOf("SuccessorConstraint")) { + } else if (def->isSubClassOf("SuccessorConstraint")) { kind = CK_Successor; } else { - assert(record->isSubClassOf("Constraint")); + assert(def->isSubClassOf("Constraint")); } } Constraint::Constraint(Kind kind, const llvm::Record *record) - : def(record), kind(kind) {} + : def(record), kind(kind) { + // Look through OpVariable's to their constraint. + if (def->isSubClassOf("OpVariable")) + def = def->getValueAsDef("constraint"); +} Pred Constraint::getPredicate() const { auto *val = def->getValue("predicate"); diff --git a/mlir/test/mlir-tblgen/op-decl.td b/mlir/test/mlir-tblgen/op-decl.td index c0297da28445..f5bf03e57ce7 100644 --- a/mlir/test/mlir-tblgen/op-decl.td +++ b/mlir/test/mlir-tblgen/op-decl.td @@ -155,7 +155,7 @@ def NS_EOp : NS_Op<"op_with_optionals", []> { def NS_FOp : NS_Op<"op_with_all_types_constraint", [AllTypesMatch<["a", "b"]>]> { let arguments = (ins AnyType:$a); - let results = (outs AnyType:$b); + let results = (outs Res:$b); } // CHECK-LABEL: class FOp :