This is an archive of the discontinued LLVM Phabricator instance.

[LegacyPM] Update InversedLastUser on the fly. NFC.
ClosedPublic

Authored by foad on Nov 30 2020, 3:49 AM.

Details

Summary

This speeds up setLastUser enough to give a 5% to 10% speed up on
trivial invocations of opt and llc, as measured by:

perf stat -r 100 opt -S -o /dev/null -O3 /dev/null
perf stat -r 100 llc -march=amdgcn /dev/null -filetype null

Don't dump last use information unless -debug-pass=Details to avoid
printing lots of spam that will break some existing lit tests. Before
this patch, dumping last use information was broken anyway, because it
used InversedLastUser before it had been populated.

Diff Detail

Event Timeline

foad created this revision.Nov 30 2020, 3:49 AM
foad requested review of this revision.Nov 30 2020, 3:49 AM

As the state of LastUser are closely tied, it would make sense to encapsulate the two members in a class that would maintain the consistency of these two states, so that the two new operations recordNewUser(Pass, User) and updatelastUser(Pass, User) become explicit ?

foad added a comment.Nov 30 2020, 6:10 AM

As the state of LastUser are closely tied, it would make sense to encapsulate the two members in a class that would maintain the consistency of these two states, so that the two new operations recordNewUser(Pass, User) and updatelastUser(Pass, User) become explicit ?

I think the best way to do that would be using a generic bidirectional map like https://theboostcpplibraries.com/boost.bimap. But there is no bimap in include/llvm/ADT/ yet and I'm not sure my C++ is good enough to write it myself.

foad added a reviewer: bjope.Jan 12 2021, 9:10 AM
bjope added inline comments.Jan 20 2021, 2:11 AM
llvm/include/llvm/IR/LegacyPassManagers.h
234

I suggest adding a comment here that the intention is to always keep InversedLastUser in sync with this map.

238

As above, I suggest adding a comment here that this map should be updated whenever LastUser is updated to keep them in sync.

foad updated this revision to Diff 317835.Jan 20 2021, 4:29 AM

Rebase. Add comments.

bjope accepted this revision.Jan 20 2021, 4:59 AM
This revision is now accepted and ready to land.Jan 20 2021, 4:59 AM
foad added a comment.Jan 20 2021, 6:16 AM

LGTM

Thanks. This patch depends on D92308. Without D92308, this patch would add lots of extra lines to the output of opt -debug-pass=Structure, which breaks various tests in test/CodeGen and test/Other.

bjope added a comment.Jan 20 2021, 6:49 AM

LGTM

Thanks. This patch depends on D92308. Without D92308, this patch would add lots of extra lines to the output of opt -debug-pass=Structure, which breaks various tests in test/CodeGen and test/Other.

Maybe an alternative to D92308 would be to bail out from dumpLastUses if (PassDebugging < Details). I.e. to limit the dumping of last uses to -debug-pass=Details.
I do not think it is that harmful to get more printouts when using Details level for debug-pass. And this way one can get the detailed information when debugging the pass manager on detailed level, while not impacting tests using -debug-pass=Structure etc.

(if that sounds good, then I guess you can even squeeze that into this revision)

foad updated this revision to Diff 317888.Jan 20 2021, 8:25 AM

Don't dump last uses unless -debug-pass=Details.

foad edited the summary of this revision. (Show Details)Jan 20 2021, 8:26 AM

LGTM

Thanks. This patch depends on D92308. Without D92308, this patch would add lots of extra lines to the output of opt -debug-pass=Structure, which breaks various tests in test/CodeGen and test/Other.

Maybe an alternative to D92308 would be to bail out from dumpLastUses if (PassDebugging < Details). I.e. to limit the dumping of last uses to -debug-pass=Details.
I do not think it is that harmful to get more printouts when using Details level for debug-pass. And this way one can get the detailed information when debugging the pass manager on detailed level, while not impacting tests using -debug-pass=Structure etc.

(if that sounds good, then I guess you can even squeeze that into this revision)

Good idea!

bjope added a comment.Jan 21 2021, 9:33 AM

Still LGTM

This revision was landed with ongoing or failed builds.Jan 22 2021, 1:49 AM
This revision was automatically updated to reflect the committed changes.