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

Class LazyTypeTable

lib/Bytecode/Reader/BytecodeReader.cpp:481–605  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

479//
480namespace {
481class LazyTypeTable {
482public:
483 LazyTypeTable(MLIRContext &context) : context(context) {}
484
485 void initialize(ArrayRef<uint8_t> payloadData, ArrayRef<uint32_t> indices,
486 const BytecodeVersion &version) {
487 payload = payloadData;
488 typeStartIndices = indices;
489 typeCache.resize(indices.size());
490 fileVersion = version;
491 }
492
493 Type getType(uint64_t typeIndex) {
494 if (typeIndex >= typeCache.size())
495 return Type();
496 if (typeCache[typeIndex])
497 return typeCache[typeIndex];
498
499 // Check for recursion.
500 if (currentlyParsing.count(typeIndex))
501 return Type();
502 // Mark this type as currently being parsed.
503 currentlyParsing.insert(typeIndex);
504 [[maybe_unused]] llvm::scope_exit removeIndex(
505 [&] { currentlyParsing.erase(typeIndex); });
506 // Calculate the boundaries for the type data.
507 uint32_t start = typeStartIndices[typeIndex];
508 uint32_t end = (typeIndex + 1 < typeStartIndices.size())
509 ? typeStartIndices[typeIndex + 1]
510 : payload.size();
511 if (end < start || end > payload.size())
512 return Type();
513 // Parse the type from its specific byte slice.
514 EncodingReader typeReader(payload.slice(start, end - start), context);
515 uint64_t typeTag;
516 if (failed(typeReader.readVarInt(typeTag)))
517 return nullptr;
518 ArrayRef<uint8_t> payloadBytes;
519 if (typeReader.remaining() > 0)
520 payloadBytes = typeReader.readBytes(typeReader.remaining());
521 Type parsedType;
522 if (failed(parseTypeImpl(typeTag, payloadBytes, parsedType)))
523 return Type();
524
525 // Cache the result.
526 typeCache[typeIndex] = parsedType;
527 return parsedType;
528 }
529
530 size_t size() const { return typeStartIndices.size(); }
531
532 /// Returns the bytecode file version.
533 BytecodeVersion getFileVersion() const { return fileVersion; }
534
535 /// Reads a type index using the provided reader and retrieves the
536 /// corresponding Type. Emits an error and returns a null Type on failure.
537 Type readAndGetType(EncodingReader &reader) {
538 uint64_t typeIndex;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected