Move optimization for member op values
commit7129a3732886a5657d9e0a1e7b8904871b8e1ca4
authorShaunak Kishore <kshaunak@fb.com>
Mon, 25 Nov 2019 19:23:31 +0000 (25 11:23 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 27 Nov 2019 11:38:52 +0000 (27 03:38 -0800)
tree757c610813aeddf859321e6cbdda5171db4507dc
parent2a87012243caf447bf6832737714ba983d2a2f0e
Move optimization for member op values

Summary:
When setting an element in an array, we call a native helper (that inc-refs the value) and then usually dec-ref the result (because the assignment result doesn't get used). We can avoid these two refcounting ops by creating a new helper that moves the value in place.

The new setMove operator on arrays has the following semantics (but for most array types, is implemented in a better way):
- Execute the normal set(k, v) operation
- Dec-ref the value v
- If the array was copied or escalated, def-ref the old array

These ops are guaranteed not to destroy the value. In irgen, we emit an inc-ref of the value after using this operation. If it's followed by a dec-ref, refcount-ops easily annihilates the two. We also have to modify consumesReference to tell refcount-opts about what's going on with these values.

This diff is a win on its own, but it should be even better with Michael's work to use specific ArraySet / DictSet ops instead of generic SetElems and to avoid the vtable dispatch. Since the new helper is a single virtual method on ArrayData, if we know the kind, we can call it directly.

Reviewed By: mofarrell

Differential Revision: D18629174

fbshipit-source-id: 1e14bd13a7b0a70a17a39c86135f24ca291ccc32
21 files changed:
hphp/doc/ir.specification
hphp/runtime/base/apc-local-array.cpp
hphp/runtime/base/apc-local-array.h
hphp/runtime/base/array-data-defs.h
hphp/runtime/base/array-data.cpp
hphp/runtime/base/array-data.h
hphp/runtime/base/array-helpers.h
hphp/runtime/base/empty-array.cpp
hphp/runtime/base/empty-array.h
hphp/runtime/base/mixed-array.cpp
hphp/runtime/base/mixed-array.h
hphp/runtime/base/packed-array.cpp
hphp/runtime/base/packed-array.h
hphp/runtime/base/record-array.cpp
hphp/runtime/base/record-array.h
hphp/runtime/base/set-array.h
hphp/runtime/vm/globals-array.cpp
hphp/runtime/vm/globals-array.h
hphp/runtime/vm/jit/ir-instruction.cpp
hphp/runtime/vm/jit/irgen-minstr.cpp
hphp/runtime/vm/jit/minstr-helpers.h