From 58ce477676c7bd9c6cee0c6d05f2708b4e178ff3 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Wed, 30 Dec 2020 00:19:31 +0000 Subject: [PATCH] Fix DRR pattern when attributes and operands are interleaved and a dag subtree appears in the rewrite This fixes an incorrect fatal error in TableGen. This code probably comes from before attributes were allowed to interleave with operands in ODS. Reviewed By: jpienaar Differential Revision: https://reviews.llvm.org/D93915 --- mlir/test/mlir-tblgen/rewriter-indexing.td | 8 ++++++++ mlir/tools/mlir-tblgen/RewriterGen.cpp | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mlir/test/mlir-tblgen/rewriter-indexing.td b/mlir/test/mlir-tblgen/rewriter-indexing.td index ed493d0..c21b04f 100644 --- a/mlir/test/mlir-tblgen/rewriter-indexing.td +++ b/mlir/test/mlir-tblgen/rewriter-indexing.td @@ -47,3 +47,11 @@ def test1 : Pat<(BOp $attr, (AOp $input)), // CHECK: castedOp0.getODSOperands(1).begin()).getDefiningOp() def test2 : Pat<(COp $attr1, $op1, $attr2, (AOp $op2)), (BOp $attr1, $op2)>; + + +// Check rewriting with a DAG subtree in the result and remapping a location. +// CHECK: struct test3 : public ::mlir::RewritePattern { +// CHECK: rewriter.create((*a.getODSResults(0).begin()).getLoc() +def test3 : Pat<(BOp $attr, (AOp:$a $input)), + (BOp $attr, (AOp $input), (location $a))>; + diff --git a/mlir/tools/mlir-tblgen/RewriterGen.cpp b/mlir/tools/mlir-tblgen/RewriterGen.cpp index da189c6..96488d9 100644 --- a/mlir/tools/mlir-tblgen/RewriterGen.cpp +++ b/mlir/tools/mlir-tblgen/RewriterGen.cpp @@ -998,7 +998,7 @@ std::string PatternEmitter::handleOpCreation(DagNode tree, int resultIndex, // First go through all the child nodes who are nested DAG constructs to // create ops for them and remember the symbol names for them, so that we can // use the results in the current node. This happens in a recursive manner. - for (int i = 0, e = resultOp.getNumOperands(); i != e; ++i) { + for (int i = 0, e = tree.getNumArgs() - hasLocationDirective; i != e; ++i) { if (auto child = tree.getArgAsNestedDag(i)) childNodeNames[i] = handleResultPattern(child, i, depth + 1); } -- 2.7.4