This follows the general nanobind porting guide and the upstream MLIR
changes in the same vein. For the most part, this is a very direct
migration accomplished with sed.
There were a couple minor differences.
Nanobind is more strict about implicit casting, which popped up in a
couple places:
* In MSFTModule, getNearestFreeInColumn was expecting a
CIRCTMSFTPrimitiveType (int), but was actually being passed
PrimitiveType enums at the call sites. Nanobind refused to
automatically cast enum to int, so it was done manually.
* In SVModule, SVAttributeAttr.get was expecting a bool for
emitAsComment, even though it was declared as having a default of
None. Nanobind refused to automatically cast None to bool, so it was
done manually, with a default of false.
Nanobind also prints enums slightly differently, so one FileCheck test
had to be updated for ESI.
Otherwise, the changes were purely mechanical.
As we transition from pybind11 to nanobind, the enums defined upstream
will be defined by nanobind. This no longer works with automatic
casting in the pybind11 APIs we define ourselves. To work around this
while we smooth the transition, this updates the APIs to work with
plain py::objects and manually cast to the appropriate C API enums in
a way that's compatible with both the pybind11 and nanobind versions
of enums.
This adds `walk_with_filter` python method to invoke callbacks
only for subset of operations. We require GIL to call python function
so this could improve performance of the tools based on Python API.
```
Starting walk_with_filter
walk_with_filter elapsed time: 0.005462 seconds cnt=1
Starting operation.walk
operation.walk elapsed time: 1.061360 seconds cnt=2
```