This is an archive of the discontinued LLVM Phabricator instance.

[LiveDebugValues] Cache LexicalScopes::getMachineBasicBlocks, NFCI
ClosedPublic

Authored by vsk on Jun 1 2020, 2:41 PM.

Details

Summary

Cache the results from getMachineBasicBlocks in LexicalScopes to speed
up UserValueScopes::dominates queries. This replaces the caching done
in UserValueScopes. Compared to the old caching method, this reduces
memory traffic when a VarLoc is copied (e.g. when a VarLocMap grows),
and enables caching across basic blocks.

When compiling sqlite 3.5.7 (CTMark version), this patch reduces the
number of calls to getMachineBasicBlocks from 10,207 to 1,093. I also
measured a small compile-time reduction (~ 0.1% of total wall time, on
average, on my machine).

As a drive-by, I made the DebugLoc in UserValueScopes a const reference
to cut down on MetadataTracking traffic.

Diff Detail

Event Timeline

vsk created this revision.Jun 1 2020, 2:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2020, 2:41 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
Orlando added a comment.EditedJun 2 2020, 2:13 AM

This makes sense to me.

If you're going to subclass and are paying for the callback indirection in LexicalScopes now anyway, would it not make sense to make getMachineBasicBlocks virtual instead of using a callback? Seems like it could be simpler that way but I don't know if one way is better than the other, I'm just curious.

vsk added a comment.Jun 2 2020, 9:41 AM

This makes sense to me.

If you're going to subclass and are paying for the callback indirection in LexicalScopes now anyway, would it not make sense to make getMachineBasicBlocks virtual instead of using a callback? Seems like it could be simpler that way but I don't know if one way is better than the other, I'm just curious.

I think that could work, but I'm not sure it'd be cleaner, since there'd still be a need for some override of dominates() to pass a cached set into getMachineBasicBlocks.

Maybe a simpler approach would be to sink the cache into the LexicalScopes instance? I'll take a stab at this.

vsk edited the summary of this revision. (Show Details)Jun 2 2020, 9:41 AM
vsk updated this revision to Diff 267910.Jun 2 2020, 9:42 AM

Move the caching into LexicalScopes.

vsk updated this revision to Diff 267993.Jun 2 2020, 2:24 PM

Simplify further by deleting the UserValueScopes class, as it no longer holds on to anything interesting.

Orlando added inline comments.Jun 3 2020, 2:05 AM
llvm/lib/CodeGen/LexicalScopes.cpp
328

I'm not familiar with the extent of the usage of LexicalScopes throughout llvm, so I wonder if there's ever a case where we don't want the caching behaviour. i.e. is it conceivable that the result of dominates should change for the same inputs between calls?

Given this unfamiliarity I probably shouldn't be the one to give the final LGTM on this.

vsk marked an inline comment as done.Jun 3 2020, 9:52 AM
vsk added inline comments.
llvm/lib/CodeGen/LexicalScopes.cpp
328

LexicalScopes is used by LiveDebugValues and the debug info generators (it's referenced by DebugHandlerBase). A LexicalScopes instance can't be used to describe a changing MachineFunction, so the result of dominates can't change for the same inputs between calls. Also, the dominates method is currently only used by LiveDebugValues, where the caching seems to be useful.

aprantl accepted this revision.Jun 3 2020, 8:52 PM
This revision is now accepted and ready to land.Jun 3 2020, 8:52 PM
Orlando marked an inline comment as done.Jun 4 2020, 12:49 AM
Orlando added inline comments.
llvm/lib/CodeGen/LexicalScopes.cpp
328

That makes sense, thanks!

jmorse accepted this revision.Jun 4 2020, 2:34 AM

LGTM

This revision was automatically updated to reflect the committed changes.