Skip to content

Conversation

@Xubaidu
Copy link

@Xubaidu Xubaidu commented Nov 26, 2025

This PR tries to close [MLIR][Timing] Nested pipeline is displayed at top level and show negative Rest field when using -mlir-timing

Here is the timing report of the inliner pass w/o and w/ this change:

# w/o this change
build/bin/mlir-opt -inline mlir/test/Transforms/inlining-repeated-use.mlir -mlir-timing -o 1.txt
===-------------------------------------------------------------------------===
                         ... Execution time report ...
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0009 seconds

  ----Wall Time----  ----Name----
    0.0003 ( 40.1%)  Parser
    0.0003 ( 37.5%)  Inliner
    0.0000 (  1.3%)    (A) CallGraph
    0.0001 (  7.9%)  'func.func' Pipeline
    0.0001 (  7.7%)    Canonicalizer
    0.0002 ( 19.9%)  Output
   -0.0000 ( -5.5%)  Rest
    0.0009 (100.0%)  Total

# w/ this change
build/bin/mlir-opt -inline mlir/test/Transforms/inlining-repeated-use.mlir -mlir-timing -o 1.txt
===-------------------------------------------------------------------------===
                         ... Execution time report ...
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0007 seconds

  ----Wall Time----  ----Name----
    0.0003 ( 46.5%)  Parser
    0.0003 ( 37.1%)  Inliner
    0.0000 (  1.1%)    (A) CallGraph
    0.0001 (  7.7%)    'func.func' Pipeline
    0.0001 (  7.4%)      Canonicalizer
    0.0001 ( 12.2%)  Output
    0.0000 (  4.2%)  Rest
    0.0007 (100.0%)  Total

Also take mlir/test/Pass/dynamic-pipeline-nested.mlir as an example:

# w/o this change
build/install/bin/mlir-opt mlir/test/Pass/dynamic-pipeline-nested.mlir -pass-pipeline='builtin.module(builtin.module(test-dynamic-pipeline{op-name=inner_mod1 dynamic-pipeline=cse}),inline)'  --mlir-disable-threading -mlir-timing > /dev/null
Dynamic execute 'cse' on builtin.module
===-------------------------------------------------------------------------===
                         ... Execution time report ...
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0005 seconds

  ----Wall Time----  ----Name----
    0.0003 ( 58.3%)  Parser
    0.0000 (  4.7%)  'builtin.module' Pipeline
    0.0000 (  4.6%)    TestDynamicPipelinePass
    0.0000 (  1.6%)  'builtin.module' Pipeline
    0.0000 (  1.5%)    CSE
    0.0000 (  0.1%)      (A) DominanceInfo
    0.0001 ( 22.7%)  Inliner
    0.0000 (  1.3%)    (A) CallGraph
    0.0000 (  3.5%)  'func.func' Pipeline
    0.0000 (  3.3%)    Canonicalizer
    0.0000 (  6.6%)  Output
    0.0000 (  1.9%)  Rest
    0.0005 (100.0%)  Total

# w/ this change
Dynamic execute 'cse' on builtin.module
===-------------------------------------------------------------------------===
                         ... Execution time report ...
===-------------------------------------------------------------------------===
  Total Execution Time: 0.0023 seconds

  ----Wall Time----  ----Name----
    0.0017 ( 71.5%)  Parser
    0.0001 (  2.6%)  'builtin.module' Pipeline
    0.0001 (  2.6%)    (anonymous namespace)::TestDynamicPipelinePass
    0.0000 (  1.5%)      'builtin.module' Pipeline
    0.0000 (  1.5%)        CSE
    0.0000 (  0.0%)          (A) DominanceInfo
    0.0003 ( 14.9%)  Inliner
    0.0000 (  1.0%)    (A) CallGraph
    0.0001 (  3.2%)    'func.func' Pipeline
    0.0001 (  3.2%)      Canonicalizer
    0.0001 (  4.8%)  Output
    0.0001 (  5.6%)  Rest
    0.0023 (100.0%)  Total

@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added mlir:core MLIR Core Infrastructure mlir labels Nov 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 26, 2025

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-core

Author: ChenyangXu (Xubaidu)

Changes

