[Mlir-commits] [mlir] 810b284 - Fixed a memory leak in the PDLToPDLInterp RootOrderingTest.

Uday Bondhugula llvmlistbot at llvm.org
Wed Dec 1 04:15:47 PST 2021


Author: Stanislav Funiak
Date: 2021-12-01T17:40:46+05:30
New Revision: 810b2849181fb2b248b1d5f586cede6618ca7120

URL: https://github.com/llvm/llvm-project/commit/810b2849181fb2b248b1d5f586cede6618ca7120
DIFF: https://github.com/llvm/llvm-project/commit/810b2849181fb2b248b1d5f586cede6618ca7120.diff

LOG: Fixed a memory leak in the PDLToPDLInterp RootOrderingTest.

RootOrderingTest is a low-level unit test that creates values and uses them as vertices in a directed graph. These vertices were created using `builder.create`, but never freed, due to my insufficient understanding of the MLIR infrastructure.

Reviewed By: mehdi_amini, bondhugula, rriddle

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

Added: 
    

Modified: 
    mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp b/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp
index 4ae30942374e6..0b58838c24da8 100644
--- a/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp
+++ b/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp
@@ -7,12 +7,13 @@
 //===----------------------------------------------------------------------===//
 
 #include "../lib/Conversion/PDLToPDLInterp/RootOrdering.h"
-#include "mlir/Dialect/StandardOps/IR/Ops.h"
+#include "mlir/Dialect/Arithmetic/IR/Arithmetic.h"
 #include "mlir/IR/Builders.h"
 #include "mlir/IR/MLIRContext.h"
 #include "gtest/gtest.h"
 
 using namespace mlir;
+using namespace mlir::arith;
 using namespace mlir::pdl_to_pdl_interp;
 
 namespace {
@@ -23,22 +24,24 @@ namespace {
 
 /// The test fixture for constructing root ordering tests and verifying results.
 /// This fixture constructs the test values v. The test populates the graph
-/// with the desired costs and then calls check(), passing the expeted optimal
+/// with the desired costs and then calls check(), passing the expected optimal
 /// cost and the list of edges in the preorder traversal of the optimal
 /// branching.
 class RootOrderingTest : public ::testing::Test {
 protected:
   RootOrderingTest() {
-    context.loadDialect<StandardOpsDialect>();
+    context.loadDialect<ArithmeticDialect>();
     createValues();
   }
 
-  /// Creates the test values.
+  /// Creates the test values. These values simply act as vertices / vertex IDs
+  /// in the cost graph, rather than being a part of an IR.
   void createValues() {
     OpBuilder builder(&context);
+    builder.setInsertionPointToStart(&block);
     for (int i = 0; i < 4; ++i)
-      v[i] = builder.create<ConstantOp>(builder.getUnknownLoc(),
-                                        builder.getI32IntegerAttr(i));
+      // Ops will be deleted when `block` is destroyed.
+      v[i] = builder.create<ConstantIntOp>(builder.getUnknownLoc(), i, 32);
   }
 
   /// Checks that optimal branching on graph has the given cost and
@@ -55,6 +58,9 @@ class RootOrderingTest : public ::testing::Test {
   /// The context for creating the values.
   MLIRContext context;
 
+  /// Block holding all the operations.
+  Block block;
+
   /// Values used in the graph definition. We always use leading `n` values.
   Value v[4];
 


        


More information about the Mlir-commits mailing list