[Mlir-commits] [mlir] Handle large integers (> 64 bits) for the IntegerAttr C-API (PR #130539)
John Demme
llvmlistbot at llvm.org
Wed Mar 19 13:50:29 PDT 2025
================
@@ -456,8 +456,30 @@ class PyIntegerAttribute : public PyConcreteAttribute<PyIntegerAttribute> {
static void bindDerived(ClassTy &c) {
c.def_static(
"get",
- [](PyType &type, int64_t value) {
- MlirAttribute attr = mlirIntegerAttrGet(type, value);
+ [](PyType &type, py::int_ value) {
+ apint_interop_t interop;
+ if (mlirTypeIsAIndex(type))
+ interop.numbits = 64;
+ else
+ interop.numbits = mlirIntegerTypeGetWidth((MlirType)type);
+
+ py::object to_bytes = value.attr("to_bytes");
+ int numbytes = (interop.numbits + 7) / 8;
+ bool Signed =
+ mlirTypeIsAIndex(type) || mlirIntegerTypeIsSigned(type);
+ py::bytes bytes_obj =
----------------
teqdruid wrote:
I'm not familiar with the internal encoding of ints in Python nor am I familiar with the internal encoding of APInt. Are they guaranteed to be the same? @stellaraccident ?
https://github.com/llvm/llvm-project/pull/130539
More information about the Mlir-commits
mailing list