[Mlir-commits] [mlir] [mlir] Use transform dialect for backward slice tests (PR #159634)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Fri Sep 19 03:41:03 PDT 2025
================
@@ -0,0 +1,98 @@
+//===- TestAnalysisOps.cpp - Test Transforms ----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines transform dialect operations for testing MLIR
+// analyses.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Analysis/SliceAnalysis.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/Transform/IR/TransformDialect.h"
+#include "mlir/Dialect/Transform/Interfaces/TransformInterfaces.h"
+#include "mlir/IR/IRMapping.h"
+#include "mlir/IR/OpDefinition.h"
+
+#define GET_OP_CLASSES
+#include "TestAnalysisOps.h.inc"
+
+using namespace mlir;
+using namespace transform;
+
+#define GET_OP_CLASSES
+#include "TestAnalysisOps.cpp.inc"
+
+/// Create a function with the same signature as the parent function of `op`
+/// with name being the function name and a `suffix`.
+static LogicalResult
+createBackwardSliceFunction(Operation *op, StringRef suffix,
+ const BackwardSliceOptions &options) {
+ func::FuncOp parentFuncOp = op->getParentOfType<func::FuncOp>();
+ if (!parentFuncOp)
+ return failure();
+ OpBuilder builder(parentFuncOp);
+ Location loc = op->getLoc();
+ std::string clonedFuncOpName = parentFuncOp.getName().str() + suffix.str();
+ func::FuncOp clonedFuncOp = func::FuncOp::create(
+ builder, loc, clonedFuncOpName, parentFuncOp.getFunctionType());
+ IRMapping mapper;
+ builder.setInsertionPointToEnd(clonedFuncOp.addEntryBlock());
+ for (const auto &arg : enumerate(parentFuncOp.getArguments()))
+ mapper.map(arg.value(), clonedFuncOp.getArgument(arg.index()));
----------------
ftynse wrote:
Nit: I think `.map` can take two lists of values.
https://github.com/llvm/llvm-project/pull/159634
More information about the Mlir-commits
mailing list