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

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

Issue 2905623003: [turbofan] Speculatively optimize string character access. (Closed)
Patch Set: Created 3 years, 7 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/builtins/builtins-string-gen.cc ('k') | src/crankshaft/hydrogen.cc » ('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/builtins/builtins-utils.h" 8 #include "src/builtins/builtins-utils.h"
9 #include "src/code-factory.h" 9 #include "src/code-factory.h"
10 #include "src/compilation-dependencies.h" 10 #include "src/compilation-dependencies.h"
(...skipping 1904 matching lines...) Expand 10 before | Expand all | Expand 10 after
1915 1915
1916 // ES6 section 21.1.3.1 String.prototype.charAt ( pos ) 1916 // ES6 section 21.1.3.1 String.prototype.charAt ( pos )
1917 Reduction JSBuiltinReducer::ReduceStringCharAt(Node* node) { 1917 Reduction JSBuiltinReducer::ReduceStringCharAt(Node* node) {
1918 // We need at least target, receiver and index parameters. 1918 // We need at least target, receiver and index parameters.
1919 if (node->op()->ValueInputCount() >= 3) { 1919 if (node->op()->ValueInputCount() >= 3) {
1920 Node* index = NodeProperties::GetValueInput(node, 2); 1920 Node* index = NodeProperties::GetValueInput(node, 2);
1921 Type* index_type = NodeProperties::GetType(index); 1921 Type* index_type = NodeProperties::GetType(index);
1922 Node* effect = NodeProperties::GetEffectInput(node); 1922 Node* effect = NodeProperties::GetEffectInput(node);
1923 Node* control = NodeProperties::GetControlInput(node); 1923 Node* control = NodeProperties::GetControlInput(node);
1924 1924
1925 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { 1925 if (Node* receiver = GetStringWitness(node)) {
1926 if (Node* receiver = GetStringWitness(node)) { 1926 if (isolate()->IsStringBoundsCheckIntact()) {
1927 // Determine the {receiver} length.
1928 Node* receiver_length = effect = graph()->NewNode(
1929 simplified()->LoadField(AccessBuilder::ForStringLength()), receiver,
1930 effect, control);
1931
1932 // Check that the {index} is within the range of {receiver}.
1933 index = effect = graph()->NewNode(simplified()->CheckBounds(), index,
1934 receiver_length, effect, control);
1935
1936 // Return the character from the {receiver} as single character string.
1937 Node* value = graph()->NewNode(simplified()->StringCharAt(), receiver,
1938 index, control);
1939
1940 ReplaceWithValue(node, value, effect, control);
1941 return Replace(value);
1942 }
1943
1944 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) {
1927 if (!index_type->Is(Type::Unsigned32())) { 1945 if (!index_type->Is(Type::Unsigned32())) {
1928 // Map -0 and NaN to 0 (as per ToInteger), and the values in 1946 // Map -0 and NaN to 0 (as per ToInteger), and the values in
1929 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will 1947 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will
1930 // be considered out-of-bounds as well, because of the maximal 1948 // be considered out-of-bounds as well, because of the maximal
1931 // String length limit in V8. 1949 // String length limit in V8.
1932 STATIC_ASSERT(String::kMaxLength <= kMaxInt); 1950 STATIC_ASSERT(String::kMaxLength <= kMaxInt);
1933 index = graph()->NewNode(simplified()->NumberToUint32(), index); 1951 index = graph()->NewNode(simplified()->NumberToUint32(), index);
1934 } 1952 }
1935 1953
1936 // Determine the {receiver} length. 1954 // Determine the {receiver} length.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 1987
1970 // ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos ) 1988 // ES6 section 21.1.3.2 String.prototype.charCodeAt ( pos )
1971 Reduction JSBuiltinReducer::ReduceStringCharCodeAt(Node* node) { 1989 Reduction JSBuiltinReducer::ReduceStringCharCodeAt(Node* node) {
1972 // We need at least target, receiver and index parameters. 1990 // We need at least target, receiver and index parameters.
1973 if (node->op()->ValueInputCount() >= 3) { 1991 if (node->op()->ValueInputCount() >= 3) {
1974 Node* index = NodeProperties::GetValueInput(node, 2); 1992 Node* index = NodeProperties::GetValueInput(node, 2);
1975 Type* index_type = NodeProperties::GetType(index); 1993 Type* index_type = NodeProperties::GetType(index);
1976 Node* effect = NodeProperties::GetEffectInput(node); 1994 Node* effect = NodeProperties::GetEffectInput(node);
1977 Node* control = NodeProperties::GetControlInput(node); 1995 Node* control = NodeProperties::GetControlInput(node);
1978 1996
1979 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) { 1997 if (Node* receiver = GetStringWitness(node)) {
1980 if (Node* receiver = GetStringWitness(node)) { 1998 if (isolate()->IsStringBoundsCheckIntact()) {
1999 // Determine the {receiver} length.
2000 Node* receiver_length = effect = graph()->NewNode(
2001 simplified()->LoadField(AccessBuilder::ForStringLength()), receiver,
2002 effect, control);
2003
2004 // Check that the {index} is within the range of {receiver}.
2005 index = effect = graph()->NewNode(simplified()->CheckBounds(), index,
2006 receiver_length, effect, control);
2007
2008 // Return the character from the {receiver} as character code.
2009 Node* value = graph()->NewNode(simplified()->StringCharCodeAt(),
2010 receiver, index, control);
2011
2012 ReplaceWithValue(node, value, effect, control);
2013 return Replace(value);
2014 }
2015
2016 if (index_type->Is(Type::Integral32OrMinusZeroOrNaN())) {
1981 if (!index_type->Is(Type::Unsigned32())) { 2017 if (!index_type->Is(Type::Unsigned32())) {
1982 // Map -0 and NaN to 0 (as per ToInteger), and the values in 2018 // Map -0 and NaN to 0 (as per ToInteger), and the values in
1983 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will 2019 // the [-2^31,-1] range to the [2^31,2^32-1] range, which will
1984 // be considered out-of-bounds as well, because of the maximal 2020 // be considered out-of-bounds as well, because of the maximal
1985 // String length limit in V8. 2021 // String length limit in V8.
1986 STATIC_ASSERT(String::kMaxLength <= kMaxInt); 2022 STATIC_ASSERT(String::kMaxLength <= kMaxInt);
1987 index = graph()->NewNode(simplified()->NumberToUint32(), index); 2023 index = graph()->NewNode(simplified()->NumberToUint32(), index);
1988 } 2024 }
1989 2025
1990 // Determine the {receiver} length. 2026 // Determine the {receiver} length.
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 return jsgraph()->simplified(); 2563 return jsgraph()->simplified();
2528 } 2564 }
2529 2565
2530 JSOperatorBuilder* JSBuiltinReducer::javascript() const { 2566 JSOperatorBuilder* JSBuiltinReducer::javascript() const {
2531 return jsgraph()->javascript(); 2567 return jsgraph()->javascript();
2532 } 2568 }
2533 2569
2534 } // namespace compiler 2570 } // namespace compiler
2535 } // namespace internal 2571 } // namespace internal
2536 } // namespace v8 2572 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-string-gen.cc ('k') | src/crankshaft/hydrogen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698