This repository was archived by the owner on Oct 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -418,6 +418,9 @@ MLIR_CAPI_EXPORTED MlirModule mlirModuleFromOperation(MlirOperation op);
418418/// Checks if two modules are equal.
419419MLIR_CAPI_EXPORTED bool mlirModuleEqual (MlirModule lhs , MlirModule rhs );
420420
421+ /// Compute a hash for the given module.
422+ MLIR_CAPI_EXPORTED size_t mlirModuleHashValue (MlirModule mod );
423+
421424//===----------------------------------------------------------------------===//
422425// Operation state.
423426//===----------------------------------------------------------------------===//
@@ -622,6 +625,9 @@ static inline bool mlirOperationIsNull(MlirOperation op) { return !op.ptr; }
622625MLIR_CAPI_EXPORTED bool mlirOperationEqual (MlirOperation op ,
623626 MlirOperation other );
624627
628+ /// Compute a hash for the given operation.
629+ MLIR_CAPI_EXPORTED size_t mlirOperationHashValue (MlirOperation op );
630+
625631/// Gets the context this operation is associated with
626632MLIR_CAPI_EXPORTED MlirContext mlirOperationGetContext (MlirOperation op );
627633
Original file line number Diff line number Diff line change @@ -3317,7 +3317,9 @@ void mlir::python::populateIRCore(nb::module_ &m) {
33173317 [](PyModule &self, PyModule &other) {
33183318 return mlirModuleEqual (self.get (), other.get ());
33193319 },
3320- " other" _a);
3320+ " other" _a)
3321+ .def (" __hash__" ,
3322+ [](PyModule &self) { return mlirModuleHashValue (self.get ()); });
33213323
33223324 // ----------------------------------------------------------------------------
33233325 // Mapping of Operation.
@@ -3336,7 +3338,7 @@ void mlir::python::populateIRCore(nb::module_ &m) {
33363338 [](PyOperationBase &self, nb::object other) { return false ; })
33373339 .def (" __hash__" ,
33383340 [](PyOperationBase &self) {
3339- return static_cast < size_t >( llvm::hash_value (& self.getOperation ()));
3341+ return mlirOperationHashValue ( self.getOperation (). get ( ));
33403342 })
33413343 .def_prop_ro (" attributes" ,
33423344 [](PyOperationBase &self) {
Original file line number Diff line number Diff line change @@ -469,6 +469,10 @@ bool mlirModuleEqual(MlirModule lhs, MlirModule rhs) {
469469 return unwrap (lhs) == unwrap (rhs);
470470}
471471
472+ size_t mlirModuleHashValue (MlirModule mod) {
473+ return OperationEquivalence::computeHash (unwrap (mod).getOperation ());
474+ }
475+
472476// ===----------------------------------------------------------------------===//
473477// Operation state API.
474478// ===----------------------------------------------------------------------===//
@@ -640,6 +644,10 @@ bool mlirOperationEqual(MlirOperation op, MlirOperation other) {
640644 return unwrap (op) == unwrap (other);
641645}
642646
647+ size_t mlirOperationHashValue (MlirOperation op) {
648+ return OperationEquivalence::computeHash (unwrap (op));
649+ }
650+
643651MlirContext mlirOperationGetContext (MlirOperation op) {
644652 return wrap (unwrap (op)->getContext ());
645653}
You can’t perform that action at this time.
0 commit comments