[Mlir-commits] [mlir] [mlir][func]: Introduce ReplaceFuncSignature tranform operation (PR #143381)
Oleksandr Alex Zinenko
llvmlistbot at llvm.org
Tue Jun 10 13:47:32 PDT 2025
================
@@ -226,6 +227,98 @@ void transform::CastAndCallOp::getEffects(
transform::modifiesPayload(effects);
}
+//===----------------------------------------------------------------------===//
+// ReplaceFuncSignatureOp
+//===----------------------------------------------------------------------===//
+
+DiagnosedSilenceableFailure
+transform::ReplaceFuncSignatureOp::apply(transform::TransformRewriter &rewriter,
+ transform::TransformResults &results,
+ transform::TransformState &state) {
+ auto payloadOps = state.getPayloadOps(getModule());
+ if (!llvm::hasSingleElement(payloadOps))
+ return emitDefiniteFailure() << "requires a single module to operate on";
+
+ auto targetModuleOp = dyn_cast<ModuleOp>(*payloadOps.begin());
+ if (!targetModuleOp)
+ return emitSilenceableFailure(getLoc())
+ << "target is expected to be module operation";
+
+ func::FuncOp funcOp =
+ targetModuleOp.lookupSymbol<func::FuncOp>(getFunctionName());
+ if (!funcOp)
+ return emitSilenceableFailure(getLoc())
+ << "function with name '" << getFunctionName() << "' not found";
+
+ int numArgs = funcOp.getNumArguments();
+ int numResults = funcOp.getNumResults();
+ // Check that the number of arguments and results matches the
+ // interchange sizes.
+ if (numArgs != (int)getArgsInterchange().size())
+ return emitSilenceableFailure(getLoc())
+ << "function with name '" << getFunctionName() << "' has " << numArgs
+ << " arguments, but " << getArgsInterchange().size()
+ << " args interchange were given";
+
+ if (numResults != (int)getResultsInterchange().size())
+ return emitSilenceableFailure(getLoc())
+ << "function with name '" << getFunctionName() << "' has "
+ << numResults << " results, but " << getResultsInterchange().size()
+ << " results interchange were given";
+
+ // Check that the args and results interchanges are unique.
+ SetVector<int> argsInterchange, resultsInterchange;
+ argsInterchange.insert_range(getArgsInterchange());
+ resultsInterchange.insert_range(getResultsInterchange());
+ if (argsInterchange.size() != getArgsInterchange().size())
+ return emitSilenceableFailure(getLoc())
+ << "args interchange must be unique";
+
+ if (resultsInterchange.size() != getResultsInterchange().size())
+ return emitSilenceableFailure(getLoc())
+ << "results interchange must be unique";
+
+ // Check that the args and results interchange indices are in bounds.
+ for (auto index : argsInterchange) {
----------------
ftynse wrote:
Nit: expand `auto` unless the type is obvious from statement-level context (casts, constructors) or difficult to spell.
https://github.com/llvm/llvm-project/pull/143381
More information about the Mlir-commits
mailing list