Commit b2ceebbc authored by Hai Dang's avatar Hai Dang Committed by Commit Bot

Add helper class to share feedback slots.

The SharedFeedbackSlot helper class allow bytecodes to share one feedback
slot. The helper will only create the slot on-demand, at the first-use.
This does not encapsulate the use-case of FeedbackSlotCache.

Change-Id: I22aec19d59e52e7395898fa2a59c5c1ec95abbe8
Reviewed-on: https://chromium-review.googlesource.com/1189904
Commit-Queue: Hai Dang <dhai@google.com>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55452}
parent a4f5c696
......@@ -370,11 +370,14 @@ class V8_EXPORT_PRIVATE FeedbackVectorSpec {
: FeedbackSlotKind::kStoreGlobalSloppy);
}
FeedbackSlot AddKeyedStoreICSlot(LanguageMode language_mode) {
FeedbackSlotKind GetKeyedStoreICSlotKind(LanguageMode language_mode) {
STATIC_ASSERT(LanguageModeSize == 2);
return AddSlot(is_strict(language_mode)
? FeedbackSlotKind::kStoreKeyedStrict
: FeedbackSlotKind::kStoreKeyedSloppy);
return is_strict(language_mode) ? FeedbackSlotKind::kStoreKeyedStrict
: FeedbackSlotKind::kStoreKeyedSloppy;
}
FeedbackSlot AddKeyedStoreICSlot(LanguageMode language_mode) {
return AddSlot(GetKeyedStoreICSlotKind(language_mode));
}
FeedbackSlot AddStoreInArrayLiteralICSlot() {
......@@ -422,6 +425,26 @@ class V8_EXPORT_PRIVATE FeedbackVectorSpec {
}
ZoneVector<unsigned char> slot_kinds_;
friend class SharedFeedbackSlot;
};
// Helper class that creates a feedback slot on-demand.
class SharedFeedbackSlot {
public:
// FeedbackSlot default constructor constructs an invalid slot.
SharedFeedbackSlot(FeedbackVectorSpec* spec, FeedbackSlotKind kind)
: kind_(kind), spec_(spec) {}
FeedbackSlot Get() {
if (slot_.IsInvalid()) slot_ = spec_->AddSlot(kind_);
return slot_;
}
private:
FeedbackSlotKind kind_;
FeedbackSlot slot_;
FeedbackVectorSpec* spec_;
};
// FeedbackMetadata is an array-like object with a slot count (indicating how
......
......@@ -908,7 +908,7 @@ BytecodeGenerator::BytecodeGenerator(
execution_context_(nullptr),
execution_result_(nullptr),
incoming_new_target_or_generator_(),
dummy_feedback_slot_(),
dummy_feedback_slot_(feedback_spec(), FeedbackSlotKind::kCompareOp),
generator_jump_table_(nullptr),
suspend_count_(0),
loop_depth_(0),
......@@ -2378,20 +2378,20 @@ void BytecodeGenerator::BuildArrayLiteralElementsInsertion(
: elements->end();
// Evaluate subexpressions and store them into the array.
FeedbackSlot keyed_store_slot;
SharedFeedbackSlot keyed_store_slot(
feedback_spec(),
feedback_spec()->GetKeyedStoreICSlotKind(language_mode()));
for (; iter != first_spread_or_end; ++iter, array_index++) {
Expression* subexpr = *iter;
DCHECK(!subexpr->IsSpread());
if (skip_constants && subexpr->IsCompileTimeValue()) continue;
if (keyed_store_slot.IsInvalid()) {
keyed_store_slot = feedback_spec()->AddKeyedStoreICSlot(language_mode());
}
builder()
->LoadLiteral(Smi::FromInt(array_index))
.StoreAccumulatorInRegister(index);
VisitForAccumulatorValue(subexpr);
builder()->StoreKeyedProperty(
array, index, feedback_index(keyed_store_slot), language_mode());
array, index, feedback_index(keyed_store_slot.Get()), language_mode());
}
if (iter != elements->end()) {
builder()->LoadLiteral(array_index).StoreAccumulatorInRegister(index);
......@@ -5175,11 +5175,7 @@ FeedbackSlot BytecodeGenerator::GetCachedCreateClosureSlot(
}
FeedbackSlot BytecodeGenerator::GetDummyCompareICSlot() {
if (!dummy_feedback_slot_.IsInvalid()) {
return dummy_feedback_slot_;
}
dummy_feedback_slot_ = feedback_spec()->AddCompareICSlot();
return dummy_feedback_slot_;
return dummy_feedback_slot_.Get();
}
Runtime::FunctionId BytecodeGenerator::StoreToSuperRuntimeId() {
......
......@@ -6,6 +6,7 @@
#define V8_INTERPRETER_BYTECODE_GENERATOR_H_
#include "src/ast/ast.h"
#include "src/feedback-vector.h"
#include "src/interpreter/bytecode-array-builder.h"
#include "src/interpreter/bytecode-label.h"
#include "src/interpreter/bytecode-register.h"
......@@ -373,7 +374,7 @@ class BytecodeGenerator final : public AstVisitor<BytecodeGenerator> {
// Dummy feedback slot for compare operations, where we don't care about
// feedback
FeedbackSlot dummy_feedback_slot_;
SharedFeedbackSlot dummy_feedback_slot_;
BytecodeJumpTable* generator_jump_table_;
int suspend_count_;
......
......@@ -87,14 +87,14 @@ bytecodes: [
B(Star), R(1),
B(LdaZero),
B(Star), R(2),
B(CreateArrayLiteral), U8(1), U8(3), U8(37),
B(CreateArrayLiteral), U8(1), U8(1), U8(37),
B(Star), R(3),
B(LdaZero),
B(Star), R(4),
B(Ldar), R(0),
/* 56 E> */ B(StaKeyedProperty), R(3), R(4), U8(4),
/* 56 E> */ B(StaKeyedProperty), R(3), R(4), U8(2),
B(Ldar), R(3),
B(StaKeyedProperty), R(1), R(2), U8(1),
B(StaKeyedProperty), R(1), R(2), U8(4),
B(LdaSmi), I8(1),
B(Star), R(2),
B(CreateArrayLiteral), U8(2), U8(6), U8(37),
......@@ -102,10 +102,10 @@ bytecodes: [
B(LdaZero),
B(Star), R(4),
B(Ldar), R(0),
/* 68 E> */ B(AddSmi), I8(2), U8(9),
B(StaKeyedProperty), R(3), R(4), U8(7),
/* 68 E> */ B(AddSmi), I8(2), U8(7),
B(StaKeyedProperty), R(3), R(4), U8(8),
B(Ldar), R(3),
B(StaKeyedProperty), R(1), R(2), U8(1),
B(StaKeyedProperty), R(1), R(2), U8(4),
B(Ldar), R(1),
/* 76 S> */ B(Return),
]
......
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