diff --git a/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp b/mlir/unittests/Conversion/PDLToPDLInterp/RootOrderingTest.cpp --- 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,31 @@ /// 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(); + context.loadDialect(); createValues(); } - /// Creates the test values. + ~RootOrderingTest() { + for (int i = 0; i < 4; ++i) { + assert(v[i] && v[i].getDefiningOp() && "empty value / defining op"); + v[i].getDefiningOp()->erase(); + } + } + + /// Creates the test values. These values simply act as vertices / vertex IDs + /// in the cost graph, rather than being a part of an IR. Therefore, we do not + /// insert them into a block. Consequently, they need to be manually erased in + /// the destructor above. void createValues() { OpBuilder builder(&context); for (int i = 0; i < 4; ++i) - v[i] = builder.create(builder.getUnknownLoc(), - builder.getI32IntegerAttr(i)); + v[i] = builder.create(builder.getUnknownLoc(), i, 32); } /// Checks that optimal branching on graph has the given cost and