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

Side by Side Diff: src/hydrogen.cc

Issue 300693002: Revert "Customized support for feedback on calls to Array." and follow-up fixes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « src/hydrogen.h ('k') | src/ia32/code-stubs-ia32.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 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 "hydrogen.h" 5 #include "hydrogen.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "v8.h" 9 #include "v8.h"
10 #include "allocation-site-scopes.h" 10 #include "allocation-site-scopes.h"
(...skipping 2456 matching lines...) Expand 10 before | Expand all | Expand 10 after
2467 double nan_double = FixedDoubleArray::hole_nan_as_double(); 2467 double nan_double = FixedDoubleArray::hole_nan_as_double();
2468 HValue* hole = IsFastSmiOrObjectElementsKind(elements_kind) 2468 HValue* hole = IsFastSmiOrObjectElementsKind(elements_kind)
2469 ? Add<HConstant>(factory->the_hole_value()) 2469 ? Add<HConstant>(factory->the_hole_value())
2470 : Add<HConstant>(nan_double); 2470 : Add<HConstant>(nan_double);
2471 2471
2472 if (to == NULL) { 2472 if (to == NULL) {
2473 to = AddLoadFixedArrayLength(elements); 2473 to = AddLoadFixedArrayLength(elements);
2474 } 2474 }
2475 2475
2476 // Special loop unfolding case 2476 // Special loop unfolding case
2477 STATIC_ASSERT(JSArray::kPreallocatedArrayElements <= 2477 static const int kLoopUnfoldLimit = 8;
2478 kElementLoopUnrollThreshold); 2478 STATIC_ASSERT(JSArray::kPreallocatedArrayElements <= kLoopUnfoldLimit);
2479 int initial_capacity = -1; 2479 int initial_capacity = -1;
2480 if (from->IsInteger32Constant() && to->IsInteger32Constant()) { 2480 if (from->IsInteger32Constant() && to->IsInteger32Constant()) {
2481 int constant_from = from->GetInteger32Constant(); 2481 int constant_from = from->GetInteger32Constant();
2482 int constant_to = to->GetInteger32Constant(); 2482 int constant_to = to->GetInteger32Constant();
2483 2483
2484 if (constant_from == 0 && constant_to <= kElementLoopUnrollThreshold) { 2484 if (constant_from == 0 && constant_to <= kLoopUnfoldLimit) {
2485 initial_capacity = constant_to; 2485 initial_capacity = constant_to;
2486 } 2486 }
2487 } 2487 }
2488 2488
2489 // Since we're about to store a hole value, the store instruction below must 2489 // Since we're about to store a hole value, the store instruction below must
2490 // assume an elements kind that supports heap object values. 2490 // assume an elements kind that supports heap object values.
2491 if (IsFastSmiOrObjectElementsKind(elements_kind)) { 2491 if (IsFastSmiOrObjectElementsKind(elements_kind)) {
2492 elements_kind = FAST_HOLEY_ELEMENTS; 2492 elements_kind = FAST_HOLEY_ELEMENTS;
2493 } 2493 }
2494 2494
(...skipping 5732 matching lines...) Expand 10 before | Expand all | Expand 10 after
8227 // as is it dropped on deserialization. 8227 // as is it dropped on deserialization.
8228 CHECK(!isolate()->serializer_enabled()); 8228 CHECK(!isolate()->serializer_enabled());
8229 Handle<JSObject> global_receiver( 8229 Handle<JSObject> global_receiver(
8230 target->context()->global_object()->global_receiver()); 8230 target->context()->global_object()->global_receiver());
8231 return Add<HConstant>(global_receiver); 8231 return Add<HConstant>(global_receiver);
8232 } 8232 }
8233 return graph()->GetConstantUndefined(); 8233 return graph()->GetConstantUndefined();
8234 } 8234 }
8235 8235
8236 8236
8237 void HOptimizedGraphBuilder::BuildArrayCall(Expression* expression,
8238 int arguments_count,
8239 HValue* function,
8240 Handle<AllocationSite> site) {
8241 Add<HCheckValue>(function, array_function());
8242
8243 if (IsCallArrayInlineable(arguments_count, site)) {
8244 BuildInlinedCallArray(expression, arguments_count, site);
8245 return;
8246 }
8247
8248 HInstruction* call = PreProcessCall(New<HCallNewArray>(
8249 function, arguments_count + 1, site->GetElementsKind()));
8250 if (expression->IsCall()) {
8251 Drop(1);
8252 }
8253 ast_context()->ReturnInstruction(call, expression->id());
8254 }
8255
8256
8257 bool HOptimizedGraphBuilder::TryHandleArrayCall(Call* expr, HValue* function) {
8258 if (!array_function().is_identical_to(expr->target())) {
8259 return false;
8260 }
8261
8262 Handle<AllocationSite> site = expr->allocation_site();
8263 if (site.is_null()) return false;
8264
8265 BuildArrayCall(expr,
8266 expr->arguments()->length(),
8267 function,
8268 site);
8269 return true;
8270 }
8271
8272
8273 bool HOptimizedGraphBuilder::TryHandleArrayCallNew(CallNew* expr,
8274 HValue* function) {
8275 if (!array_function().is_identical_to(expr->target())) {
8276 return false;
8277 }
8278
8279 BuildArrayCall(expr,
8280 expr->arguments()->length(),
8281 function,
8282 expr->allocation_site());
8283 return true;
8284 }
8285
8286
8287 void HOptimizedGraphBuilder::VisitCall(Call* expr) { 8237 void HOptimizedGraphBuilder::VisitCall(Call* expr) {
8288 ASSERT(!HasStackOverflow()); 8238 ASSERT(!HasStackOverflow());
8289 ASSERT(current_block() != NULL); 8239 ASSERT(current_block() != NULL);
8290 ASSERT(current_block()->HasPredecessor()); 8240 ASSERT(current_block()->HasPredecessor());
8291 Expression* callee = expr->expression(); 8241 Expression* callee = expr->expression();
8292 int argument_count = expr->arguments()->length() + 1; // Plus receiver. 8242 int argument_count = expr->arguments()->length() + 1; // Plus receiver.
8293 HInstruction* call = NULL; 8243 HInstruction* call = NULL;
8294 8244
8295 Property* prop = callee->AsProperty(); 8245 Property* prop = callee->AsProperty();
8296 if (prop != NULL) { 8246 if (prop != NULL) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
8371 } else { 8321 } else {
8372 VariableProxy* proxy = expr->expression()->AsVariableProxy(); 8322 VariableProxy* proxy = expr->expression()->AsVariableProxy();
8373 if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) { 8323 if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) {
8374 return Bailout(kPossibleDirectCallToEval); 8324 return Bailout(kPossibleDirectCallToEval);
8375 } 8325 }
8376 8326
8377 // The function is on the stack in the unoptimized code during 8327 // The function is on the stack in the unoptimized code during
8378 // evaluation of the arguments. 8328 // evaluation of the arguments.
8379 CHECK_ALIVE(VisitForValue(expr->expression())); 8329 CHECK_ALIVE(VisitForValue(expr->expression()));
8380 HValue* function = Top(); 8330 HValue* function = Top();
8381 if (expr->global_call()) { 8331 bool global_call = proxy != NULL && proxy->var()->IsUnallocated();
8332 if (global_call) {
8382 Variable* var = proxy->var(); 8333 Variable* var = proxy->var();
8383 bool known_global_function = false; 8334 bool known_global_function = false;
8384 // If there is a global property cell for the name at compile time and 8335 // If there is a global property cell for the name at compile time and
8385 // access check is not enabled we assume that the function will not change 8336 // access check is not enabled we assume that the function will not change
8386 // and generate optimized code for calling the function. 8337 // and generate optimized code for calling the function.
8387 LookupResult lookup(isolate()); 8338 LookupResult lookup(isolate());
8388 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, LOAD); 8339 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, LOAD);
8389 if (type == kUseCell && 8340 if (type == kUseCell &&
8390 !current_info()->global_object()->IsAccessCheckNeeded()) { 8341 !current_info()->global_object()->IsAccessCheckNeeded()) {
8391 Handle<GlobalObject> global(current_info()->global_object()); 8342 Handle<GlobalObject> global(current_info()->global_object());
(...skipping 13 matching lines...) Expand all
8405 8356
8406 if (TryInlineBuiltinFunctionCall(expr)) { 8357 if (TryInlineBuiltinFunctionCall(expr)) {
8407 if (FLAG_trace_inlining) { 8358 if (FLAG_trace_inlining) {
8408 PrintF("Inlining builtin "); 8359 PrintF("Inlining builtin ");
8409 expr->target()->ShortPrint(); 8360 expr->target()->ShortPrint();
8410 PrintF("\n"); 8361 PrintF("\n");
8411 } 8362 }
8412 return; 8363 return;
8413 } 8364 }
8414 if (TryInlineApiFunctionCall(expr, receiver)) return; 8365 if (TryInlineApiFunctionCall(expr, receiver)) return;
8415 if (TryHandleArrayCall(expr, function)) return;
8416 if (TryInlineCall(expr)) return; 8366 if (TryInlineCall(expr)) return;
8417 8367
8418 PushArgumentsFromEnvironment(argument_count); 8368 PushArgumentsFromEnvironment(argument_count);
8419 call = BuildCallConstantFunction(expr->target(), argument_count); 8369 call = BuildCallConstantFunction(expr->target(), argument_count);
8420 } else { 8370 } else {
8421 Push(graph()->GetConstantUndefined()); 8371 Push(graph()->GetConstantUndefined());
8422 CHECK_ALIVE(VisitExpressions(expr->arguments())); 8372 CHECK_ALIVE(VisitExpressions(expr->arguments()));
8423 PushArgumentsFromEnvironment(argument_count); 8373 PushArgumentsFromEnvironment(argument_count);
8424 call = New<HCallFunction>(function, argument_count); 8374 call = New<HCallFunction>(function, argument_count);
8425 } 8375 }
(...skipping 29 matching lines...) Expand all
8455 PushArgumentsFromEnvironment(argument_count); 8405 PushArgumentsFromEnvironment(argument_count);
8456 call = New<HCallFunction>(function, argument_count); 8406 call = New<HCallFunction>(function, argument_count);
8457 } 8407 }
8458 } 8408 }
8459 8409
8460 Drop(1); // Drop the function. 8410 Drop(1); // Drop the function.
8461 return ast_context()->ReturnInstruction(call, expr->id()); 8411 return ast_context()->ReturnInstruction(call, expr->id());
8462 } 8412 }
8463 8413
8464 8414
8465 void HOptimizedGraphBuilder::BuildInlinedCallArray( 8415 void HOptimizedGraphBuilder::BuildInlinedCallNewArray(CallNew* expr) {
8466 Expression* expression,
8467 int argument_count,
8468 Handle<AllocationSite> site) {
8469 ASSERT(!site.is_null());
8470 ASSERT(argument_count >= 0 && argument_count <= 1);
8471 NoObservableSideEffectsScope no_effects(this); 8416 NoObservableSideEffectsScope no_effects(this);
8472 8417
8418 int argument_count = expr->arguments()->length();
8473 // We should at least have the constructor on the expression stack. 8419 // We should at least have the constructor on the expression stack.
8474 HValue* constructor = environment()->ExpressionStackAt(argument_count); 8420 HValue* constructor = environment()->ExpressionStackAt(argument_count);
8475 8421
8422 ElementsKind kind = expr->elements_kind();
8423 Handle<AllocationSite> site = expr->allocation_site();
8424 ASSERT(!site.is_null());
8425
8476 // Register on the site for deoptimization if the transition feedback changes. 8426 // Register on the site for deoptimization if the transition feedback changes.
8477 AllocationSite::AddDependentCompilationInfo( 8427 AllocationSite::AddDependentCompilationInfo(
8478 site, AllocationSite::TRANSITIONS, top_info()); 8428 site, AllocationSite::TRANSITIONS, top_info());
8479 ElementsKind kind = site->GetElementsKind();
8480 HInstruction* site_instruction = Add<HConstant>(site); 8429 HInstruction* site_instruction = Add<HConstant>(site);
8481 8430
8482 // In the single constant argument case, we may have to adjust elements kind 8431 // In the single constant argument case, we may have to adjust elements kind
8483 // to avoid creating a packed non-empty array. 8432 // to avoid creating a packed non-empty array.
8484 if (argument_count == 1 && !IsHoleyElementsKind(kind)) { 8433 if (argument_count == 1 && !IsHoleyElementsKind(kind)) {
8485 HValue* argument = environment()->Top(); 8434 HValue* argument = environment()->Top();
8486 if (argument->IsConstant()) { 8435 if (argument->IsConstant()) {
8487 HConstant* constant_argument = HConstant::cast(argument); 8436 HConstant* constant_argument = HConstant::cast(argument);
8488 ASSERT(constant_argument->HasSmiValue()); 8437 ASSERT(constant_argument->HasSmiValue());
8489 int constant_array_size = constant_argument->Integer32Value(); 8438 int constant_array_size = constant_argument->Integer32Value();
8490 if (constant_array_size != 0) { 8439 if (constant_array_size != 0) {
8491 kind = GetHoleyElementsKind(kind); 8440 kind = GetHoleyElementsKind(kind);
8492 } 8441 }
8493 } 8442 }
8494 } 8443 }
8495 8444
8496 // Build the array. 8445 // Build the array.
8497 JSArrayBuilder array_builder(this, 8446 JSArrayBuilder array_builder(this,
8498 kind, 8447 kind,
8499 site_instruction, 8448 site_instruction,
8500 constructor, 8449 constructor,
8501 DISABLE_ALLOCATION_SITES); 8450 DISABLE_ALLOCATION_SITES);
8502 HValue* new_object = argument_count == 0 8451 HValue* new_object;
8503 ? array_builder.AllocateEmptyArray() 8452 if (argument_count == 0) {
8504 : BuildAllocateArrayFromLength(&array_builder, Top()); 8453 new_object = array_builder.AllocateEmptyArray();
8454 } else if (argument_count == 1) {
8455 HValue* argument = environment()->Top();
8456 new_object = BuildAllocateArrayFromLength(&array_builder, argument);
8457 } else {
8458 HValue* length = Add<HConstant>(argument_count);
8459 // Smi arrays need to initialize array elements with the hole because
8460 // bailout could occur if the arguments don't fit in a smi.
8461 //
8462 // TODO(mvstanton): If all the arguments are constants in smi range, then
8463 // we could set fill_with_hole to false and save a few instructions.
8464 JSArrayBuilder::FillMode fill_mode = IsFastSmiElementsKind(kind)
8465 ? JSArrayBuilder::FILL_WITH_HOLE
8466 : JSArrayBuilder::DONT_FILL_WITH_HOLE;
8467 new_object = array_builder.AllocateArray(length, length, fill_mode);
8468 HValue* elements = array_builder.GetElementsLocation();
8469 for (int i = 0; i < argument_count; i++) {
8470 HValue* value = environment()->ExpressionStackAt(argument_count - i - 1);
8471 HValue* constant_i = Add<HConstant>(i);
8472 Add<HStoreKeyed>(elements, constant_i, value, kind);
8473 }
8474 }
8505 8475
8506 int args_to_drop = argument_count + (expression->IsCall() ? 2 : 1); 8476 Drop(argument_count + 1); // drop constructor and args.
8507 Drop(args_to_drop);
8508 ast_context()->ReturnValue(new_object); 8477 ast_context()->ReturnValue(new_object);
8509 } 8478 }
8510 8479
8511 8480
8512 // Checks whether allocation using the given constructor can be inlined. 8481 // Checks whether allocation using the given constructor can be inlined.
8513 static bool IsAllocationInlineable(Handle<JSFunction> constructor) { 8482 static bool IsAllocationInlineable(Handle<JSFunction> constructor) {
8514 return constructor->has_initial_map() && 8483 return constructor->has_initial_map() &&
8515 constructor->initial_map()->instance_type() == JS_OBJECT_TYPE && 8484 constructor->initial_map()->instance_type() == JS_OBJECT_TYPE &&
8516 constructor->initial_map()->instance_size() < HAllocate::kMaxInlineSize && 8485 constructor->initial_map()->instance_size() < HAllocate::kMaxInlineSize &&
8517 constructor->initial_map()->InitialPropertiesLength() == 0; 8486 constructor->initial_map()->InitialPropertiesLength() == 0;
8518 } 8487 }
8519 8488
8520 8489
8521 bool HOptimizedGraphBuilder::IsCallArrayInlineable( 8490 bool HOptimizedGraphBuilder::IsCallNewArrayInlineable(CallNew* expr) {
8522 int argument_count,
8523 Handle<AllocationSite> site) {
8524 Handle<JSFunction> caller = current_info()->closure(); 8491 Handle<JSFunction> caller = current_info()->closure();
8525 Handle<JSFunction> target = array_function(); 8492 Handle<JSFunction> target(isolate()->native_context()->array_function(),
8493 isolate());
8494 int argument_count = expr->arguments()->length();
8526 // We should have the function plus array arguments on the environment stack. 8495 // We should have the function plus array arguments on the environment stack.
8527 ASSERT(environment()->length() >= (argument_count + 1)); 8496 ASSERT(environment()->length() >= (argument_count + 1));
8497 Handle<AllocationSite> site = expr->allocation_site();
8528 ASSERT(!site.is_null()); 8498 ASSERT(!site.is_null());
8529 8499
8530 bool inline_ok = false; 8500 bool inline_ok = false;
8531 if (site->CanInlineCall()) { 8501 if (site->CanInlineCall()) {
8532 // We also want to avoid inlining in certain 1 argument scenarios. 8502 // We also want to avoid inlining in certain 1 argument scenarios.
8533 if (argument_count == 1) { 8503 if (argument_count == 1) {
8534 HValue* argument = Top(); 8504 HValue* argument = Top();
8535 if (argument->IsConstant()) { 8505 if (argument->IsConstant()) {
8536 // Do not inline if the constant length argument is not a smi or 8506 // Do not inline if the constant length argument is not a smi or
8537 // outside the valid range for unrolled loop initialization. 8507 // outside the valid range for a fast array.
8538 HConstant* constant_argument = HConstant::cast(argument); 8508 HConstant* constant_argument = HConstant::cast(argument);
8539 if (constant_argument->HasSmiValue()) { 8509 if (constant_argument->HasSmiValue()) {
8540 int value = constant_argument->Integer32Value(); 8510 int value = constant_argument->Integer32Value();
8541 inline_ok = value >= 0 && value <= kElementLoopUnrollThreshold; 8511 inline_ok = value >= 0 &&
8512 value < JSObject::kInitialMaxFastElementArray;
8542 if (!inline_ok) { 8513 if (!inline_ok) {
8543 TraceInline(target, caller, 8514 TraceInline(target, caller,
8544 "Constant length outside of valid inlining range."); 8515 "Length outside of valid array range");
8545 } 8516 }
8546 } 8517 }
8547 } else { 8518 } else {
8548 TraceInline(target, caller, 8519 inline_ok = true;
8549 "Dont inline [new] Array(n) where n isn't constant.");
8550 } 8520 }
8551 } else if (argument_count == 0) { 8521 } else {
8552 inline_ok = true; 8522 inline_ok = true;
8553 } else {
8554 TraceInline(target, caller, "Too many arguments to inline.");
8555 } 8523 }
8556 } else { 8524 } else {
8557 TraceInline(target, caller, "AllocationSite requested no inlining."); 8525 TraceInline(target, caller, "AllocationSite requested no inlining.");
8558 } 8526 }
8559 8527
8560 if (inline_ok) { 8528 if (inline_ok) {
8561 TraceInline(target, caller, NULL); 8529 TraceInline(target, caller, NULL);
8562 } 8530 }
8563 return inline_ok; 8531 return inline_ok;
8564 } 8532 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
8669 instr->DeleteAndReplaceWith(NULL); 8637 instr->DeleteAndReplaceWith(NULL);
8670 instr = prev_instr; 8638 instr = prev_instr;
8671 } while (instr != check); 8639 } while (instr != check);
8672 environment()->SetExpressionStackAt(receiver_index, function); 8640 environment()->SetExpressionStackAt(receiver_index, function);
8673 HInstruction* call = 8641 HInstruction* call =
8674 PreProcessCall(New<HCallNew>(function, argument_count)); 8642 PreProcessCall(New<HCallNew>(function, argument_count));
8675 return ast_context()->ReturnInstruction(call, expr->id()); 8643 return ast_context()->ReturnInstruction(call, expr->id());
8676 } else { 8644 } else {
8677 // The constructor function is both an operand to the instruction and an 8645 // The constructor function is both an operand to the instruction and an
8678 // argument to the construct call. 8646 // argument to the construct call.
8679 if (TryHandleArrayCallNew(expr, function)) return; 8647 Handle<JSFunction> array_function(
8648 isolate()->native_context()->array_function(), isolate());
8649 bool use_call_new_array = expr->target().is_identical_to(array_function);
8650 if (use_call_new_array && IsCallNewArrayInlineable(expr)) {
8651 // Verify we are still calling the array function for our native context.
8652 Add<HCheckValue>(function, array_function);
8653 BuildInlinedCallNewArray(expr);
8654 return;
8655 }
8680 8656
8681 HInstruction* call = 8657 HBinaryCall* call;
8682 PreProcessCall(New<HCallNew>(function, argument_count)); 8658 if (use_call_new_array) {
8659 Add<HCheckValue>(function, array_function);
8660 call = New<HCallNewArray>(function, argument_count,
8661 expr->elements_kind());
8662 } else {
8663 call = New<HCallNew>(function, argument_count);
8664 }
8665 PreProcessCall(call);
8683 return ast_context()->ReturnInstruction(call, expr->id()); 8666 return ast_context()->ReturnInstruction(call, expr->id());
8684 } 8667 }
8685 } 8668 }
8686 8669
8687 8670
8688 // Support for generating inlined runtime functions. 8671 // Support for generating inlined runtime functions.
8689 8672
8690 // Lookup table for generators for runtime calls that are generated inline. 8673 // Lookup table for generators for runtime calls that are generated inline.
8691 // Elements of the table are member pointers to functions of 8674 // Elements of the table are member pointers to functions of
8692 // HOptimizedGraphBuilder. 8675 // HOptimizedGraphBuilder.
(...skipping 3120 matching lines...) Expand 10 before | Expand all | Expand 10 after
11813 if (ShouldProduceTraceOutput()) { 11796 if (ShouldProduceTraceOutput()) {
11814 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 11797 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
11815 } 11798 }
11816 11799
11817 #ifdef DEBUG 11800 #ifdef DEBUG
11818 graph_->Verify(false); // No full verify. 11801 graph_->Verify(false); // No full verify.
11819 #endif 11802 #endif
11820 } 11803 }
11821 11804
11822 } } // namespace v8::internal 11805 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/ia32/code-stubs-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698