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

Side by Side Diff: src/hydrogen.cc

Issue 305493003: Reland "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: Bugfix and tests 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 const int kLoopUnfoldLimit = 8; 2477 STATIC_ASSERT(JSArray::kPreallocatedArrayElements <=
2478 STATIC_ASSERT(JSArray::kPreallocatedArrayElements <= kLoopUnfoldLimit); 2478 kElementLoopUnrollThreshold);
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 <= kLoopUnfoldLimit) { 2484 if (constant_from == 0 && constant_to <= kElementLoopUnrollThreshold) {
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
8237 void HOptimizedGraphBuilder::VisitCall(Call* expr) { 8287 void HOptimizedGraphBuilder::VisitCall(Call* expr) {
8238 ASSERT(!HasStackOverflow()); 8288 ASSERT(!HasStackOverflow());
8239 ASSERT(current_block() != NULL); 8289 ASSERT(current_block() != NULL);
8240 ASSERT(current_block()->HasPredecessor()); 8290 ASSERT(current_block()->HasPredecessor());
8241 Expression* callee = expr->expression(); 8291 Expression* callee = expr->expression();
8242 int argument_count = expr->arguments()->length() + 1; // Plus receiver. 8292 int argument_count = expr->arguments()->length() + 1; // Plus receiver.
8243 HInstruction* call = NULL; 8293 HInstruction* call = NULL;
8244 8294
8245 Property* prop = callee->AsProperty(); 8295 Property* prop = callee->AsProperty();
8246 if (prop != NULL) { 8296 if (prop != NULL) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
8321 } else { 8371 } else {
8322 VariableProxy* proxy = expr->expression()->AsVariableProxy(); 8372 VariableProxy* proxy = expr->expression()->AsVariableProxy();
8323 if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) { 8373 if (proxy != NULL && proxy->var()->is_possibly_eval(isolate())) {
8324 return Bailout(kPossibleDirectCallToEval); 8374 return Bailout(kPossibleDirectCallToEval);
8325 } 8375 }
8326 8376
8327 // The function is on the stack in the unoptimized code during 8377 // The function is on the stack in the unoptimized code during
8328 // evaluation of the arguments. 8378 // evaluation of the arguments.
8329 CHECK_ALIVE(VisitForValue(expr->expression())); 8379 CHECK_ALIVE(VisitForValue(expr->expression()));
8330 HValue* function = Top(); 8380 HValue* function = Top();
8331 bool global_call = proxy != NULL && proxy->var()->IsUnallocated(); 8381 if (expr->global_call()) {
8332 if (global_call) {
8333 Variable* var = proxy->var(); 8382 Variable* var = proxy->var();
8334 bool known_global_function = false; 8383 bool known_global_function = false;
8335 // If there is a global property cell for the name at compile time and 8384 // If there is a global property cell for the name at compile time and
8336 // access check is not enabled we assume that the function will not change 8385 // access check is not enabled we assume that the function will not change
8337 // and generate optimized code for calling the function. 8386 // and generate optimized code for calling the function.
8338 LookupResult lookup(isolate()); 8387 LookupResult lookup(isolate());
8339 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, LOAD); 8388 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, LOAD);
8340 if (type == kUseCell && 8389 if (type == kUseCell &&
8341 !current_info()->global_object()->IsAccessCheckNeeded()) { 8390 !current_info()->global_object()->IsAccessCheckNeeded()) {
8342 Handle<GlobalObject> global(current_info()->global_object()); 8391 Handle<GlobalObject> global(current_info()->global_object());
(...skipping 13 matching lines...) Expand all
8356 8405
8357 if (TryInlineBuiltinFunctionCall(expr)) { 8406 if (TryInlineBuiltinFunctionCall(expr)) {
8358 if (FLAG_trace_inlining) { 8407 if (FLAG_trace_inlining) {
8359 PrintF("Inlining builtin "); 8408 PrintF("Inlining builtin ");
8360 expr->target()->ShortPrint(); 8409 expr->target()->ShortPrint();
8361 PrintF("\n"); 8410 PrintF("\n");
8362 } 8411 }
8363 return; 8412 return;
8364 } 8413 }
8365 if (TryInlineApiFunctionCall(expr, receiver)) return; 8414 if (TryInlineApiFunctionCall(expr, receiver)) return;
8415 if (TryHandleArrayCall(expr, function)) return;
8366 if (TryInlineCall(expr)) return; 8416 if (TryInlineCall(expr)) return;
8367 8417
8368 PushArgumentsFromEnvironment(argument_count); 8418 PushArgumentsFromEnvironment(argument_count);
8369 call = BuildCallConstantFunction(expr->target(), argument_count); 8419 call = BuildCallConstantFunction(expr->target(), argument_count);
8370 } else { 8420 } else {
8371 Push(graph()->GetConstantUndefined()); 8421 Push(graph()->GetConstantUndefined());
8372 CHECK_ALIVE(VisitExpressions(expr->arguments())); 8422 CHECK_ALIVE(VisitExpressions(expr->arguments()));
8373 PushArgumentsFromEnvironment(argument_count); 8423 PushArgumentsFromEnvironment(argument_count);
8374 call = New<HCallFunction>(function, argument_count); 8424 call = New<HCallFunction>(function, argument_count);
8375 } 8425 }
(...skipping 29 matching lines...) Expand all
8405 PushArgumentsFromEnvironment(argument_count); 8455 PushArgumentsFromEnvironment(argument_count);
8406 call = New<HCallFunction>(function, argument_count); 8456 call = New<HCallFunction>(function, argument_count);
8407 } 8457 }
8408 } 8458 }
8409 8459
8410 Drop(1); // Drop the function. 8460 Drop(1); // Drop the function.
8411 return ast_context()->ReturnInstruction(call, expr->id()); 8461 return ast_context()->ReturnInstruction(call, expr->id());
8412 } 8462 }
8413 8463
8414 8464
8415 void HOptimizedGraphBuilder::BuildInlinedCallNewArray(CallNew* expr) { 8465 void HOptimizedGraphBuilder::BuildInlinedCallArray(
8466 Expression* expression,
8467 int argument_count,
8468 Handle<AllocationSite> site) {
8469 ASSERT(!site.is_null());
8470 ASSERT(argument_count >= 0 && argument_count <= 1);
8416 NoObservableSideEffectsScope no_effects(this); 8471 NoObservableSideEffectsScope no_effects(this);
8417 8472
8418 int argument_count = expr->arguments()->length();
8419 // We should at least have the constructor on the expression stack. 8473 // We should at least have the constructor on the expression stack.
8420 HValue* constructor = environment()->ExpressionStackAt(argument_count); 8474 HValue* constructor = environment()->ExpressionStackAt(argument_count);
8421 8475
8422 ElementsKind kind = expr->elements_kind();
8423 Handle<AllocationSite> site = expr->allocation_site();
8424 ASSERT(!site.is_null());
8425
8426 // Register on the site for deoptimization if the transition feedback changes. 8476 // Register on the site for deoptimization if the transition feedback changes.
8427 AllocationSite::AddDependentCompilationInfo( 8477 AllocationSite::AddDependentCompilationInfo(
8428 site, AllocationSite::TRANSITIONS, top_info()); 8478 site, AllocationSite::TRANSITIONS, top_info());
8479 ElementsKind kind = site->GetElementsKind();
8429 HInstruction* site_instruction = Add<HConstant>(site); 8480 HInstruction* site_instruction = Add<HConstant>(site);
8430 8481
8431 // In the single constant argument case, we may have to adjust elements kind 8482 // In the single constant argument case, we may have to adjust elements kind
8432 // to avoid creating a packed non-empty array. 8483 // to avoid creating a packed non-empty array.
8433 if (argument_count == 1 && !IsHoleyElementsKind(kind)) { 8484 if (argument_count == 1 && !IsHoleyElementsKind(kind)) {
8434 HValue* argument = environment()->Top(); 8485 HValue* argument = environment()->Top();
8435 if (argument->IsConstant()) { 8486 if (argument->IsConstant()) {
8436 HConstant* constant_argument = HConstant::cast(argument); 8487 HConstant* constant_argument = HConstant::cast(argument);
8437 ASSERT(constant_argument->HasSmiValue()); 8488 ASSERT(constant_argument->HasSmiValue());
8438 int constant_array_size = constant_argument->Integer32Value(); 8489 int constant_array_size = constant_argument->Integer32Value();
8439 if (constant_array_size != 0) { 8490 if (constant_array_size != 0) {
8440 kind = GetHoleyElementsKind(kind); 8491 kind = GetHoleyElementsKind(kind);
8441 } 8492 }
8442 } 8493 }
8443 } 8494 }
8444 8495
8445 // Build the array. 8496 // Build the array.
8446 JSArrayBuilder array_builder(this, 8497 JSArrayBuilder array_builder(this,
8447 kind, 8498 kind,
8448 site_instruction, 8499 site_instruction,
8449 constructor, 8500 constructor,
8450 DISABLE_ALLOCATION_SITES); 8501 DISABLE_ALLOCATION_SITES);
8451 HValue* new_object; 8502 HValue* new_object = argument_count == 0
8452 if (argument_count == 0) { 8503 ? array_builder.AllocateEmptyArray()
8453 new_object = array_builder.AllocateEmptyArray(); 8504 : BuildAllocateArrayFromLength(&array_builder, Top());
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 }
8475 8505
8476 Drop(argument_count + 1); // drop constructor and args. 8506 int args_to_drop = argument_count + (expression->IsCall() ? 2 : 1);
8507 Drop(args_to_drop);
8477 ast_context()->ReturnValue(new_object); 8508 ast_context()->ReturnValue(new_object);
8478 } 8509 }
8479 8510
8480 8511
8481 // Checks whether allocation using the given constructor can be inlined. 8512 // Checks whether allocation using the given constructor can be inlined.
8482 static bool IsAllocationInlineable(Handle<JSFunction> constructor) { 8513 static bool IsAllocationInlineable(Handle<JSFunction> constructor) {
8483 return constructor->has_initial_map() && 8514 return constructor->has_initial_map() &&
8484 constructor->initial_map()->instance_type() == JS_OBJECT_TYPE && 8515 constructor->initial_map()->instance_type() == JS_OBJECT_TYPE &&
8485 constructor->initial_map()->instance_size() < HAllocate::kMaxInlineSize && 8516 constructor->initial_map()->instance_size() < HAllocate::kMaxInlineSize &&
8486 constructor->initial_map()->InitialPropertiesLength() == 0; 8517 constructor->initial_map()->InitialPropertiesLength() == 0;
8487 } 8518 }
8488 8519
8489 8520
8490 bool HOptimizedGraphBuilder::IsCallNewArrayInlineable(CallNew* expr) { 8521 bool HOptimizedGraphBuilder::IsCallArrayInlineable(
8522 int argument_count,
8523 Handle<AllocationSite> site) {
8491 Handle<JSFunction> caller = current_info()->closure(); 8524 Handle<JSFunction> caller = current_info()->closure();
8492 Handle<JSFunction> target(isolate()->native_context()->array_function(), 8525 Handle<JSFunction> target = array_function();
8493 isolate());
8494 int argument_count = expr->arguments()->length();
8495 // We should have the function plus array arguments on the environment stack. 8526 // We should have the function plus array arguments on the environment stack.
8496 ASSERT(environment()->length() >= (argument_count + 1)); 8527 ASSERT(environment()->length() >= (argument_count + 1));
8497 Handle<AllocationSite> site = expr->allocation_site();
8498 ASSERT(!site.is_null()); 8528 ASSERT(!site.is_null());
8499 8529
8500 bool inline_ok = false; 8530 bool inline_ok = false;
8501 if (site->CanInlineCall()) { 8531 if (site->CanInlineCall()) {
8502 // We also want to avoid inlining in certain 1 argument scenarios. 8532 // We also want to avoid inlining in certain 1 argument scenarios.
8503 if (argument_count == 1) { 8533 if (argument_count == 1) {
8504 HValue* argument = Top(); 8534 HValue* argument = Top();
8505 if (argument->IsConstant()) { 8535 if (argument->IsConstant()) {
8506 // Do not inline if the constant length argument is not a smi or 8536 // Do not inline if the constant length argument is not a smi or
8507 // outside the valid range for a fast array. 8537 // outside the valid range for unrolled loop initialization.
8508 HConstant* constant_argument = HConstant::cast(argument); 8538 HConstant* constant_argument = HConstant::cast(argument);
8509 if (constant_argument->HasSmiValue()) { 8539 if (constant_argument->HasSmiValue()) {
8510 int value = constant_argument->Integer32Value(); 8540 int value = constant_argument->Integer32Value();
8511 inline_ok = value >= 0 && 8541 inline_ok = value >= 0 && value <= kElementLoopUnrollThreshold;
8512 value < JSObject::kInitialMaxFastElementArray;
8513 if (!inline_ok) { 8542 if (!inline_ok) {
8514 TraceInline(target, caller, 8543 TraceInline(target, caller,
8515 "Length outside of valid array range"); 8544 "Constant length outside of valid inlining range.");
8516 } 8545 }
8517 } 8546 }
8518 } else { 8547 } else {
8519 inline_ok = true; 8548 TraceInline(target, caller,
8549 "Dont inline [new] Array(n) where n isn't constant.");
8520 } 8550 }
8551 } else if (argument_count == 0) {
8552 inline_ok = true;
8521 } else { 8553 } else {
8522 inline_ok = true; 8554 TraceInline(target, caller, "Too many arguments to inline.");
8523 } 8555 }
8524 } else { 8556 } else {
8525 TraceInline(target, caller, "AllocationSite requested no inlining."); 8557 TraceInline(target, caller, "AllocationSite requested no inlining.");
8526 } 8558 }
8527 8559
8528 if (inline_ok) { 8560 if (inline_ok) {
8529 TraceInline(target, caller, NULL); 8561 TraceInline(target, caller, NULL);
8530 } 8562 }
8531 return inline_ok; 8563 return inline_ok;
8532 } 8564 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
8637 instr->DeleteAndReplaceWith(NULL); 8669 instr->DeleteAndReplaceWith(NULL);
8638 instr = prev_instr; 8670 instr = prev_instr;
8639 } while (instr != check); 8671 } while (instr != check);
8640 environment()->SetExpressionStackAt(receiver_index, function); 8672 environment()->SetExpressionStackAt(receiver_index, function);
8641 HInstruction* call = 8673 HInstruction* call =
8642 PreProcessCall(New<HCallNew>(function, argument_count)); 8674 PreProcessCall(New<HCallNew>(function, argument_count));
8643 return ast_context()->ReturnInstruction(call, expr->id()); 8675 return ast_context()->ReturnInstruction(call, expr->id());
8644 } else { 8676 } else {
8645 // The constructor function is both an operand to the instruction and an 8677 // The constructor function is both an operand to the instruction and an
8646 // argument to the construct call. 8678 // argument to the construct call.
8647 Handle<JSFunction> array_function( 8679 if (TryHandleArrayCallNew(expr, function)) return;
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 }
8656 8680
8657 HBinaryCall* call; 8681 HInstruction* call =
8658 if (use_call_new_array) { 8682 PreProcessCall(New<HCallNew>(function, argument_count));
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);
8666 return ast_context()->ReturnInstruction(call, expr->id()); 8683 return ast_context()->ReturnInstruction(call, expr->id());
8667 } 8684 }
8668 } 8685 }
8669 8686
8670 8687
8671 // Support for generating inlined runtime functions. 8688 // Support for generating inlined runtime functions.
8672 8689
8673 // Lookup table for generators for runtime calls that are generated inline. 8690 // Lookup table for generators for runtime calls that are generated inline.
8674 // Elements of the table are member pointers to functions of 8691 // Elements of the table are member pointers to functions of
8675 // HOptimizedGraphBuilder. 8692 // HOptimizedGraphBuilder.
(...skipping 3120 matching lines...) Expand 10 before | Expand all | Expand 10 after
11796 if (ShouldProduceTraceOutput()) { 11813 if (ShouldProduceTraceOutput()) {
11797 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 11814 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
11798 } 11815 }
11799 11816
11800 #ifdef DEBUG 11817 #ifdef DEBUG
11801 graph_->Verify(false); // No full verify. 11818 graph_->Verify(false); // No full verify.
11802 #endif 11819 #endif
11803 } 11820 }
11804 11821
11805 } } // namespace v8::internal 11822 } } // 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