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

GitOrigin-RevId: 810b2849181fb2b248b1d5f586cede6618ca7120
diff --git a/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp b/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp
index 4ae3094..0b58838 100644
--- a/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp
+++ b/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 @@
 
 /// 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 @@
   /// 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];