Commit 0aa15e94 authored by Nathan Bronson's avatar Nathan Bronson Committed by Facebook Github Bot

mark uses of folly::assume used to optimize placement new

Summary:
F14 currently has numerous places where folly::assume is used to
help optimization on GCC < 6.  These are all things the optimizer should
be able to deduce itself, so it would be nice to eventually remove them.
This diff marks them with TODO(T31574848), as well as removing two
occurrences in F14Table that duplicated an assume in F14Policy.

Reviewed By: yfeldblum

Differential Revision: D8849832

fbshipit-source-id: e88143b4d29f1a633b51467206c6fb6afd1cd296
parent 001320e2
......@@ -529,9 +529,13 @@ class ValueContainerPolicy : public BasePolicy<
void
constructValueAtItem(std::size_t /*size*/, Item* itemAddr, Args&&... args) {
Alloc& a = this->alloc();
// This assume helps GCC and MSVC avoid a null-check in the subsequent
// placement new. GCC >= 6 and clang seem to figure it out themselves.
// MSVC as of 19 2017 still has the issue.
// GCC < 6 doesn't use the fact that itemAddr came from a reference
// to avoid a null-check in the placement new. folly::assume-ing it
// here gets rid of that branch. The branch is very predictable,
// but spoils some further optimizations. All clang versions that
// compile folly seem to be okay.
//
// TODO(T31574848): clean up assume-s used to optimize placement new
assume(itemAddr != nullptr);
AllocTraits::construct(a, itemAddr, std::forward<Args>(args)...);
}
......@@ -772,9 +776,11 @@ class NodeContainerPolicy
void
constructValueAtItem(std::size_t /*size*/, Item* itemAddr, Args&&... args) {
Alloc& a = this->alloc();
// TODO(T31574848): clean up assume-s used to optimize placement new
assume(itemAddr != nullptr);
new (itemAddr) Item{AllocTraits::allocate(a, 1)};
auto p = std::addressof(**itemAddr);
// TODO(T31574848): clean up assume-s used to optimize placement new
assume(p != nullptr);
AllocTraits::construct(a, p, std::forward<Args>(args)...);
}
......@@ -782,6 +788,7 @@ class NodeContainerPolicy
void moveItemDuringRehash(Item* itemAddr, Item& src) {
// This is basically *itemAddr = src; src = nullptr, but allowing
// for fancy pointers.
// TODO(T31574848): clean up assume-s used to optimize placement new
assume(itemAddr != nullptr);
new (itemAddr) Item{std::move(src)};
src = nullptr;
......@@ -1110,6 +1117,7 @@ class VectorContainerPolicy : public BasePolicy<
Alloc& a = this->alloc();
*itemAddr = size;
auto dst = std::addressof(values_[size]);
// TODO(T31574848): clean up assume-s used to optimize placement new
assume(dst != nullptr);
AllocTraits::construct(a, dst, std::forward<Args>(args)...);
}
......@@ -1142,6 +1150,7 @@ class VectorContainerPolicy : public BasePolicy<
std::memcpy(dst, src, n * sizeof(Value));
} else {
for (std::size_t i = 0; i < n; ++i, ++src, ++dst) {
// TODO(T31574848): clean up assume-s used to optimize placement new
assume(dst != nullptr);
AllocTraits::construct(a, dst, Super::moveValue(*src));
if (kIsMap) {
......@@ -1167,6 +1176,7 @@ class VectorContainerPolicy : public BasePolicy<
} else {
for (std::size_t i = 0; i < size; ++i, ++src, ++dst) {
try {
// TODO(T31574848): clean up assume-s used to optimize placement new
assume(dst != nullptr);
AllocTraits::construct(a, dst, constructorArgFor(*src));
} catch (...) {
......
......@@ -1526,7 +1526,6 @@ class F14Table : public Policy {
void insertAtBlank(ItemIter pos, HashPair hp, Args&&... args) {
try {
auto dst = pos.itemAddr();
assume(dst != nullptr);
this->constructValueAtItem(size(), dst, std::forward<Args>(args)...);
} catch (...) {
eraseBlank(pos, hp);
......@@ -1628,7 +1627,6 @@ class F14Table : public Policy {
auto&& srcArg =
std::forward<T>(src).buildArgForItem(srcChunk->item(srcI));
auto dst = dstChunk->itemAddr(dstI);
assume(dst != nullptr);
this->constructValueAtItem(
0, dst, std::forward<decltype(srcArg)>(srcArg));
dstChunk->setTag(dstI, srcChunk->tag(srcI));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment