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

Side by Side Diff: src/compiler/js-builtin-reducer.cc

Issue 2657243002: [turbofan] Introduce dedicated StringIndexOf operator. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « src/compiler/escape-analysis.cc ('k') | src/compiler/opcodes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler/js-builtin-reducer.h" 5 #include "src/compiler/js-builtin-reducer.h"
6 6
7 #include "src/base/bits.h" 7 #include "src/base/bits.h"
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 #include "src/compilation-dependencies.h" 9 #include "src/compilation-dependencies.h"
10 #include "src/compiler/access-builder.h" 10 #include "src/compiler/access-builder.h"
(...skipping 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 } 1718 }
1719 } 1719 }
1720 } 1720 }
1721 1721
1722 return NoChange(); 1722 return NoChange();
1723 } 1723 }
1724 1724
1725 // ES6 String.prototype.indexOf(searchString [, position]) 1725 // ES6 String.prototype.indexOf(searchString [, position])
1726 // #sec-string.prototype.indexof 1726 // #sec-string.prototype.indexof
1727 Reduction JSBuiltinReducer::ReduceStringIndexOf(Node* node) { 1727 Reduction JSBuiltinReducer::ReduceStringIndexOf(Node* node) {
1728 int arg_count = node->op()->ValueInputCount(); 1728 // We need at least target, receiver and search_string parameters.
1729 if (arg_count != 3 && arg_count != 4) return NoChange(); 1729 if (node->op()->ValueInputCount() >= 3) {
1730 Node* receiver; 1730 Node* search_string = NodeProperties::GetValueInput(node, 2);
1731 if (!(receiver = GetStringWitness(node))) return NoChange(); 1731 Type* search_string_type = NodeProperties::GetType(search_string);
1732 Node* search_string = NodeProperties::GetValueInput(node, 2); 1732 Node* position = (node->op()->ValueInputCount() >= 4)
1733 if (!NodeProperties::GetType(search_string)->Is(Type::String())) { 1733 ? NodeProperties::GetValueInput(node, 3)
1734 return NoChange(); 1734 : jsgraph()->ZeroConstant();
1735 Type* position_type = NodeProperties::GetType(position);
1736
1737 if (search_string_type->Is(Type::String()) &&
1738 position_type->Is(Type::SignedSmall())) {
1739 if (Node* receiver = GetStringWitness(node)) {
1740 RelaxEffectsAndControls(node);
1741 node->ReplaceInput(0, receiver);
1742 node->ReplaceInput(1, search_string);
1743 node->ReplaceInput(2, position);
1744 node->TrimInputCount(3);
1745 NodeProperties::ChangeOp(node, simplified()->StringIndexOf());
1746 return Changed(node);
1747 }
1748 }
1735 } 1749 }
1736 // Replace the current JSFunctionCall to String.prototype.indexOf with a 1750 return NoChange();
1737 // simple Call to the unchecked StringIndexOf builtin.
1738 Callable callable = CodeFactory::StringIndexOf(isolate());
1739 const CallInterfaceDescriptor& descriptor = callable.descriptor();
1740 CallDescriptor* desc =
1741 Linkage::GetStubCallDescriptor(isolate(), graph()->zone(), descriptor,
1742 descriptor.GetStackParameterCount(),
1743 CallDescriptor::kNoFlags, Operator::kPure);
1744 Node* stub_code = jsgraph()->HeapConstant(callable.code());
1745 // The Call Operator doesn't require an effect nor a control input.
1746 RelaxEffectsAndControls(node);
1747 // Remove framestate since StringIndexOf cannot deopt.
1748 node->RemoveInput(arg_count + 1);
1749 // Remove the control input.
1750 node->RemoveInput(arg_count + 2);
1751 // Replace the JSFunction from the JSFunctionCall node with the CodeStub.
1752 node->ReplaceInput(0, stub_code);
1753 if (arg_count == 3) {
1754 // Insert the missing position argument.
1755 node->InsertInput(graph()->zone(), 3, jsgraph()->ZeroConstant());
1756 }
1757 const Operator* op = common()->Call(desc);
1758 node->TrimInputCount(op->ValueInputCount());
1759 NodeProperties::ChangeOp(node, op);
1760 return Changed(node);
1761 } 1751 }
1762 1752
1763 Reduction JSBuiltinReducer::ReduceStringIterator(Node* node) { 1753 Reduction JSBuiltinReducer::ReduceStringIterator(Node* node) {
1764 if (Node* receiver = GetStringWitness(node)) { 1754 if (Node* receiver = GetStringWitness(node)) {
1765 Node* effect = NodeProperties::GetEffectInput(node); 1755 Node* effect = NodeProperties::GetEffectInput(node);
1766 Node* control = NodeProperties::GetControlInput(node); 1756 Node* control = NodeProperties::GetControlInput(node);
1767 1757
1768 Node* map = jsgraph()->HeapConstant( 1758 Node* map = jsgraph()->HeapConstant(
1769 handle(native_context()->string_iterator_map(), isolate())); 1759 handle(native_context()->string_iterator_map(), isolate()));
1770 1760
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 return jsgraph()->simplified(); 2192 return jsgraph()->simplified();
2203 } 2193 }
2204 2194
2205 JSOperatorBuilder* JSBuiltinReducer::javascript() const { 2195 JSOperatorBuilder* JSBuiltinReducer::javascript() const {
2206 return jsgraph()->javascript(); 2196 return jsgraph()->javascript();
2207 } 2197 }
2208 2198
2209 } // namespace compiler 2199 } // namespace compiler
2210 } // namespace internal 2200 } // namespace internal
2211 } // namespace v8 2201 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/escape-analysis.cc ('k') | src/compiler/opcodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698