aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Bytecode/Reader/BytecodeReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mlir/lib/Bytecode/Reader/BytecodeReader.cpp')
-rw-r--r--mlir/lib/Bytecode/Reader/BytecodeReader.cpp30
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);
}