}
def MyRule : Pat<(OpA $input, $attr), (OpB $input, $attr)>;
+def MyRule2 : Pat<(OpA (OpA $input, $attr), $attr), (OpB $input, $attr)>;
// Test rewrite rule naming
// ---
// CHECK-NEXT: {{.*pattern.td.*}}
// CHECK: struct MyRule : public RewritePattern
+// CHECK-LABEL: struct MyRule2 : public RewritePattern
+// CHECK: s.autogeneratedRewritePatternOps[0] = op0;
+// CHECK: s.autogeneratedRewritePatternOps[1] = op1;
+// CHECK: rewriter.getFusedLoc({
+// CHECK-SAME: s.autogeneratedRewritePatternOps[0]->getLoc()
+// CHECK-SAME: s.autogeneratedRewritePatternOps[1]->getLoc()
+
def : Pat<(OpA $input, $attr), (OpB $input, $attr)>;
// Test basic structure generated from Pattern
// Emits C++ statements for matching the `index`-th argument of the given DAG
// `tree` as an operand.
void emitOperandMatch(DagNode tree, int index, int depth, int indent);
+
// Emits C++ statements for matching the `index`-th argument of the given DAG
// `tree` as an attribute.
void emitAttributeMatch(DagNode tree, int index, int depth, int indent);
FmtContext matchCtx;
// Format contexts containing placeholder substitutations for rewrite().
FmtContext rewriteCtx;
+
+ // Number of op processed.
+ int opCounter = 0;
};
} // end anonymous namespace
<< formatv("auto op{0} = op{1}->getOperand({2})->getDefiningOp();\n",
depth + 1, depth, i);
emitOpMatch(argTree, depth + 1);
+ os.indent(indent + 2)
+ << formatv("s.autogeneratedRewritePatternOps[{0}] = op{1};\n",
+ ++opCounter, depth + 1);
os.indent(indent) << "}\n";
continue;
}
auto ctx = op0->getContext(); (void)ctx;
auto state = llvm::make_unique<MatchedState>();
auto &s = *state;
+ s.autogeneratedRewritePatternOps[0] = op0;
)";
// The rewrite pattern may specify that certain outputs should be unused in
for (const auto &result : pattern.getSourcePatternBoundOps()) {
os.indent(4) << "Operation *" << result.getKey() << ";\n";
}
+ // TODO(jpienaar): Change to matchAndRewrite & capture ops with consistent
+ // numbering so that it can be reused for fused loc.
+ os.indent(4) << "Operation* autogeneratedRewritePatternOps["
+ << pattern.getSourcePattern().getNumOps() << "];\n";
os << " };\n";
emitMatchMethod(tree);
void rewrite(Operation *op, std::unique_ptr<PatternState> state,
PatternRewriter &rewriter) const override {
auto& s = *static_cast<MatchedState *>(state.get());
- auto loc = op->getLoc(); (void)loc;
-)";
+ auto loc = rewriter.getFusedLoc({)";
+ for (int i = 0, e = pattern.getSourcePattern().getNumOps(); i != e; ++i) {
+ os << (i ? ", " : "") << "s.autogeneratedRewritePatternOps[" << i
+ << "]->getLoc()";
+ }
+ os << "}); (void)loc;\n";
// Collect the replacement value for each result
llvm::SmallVector<std::string, 2> resultValues;