[Mlir-commits] [mlir] [mlir][func]: Introduce ReplaceFuncSignature tranform operation (PR #143381)

Aviad Cohen llvmlistbot at llvm.org
Sat Jun 14 05:29:12 PDT 2025


================
@@ -0,0 +1,103 @@
+//===- Utils.cpp - Utilities to support the Func dialect ----------------===//
+//
+// 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 implements utilities for the Func dialect.
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Func/Utils/Utils.h"
+#include "mlir/IR/IRMapping.h"
+#include "mlir/IR/PatternMatch.h"
+
+using namespace mlir;
+
+func::FuncOp func::replaceFuncWithNewOrder(func::FuncOp funcOp,
+                                           ArrayRef<int> newArgsOrder,
+                                           ArrayRef<int> newResultsOrder) {
+  // Generate an empty new function operation with the same name as the
+  // original.
+  assert(funcOp.getNumArguments() == newArgsOrder.size());
+  assert(funcOp.getNumResults() == newResultsOrder.size());
+  auto origInputTypes = funcOp.getFunctionType().getInputs();
+  auto origOutputTypes = funcOp.getFunctionType().getResults();
+  SmallVector<Type> newInputTypes, newOutputTypes;
+  for (unsigned int i = 0; i < origInputTypes.size(); ++i)
+    newInputTypes.push_back(origInputTypes[newArgsOrder[i]]);
+  for (unsigned int i = 0; i < origOutputTypes.size(); ++i)
+    newOutputTypes.push_back(origOutputTypes[newResultsOrder[i]]);
+  IRRewriter rewriter(funcOp);
----------------
AviadCo wrote:

Ack, added.

https://github.com/llvm/llvm-project/pull/143381


More information about the Mlir-commits mailing list