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

Side by Side Diff: src/ic.cc

Issue 15735005: Collect type feedback for power-of-2 right operands in BinaryOps. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased. Created 7 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 2480 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 2491
2492 UnaryOpIC::TypeInfo type = UnaryOpIC::GetTypeInfo(operand); 2492 UnaryOpIC::TypeInfo type = UnaryOpIC::GetTypeInfo(operand);
2493 type = UnaryOpIC::ComputeNewType(type, previous_type); 2493 type = UnaryOpIC::ComputeNewType(type, previous_type);
2494 2494
2495 UnaryOpStub stub(op, mode, type); 2495 UnaryOpStub stub(op, mode, type);
2496 Handle<Code> code = stub.GetCode(isolate); 2496 Handle<Code> code = stub.GetCode(isolate);
2497 if (!code.is_null()) { 2497 if (!code.is_null()) {
2498 if (FLAG_trace_ic) { 2498 if (FLAG_trace_ic) {
2499 PrintF("[UnaryOpIC in "); 2499 PrintF("[UnaryOpIC in ");
2500 JavaScriptFrame::PrintTop(isolate, stdout, false, true); 2500 JavaScriptFrame::PrintTop(isolate, stdout, false, true);
2501 PrintF(" (%s->%s)#%s @ %p]\n", 2501 PrintF(" %s => %s #%s @ %p]\n",
2502 UnaryOpIC::GetName(previous_type), 2502 UnaryOpIC::GetName(previous_type),
2503 UnaryOpIC::GetName(type), 2503 UnaryOpIC::GetName(type),
2504 Token::Name(op), 2504 Token::Name(op),
2505 static_cast<void*>(*code)); 2505 static_cast<void*>(*code));
2506 } 2506 }
2507 UnaryOpIC ic(isolate); 2507 UnaryOpIC ic(isolate);
2508 ic.patch(*code); 2508 ic.patch(*code);
2509 } 2509 }
2510 2510
2511 Handle<JSBuiltinsObject> builtins(isolate->js_builtins_object()); 2511 Handle<JSBuiltinsObject> builtins(isolate->js_builtins_object());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2565 Token::Value op) { 2565 Token::Value op) {
2566 BinaryOpIC::TypeInfo new_type = TypeInfoFromValue(value, op); 2566 BinaryOpIC::TypeInfo new_type = TypeInfoFromValue(value, op);
2567 if (old_type == BinaryOpIC::STRING) { 2567 if (old_type == BinaryOpIC::STRING) {
2568 if (new_type == BinaryOpIC::STRING) return new_type; 2568 if (new_type == BinaryOpIC::STRING) return new_type;
2569 return BinaryOpIC::GENERIC; 2569 return BinaryOpIC::GENERIC;
2570 } 2570 }
2571 return Max(old_type, new_type); 2571 return Max(old_type, new_type);
2572 } 2572 }
2573 2573
2574 2574
2575 static bool TryToInt32(Handle<Object> object, int32_t* result) {
Jakob Kummerow 2013/06/03 09:49:30 In deoptimizer.cc, we have a "static bool ObjectTo
Sven Panne 2013/06/03 12:37:02 Done: I've moved the conversion routines to int32_
2576 if (object->IsSmi()) {
2577 *result = Smi::cast(*object)->value();
2578 return true;
2579 }
2580 if (object->IsHeapNumber()) {
2581 double value = HeapNumber::cast(*object)->value();
2582 if (TypeInfo::IsInt32Double(value)) {
2583 *result = static_cast<int32_t>(value);
2584 return true;
2585 }
2586 }
2587 return false;
2588 }
2589
2590
2591 #ifdef DEBUG
2592 static void TraceBinaryOp(BinaryOpIC::TypeInfo left,
2593 BinaryOpIC::TypeInfo right,
2594 bool has_fixed_right_arg,
2595 int32_t fixed_right_arg_value,
2596 BinaryOpIC::TypeInfo result) {
2597 PrintF("%s*%s", BinaryOpIC::GetName(left), BinaryOpIC::GetName(right));
2598 if (has_fixed_right_arg) PrintF("{%d}", fixed_right_arg_value);
2599 PrintF("->%s", BinaryOpIC::GetName(result));
2600 }
2601 #endif
2602
2603
2575 RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { 2604 RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) {
2576 ASSERT(args.length() == 3); 2605 ASSERT(args.length() == 3);
2577 2606
2578 HandleScope scope(isolate); 2607 HandleScope scope(isolate);
2579 Handle<Object> left = args.at<Object>(0); 2608 Handle<Object> left = args.at<Object>(0);
2580 Handle<Object> right = args.at<Object>(1); 2609 Handle<Object> right = args.at<Object>(1);
2581 int key = args.smi_at(2); 2610 int key = args.smi_at(2);
2582 Token::Value op = BinaryOpStub::decode_op_from_minor_key(key); 2611 Token::Value op = BinaryOpStub::decode_op_from_minor_key(key);
2583 BinaryOpIC::TypeInfo previous_left, previous_right, unused_previous_result; 2612
2613 BinaryOpIC::TypeInfo previous_left, previous_right, previous_result;
2584 BinaryOpStub::decode_types_from_minor_key( 2614 BinaryOpStub::decode_types_from_minor_key(
2585 key, &previous_left, &previous_right, &unused_previous_result); 2615 key, &previous_left, &previous_right, &previous_result);
2586 2616
2587 BinaryOpIC::TypeInfo new_left = InputState(previous_left, left, op); 2617 BinaryOpIC::TypeInfo new_left = InputState(previous_left, left, op);
2588 BinaryOpIC::TypeInfo new_right = InputState(previous_right, right, op); 2618 BinaryOpIC::TypeInfo new_right = InputState(previous_right, right, op);
2589 BinaryOpIC::TypeInfo result_type = BinaryOpIC::UNINITIALIZED; 2619 BinaryOpIC::TypeInfo result_type = BinaryOpIC::UNINITIALIZED;
2590 2620
2591 // STRING is only used for ADD operations. 2621 // STRING is only used for ADD operations.
2592 if ((new_left == BinaryOpIC::STRING || new_right == BinaryOpIC::STRING) && 2622 if ((new_left == BinaryOpIC::STRING || new_right == BinaryOpIC::STRING) &&
2593 op != Token::ADD) { 2623 op != Token::ADD) {
2594 new_left = new_right = BinaryOpIC::GENERIC; 2624 new_left = new_right = BinaryOpIC::GENERIC;
2595 } 2625 }
2596 2626
2597 BinaryOpIC::TypeInfo new_overall = Max(new_left, new_right); 2627 BinaryOpIC::TypeInfo new_overall = Max(new_left, new_right);
2598 BinaryOpIC::TypeInfo previous_overall = Max(previous_left, previous_right); 2628 BinaryOpIC::TypeInfo previous_overall = Max(previous_left, previous_right);
2599 2629
2600 if (new_overall == BinaryOpIC::SMI && previous_overall == BinaryOpIC::SMI) { 2630 bool previous_has_fixed_right_arg =
2601 if (op == Token::DIV || 2631 BinaryOpStub::decode_has_fixed_right_arg_from_minor_key(key);
2602 op == Token::MUL || 2632 int previous_fixed_right_arg_value =
2603 op == Token::SHR || 2633 BinaryOpStub::decode_fixed_right_arg_value_from_minor_key(key);
2604 kSmiValueSize == 32) { 2634
2605 // Arithmetic on two Smi inputs has yielded a heap number. 2635 int32_t value;
2606 // That is the only way to get here from the Smi stub. 2636 bool new_has_fixed_right_arg =
2607 // With 32-bit Smis, all overflows give heap numbers, but with 2637 op == Token::MOD &&
2608 // 31-bit Smis, most operations overflow to int32 results. 2638 TryToInt32(right, &value) &&
2609 result_type = BinaryOpIC::NUMBER; 2639 BinaryOpStub::can_encode_arg_value(value) &&
2610 } else { 2640 (previous_overall == BinaryOpIC::UNINITIALIZED ||
2611 // Other operations on SMIs that overflow yield int32s. 2641 (previous_has_fixed_right_arg &&
2612 result_type = BinaryOpIC::INT32; 2642 previous_fixed_right_arg_value == value));
2643 int32_t new_fixed_right_arg_value = new_has_fixed_right_arg ? value : 1;
2644
2645 if (previous_has_fixed_right_arg == new_has_fixed_right_arg) {
2646 if (new_overall == BinaryOpIC::SMI && previous_overall == BinaryOpIC::SMI) {
2647 if (op == Token::DIV ||
2648 op == Token::MUL ||
2649 op == Token::SHR ||
2650 kSmiValueSize == 32) {
2651 // Arithmetic on two Smi inputs has yielded a heap number.
2652 // That is the only way to get here from the Smi stub.
2653 // With 32-bit Smis, all overflows give heap numbers, but with
2654 // 31-bit Smis, most operations overflow to int32 results.
2655 result_type = BinaryOpIC::NUMBER;
2656 } else {
2657 // Other operations on SMIs that overflow yield int32s.
2658 result_type = BinaryOpIC::INT32;
2659 }
2613 } 2660 }
2614 } 2661 if (new_overall == BinaryOpIC::INT32 &&
2615 if (new_overall == BinaryOpIC::INT32 && 2662 previous_overall == BinaryOpIC::INT32) {
2616 previous_overall == BinaryOpIC::INT32) { 2663 if (new_left == previous_left && new_right == previous_right) {
2617 if (new_left == previous_left && new_right == previous_right) { 2664 result_type = BinaryOpIC::NUMBER;
2618 result_type = BinaryOpIC::NUMBER; 2665 }
2619 } 2666 }
2620 } 2667 }
2621 2668
2622 BinaryOpStub stub(key, new_left, new_right, result_type); 2669 BinaryOpStub stub(key, new_left, new_right, result_type,
2670 new_has_fixed_right_arg, new_fixed_right_arg_value);
2623 Handle<Code> code = stub.GetCode(isolate); 2671 Handle<Code> code = stub.GetCode(isolate);
2624 if (!code.is_null()) { 2672 if (!code.is_null()) {
2625 #ifdef DEBUG 2673 #ifdef DEBUG
2626 if (FLAG_trace_ic) { 2674 if (FLAG_trace_ic) {
2627 PrintF("[BinaryOpIC in "); 2675 PrintF("[BinaryOpIC in ");
2628 JavaScriptFrame::PrintTop(isolate, stdout, false, true); 2676 JavaScriptFrame::PrintTop(isolate, stdout, false, true);
2629 PrintF(" ((%s+%s)->((%s+%s)->%s))#%s @ %p]\n", 2677 PrintF(" ");
2630 BinaryOpIC::GetName(previous_left), 2678 TraceBinaryOp(previous_left, previous_right, previous_has_fixed_right_arg,
2631 BinaryOpIC::GetName(previous_right), 2679 previous_fixed_right_arg_value, previous_result);
2632 BinaryOpIC::GetName(new_left), 2680 PrintF(" => ");
2633 BinaryOpIC::GetName(new_right), 2681 TraceBinaryOp(new_left, new_right, new_has_fixed_right_arg,
2634 BinaryOpIC::GetName(result_type), 2682 new_fixed_right_arg_value, result_type);
2635 Token::Name(op), 2683 PrintF(" #%s @ %p]\n", Token::Name(op), static_cast<void*>(*code));
2636 static_cast<void*>(*code));
2637 } 2684 }
2638 #endif 2685 #endif
2639 BinaryOpIC ic(isolate); 2686 BinaryOpIC ic(isolate);
2640 ic.patch(*code); 2687 ic.patch(*code);
2641 2688
2642 // Activate inlined smi code. 2689 // Activate inlined smi code.
2643 if (previous_overall == BinaryOpIC::UNINITIALIZED) { 2690 if (previous_overall == BinaryOpIC::UNINITIALIZED) {
2644 PatchInlinedSmiCode(ic.address(), ENABLE_INLINED_SMI_CHECK); 2691 PatchInlinedSmiCode(ic.address(), ENABLE_INLINED_SMI_CHECK);
2645 } 2692 }
2646 } 2693 }
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
3004 #undef ADDR 3051 #undef ADDR
3005 }; 3052 };
3006 3053
3007 3054
3008 Address IC::AddressFromUtilityId(IC::UtilityId id) { 3055 Address IC::AddressFromUtilityId(IC::UtilityId id) {
3009 return IC_utilities[id]; 3056 return IC_utilities[id];
3010 } 3057 }
3011 3058
3012 3059
3013 } } // namespace v8::internal 3060 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698