From 9b913366d4eeb32a498484c29710aeae2bdd970b Mon Sep 17 00:00:00 2001 From: Clemens Backes Date: Wed, 20 Jul 2022 10:54:35 +0200 Subject: [PATCH] [liftoff] Mark tagged safepoint slots in reversed order Setting the highest bit first saves cost for repeatedly growing the underlying bitvector. R=jkummerow@chromium.org Bug: v8:13063 Change-Id: Ic324caa20c91dd6f55760944c3dafe7f1dc018b4 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3776340 Commit-Queue: Clemens Backes Reviewed-by: Jakob Kummerow Cr-Commit-Position: refs/heads/main@{#81849} --- src/base/small-vector.h | 6 ++++++ src/wasm/baseline/liftoff-assembler.cc | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/base/small-vector.h b/src/base/small-vector.h index 0591b2a2f2..dc24af3286 100644 --- a/src/base/small-vector.h +++ b/src/base/small-vector.h @@ -100,6 +100,12 @@ class SmallVector { T* end() { return end_; } const T* end() const { return end_; } + auto rbegin() { return std::reverse_iterator{end_}; } + auto rbegin() const { return std::reverse_iterator{end_}; } + + auto rend() { return std::reverse_iterator{begin_}; } + auto rend() const { return std::reverse_iterator{begin_}; } + size_t size() const { return end_ - begin_; } bool empty() const { return end_ == begin_; } size_t capacity() const { return end_of_storage_ - begin_; } diff --git a/src/wasm/baseline/liftoff-assembler.cc b/src/wasm/baseline/liftoff-assembler.cc index c1a3ed8243..9bcff7a180 100644 --- a/src/wasm/baseline/liftoff-assembler.cc +++ b/src/wasm/baseline/liftoff-assembler.cc @@ -569,7 +569,9 @@ void LiftoffAssembler::CacheState::GetTaggedSlotsForOOLCode( void LiftoffAssembler::CacheState::DefineSafepoint( SafepointTableBuilder::Safepoint& safepoint) { - for (const auto& slot : stack_state) { + // Go in reversed order to set the higher bits first; this avoids cost for + // growing the underlying bitvector. + for (const auto& slot : base::Reversed(stack_state)) { if (is_reference(slot.kind())) { DCHECK(slot.is_stack()); safepoint.DefineTaggedStackSlot(GetSafepointIndexForStackSlot(slot));