From e59cdcd070249488c5c5de668bb84a3033ab62c9 Mon Sep 17 00:00:00 2001 From: Alexander Batashev Date: Mon, 18 Jul 2022 11:56:34 -0400 Subject: [PATCH] [mlir][spirv] Allow unnamed entry point functions SPIR-V specification does not require a function to have a name if it is an entry point. Adjust deserializer to allow those kinds of SPIR-V binaries. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D120181 --- .../Target/SPIRV/Deserialization/DeserializeOps.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp b/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp index 1db8e95b084d..9566b9ed1bbe 100644 --- a/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp +++ b/mlir/lib/Target/SPIRV/Deserialization/DeserializeOps.cpp @@ -347,9 +347,15 @@ Deserializer::processOp(ArrayRef words) { return emitError(unknownLoc, "no function matching ") << fnID; } if (parsedFunc.getName() != fnName) { - return emitError(unknownLoc, "function name mismatch between OpEntryPoint " - "and OpFunction with ") - << fnID << ": " << fnName << " vs. " << parsedFunc.getName(); + // The deserializer uses "spirv_fn_" as the function name if the input + // SPIR-V blob does not contain a name for it. We should use a more clear + // indication for such case rather than relying on naming details. + if (!parsedFunc.getName().startswith("spirv_fn_")) + return emitError(unknownLoc, + "function name mismatch between OpEntryPoint " + "and OpFunction with ") + << fnID << ": " << fnName << " vs. " << parsedFunc.getName(); + parsedFunc.setName(fnName); } SmallVector interface; while (wordIndex < words.size()) {