This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo][InstrRef][NFC] Cache some PHI resolutions
ClosedPublic

Authored by jmorse on Jan 28 2022, 4:53 AM.

Details

Summary

Install a cache of DBG_INSTR_REF -> ValueIDNum resolutions, for scenarios where the value has to be reconstructed from several DBG_PHIs. Whenever this happens, it's because branch folding + tail duplication has messed with the SSA form of the program, and we have to solve a mini SSA problem to find the variable value. This is always called twice, so it makes sense to cache the value.

There's a secondary reason, which is that the resolveDbgPHIs function makes use of the per-register machine-value tables, potentially late in the LiveDebugValues process. Those are about to be freed earlier in the next patch I upload, so it's good to cache and avoid the second call to resolveDbgPHIs. There's also a compile time improvement for a few benchmarks [0]

[0] http://llvm-compile-time-tracker.com/compare.php?from=7dfb73512c6ba1eb720e6a0da954f262c6bb53fe&to=fd6b2a1e76dc22f808f031e4e50b27a851776e48&stat=instructions

Diff Detail

Event Timeline

jmorse created this revision.Jan 28 2022, 4:53 AM
jmorse requested review of this revision.Jan 28 2022, 4:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 28 2022, 4:53 AM
dblaikie added inline comments.
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
3455–3456

Given the need to touch every return from this function, and they're fairly spread out - might be good to refactor the non-cache-hit part of the function into another function, call that from the caching version and only have to have one SeenDbgPHIs.insert call that then ends up relatively close to the SeenDbgPHIs lookup code too?

(& I guess operations in this function invalidate the SeenDbgPHIs iterator, otherwise you could use that (possibly even call insert) later on to save the extra lookup)

Seems like a good change - the compile time improvement is nice, and this doesn't look like it should have a noticeable memory footprint. LGTM with the other comments addressed.

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
3455–3456

+1, better readability + prevents someone in the future from adding a new return without the cache insert.

llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.h
869

Nit.

jmorse added inline comments.Feb 2 2022, 3:09 AM
llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp
3455–3456

Clearly I was missing a lot of caffeine when writing this patch, this is definitely the right solution.

jmorse updated this revision to Diff 405199.Feb 2 2022, 3:41 AM

Shuffle PHI-resolution-caching into its own method.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 2 2022, 4:22 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.