This is an archive of the discontinued LLVM Phabricator instance.

[RegAlloc] Add a complexity limit in growRegion() to cap compilation time.
ClosedPublic

Authored by vporpo on Mar 1 2022, 10:25 AM.

Details

Summary

growRegion() does not scale in code with BBs with a very large number of edges.
In such code growRegion() becomes a compile-time bottleneck, consuming 60% of
the total compilation time.
This patch adds a limit to the complexity of growRegion() by incrementing a counter
in each iteration. We bail out once the limit is reached.

Diff Detail

Event Timeline

vporpo created this revision.Mar 1 2022, 10:25 AM
vporpo requested review of this revision.Mar 1 2022, 10:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2022, 10:25 AM
vporpo updated this revision to Diff 412558.Mar 2 2022, 3:22 PM

Improved the option's description.

Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 3:22 PM
mtrofin accepted this revision.Mar 3 2022, 10:11 AM
mtrofin added a subscriber: mtrofin.

Nit: can you please rephrase the commit message, last statement: the patch (correctly) doesn't place a limit on time (which would be non-deterministic), rather, it places a limit on the number of Blocks visited (deterministic).

The patch LGTM, but I'm curious, why do we end up with a bazillion edges, like what property do the blocks pointed at the edges have, like are they all going to an exit block, or in any case, is this a meaningful pattern - maybe we could avoid placement via the Hopfield Network, and instead do something simpler (and maybe it benefits the rest of the allocation)?

llvm/lib/CodeGen/RegAllocGreedy.cpp
793

You could just take Visited out of its conditional compilation block and compare it to GrowRegionComplexityBudget. I realize Visited is incremented less often than Budget is currently decremented, but it does achieve the same goal?

This revision is now accepted and ready to land.Mar 3 2022, 10:11 AM
vporpo added inline comments.Mar 3 2022, 10:26 AM
llvm/lib/CodeGen/RegAllocGreedy.cpp
793

Yes, it would be similar I guess, but I think it is probably best to keep the counters separate as their purpose is different.

vporpo edited the summary of this revision. (Show Details)Mar 3 2022, 10:27 AM
This revision was landed with ongoing or failed builds.Mar 3 2022, 11:34 AM
This revision was automatically updated to reflect the committed changes.