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

Method parseOpAttribute

lib/Bytecode/Reader/BytecodeReader.cpp:1482–1736  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1480 /// TODO: Auto-generate CudaTile attribute parsing from TableGen (like types).
1481 template <typename T>
1482 static LogicalResult
1483 parseOpAttribute(EncodingReader &reader, MLIRContext &context,
1484 LazyTypeTable &types, ArrayRef<ArrayRef<uint8_t>> constants,
1485 DenseElementsAttrCache &constCache, T &nativeValue,
1486 Type expectedType = nullptr) {
1487 Attribute parsedAttr;
1488 // The logic here determines how to read the attribute based on the
1489 // *expected C++ type T*, because the bytecode format doesn't explicitly
1490 // store how each attribute was encoded (inline vs index).
1491 if constexpr (std::is_same_v<T, UnitAttr>) {
1492 // UnitAttr presence is stored as inline bool (i1).
1493 BoolAttr presentAttr;
1494 if (failed(parseScalarAttributeInline(
1495 reader, context, IntegerType::get(&context, 1), presentAttr)))
1496 return failure();
1497 // Convert the parsed BoolAttr to UnitAttr (or nullptr if false)
1498 nativeValue = presentAttr.getValue() ? UnitAttr::get(&context) : nullptr;
1499 return success();
1500 } else if constexpr (std::is_same_v<T, BoolAttr>) {
1501 // BoolAttr is stored as inline bool (i1).
1502 return parseScalarAttributeInline(
1503 reader, context, IntegerType::get(&context, 1), nativeValue);
1504 } else if constexpr (std::is_same_v<T, IntegerAttr>) {
1505 if (!expectedType) {
1506 expectedType = types.readAndGetType(reader);
1507 if (!isa_and_nonnull<IntegerType>(expectedType))
1508 return reader.emitError()
1509 << "failed to read valid IntegerType for IntegerAttr";
1510 }
1511 if (failed(parseScalarAttributeInline(reader, context, expectedType,
1512 parsedAttr)))
1513 return failure();
1514 nativeValue = dyn_cast_or_null<IntegerAttr>(parsedAttr);
1515 if (!nativeValue)
1516 return reader.emitError()
1517 << "failed to cast parsed attribute to IntegerAttr";
1518 return success();
1519 } else if constexpr (std::is_same_v<T, FloatAttr>) {
1520 if (!expectedType) {
1521 expectedType = types.readAndGetType(reader);
1522 if (!isa_and_nonnull<FloatType>(expectedType))
1523 return reader.emitError()
1524 << "failed to read valid FloatType for FloatAttr";
1525 }
1526 if (failed(parseScalarAttributeInline(reader, context, expectedType,
1527 parsedAttr)))
1528 return failure();
1529 nativeValue = dyn_cast_or_null<FloatAttr>(parsedAttr);
1530 if (!nativeValue)
1531 return reader.emitError()
1532 << "failed to cast parsed attribute to FloatAttr";
1533 return success();
1534 } else if constexpr (std::is_same_v<T, TypeAttr>) {
1535 // TypeAttr is stored as an index into the type table.
1536 Type referencedType = types.readAndGetType(reader);
1537 if (!referencedType)
1538 return reader.emitError()
1539 << "failed to get referenced type for TypeAttr";

Callers

nothing calls this directly

Calls 11

parseGenericEnumAttrFunction · 0.85
maxFunction · 0.85
readAndGetTypeMethod · 0.80
emitErrorMethod · 0.80
readAndGetStringMethod · 0.80
readLEVarSizeMethod · 0.80
getFileVersionMethod · 0.80
readVarIntMethod · 0.80
readLEMethod · 0.80
readSignedVarIntMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected