[Mlir-commits] [mlir] [mlir][func]-Add deduplicate funcOp arguments transform (PR #158266)

Amir Bishara llvmlistbot at llvm.org
Fri Sep 12 07:41:22 PDT 2025


================
@@ -37,12 +37,49 @@ func::replaceFuncWithNewOrder(RewriterBase &rewriter, func::FuncOp funcOp,
   ArrayRef<Type> origOutputTypes = funcOp.getFunctionType().getResults();
   SmallVector<Type> newInputTypes, newOutputTypes;
   SmallVector<Location> locs;
-  for (unsigned int idx : newArgsOrder) {
-    newInputTypes.push_back(origInputTypes[idx]);
-    locs.push_back(funcOp.getArgument(newArgsOrder[idx]).getLoc());
+
+  std::map<unsigned, SmallVector<unsigned>> newArgToOldArg;
----------------
amirBish wrote:

The utils of the `replaceFuncWithNewMapping` now should have a mapping between the old argument index to the new argument index of the function operation. And we may have many (duplicated arguments) which should map to the same new argument index in the new function.

Now after the changes, I've used for the oldIndexToTheNewIndex mapping the `SmallVector<unsigned>`. And for the inverse mapping I'm using a SmallVector<SmallVector<unsigned>> since many old indexes may be mapped to a new index.

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


More information about the Mlir-commits mailing list