MCPcopy Create free account
hub / github.com/NVIDIA/cuda-tile / parseTypeSection

Function parseTypeSection

lib/Bytecode/Reader/BytecodeReader.cpp:609–648  ·  view source on GitHub ↗

Parses the type section and initializes the lazy type table

Source from the content-addressed store, hash-verified

607
608/// Parses the type section and initializes the lazy type table
609static LogicalResult parseTypeSection(ArrayRef<uint8_t> payload,
610 LazyTypeTable &types,
611 MLIRContext &context,
612 const BytecodeVersion &bytecodeVersion) {
613 EncodingReader reader(payload, context);
614 uint64_t numTypes;
615 if (failed(reader.readVarInt(numTypes)))
616 return failure();
617
618 // Handle empty type table case.
619 if (numTypes == 0) {
620 types.initialize(ArrayRef<uint8_t>(), ArrayRef<uint32_t>(),
621 bytecodeVersion);
622 return success();
623 }
624
625 if (numTypes > (payload.size() - reader.currentOffset()) / sizeof(uint32_t)) {
626 return reader.emitError()
627 << "number of types (" << numTypes << ") exceeds the maximum of "
628 << (payload.size() - reader.currentOffset()) / sizeof(uint32_t)
629 << " that can fit in the remaining payload of "
630 << (payload.size() - reader.currentOffset()) << " bytes.";
631 }
632
633 // Ensure 4-byte alignment for the start indices array
634 if (failed(reader.skipPadding(alignof(uint32_t))))
635 return failure();
636 // Read type start indices as a contiguous array
637 const uint32_t *startIndicesPtr =
638 reinterpret_cast<const uint32_t *>(reader.getCurrentPtr());
639 if (!startIndicesPtr)
640 return failure();
641 ArrayRef<uint32_t> typeStartIndices(startIndicesPtr, numTypes);
642 if (failed(reader.skip(numTypes * sizeof(uint32_t))))
643 return failure();
644 // Initialize the lazy type table with the payload and indices
645 ArrayRef<uint8_t> typeData = payload.slice(reader.currentOffset());
646 types.initialize(typeData, typeStartIndices, bytecodeVersion);
647 return success();
648}
649
650//===----------------------------------------------------------------------===//
651// Constant Section

Callers 1

readBytecodeMethod · 0.85

Calls 8

readVarIntMethod · 0.80
sizeMethod · 0.80
currentOffsetMethod · 0.80
emitErrorMethod · 0.80
skipPaddingMethod · 0.80
getCurrentPtrMethod · 0.80
skipMethod · 0.80
initializeMethod · 0.45

Tested by

no test coverage detected