Index: src/compiler/js-builtin-reducer.cc |
diff --git a/src/compiler/js-builtin-reducer.cc b/src/compiler/js-builtin-reducer.cc |
index bf72ca47302545484b5bef10b88627210a6daa63..2678d5a787e919818fc0224c3bb66dca777a2c5a 100644 |
--- a/src/compiler/js-builtin-reducer.cc |
+++ b/src/compiler/js-builtin-reducer.cc |
@@ -5,9 +5,11 @@ |
#include "src/compiler/js-builtin-reducer.h" |
#include "src/base/bits.h" |
+#include "src/code-factory.h" |
#include "src/compilation-dependencies.h" |
#include "src/compiler/access-builder.h" |
#include "src/compiler/js-graph.h" |
+#include "src/compiler/linkage.h" |
#include "src/compiler/node-matchers.h" |
#include "src/compiler/node-properties.h" |
#include "src/compiler/simplified-operator.h" |
@@ -1598,18 +1600,17 @@ Reduction JSBuiltinReducer::ReduceStringFromCharCode(Node* node) { |
} |
namespace { |
- |
-Node* GetStringWitness(Node* node) { |
- Node* receiver = NodeProperties::GetValueInput(node, 1); |
- Type* receiver_type = NodeProperties::GetType(receiver); |
+Node* GetInputStringWitness(Node* node, int input_index) { |
Benedikt Meurer
2017/01/24 18:12:26
Please undo this change as well, since you only ch
|
+ Node* input = NodeProperties::GetValueInput(node, input_index); |
+ Type* input_type = NodeProperties::GetType(input); |
Node* effect = NodeProperties::GetEffectInput(node); |
- if (receiver_type->Is(Type::String())) return receiver; |
+ if (input_type->Is(Type::String())) return input; |
// Check if the {node} is dominated by a CheckString renaming for |
// it's {receiver}, and if so use that renaming as {receiver} for |
// the lowering below. |
for (Node* dominator = effect;;) { |
if (dominator->opcode() == IrOpcode::kCheckString && |
- NodeProperties::IsSame(dominator->InputAt(0), receiver)) { |
+ NodeProperties::IsSame(dominator->InputAt(0), input)) { |
return dominator; |
} |
if (dominator->op()->EffectInputCount() != 1) { |
@@ -1620,6 +1621,7 @@ Node* GetStringWitness(Node* node) { |
} |
} |
+Node* GetStringWitness(Node* node) { return GetInputStringWitness(node, 1); } |
} // namespace |
// ES6 section 21.1.3.1 String.prototype.charAt ( pos ) |
@@ -1730,6 +1732,41 @@ Reduction JSBuiltinReducer::ReduceStringCharCodeAt(Node* node) { |
return NoChange(); |
} |
+// ES6 String.prototype.indexOf(searchString [, position]) |
+// #sec-string.prototype.indexof |
+Reduction JSBuiltinReducer::ReduceStringIndexOf(Node* node) { |
+ int arg_count = node->op()->ValueInputCount(); |
+ if (arg_count != 3 && arg_count != 4) return NoChange(); |
+ Node* receiver; |
+ if (!(receiver = GetStringWitness(node))) return NoChange(); |
+ Node* search_string = NodeProperties::GetValueInput(node, 2); |
+ if (!NodeProperties::GetType(search_string)->Is(Type::String())) { |
+ return NoChange(); |
+ } |
+ // Replace the current JSFunctionCall to String.prototype.indexOf with a |
+ // simple Call to the unchecked StringIndexOf builtin. |
+ Callable callable = CodeFactory::StringIndexOf(isolate()); |
+ const CallInterfaceDescriptor& descriptor = callable.descriptor(); |
+ CallDescriptor* desc = Linkage::GetStubCallDescriptor( |
+ isolate(), graph()->zone(), descriptor, |
+ descriptor.GetStackParameterCount(), CallDescriptor::kNoFlags, |
+ Operator::kEliminatable); |
Benedikt Meurer
2017/01/24 18:12:26
This should even be pure, since Strings are immuta
Camillo Bruni
2017/01/25 23:11:40
done.
|
+ Node* stub_code = jsgraph()->HeapConstant(callable.code()); |
+ RelaxControls(node); |
+ // Remove framestate since StringIndexOf cannot deopt. |
+ node->RemoveInput(arg_count + 1); |
+ // Remove the control input. |
+ node->RemoveInput(arg_count + 2); |
+ // Replace the JSFunction from the JSFunctionCall node with the CodeStub. |
+ node->ReplaceInput(0, stub_code); |
+ if (arg_count == 3) { |
+ // Insert the missing position argument. |
+ node->InsertInput(graph()->zone(), 3, jsgraph()->ZeroConstant()); |
+ } |
+ NodeProperties::ChangeOp(node, common()->Call(desc)); |
+ return Changed(node); |
+} |
+ |
Reduction JSBuiltinReducer::ReduceStringIterator(Node* node) { |
if (Node* receiver = GetStringWitness(node)) { |
Node* effect = NodeProperties::GetEffectInput(node); |
@@ -2101,6 +2138,8 @@ Reduction JSBuiltinReducer::Reduce(Node* node) { |
return ReduceStringCharAt(node); |
case kStringCharCodeAt: |
return ReduceStringCharCodeAt(node); |
+ case kStringIndexOf: |
+ return ReduceStringIndexOf(node); |
case kStringIterator: |
return ReduceStringIterator(node); |
case kStringIteratorNext: |