Commit b73d9414 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[turbofan] Refactor ReduceKeyedAccess for readability

...by moving a special case into a separate method.

Change-Id: I880768ed6fbb7d29b94588435c9da65b01f07fde
Reviewed-on: https://chromium-review.googlesource.com/c/1462960
Commit-Queue: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59555}
parent 793f025b
......@@ -1693,26 +1693,24 @@ Reduction JSNativeContextSpecialization::ReduceElementAccess(
return Replace(value);
}
Reduction JSNativeContextSpecialization::ReduceKeyedAccess(
Node* node, Node* index, Node* value, FeedbackNexus const& nexus,
AccessMode access_mode, KeyedAccessLoadMode load_mode,
KeyedAccessStoreMode store_mode) {
DCHECK(node->opcode() == IrOpcode::kJSLoadProperty ||
node->opcode() == IrOpcode::kJSStoreProperty);
Reduction JSNativeContextSpecialization::ReduceKeyedLoadFromHeapConstant(
Node* node, Node* index, FeedbackNexus const& nexus,
KeyedAccessLoadMode load_mode) {
DCHECK_EQ(node->opcode(), IrOpcode::kJSLoadProperty);
Node* receiver = NodeProperties::GetValueInput(node, 0);
Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node);
// Optimize the case where we load from a constant {receiver}.
if (access_mode == AccessMode::kLoad) {
HeapObjectMatcher mreceiver(receiver);
if (mreceiver.HasValue()) {
HeapObjectRef receiver_ref = mreceiver.Ref(broker()).AsHeapObject();
if (receiver_ref.map().oddball_type() != OddballType::kHole &&
receiver_ref.map().oddball_type() != OddballType::kNull &&
receiver_ref.map().oddball_type() != OddballType::kUndefined) {
if (receiver_ref.map().oddball_type() == OddballType::kHole ||
receiver_ref.map().oddball_type() == OddballType::kNull ||
receiver_ref.map().oddball_type() == OddballType::kUndefined) {
return NoChange();
}
// Check whether we're accessing a known element on the {receiver}
// that is non-configurable, non-writable (i.e. the {receiver} was
// that is non-configurable, non-writable (e.g. the {receiver} was
// frozen using Object.freeze).
NumberMatcher mindex(index);
if (mindex.IsInteger() && mindex.IsInRange(0.0, kMaxUInt32 - 1.0)) {
......@@ -1724,7 +1722,7 @@ Reduction JSNativeContextSpecialization::ReduceKeyedAccess(
// We can safely constant-fold the {index} access to {receiver},
// since the element is non-configurable, non-writable and thus
// cannot change anymore.
value = jsgraph()->Constant(it.GetDataValue());
Node* value = jsgraph()->Constant(it.GetDataValue());
ReplaceWithValue(node, value, effect, control);
return Replace(value);
}
......@@ -1742,20 +1740,18 @@ Reduction JSNativeContextSpecialization::ReduceKeyedAccess(
if (receiver_ref.IsJSArray()) {
Handle<JSArray> array = receiver_ref.AsJSArray().object();
if (array->elements()->IsCowArray()) {
Node* elements = effect =
graph()->NewNode(simplified()->LoadField(
AccessBuilder::ForJSObjectElements()),
Node* elements = effect = graph()->NewNode(
simplified()->LoadField(AccessBuilder::ForJSObjectElements()),
receiver, effect, control);
Handle<FixedArray> array_elements(
FixedArray::cast(array->elements()), isolate());
Handle<FixedArray> array_elements(FixedArray::cast(array->elements()),
isolate());
Node* check =
graph()->NewNode(simplified()->ReferenceEqual(), elements,
jsgraph()->HeapConstant(array_elements));
effect = graph()->NewNode(
simplified()->CheckIf(
DeoptimizeReason::kCowArrayElementsChanged),
simplified()->CheckIf(DeoptimizeReason::kCowArrayElementsChanged),
check, effect, control);
value = jsgraph()->Constant(it.GetDataValue());
Node* value = jsgraph()->Constant(it.GetDataValue());
ReplaceWithValue(node, value, effect, control);
return Replace(value);
}
......@@ -1769,23 +1765,37 @@ Reduction JSNativeContextSpecialization::ReduceKeyedAccess(
// We can only assume that the {index} is a valid array index if the
// IC is in element access mode and not MEGAMORPHIC, otherwise there's
// no guard for the bounds check below.
if (nexus.ic_state() != MEGAMORPHIC &&
nexus.GetKeyType() == ELEMENT) {
if (nexus.ic_state() != MEGAMORPHIC && nexus.GetKeyType() == ELEMENT) {
// Ensure that {index} is less than {receiver} length.
Node* length =
jsgraph()->Constant(receiver_ref.AsString().length());
Node* length = jsgraph()->Constant(receiver_ref.AsString().length());
// Load the single character string from {receiver} or yield
// undefined if the {index} is out of bounds (depending on the
// {load_mode}).
value = BuildIndexedStringLoad(receiver, index, length, &effect,
Node* value = BuildIndexedStringLoad(receiver, index, length, &effect,
&control, load_mode);
ReplaceWithValue(node, value, effect, control);
return Replace(value);
}
}
}
}
return NoChange();
}
Reduction JSNativeContextSpecialization::ReduceKeyedAccess(
Node* node, Node* index, Node* value, FeedbackNexus const& nexus,
AccessMode access_mode, KeyedAccessLoadMode load_mode,
KeyedAccessStoreMode store_mode) {
DCHECK(node->opcode() == IrOpcode::kJSLoadProperty ||
node->opcode() == IrOpcode::kJSStoreProperty);
Node* receiver = NodeProperties::GetValueInput(node, 0);
Node* effect = NodeProperties::GetEffectInput(node);
if (access_mode == AccessMode::kLoad &&
receiver->opcode() == IrOpcode::kHeapConstant) {
Reduction reduction =
ReduceKeyedLoadFromHeapConstant(node, index, nexus, load_mode);
if (reduction.Changed()) return reduction;
}
// Extract receiver maps from the {nexus}.
......
......@@ -115,6 +115,9 @@ class V8_EXPORT_PRIVATE JSNativeContextSpecialization final
Reduction ReduceGlobalAccess(Node* node, Node* receiver, Node* value,
Handle<Name> name, AccessMode access_mode,
Node* index, Handle<PropertyCell> property_cell);
Reduction ReduceKeyedLoadFromHeapConstant(Node* node, Node* index,
FeedbackNexus const& nexus,
KeyedAccessLoadMode load_mode);
Reduction ReduceSoftDeoptimize(Node* node, DeoptimizeReason reason);
Reduction ReduceJSToString(Node* node);
......
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