[Mlir-commits] [mlir] 40ba0ca - [mlir][SCF] Fix memory leak in LoopLikeSCFOpsTest.cpp

Adrian Kuegel llvmlistbot at llvm.org
Fri Oct 20 04:37:35 PDT 2023


Author: Adrian Kuegel
Date: 2023-10-20T11:36:50Z
New Revision: 40ba0ca5213d98b75fe204899cb9e46f91351f04

URL: https://github.com/llvm/llvm-project/commit/40ba0ca5213d98b75fe204899cb9e46f91351f04
DIFF: https://github.com/llvm/llvm-project/commit/40ba0ca5213d98b75fe204899cb9e46f91351f04.diff

LOG: [mlir][SCF] Fix memory leak in LoopLikeSCFOpsTest.cpp

Added: 
    

Modified: 
    mlir/unittests/Dialect/SCF/LoopLikeSCFOpsTest.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/unittests/Dialect/SCF/LoopLikeSCFOpsTest.cpp b/mlir/unittests/Dialect/SCF/LoopLikeSCFOpsTest.cpp
index f75b84f12b6f1f1..f87c28e1876ec6b 100644
--- a/mlir/unittests/Dialect/SCF/LoopLikeSCFOpsTest.cpp
+++ b/mlir/unittests/Dialect/SCF/LoopLikeSCFOpsTest.cpp
@@ -10,6 +10,7 @@
 #include "mlir/Dialect/SCF/IR/SCF.h"
 #include "mlir/IR/Diagnostics.h"
 #include "mlir/IR/MLIRContext.h"
+#include "mlir/IR/OwningOpRef.h"
 #include "gtest/gtest.h"
 
 using namespace mlir;
@@ -55,35 +56,50 @@ class SCFLoopLikeTest : public ::testing::Test {
 };
 
 TEST_F(SCFLoopLikeTest, queryUnidimensionalLooplikes) {
-  Value lb = b.create<arith::ConstantIndexOp>(loc, 0);
-  Value ub = b.create<arith::ConstantIndexOp>(loc, 10);
-  Value step = b.create<arith::ConstantIndexOp>(loc, 2);
+  OwningOpRef<arith::ConstantIndexOp> lb =
+      b.create<arith::ConstantIndexOp>(loc, 0);
+  OwningOpRef<arith::ConstantIndexOp> ub =
+      b.create<arith::ConstantIndexOp>(loc, 10);
+  OwningOpRef<arith::ConstantIndexOp> step =
+      b.create<arith::ConstantIndexOp>(loc, 2);
 
-  auto forOp = b.create<scf::ForOp>(loc, lb, ub, step);
-  checkUnidimensional(forOp);
+  OwningOpRef<scf::ForOp> forOp =
+      b.create<scf::ForOp>(loc, lb.get(), ub.get(), step.get());
+  checkUnidimensional(forOp.get());
 
-  auto forallOp = b.create<scf::ForallOp>(
-      loc, ArrayRef<OpFoldResult>(lb), ArrayRef<OpFoldResult>(ub),
-      ArrayRef<OpFoldResult>(step), ValueRange(), std::nullopt);
-  checkUnidimensional(forallOp);
+  OwningOpRef<scf::ForallOp> forallOp = b.create<scf::ForallOp>(
+      loc, ArrayRef<OpFoldResult>(static_cast<Value>(lb.get())),
+      ArrayRef<OpFoldResult>(static_cast<Value>(ub.get())),
+      ArrayRef<OpFoldResult>(static_cast<Value>(step.get())), ValueRange(),
+      std::nullopt);
+  checkUnidimensional(forallOp.get());
 
-  auto parallelOp = b.create<scf::ParallelOp>(
-      loc, ValueRange(lb), ValueRange(ub), ValueRange(step), ValueRange());
-  checkUnidimensional(parallelOp);
+  OwningOpRef<scf::ParallelOp> parallelOp =
+      b.create<scf::ParallelOp>(loc, ValueRange(lb.get()), ValueRange(ub.get()),
+                                ValueRange(step.get()), ValueRange());
+  checkUnidimensional(parallelOp.get());
 }
 
 TEST_F(SCFLoopLikeTest, queryMultidimensionalLooplikes) {
-  Value lb = b.create<arith::ConstantIndexOp>(loc, 0);
-  Value ub = b.create<arith::ConstantIndexOp>(loc, 10);
-  Value step = b.create<arith::ConstantIndexOp>(loc, 2);
+  OwningOpRef<arith::ConstantIndexOp> lb =
+      b.create<arith::ConstantIndexOp>(loc, 0);
+  OwningOpRef<arith::ConstantIndexOp> ub =
+      b.create<arith::ConstantIndexOp>(loc, 10);
+  OwningOpRef<arith::ConstantIndexOp> step =
+      b.create<arith::ConstantIndexOp>(loc, 2);
+  auto lbValue = static_cast<Value>(lb.get());
+  auto ubValue = static_cast<Value>(ub.get());
+  auto stepValue = static_cast<Value>(step.get());
 
-  auto forallOp = b.create<scf::ForallOp>(
-      loc, ArrayRef<OpFoldResult>({lb, lb}), ArrayRef<OpFoldResult>({ub, ub}),
-      ArrayRef<OpFoldResult>({step, step}), ValueRange(), std::nullopt);
-  checkMultidimensional(forallOp);
+  OwningOpRef<scf::ForallOp> forallOp =
+      b.create<scf::ForallOp>(loc, ArrayRef<OpFoldResult>({lbValue, lbValue}),
+                              ArrayRef<OpFoldResult>({ubValue, ubValue}),
+                              ArrayRef<OpFoldResult>({stepValue, stepValue}),
+                              ValueRange(), std::nullopt);
+  checkMultidimensional(forallOp.get());
 
-  auto parallelOp =
-      b.create<scf::ParallelOp>(loc, ValueRange({lb, lb}), ValueRange({ub, ub}),
-                                ValueRange({step, step}), ValueRange());
-  checkMultidimensional(parallelOp);
+  OwningOpRef<scf::ParallelOp> parallelOp = b.create<scf::ParallelOp>(
+      loc, ValueRange({lbValue, lbValue}), ValueRange({ubValue, ubValue}),
+      ValueRange({stepValue, stepValue}), ValueRange());
+  checkMultidimensional(parallelOp.get());
 }


        


More information about the Mlir-commits mailing list