From c075fb8c37856365fb76d986ad3aefa2400b3240 Mon Sep 17 00:00:00 2001 From: Hank <49036880+hankluo6@users.noreply.github.com> Date: Wed, 20 Aug 2025 06:03:26 -0700 Subject: [MLIR] Fix duplicated attribute nodes in MLIR bytecode deserialization (#151267) Fixes #150163 MLIR bytecode does not preserve alias definitions, so each attribute encountered during deserialization is treated as a new one. This can generate duplicate `DISubprogram` nodes during deserialization. The patch adds a `StringMap` cache that records attributes and fetches them when encountered again. --- mlir/lib/Bytecode/Reader/BytecodeReader.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'mlir/lib/Bytecode/Reader/BytecodeReader.cpp') diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp index 44458d0..0f97443 100644 --- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -895,6 +895,10 @@ private: SmallVector attributes; SmallVector types; + /// The map of cached attributes, used to avoid re-parsing the same + /// attribute multiple times. + llvm::StringMap attributesCache; + /// A location used for error emission. Location fileLoc; @@ -1235,7 +1239,7 @@ LogicalResult AttrTypeReader::parseAsmEntry(T &result, EncodingReader &reader, ::parseType(asmStr, context, &numRead, /*isKnownNullTerminated=*/true); else result = ::parseAttribute(asmStr, context, Type(), &numRead, - /*isKnownNullTerminated=*/true); + /*isKnownNullTerminated=*/true, &attributesCache); if (!result) return failure(); -- cgit v1.1