Improve spill weight calculation
Summary:
Calculating spill weights consumes a significant portion of
vasm-graph-color's runtime. Right now, the spill weight calculation
keeps a set of "interesting" Vregs, which it adds to when it finds a
copy (and removes when it finds a use). However, after thinking about
this, I realized this is actually unnecessary. When you encounter a
copy, there's two possibilities. Either the src Vreg is not live after
the copy, in which case there's no point in keeping it in the
interesting set because it's dead. Or, the src Vreg is live after the
copy. However in that case we want to treat like a use because we'll
most likely emit a reload for that copy (to avoid an expensive memory
to memory copy). So, we never want to track both the src and the dest
at the same time. This means the interesting set is really only a
single Vreg. Rewrite the logic to track a single Vreg instead of a
whole set. This simplifies quite a number of things, since it means we
can return immediately when we find a use, instead of updating the
current weight.
The spill weight calculation was also trying to avoid recursion in the
common case where there's a single successor. Now that the rest has
been simplified, this is more trouble than it's worth. Surprisingly,
it turns out to be faster to just tail call the function recursively
on the successor. This again simplifies more logic.
Reviewed By: mofarrell
Differential Revision:
D18873701
fbshipit-source-id:
4929d96c4f04bdb72db39289b3ab5639e2d123c3