Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Unified Diff: src/compiler/js-builtin-reducer.cc

Issue 2373983004: [turbofan] inline %StringIteratorPrototype%.next in JSBuiltinReducer. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/compiler/js-builtin-reducer.cc
diff --git a/src/compiler/js-builtin-reducer.cc b/src/compiler/js-builtin-reducer.cc
index 762020438878fdbc5566ba07848fd601c870b6ca..991c35ee98a0027f52ff898ce1ca838a65343992 100644
--- a/src/compiler/js-builtin-reducer.cc
+++ b/src/compiler/js-builtin-reducer.cc
@@ -9,11 +9,11 @@
#include "src/compiler/js-graph.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
+#include "src/compiler/operator-properties.h"
#include "src/compiler/simplified-operator.h"
#include "src/compiler/type-cache.h"
#include "src/compiler/types.h"
#include "src/objects-inl.h"
-
namespace v8 {
namespace internal {
namespace compiler {
@@ -1026,6 +1026,156 @@ Reduction JSBuiltinReducer::ReduceStringCharCodeAt(Node* node) {
return NoChange();
}
+Reduction JSBuiltinReducer::ReduceStringIteratorPrototypeNext(Node* node) {
+ Node* receiver = NodeProperties::GetValueInput(node, 1);
+ Node* effect = NodeProperties::GetEffectInput(node);
+ Node* control = NodeProperties::GetControlInput(node);
+ Node* context = NodeProperties::GetContextInput(node);
+ if (HasInstanceTypeWitness(receiver, effect, JS_STRING_ITERATOR_TYPE)) {
+ Node* string = effect = graph()->NewNode(
+ simplified()->LoadField(AccessBuilder::ForJSStringIteratorString()),
+ receiver, effect, control);
+ Node* index = effect = graph()->NewNode(
+ simplified()->LoadField(AccessBuilder::ForJSStringIteratorIndex()),
+ receiver, effect, control);
+ Node* length = effect = graph()->NewNode(
+ simplified()->LoadField(AccessBuilder::ForStringLength()), string,
+ effect, control);
+
+ // branch0: if (index < length)
+ Node* check0 =
+ graph()->NewNode(simplified()->NumberLessThan(), index, length);
+ Node* branch0 =
+ graph()->NewNode(common()->Branch(BranchHint::kTrue), check0, control);
+
+ Node* etrue0 = effect;
Benedikt Meurer 2016/09/29 13:04:27 You don't need the etrue0.
+ Node* vtrue0;
+ Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0);
+ Node* done_true;
Benedikt Meurer 2016/09/29 13:04:27 Can you indent the branches below and add { } for
+ {
+ done_true = jsgraph()->FalseConstant();
+ Node* uint32_index =
Benedikt Meurer 2016/09/29 13:04:27 You don't need this NumberToUint32. The type of th
caitp 2016/09/29 17:21:44 Ah, makes sense. Thanks!
+ graph()->NewNode(simplified()->NumberToUint32(), index);
+ Node* lead = graph()->NewNode(simplified()->StringCharCodeAt(), string,
+ uint32_index, if_true0);
+ Node* codepoint;
+ Node* control;
+ Node* check1 = graph()->NewNode(simplified()->NumberLessThan(), lead,
+ jsgraph()->Int32Constant(0xD800));
+ Node* branch1 = graph()->NewNode(common()->Branch(BranchHint::kTrue),
+ check1, if_true0);
+
+ Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1);
+ Node* check2 = graph()->NewNode(simplified()->NumberLessThanOrEqual(),
+ lead, jsgraph()->Int32Constant(0xDC00));
+ Node* branch2 = graph()->NewNode(common()->Branch(BranchHint::kTrue),
+ check2, if_false1);
+
+ Node* if_true2 = graph()->NewNode(common()->IfTrue(), branch2);
+ Node* next_index = graph()->NewNode(simplified()->NumberAdd(), index,
+ jsgraph()->OneConstant());
+ Node* check3 =
+ graph()->NewNode(simplified()->NumberLessThan(), next_index, length);
+ Node* branch3 = graph()->NewNode(common()->Branch(BranchHint::kTrue),
+ check3, if_true2);
+
+ Node* if_true3 = graph()->NewNode(common()->IfTrue(), branch3);
+ Node* uint32_next_index =
+ graph()->NewNode(simplified()->NumberToUint32(), next_index);
Benedikt Meurer 2016/09/29 13:04:27 Same here, you don't need it if you have the types
+ Node* trail = graph()->NewNode(simplified()->StringCharCodeAt(), string,
+ uint32_next_index, if_true3);
+ Node* check4 = graph()->NewNode(simplified()->NumberLessThanOrEqual(),
+ jsgraph()->Int32Constant(0xDC00), trail);
+ Node* branch4 = graph()->NewNode(common()->Branch(BranchHint::kTrue),
+ check4, if_true3);
+
+ Node* if_true4 = graph()->NewNode(common()->IfTrue(), branch4);
+ Node* check5 = graph()->NewNode(simplified()->NumberLessThanOrEqual(),
+ trail, jsgraph()->Int32Constant(0xDFFF));
+ Node* branch5 = graph()->NewNode(common()->Branch(BranchHint::kTrue),
+ check5, if_true4);
+
+ Node* if_true5 = graph()->NewNode(common()->IfTrue(), branch5);
+ codepoint = graph()->NewNode(
+ simplified()->NumberBitwiseOr(),
+ graph()->NewNode(simplified()->NumberShiftLeft(), trail,
+ jsgraph()->Int32Constant(16)),
+ lead);
+
+ Node* if_false5 = graph()->NewNode(common()->IfFalse(), branch5);
+ control = graph()->NewNode(common()->Merge(2), if_true5, if_false5);
+ codepoint =
+ graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2),
+ codepoint, lead, control);
+
+ Node* if_false4 = graph()->NewNode(common()->IfFalse(), branch4);
+ control = graph()->NewNode(common()->Merge(2), if_true4, if_false4);
+ codepoint =
+ graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2),
+ codepoint, lead, control);
+ Node* if_false3 = graph()->NewNode(common()->IfFalse(), branch3);
+ control = graph()->NewNode(common()->Merge(2), if_true3, if_false3);
+ codepoint =
+ graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2),
+ codepoint, lead, control);
+ Node* if_false2 = graph()->NewNode(common()->IfFalse(), branch2);
+ control = graph()->NewNode(common()->Merge(2), if_true2, if_false2);
+ codepoint =
+ graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2),
+ codepoint, lead, control);
+ Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1);
+ control = graph()->NewNode(common()->Merge(2), if_true1, if_false1);
+ codepoint =
+ graph()->NewNode(common()->Phi(MachineRepresentation::kWord32, 2),
+ codepoint, lead, control);
+
+ vtrue0 = etrue0 = graph()->NewNode(
Benedikt Meurer 2016/09/29 13:04:27 StringFromCodePoint doesn't produce an effect.
+ simplified()->StringFromCodePoint(UnicodeEncoding::UTF16), codepoint);
+ }
+
+ Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0);
+ Node* vfalse0;
+ Node* done_false;
+ {
+ done_false = jsgraph()->TrueConstant();
+ vfalse0 = jsgraph()->UndefinedConstant();
+ }
+
+ control = graph()->NewNode(common()->Merge(2), if_true0, if_false0);
+ Node* value_phi =
+ graph()->NewNode(common()->Phi(MachineRepresentation::kTagged, 2),
+ vtrue0, vfalse0, control);
+ Node* done_phi =
+ graph()->NewNode(common()->Phi(MachineRepresentation::kTagged, 2),
+ done_true, done_false, control);
+
+ Node* native_context = effect =
+ graph()->NewNode(jsgraph()->javascript()->LoadContext(
+ 0, Context::NATIVE_CONTEXT_INDEX, true),
+ context, context, effect);
+ Node* map = effect =
+ graph()->NewNode(jsgraph()->javascript()->LoadContext(
+ 0, Context::ITERATOR_RESULT_MAP_INDEX, true),
+ context, native_context, effect);
+
+ Node* value = effect = graph()->NewNode(
+ simplified()->Allocate(NOT_TENURED),
+ jsgraph()->Int32Constant(JSIteratorResult::kSize), effect, control);
+ effect = graph()->NewNode(simplified()->StoreField(AccessBuilder::ForMap()),
+ value, map, effect, control);
Benedikt Meurer 2016/09/29 13:04:27 You need to initialize properties and elements her
+ effect = graph()->NewNode(
+ simplified()->StoreField(AccessBuilder::ForJSIteratorResultDone()),
+ value, done_phi, effect, control);
+ effect = graph()->NewNode(
+ simplified()->StoreField(AccessBuilder::ForJSIteratorResultValue()),
+ value, value_phi, effect, control);
+
+ ReplaceWithValue(node, value, effect, control);
+ return Replace(value);
+ }
+ return NoChange();
+}
+
Reduction JSBuiltinReducer::ReduceArrayBufferViewAccessor(
Node* node, InstanceType instance_type, FieldAccess const& access) {
Node* receiver = NodeProperties::GetValueInput(node, 1);
@@ -1195,6 +1345,8 @@ Reduction JSBuiltinReducer::Reduce(Node* node) {
return ReduceStringCharAt(node);
case kStringCharCodeAt:
return ReduceStringCharCodeAt(node);
+ case kStringIteratorPrototypeNext:
+ return ReduceStringIteratorPrototypeNext(node);
case kDataViewByteLength:
return ReduceArrayBufferViewAccessor(
node, JS_DATA_VIEW_TYPE,

Powered by Google App Engine
This is Rietveld 408576698