Better reffiness checks
commit412dce677f0a4b73194b8cdae3d3a3213a821047
authormwilliams <mwilliams@fb.com>
Fri, 7 Jun 2013 14:56:45 +0000 (7 07:56 -0700)
committersgolemon <sgolemon@hiphop-ubuntu-12.04-64>
Tue, 11 Jun 2013 18:48:25 +0000 (11 11:48 -0700)
treee98003af634c48714c71ef26a8d82ddc7e59d032
parent94ad2fd0ee2727c5fcb60bf7f34b817582edbd10
Better reffiness checks

While debugging a sandbox crash, I spent some time looking at a huge
sequnce of conditional masks, compares and branches that didnt seem
to belong in the code I was debugging. Finally realized that it was
a reffiness check. It looked way too complicated, so I investigated.

Part of the problem was that we were avoiding a malloc in the case
of a zero param function at the expense of an extra check.

Instead, this diff always sets up at least 64 bits worth of m_refBitVec.
But by using the space set aside for the pointer in Func::m_shared it
avoids a malloc for any function with fewer than 65 arguments, and
avoids the numParams check for the first 64 parameters.

In addition, the existing code was spitting out a generic test for
the guard condition - (mask & bits) == value - where mask and value
are known constants. Since the most common case is that value == 0
(all the parameters are expected to be by value), we can usually omit
the compare. In addition, since most functions only have a small
number of parameters, we can usually get away with 8 bit, or 32
bit operations.

The result is that for a typical function (fewer than 64 args, args
expected to be by value) the reffiness guard is now

  test <mask>, Func::m_refBitVec[0]
  jne exit

Rather than:

  move <mask>, reg1
  xor reg2, reg2
  cmp 1, Func::m_numParams
  jnl ok
  test AttrVarArgs, Func::m_attrs
  jne exit
  jmp done
ok:
  load reg3, Func::m_refBitVec[0]
  and mask, reg3
  cmp reg3, reg2
  jne exit
done:
hphp/doc/ir.specification
hphp/runtime/vm/func.cpp
hphp/runtime/vm/func.h
hphp/runtime/vm/jit/codegen.cpp
hphp/runtime/vm/jit/hhbctranslator.cpp
hphp/runtime/vm/jit/ir.h
hphp/runtime/vm/jit/translator-x64.cpp
hphp/test/quick/args-test.php [new file with mode: 0644]
hphp/test/quick/args-test.php.expect [new file with mode: 0644]
hphp/test/quick/va_poly.php
hphp/test/quick/va_poly.php.expect