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

Side by Side Diff: src/hydrogen.cc

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