diff options
| author | Hank <49036880+hankluo6@users.noreply.github.com> | 2025-08-20 06:03:26 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-20 13:03:26 +0000 |
| commit | c075fb8c37856365fb76d986ad3aefa2400b3240 (patch) | |
| tree | c22022fb28631007cfede764dd52c7a3b0915d2c /mlir/lib/Bytecode/Reader/BytecodeReader.cpp | |
| parent | 5f0515debd4873fc20cc2afa3f01722e02281d6c (diff) | |
| download | llvm-c075fb8c37856365fb76d986ad3aefa2400b3240.zip llvm-c075fb8c37856365fb76d986ad3aefa2400b3240.tar.gz llvm-c075fb8c37856365fb76d986ad3aefa2400b3240.tar.bz2 | |
[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.
Diffstat (limited to 'mlir/lib/Bytecode/Reader/BytecodeReader.cpp')
| -rw-r--r-- | mlir/lib/Bytecode/Reader/BytecodeReader.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
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<AttrEntry> attributes; SmallVector<TypeEntry> types; + /// The map of cached attributes, used to avoid re-parsing the same + /// attribute multiple times. + llvm::StringMap<Attribute> 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(); |
