This is an archive of the discontinued LLVM Phabricator instance.

[DebugInfo][InstrRef] Avoid un-necessary densemap copies and comparisons
ClosedPublic

Authored by jmorse on Oct 13 2021, 7:41 AM.

Details

Summary

This is a plain and simple performance patch: InstrRefBasedLDV passes uses three distinct DenseMaps when calculating what variable values are in a block: two "long term" dense maps, and one "working" dense map. The live-ins are:

  • Placed into the working set, as vlocJoin works out what each variables value should be,
  • Copied into the "long term" live-in storage back in buildVLocValueMap,
  • The working set has its values updated by the blocks transfer function,
  • The working set is copied into the blocks live-out DenseMap.

This works well enough, but it involves two dense map comparisons and two dense map assignments, when each of the live-in / live-out dense maps are updated. For scopes with a small number of variables, this can take a large amount of time, seeing how (I think?) the initial DenseMap allocation is 64 elements. We could pay with SmallDenseMaps, however instead, lets just reduce the total number of densemaps. We can update live-ins and live-outs in-place, as appropriate, avoiding the comparisons and copies.

Practically, this means passing fewer bits of information around. Every time we make an assignment to a live-in or live-out because vlocJoin (or the transfer function) has changed it, we have to do an explicit comparison to see whether we're changing the value. Otherwise, everything works as before.

This claws back another slice of performance: http://llvm-compile-time-tracker.com/compare.php?from=bc07cf76a31fa769786d6631fe25586bd1396c34&to=231cbb7cbd13e01cf81fa97db441582af2efbbb7&stat=instructions

Diff Detail

Event Timeline

jmorse created this revision.Oct 13 2021, 7:41 AM
jmorse requested review of this revision.Oct 13 2021, 7:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 13 2021, 7:41 AM
Orlando accepted this revision.Oct 13 2021, 8:50 AM

Nice, LGTM. Might be worth adding NFC to the patch title?

This revision is now accepted and ready to land.Oct 13 2021, 8:50 AM
This revision was landed with ongoing or failed builds.Oct 19 2021, 3:10 AM
This revision was automatically updated to reflect the committed changes.