diff options
| author | Jacques Pienaar <jpienaar@google.com> | 2023-05-25 09:24:50 -0700 |
|---|---|---|
| committer | Jacques Pienaar <jpienaar@google.com> | 2023-05-25 09:24:50 -0700 |
| commit | 1826fadb0d2bc5b61d6c028d8006b2a7d1249ec0 (patch) | |
| tree | 95a7382117a98ef1c0cc549f595cce5bcc75a76e /mlir/lib/Bytecode/Reader/BytecodeReader.cpp | |
| parent | 12ccc59594916caf8a833f749cc820dde961d83d (diff) | |
| download | llvm-1826fadb0d2bc5b61d6c028d8006b2a7d1249ec0.zip llvm-1826fadb0d2bc5b61d6c028d8006b2a7d1249ec0.tar.gz llvm-1826fadb0d2bc5b61d6c028d8006b2a7d1249ec0.tar.bz2 | |
[mlir][bytecode] Avoid recording null arglocs & realloc opnames.
For block arg locs a common case is no/uknown location (where the producer
signifies they don't care about blockarg location). Also avoid needing to
dynamically resize opnames during parsing.
Assumed to be post lazy loading change, so chose version 3.
Differential Revision: https://reviews.llvm.org/D151038
Diffstat (limited to 'mlir/lib/Bytecode/Reader/BytecodeReader.cpp')
| -rw-r--r-- | mlir/lib/Bytecode/Reader/BytecodeReader.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp index 8ff48ad..ca05eac 100644 --- a/mlir/lib/Bytecode/Reader/BytecodeReader.cpp +++ b/mlir/lib/Bytecode/Reader/BytecodeReader.cpp @@ -1603,6 +1603,14 @@ BytecodeReader::Impl::parseDialectSection(ArrayRef<uint8_t> sectionData) { opNames.emplace_back(dialect, opName); return success(); }; + // Avoid re-allocation in bytecode version > 3 where the number of ops are + // known. + if (version > 3) { + uint64_t numOps; + if (failed(sectionReader.parseVarInt(numOps))) + return failure(); + opNames.reserve(numOps); + } while (!sectionReader.empty()) if (failed(parseDialectGrouping(sectionReader, dialects, parseOpName))) return failure(); @@ -2175,13 +2183,25 @@ LogicalResult BytecodeReader::Impl::parseBlockArguments(EncodingReader &reader, argTypes.reserve(numArgs); argLocs.reserve(numArgs); + Location unknownLoc = UnknownLoc::get(config.getContext()); while (numArgs--) { Type argType; - LocationAttr argLoc; - if (failed(parseType(reader, argType)) || - failed(parseAttribute(reader, argLoc))) - return failure(); - + LocationAttr argLoc = unknownLoc; + if (version > 3) { + // Parse the type with hasLoc flag to determine if it has type. + uint64_t typeIdx; + bool hasLoc; + if (failed(reader.parseVarIntWithFlag(typeIdx, hasLoc)) || + !(argType = attrTypeReader.resolveType(typeIdx))) + return failure(); + if (hasLoc && failed(parseAttribute(reader, argLoc))) + return failure(); + } else { + // All args has type and location. + if (failed(parseType(reader, argType)) || + failed(parseAttribute(reader, argLoc))) + return failure(); + } argTypes.push_back(argType); argLocs.push_back(argLoc); } |
