Skip to content

Conversation

@rolfmorel
Copy link
Contributor

Updates the derived Op-classes for the main transform ops to have all the arguments, etc, from the auto-generated classes. Additionally updates and adds missing snake_case wrappers for the derived classes which shadow the snake_case wrappers of the auto-generated classes, which were hitherto exposed alongside the derived classes.

Updates the derived Op-classes for the main transform ops to have all the
arguments, etc, from the auto-generated classes. Additionally updates and
adds missing snake_case wrappers for the derived classes which shadow
the snake_case wrappers which were exposed alongside the derived classes.
@github-actions
Copy link

github-actions bot commented Nov 7, 2025

✅ With the latest revision this PR passed the Python code formatter.

@rolfmorel
Copy link
Contributor Author

Meant to address: #166765

Copy link
Member

@ftynse ftynse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow automate generation of these wrappers? They are marginally more usable, but seem to have high maintenance cost.

@rolfmorel
Copy link
Contributor Author

Discussed it with @makslevental yesterday. In the case of these transform ops, the derived classes and wrappers really only serve two purposes: add type hints and add _ods_common.get_op_result_or_value around operand arguments. Both of these could in principle be derived from tablegen and be part of the auto-generated classes and wrappers.

From my perspective, the main issue is the mapping from tablegen types, i.e. C++ types, to the type hints. I figure it would be something like

static std::string getPythonAttrName(mlir::tblgen::Attribute attr) {
auto storageTypeStr = attr.getStorageType();
if (storageTypeStr == "::mlir::AffineMapAttr")
return "AffineMapAttr";
if (storageTypeStr == "::mlir::ArrayAttr")
return "ArrayAttr";
if (storageTypeStr == "::mlir::BoolAttr")
return "BoolAttr";
if (storageTypeStr == "::mlir::DenseBoolArrayAttr")
return "DenseBoolArrayAttr";
if (storageTypeStr == "::mlir::DenseElementsAttr") {
llvm::StringSet<> superClasses;
for (const Record *sc : attr.getDef().getSuperClasses())
superClasses.insert(sc->getNameInitAsString());
if (superClasses.contains("FloatElementsAttr") ||
superClasses.contains("RankedFloatElementsAttr")) {
return "DenseFPElementsAttr";
}
return "DenseElementsAttr";
}
if (storageTypeStr == "::mlir::DenseF32ArrayAttr")
return "DenseF32ArrayAttr";
if (storageTypeStr == "::mlir::DenseF64ArrayAttr")
return "DenseF64ArrayAttr";
if (storageTypeStr == "::mlir::DenseFPElementsAttr")
return "DenseFPElementsAttr";
if (storageTypeStr == "::mlir::DenseI16ArrayAttr")
return "DenseI16ArrayAttr";
if (storageTypeStr == "::mlir::DenseI32ArrayAttr")
return "DenseI32ArrayAttr";
if (storageTypeStr == "::mlir::DenseI64ArrayAttr")
return "DenseI64ArrayAttr";
if (storageTypeStr == "::mlir::DenseI8ArrayAttr")
return "DenseI8ArrayAttr";
if (storageTypeStr == "::mlir::DenseIntElementsAttr")
return "DenseIntElementsAttr";
if (storageTypeStr == "::mlir::DenseResourceElementsAttr")
return "DenseResourceElementsAttr";
if (storageTypeStr == "::mlir::DictionaryAttr")
return "DictAttr";
if (storageTypeStr == "::mlir::FlatSymbolRefAttr")
return "FlatSymbolRefAttr";
if (storageTypeStr == "::mlir::FloatAttr")
return "FloatAttr";
if (storageTypeStr == "::mlir::IntegerAttr") {
if (attr.getAttrDefName().str() == "I1Attr")
return "BoolAttr";
return "IntegerAttr";
}
if (storageTypeStr == "::mlir::IntegerSetAttr")
return "IntegerSetAttr";
if (storageTypeStr == "::mlir::OpaqueAttr")
return "OpaqueAttr";
if (storageTypeStr == "::mlir::StridedLayoutAttr")
return "StridedLayoutAttr";
if (storageTypeStr == "::mlir::StringAttr")
return "StringAttr";
if (storageTypeStr == "::mlir::SymbolRefAttr")
return "SymbolRefAttr";
if (storageTypeStr == "::mlir::TypeAttr")
return "TypeAttr";
if (storageTypeStr == "::mlir::UnitAttr")
return "UnitAttr";
return "Attribute";
}

When I find some time, I can try implement something like that. If someone has a better idea of how to encode the mapping from MLIR/C++ types to Python type hints, please let me know!

@rolfmorel rolfmorel merged commit d78e0de into llvm:main Nov 7, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants