[Mlir-commits] [mlir] [mlir][func]-Add deduplicate funcOp arguments transform (PR #158266)
Mehdi Amini
llvmlistbot at llvm.org
Fri Sep 12 09:28:00 PDT 2025
================
@@ -37,12 +38,62 @@ 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());
+
+ // We may have some duplicate arguments in the old function, i.e.
+ // in the mapping `newArgIdxToOldArgIdxs` for some new argument index
+ // there may be multiple old argument indices.
+ unsigned numOfNewArgs = 0;
+ auto maxNewArgIdx = llvm::max_element(oldArgToNewArg);
+ if (maxNewArgIdx != oldArgToNewArg.end())
+ numOfNewArgs = *maxNewArgIdx + 1;
----------------
joker-eph wrote:
What is this condition guarding? Only if the input is empty? If so, this seems more direct:
```suggestion
if (! oldArgToNewArg.empty()
numOfNewArgs = 1 + *llvm::max_element(oldArgToNewArg);
```
https://github.com/llvm/llvm-project/pull/158266
More information about the Mlir-commits
mailing list