[Mlir-commits] [mlir] 2cff9ee - [mlir] Use SetVector to deduplicate shape ops operands

Eugene Zhulenev llvmlistbot at llvm.org
Fri Feb 4 11:34:19 PST 2022


Author: Eugene Zhulenev
Date: 2022-02-04T11:34:13-08:00
New Revision: 2cff9ee46bffb5c62b97df51590c28cd4230c551

URL: https://github.com/llvm/llvm-project/commit/2cff9ee46bffb5c62b97df51590c28cd4230c551
DIFF: https://github.com/llvm/llvm-project/commit/2cff9ee46bffb5c62b97df51590c28cd4230c551.diff

LOG: [mlir] Use SetVector to deduplicate shape ops operands

Do not use quadratic complexity algorithm to find unique operands

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D119021

Added: 
    

Modified: 
    mlir/lib/Dialect/Shape/IR/Shape.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Shape/IR/Shape.cpp b/mlir/lib/Dialect/Shape/IR/Shape.cpp
index aaad72e5c1788..661f621f1cee1 100644
--- a/mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ b/mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -490,16 +490,12 @@ struct RemoveDuplicateOperandsPattern : public OpRewritePattern<OpTy> {
   LogicalResult matchAndRewrite(OpTy op,
                                 PatternRewriter &rewriter) const override {
     // Find unique operands.
-    SmallVector<Value, 2> unique;
-    for (Value v : op.getOperands()) {
-      if (!llvm::is_contained(unique, v))
-        unique.push_back(v);
-    }
+    SetVector<Value> unique(op.operand_begin(), op.operand_end());
 
     // Reduce op to equivalent with unique operands.
     if (unique.size() < op.getNumOperands()) {
-      rewriter.replaceOpWithNewOp<OpTy>(op, op->getResultTypes(), unique,
-                                        op->getAttrs());
+      rewriter.replaceOpWithNewOp<OpTy>(op, op->getResultTypes(),
+                                        unique.takeVector(), op->getAttrs());
       return success();
     }
 
@@ -919,7 +915,7 @@ OpFoldResult CstrBroadcastableOp::fold(ArrayRef<Attribute> operands) {
 }
 
 LogicalResult CstrBroadcastableOp::verify() {
-  // Ensure that AssumingAllOp contains at least one operand
+  // Ensure that CstrBroadcastableOp contains at least two operands
   if (getNumOperands() < 2)
     return emitOpError("required at least 2 input shapes");
   return success();


        


More information about the Mlir-commits mailing list