Skip to content

Conversation

@alanzhao1
Copy link
Contributor

After #131217 was submitted, time-passes.ll fails because opt prints -time-report when ManagedTimerGlobals is destroyed. ManagedTimerGlobals stores TimerGroups in an unordered map, so the ordering of the output TimerGroups depends on the underlying iterator.

To fix this, we do what Clang does and use
llvm::TimerGroup::printAll(...), which is deterministic. This is also what Clang does. This does put move analysis section before the pass section for -time-report, but again, this is also what Clang currently does.

After llvm#131217 was submitted,
time-passes.ll fails because `opt` prints `-time-report` when
`ManagedTimerGlobals` is destroyed. `ManagedTimerGlobals` stores
`TimerGroup`s in an unordered map, so the ordering of the output
`TimerGroup`s depends on the underlying iterator.

To fix this, we do what Clang does and use
`llvm::TimerGroup::printAll(...)`, which *is* deterministic. This is
also what Clang does. This does put move analysis section before the
pass section for `-time-report`, but again, this is also what Clang
currently does.
@alanzhao1 alanzhao1 requested a review from aeubanks March 19, 2025 00:08
Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

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

the fact that we have to duplicate printAll/clearAll in multiple places suggests that we should just make ManagedTimerGlobals deterministically destruct its timers. can we do that? somehow sort by name before destructing?

@alanzhao1
Copy link
Contributor Author

the fact that we have to duplicate printAll/clearAll in multiple places suggests that we should just make ManagedTimerGlobals deterministically destruct its timers. can we do that? somehow sort by name before destructing?

This is doable, but I'm not a huge fan of the print metrics on object destruction pattern as it ends up being a painful exercise in object lifetime management rather than something that improves code quality. This is even worse given that this is a global.

Copy link
Contributor

@aeubanks aeubanks left a comment

Choose a reason for hiding this comment

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

sgtm with nits

@alanzhao1 alanzhao1 merged commit 50ea777 into llvm:main Mar 27, 2025
5 of 9 checks passed
@alanzhao1 alanzhao1 deleted the bugfix/opt-timer-order branch March 27, 2025 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants