[Mlir-commits] [mlir] [mlir][python] expose remaining Location inspection API (PR #192630)

Soowon Jeong llvmlistbot at llvm.org
Fri Apr 17 04:10:03 PDT 2026


https://github.com/swjng created https://github.com/llvm/llvm-project/pull/192630

Rounds out `Location` deconstruction/inspection (#53169). Prior to this PR, `UnknownLoc` lacked an isA check, `FusedLoc.metadata` was reachable from the C API but not from Python, and `OpaqueLoc` had no C API or Python surface at all. Any Python tool iterating over arbitrary locations hit a wall on those three.

### Changes

C API (`mlir/include/mlir-c/IR.h`, `mlir/lib/CAPI/IR/IR.cpp`):
- `mlirLocationIsAUnknown`, `mlirLocationUnknownGetTypeID`
- `mlirLocationOpaqueGet`, `mlirLocationOpaqueGetUnderlyingLocation`, `mlirLocationOpaqueGetUnderlyingTypeID`, `mlirLocationOpaqueGetFallbackLocation`, `mlirLocationOpaqueGetTypeID`, `mlirLocationIsAOpaque`

Python (`mlir/lib/Bindings/Python/IRCore.cpp`):
- `Location.is_a_unknown()`
- `FusedLoc.metadata` (returns `None` when absent)
- `Location.opaque(underlying_location, underlying_type_id, fallback_location)` plus `is_a_opaque()`, `underlying_location`, `underlying_type_id`, `fallback_location`

Tests:
- `mlir/test/python/ir/location.py` — `testUnknown` gets isA coverage, `testFused` checks metadata (absent / present), new `testOpaque` exercises round-trip construction and accessors.
- `mlir/test/CAPI/ir.c` — `testLocation` covers the new C API.

### Notes

`OpaqueLoc.underlying_location` surfaces the raw `uintptr_t` as a Python `int`; interpreting it is the caller's responsibility (e.g. via `ctypes`), same contract as the C++ side. TypeIDs are passed through as opaque tokens.

The server is unavailable at this time. Please wait a few minutes before you try again.


More information about the Mlir-commits mailing list