| 32 | //===----------------------------------------------------------------------===// |
| 33 | |
| 34 | BytecodeAttrStructure |
| 35 | mlir::tblgen::analyzeBytecodeAttrs(const RecordKeeper &records) { |
| 36 | BytecodeAttrStructure structure; |
| 37 | |
| 38 | // Build map of MLIR built-in attrs from CudaTileAttrAlias records. |
| 39 | // These provide version info for MLIR built-in attributes we serialize. |
| 40 | StringMap<StringRef> aliasVersions; |
| 41 | for (const Record *record : |
| 42 | records.getAllDerivedDefinitions("CudaTileAttrAlias")) { |
| 43 | StringRef attrName = record->getValueAsString("attrName"); |
| 44 | StringRef version = record->getValueAsString("sinceVersion"); |
| 45 | if (attrName.empty()) |
| 46 | PrintFatalError(record->getLoc(), "CudaTileAttrAlias '" + |
| 47 | record->getName().str() + |
| 48 | "' has empty 'attrName'"); |
| 49 | if (version.empty()) |
| 50 | PrintFatalError(record->getLoc(), "CudaTileAttrAlias '" + |
| 51 | record->getName().str() + |
| 52 | "' has empty 'sinceVersion'"); |
| 53 | aliasVersions[attrName] = version; |
| 54 | } |
| 55 | |
| 56 | // Build map of CudaTileAttrDef records. |
| 57 | struct AttrDefInfo { |
| 58 | StringRef sinceVersion; |
| 59 | bool skipsVersionCheck; |
| 60 | }; |
| 61 | StringMap<AttrDefInfo> attrDefInfo; |
| 62 | for (const Record *record : |
| 63 | records.getAllDerivedDefinitions("CudaTileAttrDef")) { |
| 64 | bool skips = false; |
| 65 | StringRef version; |
| 66 | if (record->getValue("sinceVersion") && |
| 67 | !record->isValueUnset("sinceVersion")) { |
| 68 | version = record->getValueAsString("sinceVersion"); |
| 69 | } |
| 70 | |
| 71 | if (!skips && version.empty()) |
| 72 | PrintFatalError(record->getLoc(), |
| 73 | "CudaTileAttrDef '" + record->getName().str() + |
| 74 | "' is missing or has empty 'sinceVersion'"); |
| 75 | |
| 76 | attrDefInfo[extractAttrTagName(record->getName())] = {version, skips}; |
| 77 | } |
| 78 | |
| 79 | // Process BytecodeAttrTag records. |
| 80 | for (const Record *record : |
| 81 | records.getAllDerivedDefinitions("BytecodeAttrTag")) { |
| 82 | StringRef attrName = record->getValueAsString("cppAttrName"); |
| 83 | |
| 84 | BytecodeAttr attr; |
| 85 | attr.attrName = attrName.str(); |
| 86 | attr.tagValue = record->getValueAsInt("attrTagValue"); |
| 87 | |
| 88 | // Look up version from CudaTileAttrAlias or CudaTileAttrDef. |
| 89 | // Every BytecodeAttrTag must have version info from one of these sources. |
| 90 | if (auto it = aliasVersions.find(attrName); it != aliasVersions.end()) { |
| 91 | attr.sinceVersion = it->second.str(); |
nothing calls this directly
no test coverage detected