Improve spill weight calculation
commit03b3923c5c7aafd2ff0bae4946ea5e9ba2c561e7
authorRick Lavoie <rlavoie@fb.com>
Thu, 12 Dec 2019 19:45:50 +0000 (12 11:45 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 12 Dec 2019 19:47:47 +0000 (12 11:47 -0800)
treef81fe88493e106043f7841813d74f0f760e878bd
parente5a60e84114f58b9d6cd1cb02878ef2b0a963797
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
hphp/runtime/vm/jit/vasm-graph-color.cpp