<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84190>84190</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[MLIR] Support returning IntegerAttr larger than 64 bits to Python
</td>
</tr>
<tr>
<th>Labels</th>
<td>
mlir:python
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mikeurbach
</td>
</tr>
</table>
<pre>
I'm using the MLIR Python bindings in CIRCT to represent some large integers, and while both IntegerAttr and Python can support arbitrary precision integers, the bindings currently use these methods that force the value into an int64_t or uint64_t: https://github.com/llvm/llvm-project/blob/67c6ad6f30e35c7670bce9bca902caa4b1c8c0e8/mlir/lib/Bindings/Python/IRAttributes.cpp#L452-L459
I'm currently [handling](https://github.com/llvm/circt/pull/6787) this downstream, by calling `int(str(myattr))`, with a custom `__str__` that uses a C API to call APInt's toString. This feels like a hack, so I'm wondering if there is interest in returning large bitwidth IntegerAttrs to Python upstream.
@uenoku pointed me to an old Discourse thread discussing C APIs for APInt here: https://discourse.llvm.org/t/llvm-support-types-in-c-api/1751. That discussion seemed to fizzle out. Is there interest in providing some sort of C API to support this Python binding use case?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUlE-L4zgQxT-NcikSFPn_IYdMN4ZALww9c29kuWxrW5aMVOom8-kX2Un_YQ_LQkgEUp7qPf2qZAh6tIgnVvxgxeNORpqcP836FaPvpJp2neuvpwsT1QwxaDsCTQh_PV2e4eeVJmeh07bXdgygLTxcnh9-AznwuHgMaAmCmxGM9COCtoQj-sDEA0jbw_ukDULnaILLtnUm8uvWTVtJCyEui_ME0neavPRXWDwqHbSz3xRTXR-1qOg9WjJXiAHTVkCYkSbXB6BJEgzOq3UD3qSJa20O5KpY5i8EzkO8rVl2holoCSw7M9Ey0Y6aptgdlJuZaI15u__sF-_-RkVMtJ1xHRNtWalS9uWQccwKVZUV7xQ2nZINF0rKvDuqW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