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

Method serializeAttribute

lib/Bytecode/Writer/BytecodeWriter.cpp:501–524  ·  view source on GitHub ↗

Serializes a single MLIR attribute into its raw byte representation. This function handles different attribute types, focusing on scalar and dense element attributes suitable for the constant pool.

Source from the content-addressed store, hash-verified

499 /// This function handles different attribute types, focusing on scalar
500 /// and dense element attributes suitable for the constant pool.
501 LogicalResult serializeAttribute(Attribute attr, EncodingWriter &writer) {
502 if (auto denseAttr = dyn_cast<DenseElementsAttr>(attr)) {
503 // Get the raw data buffer in little-endian format.
504 ArrayRef<char> rawData = denseAttr.getRawData();
505 // Write the size of the raw buffer.
506 writer.writeVarInt(rawData.size());
507 // Write the raw buffer content.
508 writer.write(rawData.data(), rawData.size());
509 return success();
510 } else if (auto intAttr = dyn_cast<IntegerAttr>(attr)) {
511 APInt value = intAttr.getValue();
512 writer.writeLE<uint64_t>(value.getZExtValue());
513 return success();
514 } else if (auto boolAttr = dyn_cast<BoolAttr>(attr)) {
515 uint8_t boolValue = boolAttr.getValue() ? 0x01 : 0x00;
516 writer.writeByte(boolValue);
517 return success();
518 } else if (auto floatAttr = dyn_cast<FloatAttr>(attr)) {
519 writeAPFloatRepresentation(floatAttr.getValue(), writer);
520 return success();
521 }
522 return emitError(UnknownLoc::get(attr.getContext()),
523 "unsupported attribute type in constant data");
524 }
525
526 LogicalResult writeConstantSection(raw_ostream &stream) {
527 // If there are no constants, skip writing this section entirely

Callers

nothing calls this directly

Calls 5

writeVarIntMethod · 0.80
sizeMethod · 0.80
writeMethod · 0.80
writeByteMethod · 0.80

Tested by

no test coverage detected