[Mlir-commits] [mlir] [MLIR] [Python] Added a way to extend MLIR->Python type mappings (PR #189368)
Maksim Levental
llvmlistbot at llvm.org
Mon Mar 30 09:52:38 PDT 2026
================
@@ -1451,6 +1489,34 @@ static bool emitAllOps(const RecordKeeper &records, raw_ostream &os) {
if (dialectNameStorage.empty())
llvm::PrintFatalError("dialect name not provided");
+ pythonTypeMap.clear();
+ for (auto [key, value] : builtinTypeMappings)
+ pythonTypeMap[key] = value.str();
+ for (const Record *rec :
+ records.getAllDerivedDefinitionsIfDefined("PythonTypeName")) {
+ StringRef key = rec->getValueAsString("cppName");
+ std::string value = rec->getValueAsString("pyName").str();
+ auto [it, inserted] = pythonTypeMap.try_emplace(key, std::move(value));
+ if (!inserted && it->second != value)
+ llvm::PrintFatalError(rec->getLoc(), "conflicting PythonTypeName for '" +
+ key + "': '" + it->second +
+ "' vs '" + value + "'");
+ }
+
+ pythonAttrTypeMap.clear();
+ for (auto [key, value] : builtinAttrTypeMappings)
+ pythonAttrTypeMap[key] = value.str();
+ for (const Record *rec :
+ records.getAllDerivedDefinitionsIfDefined("PythonAttrType")) {
+ StringRef key = rec->getValueAsString("defName");
+ std::string value = rec->getValueAsString("pyType").str();
+ auto [it, inserted] = pythonAttrTypeMap.try_emplace(key, std::move(value));
+ if (!inserted && it->second != value)
+ llvm::PrintFatalError(rec->getLoc(), "conflicting PythonAttrType for '" +
+ key + "': '" + it->second +
+ "' vs '" + value + "'");
+ }
+
----------------
makslevental wrote:
i have literally never in my life made this ask/comment but: can you please factor this out in a helper (possibly one for kind of map).
https://github.com/llvm/llvm-project/pull/189368
More information about the Mlir-commits
mailing list