[Mlir-commits] [mlir] [mlir] add optional type functor to call and function interfaces (PR #146979)
River Riddle
llvmlistbot at llvm.org
Wed Jul 9 09:32:26 PDT 2025
================
@@ -90,22 +111,41 @@ static void printFunctionResultList(OpAsmPrinter &p, TypeRange types,
if (needsParens)
os << '(';
llvm::interleaveComma(llvm::seq<size_t>(0, types.size()), os, [&](size_t i) {
- p.printType(types[i]);
+ typePrinter(p, types[i]);
if (attrs)
p.printOptionalAttrDict(llvm::cast<DictionaryAttr>(attrs[i]).getValue());
});
if (needsParens)
os << ')';
}
+static void
+printFunctionalType(OpAsmPrinter &p, TypeRange &inputs, TypeRange &results,
+ function_ref<void(OpAsmPrinter &, Type)> typePrinter) {
+ p << '(';
+ llvm::interleaveComma(inputs, p, [&](Type ty) { typePrinter(p, ty); });
+ p << ')';
+
+ bool wrapped = !llvm::hasSingleElement(results) ||
+ llvm::isa<FunctionType>((*results.begin()));
+ if (wrapped)
+ p << '(';
+ llvm::interleaveComma(results, p, [&](Type ty) { typePrinter(p, ty); });
+ if (wrapped)
+ p << ')';
+}
void call_interface_impl::printFunctionSignature(
OpAsmPrinter &p, TypeRange argTypes, ArrayAttr argAttrs, bool isVariadic,
TypeRange resultTypes, ArrayAttr resultAttrs, Region *body,
- bool printEmptyResult) {
+ bool printEmptyResult,
+ function_ref<void(OpAsmPrinter &, Type)> typePrinter) {
+ if (!typePrinter)
+ typePrinter = defaultTypePrinter;
+
bool isExternal = !body || body->empty();
if (!isExternal && !isVariadic && !argAttrs && !resultAttrs &&
printEmptyResult) {
- p.printFunctionalType(argTypes, resultTypes);
+ printFunctionalType(p, argTypes, resultTypes, typePrinter);
----------------
River707 wrote:
Given the addition to other functions, maybe it's be fine to just adjust `printFunctionalType` to also accept an optional functor?
https://github.com/llvm/llvm-project/pull/146979
More information about the Mlir-commits
mailing list