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

Side by Side Diff: src/hydrogen.cc

Issue 1066873002: Simplify instanceof optimization; don't duplicate lookup (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Update comment Created 5 years, 8 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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/hydrogen.h" 5 #include "src/hydrogen.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "src/v8.h" 9 #include "src/v8.h"
10 10
(...skipping 10810 matching lines...) Expand 10 before | Expand all | Expand 10 after
10821 HValue* left = Pop(); 10821 HValue* left = Pop();
10822 Token::Value op = expr->op(); 10822 Token::Value op = expr->op();
10823 10823
10824 if (IsLiteralCompareBool(isolate(), left, op, right)) { 10824 if (IsLiteralCompareBool(isolate(), left, op, right)) {
10825 HCompareObjectEqAndBranch* result = 10825 HCompareObjectEqAndBranch* result =
10826 New<HCompareObjectEqAndBranch>(left, right); 10826 New<HCompareObjectEqAndBranch>(left, right);
10827 return ast_context()->ReturnControl(result, expr->id()); 10827 return ast_context()->ReturnControl(result, expr->id());
10828 } 10828 }
10829 10829
10830 if (op == Token::INSTANCEOF) { 10830 if (op == Token::INSTANCEOF) {
10831 // Check to see if the rhs of the instanceof is a global function not 10831 // Check to see if the rhs of the instanceof is a known function.
10832 // residing in new space. If it is we assume that the function will stay the 10832 if (right->IsConstant() &&
10833 // same. 10833 HConstant::cast(right)->handle(isolate())->IsJSFunction()) {
10834 Handle<JSFunction> target = Handle<JSFunction>::null(); 10834 Handle<Object> function = HConstant::cast(right)->handle(isolate());
10835 VariableProxy* proxy = expr->right()->AsVariableProxy(); 10835 Handle<JSFunction> target = Handle<JSFunction>::cast(function);
10836 bool global_function = (proxy != NULL) && proxy->var()->IsUnallocated();
10837 if (global_function && current_info()->has_global_object()) {
10838 Handle<String> name = proxy->name();
10839 Handle<GlobalObject> global(current_info()->global_object());
10840 LookupIterator it(global, name, LookupIterator::OWN_SKIP_INTERCEPTOR);
10841 Handle<Object> value = JSObject::GetDataProperty(&it);
10842 if (it.IsFound() && value->IsJSFunction()) {
10843 Handle<JSFunction> candidate = Handle<JSFunction>::cast(value);
10844 // If the function is in new space we assume it's more likely to
10845 // change and thus prefer the general IC code.
10846 if (!isolate()->heap()->InNewSpace(*candidate)) {
10847 target = candidate;
10848 }
10849 }
10850 }
10851
10852 // If the target is not null we have found a known global function that is
10853 // assumed to stay the same for this instanceof.
10854 if (target.is_null()) {
10855 HInstanceOf* result = New<HInstanceOf>(left, right);
10856 return ast_context()->ReturnInstruction(result, expr->id());
10857 } else {
10858 Add<HCheckValue>(right, target);
10859 HInstanceOfKnownGlobal* result = 10836 HInstanceOfKnownGlobal* result =
10860 New<HInstanceOfKnownGlobal>(left, target); 10837 New<HInstanceOfKnownGlobal>(left, target);
10861 return ast_context()->ReturnInstruction(result, expr->id()); 10838 return ast_context()->ReturnInstruction(result, expr->id());
10862 } 10839 }
10863 10840
10864 // Code below assumes that we don't fall through. 10841 HInstanceOf* result = New<HInstanceOf>(left, right);
10865 UNREACHABLE(); 10842 return ast_context()->ReturnInstruction(result, expr->id());
10843
10866 } else if (op == Token::IN) { 10844 } else if (op == Token::IN) {
10867 HValue* function = AddLoadJSBuiltin(Builtins::IN); 10845 HValue* function = AddLoadJSBuiltin(Builtins::IN);
10868 Add<HPushArguments>(left, right); 10846 Add<HPushArguments>(left, right);
10869 // TODO(olivf) InvokeFunction produces a check for the parameter count, 10847 // TODO(olivf) InvokeFunction produces a check for the parameter count,
10870 // even though we are certain to pass the correct number of arguments here. 10848 // even though we are certain to pass the correct number of arguments here.
10871 HInstruction* result = New<HInvokeFunction>(function, 2); 10849 HInstruction* result = New<HInvokeFunction>(function, 2);
10872 return ast_context()->ReturnInstruction(result, expr->id()); 10850 return ast_context()->ReturnInstruction(result, expr->id());
10873 } 10851 }
10874 10852
10875 PushBeforeSimulateBehavior push_behavior = 10853 PushBeforeSimulateBehavior push_behavior =
(...skipping 2060 matching lines...) Expand 10 before | Expand all | Expand 10 after
12936 if (ShouldProduceTraceOutput()) { 12914 if (ShouldProduceTraceOutput()) {
12937 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 12915 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
12938 } 12916 }
12939 12917
12940 #ifdef DEBUG 12918 #ifdef DEBUG
12941 graph_->Verify(false); // No full verify. 12919 graph_->Verify(false); // No full verify.
12942 #endif 12920 #endif
12943 } 12921 }
12944 12922
12945 } } // namespace v8::internal 12923 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698