This PR tries to close [MLIR][Timing] Nested pipeline is displayed at top level and show negative Rest field when using -mlir-timing


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

1 Files Affected:

  • (modified) mlir/lib/Pass/PassTiming.cpp (+5-2)
diff --git a/mlir/lib/Pass/PassTiming.cpp b/mlir/lib/Pass/PassTiming.cpp
index dab56f09a72eb..8b78a99069cc9 100644
--- a/mlir/lib/Pass/PassTiming.cpp
+++ b/mlir/lib/Pass/PassTiming.cpp
@@ -90,6 +90,9 @@ struct PassTiming : public PassInstrumentation {
     auto &activeTimers = activeThreadTimers[tid];
     auto &parentScope = activeTimers.empty() ? rootScope : activeTimers.back();
 
+    // Record the parent information for this pass so nested pipelines can find it,
+    // regardless of whether this is an adaptor pass or a regular pass.
+    parentTimerIndices[{tid, pass}] = activeTimers.size();
     if (auto *adaptor = dyn_cast<OpToOpPassAdaptor>(pass)) {
       parentTimerIndices[{tid, pass}] = activeTimers.size();
       auto scope =
@@ -107,8 +110,8 @@ struct PassTiming : public PassInstrumentation {
 
   void runAfterPass(Pass *pass, Operation *) override {
     auto tid = llvm::get_threadid();
-    if (isa<OpToOpPassAdaptor>(pass))
-      parentTimerIndices.erase({tid, pass});
+    // Erase the parent index mapping for this pass (adaptor or not).
+    parentTimerIndices.erase({tid, pass});
     auto &activeTimers = activeThreadTimers[tid];
     assert(!activeTimers.empty() && "expected active timer");
     activeTimers.pop_back();

@Xubaidu Xubaidu changed the title [MLIR][Timing] Fix timing report of nested pass pipeline and negative Rest field when using -mlir-timing Resolve #169443: [MLIR][Timing] Fix timing report of nested pass pipeline and negative Rest field when using -mlir-timing Nov 26, 2025
@Xubaidu Xubaidu changed the title Resolve #169443: [MLIR][Timing] Fix timing report of nested pass pipeline and negative Rest field when using -mlir-timing [MLIR][Timing] Fix timing report of nested pass pipeline and negative Rest field when using -mlir-timing (Try to resolve #169443) Nov 26, 2025
@Xubaidu Xubaidu changed the title [MLIR][Timing] Fix timing report of nested pass pipeline and negative Rest field when using -mlir-timing (Try to resolve #169443) [MLIR][Timing] Fix timing report of nested pass pipeline and negative Rest field when using -mlir-timing (Try to close #169443) Nov 26, 2025
// regardless of whether this is an adaptor pass or a regular pass.
parentTimerIndices[{tid, pass}] = activeTimers.size();
if (auto *adaptor = dyn_cast<OpToOpPassAdaptor>(pass)) {
parentTimerIndices[{tid, pass}] = activeTimers.size();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this line redundant now?

Copy link
Author

Choose a reason for hiding this comment

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

Removed the redundant code now. Please take a look again.

Copy link
Collaborator

@joker-eph joker-eph left a comment

Choose a reason for hiding this comment

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

That seems fine, how could this be tested though?

@github-actions
Copy link

github-actions bot commented Nov 26, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@Xubaidu Xubaidu closed this Nov 27, 2025
@Xubaidu Xubaidu reopened this Nov 27, 2025
@Xubaidu
Copy link
Author

Xubaidu commented Nov 27, 2025

That seems fine, how could this be tested though?

@joker-eph I added two tests in the test file but I am not sure if they are sufficient. Would you mind adding more reviewers of dynamic pass pipeline and MLIR core to review it?

// DYNAMIC-PIPELINE-NEXT: Canonicalizer
// DYNAMIC-PIPELINE-NEXT: Output
// DYNAMIC-PIPELINE-NEXT: Rest
// DYNAMIC-PIPELINE-NEXT: Total
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is passing at HEAD apparently, so may not be testing what you think it is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:core MLIR Core Infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MLIR][Timing] Nested pipeline is displayed at top level and show negative Rest field when using -mlir-timing

3 participants