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

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

Issue 2511223003: [turbofan] Properly optimize instanceof (even in the presence of @@hasInstance). (Closed)
Patch Set: Created 4 years, 1 month 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
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/compilation-dependencies.h" 7 #include "src/compilation-dependencies.h"
8 #include "src/compiler/access-builder.h" 8 #include "src/compiler/access-builder.h"
9 #include "src/compiler/js-graph.h" 9 #include "src/compiler/js-graph.h"
10 #include "src/compiler/node-matchers.h" 10 #include "src/compiler/node-matchers.h"
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 if (HasInstanceTypeWitness(receiver, effect, JS_DATE_TYPE)) { 955 if (HasInstanceTypeWitness(receiver, effect, JS_DATE_TYPE)) {
956 Node* value = effect = graph()->NewNode( 956 Node* value = effect = graph()->NewNode(
957 simplified()->LoadField(AccessBuilder::ForJSDateValue()), receiver, 957 simplified()->LoadField(AccessBuilder::ForJSDateValue()), receiver,
958 effect, control); 958 effect, control);
959 ReplaceWithValue(node, value, effect, control); 959 ReplaceWithValue(node, value, effect, control);
960 return Replace(value); 960 return Replace(value);
961 } 961 }
962 return NoChange(); 962 return NoChange();
963 } 963 }
964 964
965 // ES6 section 19.2.3.6 Function.prototype [ @@hasInstance ] ( V )
966 Reduction JSBuiltinReducer::ReduceFunctionHasInstance(Node* node) {
967 Node* receiver = NodeProperties::GetValueInput(node, 1);
968 Node* object = (node->op()->ValueInputCount() >= 3)
969 ? NodeProperties::GetValueInput(node, 2)
970 : jsgraph()->UndefinedConstant();
971 Node* context = NodeProperties::GetContextInput(node);
972 Node* frame_state = NodeProperties::GetFrameStateInput(node);
973 Node* effect = NodeProperties::GetEffectInput(node);
974 Node* control = NodeProperties::GetControlInput(node);
975
976 // TODO(turbofan): If JSOrdinaryToInstance raises an exception, the
977 // stack trace doesn't contain the @@hasInstance call; we have the
978 // corresponding bug in the baseline case. Some massaging of the frame
979 // state would be necessary here.
980
981 // Morph this {node} into a JSOrdinaryHasInstance node.
982 node->ReplaceInput(0, receiver);
983 node->ReplaceInput(1, object);
984 node->ReplaceInput(2, context);
985 node->ReplaceInput(3, frame_state);
986 node->ReplaceInput(4, effect);
987 node->ReplaceInput(5, control);
988 node->TrimInputCount(6);
989 NodeProperties::ChangeOp(node, javascript()->OrdinaryHasInstance());
990 return Changed(node);
991 }
992
965 // ES6 section 18.2.2 isFinite ( number ) 993 // ES6 section 18.2.2 isFinite ( number )
966 Reduction JSBuiltinReducer::ReduceGlobalIsFinite(Node* node) { 994 Reduction JSBuiltinReducer::ReduceGlobalIsFinite(Node* node) {
967 JSCallReduction r(node); 995 JSCallReduction r(node);
968 if (r.InputsMatchOne(Type::PlainPrimitive())) { 996 if (r.InputsMatchOne(Type::PlainPrimitive())) {
969 // isFinite(a:plain-primitive) -> NumberEqual(a', a') 997 // isFinite(a:plain-primitive) -> NumberEqual(a', a')
970 // where a' = NumberSubtract(ToNumber(a), ToNumber(a)) 998 // where a' = NumberSubtract(ToNumber(a), ToNumber(a))
971 Node* input = ToNumber(r.GetJSCallInput(0)); 999 Node* input = ToNumber(r.GetJSCallInput(0));
972 Node* diff = graph()->NewNode(simplified()->NumberSubtract(), input, input); 1000 Node* diff = graph()->NewNode(simplified()->NumberSubtract(), input, input);
973 Node* value = graph()->NewNode(simplified()->NumberEqual(), diff, diff); 1001 Node* value = graph()->NewNode(simplified()->NumberEqual(), diff, diff);
974 return Replace(value); 1002 return Replace(value);
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1838 case kArrayValues: 1866 case kArrayValues:
1839 return ReduceArrayIterator(node, IterationKind::kValues); 1867 return ReduceArrayIterator(node, IterationKind::kValues);
1840 case kArrayIteratorNext: 1868 case kArrayIteratorNext:
1841 return ReduceArrayIteratorNext(node); 1869 return ReduceArrayIteratorNext(node);
1842 case kArrayPop: 1870 case kArrayPop:
1843 return ReduceArrayPop(node); 1871 return ReduceArrayPop(node);
1844 case kArrayPush: 1872 case kArrayPush:
1845 return ReduceArrayPush(node); 1873 return ReduceArrayPush(node);
1846 case kDateGetTime: 1874 case kDateGetTime:
1847 return ReduceDateGetTime(node); 1875 return ReduceDateGetTime(node);
1876 case kFunctionHasInstance:
1877 return ReduceFunctionHasInstance(node);
1878 break;
1848 case kGlobalIsFinite: 1879 case kGlobalIsFinite:
1849 reduction = ReduceGlobalIsFinite(node); 1880 reduction = ReduceGlobalIsFinite(node);
1850 break; 1881 break;
1851 case kGlobalIsNaN: 1882 case kGlobalIsNaN:
1852 reduction = ReduceGlobalIsNaN(node); 1883 reduction = ReduceGlobalIsNaN(node);
1853 break; 1884 break;
1854 case kMathAbs: 1885 case kMathAbs:
1855 reduction = ReduceMathAbs(node); 1886 reduction = ReduceMathAbs(node);
1856 break; 1887 break;
1857 case kMathAcos: 1888 case kMathAcos:
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 return jsgraph()->simplified(); 2072 return jsgraph()->simplified();
2042 } 2073 }
2043 2074
2044 JSOperatorBuilder* JSBuiltinReducer::javascript() const { 2075 JSOperatorBuilder* JSBuiltinReducer::javascript() const {
2045 return jsgraph()->javascript(); 2076 return jsgraph()->javascript();
2046 } 2077 }
2047 2078
2048 } // namespace compiler 2079 } // namespace compiler
2049 } // namespace internal 2080 } // namespace internal
2050 } // namespace v8 2081 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698