diff --git a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp --- a/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp +++ b/mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp @@ -52,16 +52,15 @@ void removeFromWorklist(Operation *op); protected: - // Implement the hook for inserting operations, and make sure that newly - // inserted ops are added to the worklist for processing. - void notifyOperationInserted(Operation *op) override; - // Look over the provided operands for any defining operations that should // be re-added to the worklist. This function should be called when an // operation is modified or removed, as it may trigger further // simplifications. - template - void addToWorklist(Operands &&operands); + virtual void addOperandsToWorklist(ValueRange operands); + + // Implement the hook for inserting operations, and make sure that newly + // inserted ops are added to the worklist for processing. + void notifyOperationInserted(Operation *op) override; // If an operation is about to be removed, make sure it is not in our // worklist anymore because we'd get dangling references to it. @@ -219,7 +218,7 @@ originalOperands.assign(op->operand_begin(), op->operand_end()); auto preReplaceAction = [&](Operation *op) { // Add the operands to the worklist for visitation. - addToWorklist(originalOperands); + addOperandsToWorklist(originalOperands); // Add all the users of the result to the worklist so we make sure // to revisit them. @@ -327,8 +326,7 @@ addToWorklist(op); } -template -void GreedyPatternRewriteDriver::addToWorklist(Operands &&operands) { +void GreedyPatternRewriteDriver::addOperandsToWorklist(ValueRange operands) { for (Value operand : operands) { // If the use count of this operand is now < 2, we re-add the defining // operation to the worklist. @@ -343,7 +341,7 @@ } void GreedyPatternRewriteDriver::notifyOperationRemoved(Operation *op) { - addToWorklist(op->getOperands()); + addOperandsToWorklist(op->getOperands()); op->walk([this](Operation *operation) { removeFromWorklist(operation); folder.notifyRemoval(operation); @@ -529,8 +527,7 @@ // operation is modified or removed, as it may trigger further // simplifications. If `strict` is set to true, only ops in // `strictModeFilteredOps` are considered. - template - void addOperandsToWorklist(Operands &&operands) { + void addOperandsToWorklist(ValueRange operands) override { for (Value operand : operands) { if (auto *defOp = operand.getDefiningOp()) { if (!strictMode || strictModeFilteredOps.contains(defOp))