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

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

Issue 2934893002: [builtins] Properly optimize Object.prototype.isPrototypeOf. (Closed)
Patch Set: Address feedback. Created 3 years, 6 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/js-call-reducer.h ('k') | src/compiler/js-generic-lowering.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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-call-reducer.h" 5 #include "src/compiler/js-call-reducer.h"
6 6
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.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 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 return ReduceObjectGetPrototype(node, object); 335 return ReduceObjectGetPrototype(node, object);
336 } 336 }
337 337
338 // ES6 section B.2.2.1.1 get Object.prototype.__proto__ 338 // ES6 section B.2.2.1.1 get Object.prototype.__proto__
339 Reduction JSCallReducer::ReduceObjectPrototypeGetProto(Node* node) { 339 Reduction JSCallReducer::ReduceObjectPrototypeGetProto(Node* node) {
340 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); 340 DCHECK_EQ(IrOpcode::kJSCall, node->opcode());
341 Node* receiver = NodeProperties::GetValueInput(node, 1); 341 Node* receiver = NodeProperties::GetValueInput(node, 1);
342 return ReduceObjectGetPrototype(node, receiver); 342 return ReduceObjectGetPrototype(node, receiver);
343 } 343 }
344 344
345 // ES #sec-object.prototype.isprototypeof
346 Reduction JSCallReducer::ReduceObjectPrototypeIsPrototypeOf(Node* node) {
347 DCHECK_EQ(IrOpcode::kJSCall, node->opcode());
348 Node* receiver = NodeProperties::GetValueInput(node, 1);
349 Node* value = node->op()->ValueInputCount() > 2
350 ? NodeProperties::GetValueInput(node, 2)
351 : jsgraph()->UndefinedConstant();
352 Node* effect = NodeProperties::GetEffectInput(node);
353
354 // Ensure that the {receiver} is known to be a JSReceiver (so that
355 // the ToObject step of Object.prototype.isPrototypeOf is a no-op).
356 ZoneHandleSet<Map> receiver_maps;
357 NodeProperties::InferReceiverMapsResult result =
358 NodeProperties::InferReceiverMaps(receiver, effect, &receiver_maps);
359 if (result == NodeProperties::kNoReceiverMaps) return NoChange();
360 for (size_t i = 0; i < receiver_maps.size(); ++i) {
361 if (!receiver_maps[i]->IsJSReceiverMap()) return NoChange();
362 }
363
364 // We don't check whether {value} is a proper JSReceiver here explicitly,
365 // and don't explicitly rule out Primitive {value}s, since all of them
366 // have null as their prototype, so the prototype chain walk inside the
367 // JSHasInPrototypeChain operator immediately aborts and yields false.
368 NodeProperties::ReplaceValueInput(node, value, 0);
369 NodeProperties::ReplaceValueInput(node, receiver, 1);
370 for (int i = node->op()->ValueInputCount(); i-- > 2;) {
371 node->RemoveInput(i);
372 }
373 NodeProperties::ChangeOp(node, javascript()->HasInPrototypeChain());
374 return Changed(node);
375 }
376
345 // ES6 section 26.1.7 Reflect.getPrototypeOf ( target ) 377 // ES6 section 26.1.7 Reflect.getPrototypeOf ( target )
346 Reduction JSCallReducer::ReduceReflectGetPrototypeOf(Node* node) { 378 Reduction JSCallReducer::ReduceReflectGetPrototypeOf(Node* node) {
347 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); 379 DCHECK_EQ(IrOpcode::kJSCall, node->opcode());
348 Node* target = (node->op()->ValueInputCount() >= 3) 380 Node* target = (node->op()->ValueInputCount() >= 3)
349 ? NodeProperties::GetValueInput(node, 2) 381 ? NodeProperties::GetValueInput(node, 2)
350 : jsgraph()->UndefinedConstant(); 382 : jsgraph()->UndefinedConstant();
351 return ReduceObjectGetPrototype(node, target); 383 return ReduceObjectGetPrototype(node, target);
352 } 384 }
353 385
354 Reduction JSCallReducer::ReduceArrayForEach(Handle<JSFunction> function, 386 Reduction JSCallReducer::ReduceArrayForEach(Handle<JSFunction> function,
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 case Builtins::kFunctionPrototypeCall: 766 case Builtins::kFunctionPrototypeCall:
735 return ReduceFunctionPrototypeCall(node); 767 return ReduceFunctionPrototypeCall(node);
736 case Builtins::kFunctionPrototypeHasInstance: 768 case Builtins::kFunctionPrototypeHasInstance:
737 return ReduceFunctionPrototypeHasInstance(node); 769 return ReduceFunctionPrototypeHasInstance(node);
738 case Builtins::kNumberConstructor: 770 case Builtins::kNumberConstructor:
739 return ReduceNumberConstructor(node); 771 return ReduceNumberConstructor(node);
740 case Builtins::kObjectGetPrototypeOf: 772 case Builtins::kObjectGetPrototypeOf:
741 return ReduceObjectGetPrototypeOf(node); 773 return ReduceObjectGetPrototypeOf(node);
742 case Builtins::kObjectPrototypeGetProto: 774 case Builtins::kObjectPrototypeGetProto:
743 return ReduceObjectPrototypeGetProto(node); 775 return ReduceObjectPrototypeGetProto(node);
776 case Builtins::kObjectPrototypeIsPrototypeOf:
777 return ReduceObjectPrototypeIsPrototypeOf(node);
744 case Builtins::kReflectGetPrototypeOf: 778 case Builtins::kReflectGetPrototypeOf:
745 return ReduceReflectGetPrototypeOf(node); 779 return ReduceReflectGetPrototypeOf(node);
746 case Builtins::kArrayForEach: 780 case Builtins::kArrayForEach:
747 return ReduceArrayForEach(function, node); 781 return ReduceArrayForEach(function, node);
748 default: 782 default:
749 break; 783 break;
750 } 784 }
751 785
752 // Check for the Array constructor. 786 // Check for the Array constructor.
753 if (*function == function->native_context()->array_function()) { 787 if (*function == function->native_context()->array_function()) {
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 return jsgraph()->javascript(); 1055 return jsgraph()->javascript();
1022 } 1056 }
1023 1057
1024 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { 1058 SimplifiedOperatorBuilder* JSCallReducer::simplified() const {
1025 return jsgraph()->simplified(); 1059 return jsgraph()->simplified();
1026 } 1060 }
1027 1061
1028 } // namespace compiler 1062 } // namespace compiler
1029 } // namespace internal 1063 } // namespace internal
1030 } // namespace v8 1064 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-call-reducer.h ('k') | src/compiler/js-generic-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698