Skip to content

[mlir] Add Python bindings to enable default passmanager timing #149087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2025

Conversation

maerhart
Copy link
Member

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Jul 16, 2025

@llvm/pr-subscribers-mlir

Author: Martin Erhart (maerhart)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/149087.diff

3 Files Affected:

  • (modified) mlir/include/mlir-c/Pass.h (+4)
  • (modified) mlir/lib/Bindings/Python/Pass.cpp (+6)
  • (modified) mlir/lib/CAPI/IR/Pass.cpp (+4)
diff --git a/mlir/include/mlir-c/Pass.h b/mlir/include/mlir-c/Pass.h
index 8fd8e9956a65a..0d2e19ee7fb0a 100644
--- a/mlir/include/mlir-c/Pass.h
+++ b/mlir/include/mlir-c/Pass.h
@@ -88,6 +88,10 @@ MLIR_CAPI_EXPORTED void mlirPassManagerEnableIRPrinting(
 MLIR_CAPI_EXPORTED void
 mlirPassManagerEnableVerifier(MlirPassManager passManager, bool enable);
 
+/// Enable pass timing.
+MLIR_CAPI_EXPORTED void
+mlirPassManagerEnableTiming(MlirPassManager passManager);
+
 /// Nest an OpPassManager under the top-level PassManager, the nested
 /// passmanager will only run on operations matching the provided name.
 /// The returned OpPassManager will be destroyed when the parent is destroyed.
diff --git a/mlir/lib/Bindings/Python/Pass.cpp b/mlir/lib/Bindings/Python/Pass.cpp
index 858c3bd5745fe..8d84864b9db4d 100644
--- a/mlir/lib/Bindings/Python/Pass.cpp
+++ b/mlir/lib/Bindings/Python/Pass.cpp
@@ -112,6 +112,12 @@ void mlir::python::populatePassManagerSubmodule(nb::module_ &m) {
             mlirPassManagerEnableVerifier(passManager.get(), enable);
           },
           "enable"_a, "Enable / disable verify-each.")
+      .def(
+          "enable_timing",
+          [](PyPassManager &passManager) {
+            mlirPassManagerEnableTiming(passManager.get());
+          },
+          "Enable pass timing.")
       .def_static(
           "parse",
           [](const std::string &pipeline, DefaultingPyMlirContext context) {
diff --git a/mlir/lib/CAPI/IR/Pass.cpp b/mlir/lib/CAPI/IR/Pass.cpp
index 883b7e8bb832d..3c499c3e4974d 100644
--- a/mlir/lib/CAPI/IR/Pass.cpp
+++ b/mlir/lib/CAPI/IR/Pass.cpp
@@ -75,6 +75,10 @@ void mlirPassManagerEnableVerifier(MlirPassManager passManager, bool enable) {
   unwrap(passManager)->enableVerifier(enable);
 }
 
+void mlirPassManagerEnableTiming(MlirPassManager passManager) {
+  unwrap(passManager)->enableTiming();
+}
+
 MlirOpPassManager mlirPassManagerGetNestedUnder(MlirPassManager passManager,
                                                 MlirStringRef operationName) {
   return wrap(&unwrap(passManager)->nest(unwrap(operationName)));

Copy link
Contributor

@makslevental makslevental left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have disable too? Or is that unneccessary for some reason that I can't think of right now?

@maerhart
Copy link
Member Author

Should we have disable too? Or is that unneccessary for some reason that I can't think of right now?

Enabling timing adds an instrumentation and AFAIK we don't even have a way to remove instrumentations in the C++ implementation of the passmanager, so it would be more than just a CAPI and Python bindings change.
Also, I never had the need to disable timing again after enabling it. Usually it's enough to just not enable it in the first place. However, if the need arises, we can always add it later on.

@maerhart maerhart merged commit 616e4c4 into main Jul 16, 2025
11 checks passed
@maerhart maerhart deleted the users/maerhart/mlir-passmanager-timing-python branch July 16, 2025 14:45
seldridge pushed a commit to llvm/circt that referenced this pull request Jul 16, 2025
Preparing this week's bump to get
* llvm/llvm-project#149087
* llvm/llvm-project#139694

Changes:
* Remove ambiguous builder in SV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants