OLD | NEW |
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 Loading... |
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 Loading... |
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 #ifdef DEBUG |
| 2576 static void TraceBinaryOp(BinaryOpIC::TypeInfo left, |
| 2577 BinaryOpIC::TypeInfo right, |
| 2578 bool has_fixed_right_arg, |
| 2579 int32_t fixed_right_arg_value, |
| 2580 BinaryOpIC::TypeInfo result) { |
| 2581 PrintF("%s*%s", BinaryOpIC::GetName(left), BinaryOpIC::GetName(right)); |
| 2582 if (has_fixed_right_arg) PrintF("{%d}", fixed_right_arg_value); |
| 2583 PrintF("->%s", BinaryOpIC::GetName(result)); |
| 2584 } |
| 2585 #endif |
| 2586 |
| 2587 |
2575 RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { | 2588 RUNTIME_FUNCTION(MaybeObject*, BinaryOp_Patch) { |
2576 ASSERT(args.length() == 3); | 2589 ASSERT(args.length() == 3); |
2577 | 2590 |
2578 HandleScope scope(isolate); | 2591 HandleScope scope(isolate); |
2579 Handle<Object> left = args.at<Object>(0); | 2592 Handle<Object> left = args.at<Object>(0); |
2580 Handle<Object> right = args.at<Object>(1); | 2593 Handle<Object> right = args.at<Object>(1); |
2581 int key = args.smi_at(2); | 2594 int key = args.smi_at(2); |
2582 Token::Value op = BinaryOpStub::decode_op_from_minor_key(key); | 2595 Token::Value op = BinaryOpStub::decode_op_from_minor_key(key); |
2583 BinaryOpIC::TypeInfo previous_left, previous_right, unused_previous_result; | 2596 |
| 2597 BinaryOpIC::TypeInfo previous_left, previous_right, previous_result; |
2584 BinaryOpStub::decode_types_from_minor_key( | 2598 BinaryOpStub::decode_types_from_minor_key( |
2585 key, &previous_left, &previous_right, &unused_previous_result); | 2599 key, &previous_left, &previous_right, &previous_result); |
2586 | 2600 |
2587 BinaryOpIC::TypeInfo new_left = InputState(previous_left, left, op); | 2601 BinaryOpIC::TypeInfo new_left = InputState(previous_left, left, op); |
2588 BinaryOpIC::TypeInfo new_right = InputState(previous_right, right, op); | 2602 BinaryOpIC::TypeInfo new_right = InputState(previous_right, right, op); |
2589 BinaryOpIC::TypeInfo result_type = BinaryOpIC::UNINITIALIZED; | 2603 BinaryOpIC::TypeInfo result_type = BinaryOpIC::UNINITIALIZED; |
2590 | 2604 |
2591 // STRING is only used for ADD operations. | 2605 // STRING is only used for ADD operations. |
2592 if ((new_left == BinaryOpIC::STRING || new_right == BinaryOpIC::STRING) && | 2606 if ((new_left == BinaryOpIC::STRING || new_right == BinaryOpIC::STRING) && |
2593 op != Token::ADD) { | 2607 op != Token::ADD) { |
2594 new_left = new_right = BinaryOpIC::GENERIC; | 2608 new_left = new_right = BinaryOpIC::GENERIC; |
2595 } | 2609 } |
2596 | 2610 |
2597 BinaryOpIC::TypeInfo new_overall = Max(new_left, new_right); | 2611 BinaryOpIC::TypeInfo new_overall = Max(new_left, new_right); |
2598 BinaryOpIC::TypeInfo previous_overall = Max(previous_left, previous_right); | 2612 BinaryOpIC::TypeInfo previous_overall = Max(previous_left, previous_right); |
2599 | 2613 |
2600 if (new_overall == BinaryOpIC::SMI && previous_overall == BinaryOpIC::SMI) { | 2614 bool previous_has_fixed_right_arg = |
2601 if (op == Token::DIV || | 2615 BinaryOpStub::decode_has_fixed_right_arg_from_minor_key(key); |
2602 op == Token::MUL || | 2616 int previous_fixed_right_arg_value = |
2603 op == Token::SHR || | 2617 BinaryOpStub::decode_fixed_right_arg_value_from_minor_key(key); |
2604 kSmiValueSize == 32) { | 2618 |
2605 // Arithmetic on two Smi inputs has yielded a heap number. | 2619 int32_t value; |
2606 // That is the only way to get here from the Smi stub. | 2620 bool new_has_fixed_right_arg = |
2607 // With 32-bit Smis, all overflows give heap numbers, but with | 2621 op == Token::MOD && |
2608 // 31-bit Smis, most operations overflow to int32 results. | 2622 right->ToInt32(&value) && |
2609 result_type = BinaryOpIC::NUMBER; | 2623 BinaryOpStub::can_encode_arg_value(value) && |
2610 } else { | 2624 (previous_overall == BinaryOpIC::UNINITIALIZED || |
2611 // Other operations on SMIs that overflow yield int32s. | 2625 (previous_has_fixed_right_arg && |
2612 result_type = BinaryOpIC::INT32; | 2626 previous_fixed_right_arg_value == value)); |
| 2627 int32_t new_fixed_right_arg_value = new_has_fixed_right_arg ? value : 1; |
| 2628 |
| 2629 if (previous_has_fixed_right_arg == new_has_fixed_right_arg) { |
| 2630 if (new_overall == BinaryOpIC::SMI && previous_overall == BinaryOpIC::SMI) { |
| 2631 if (op == Token::DIV || |
| 2632 op == Token::MUL || |
| 2633 op == Token::SHR || |
| 2634 kSmiValueSize == 32) { |
| 2635 // Arithmetic on two Smi inputs has yielded a heap number. |
| 2636 // That is the only way to get here from the Smi stub. |
| 2637 // With 32-bit Smis, all overflows give heap numbers, but with |
| 2638 // 31-bit Smis, most operations overflow to int32 results. |
| 2639 result_type = BinaryOpIC::NUMBER; |
| 2640 } else { |
| 2641 // Other operations on SMIs that overflow yield int32s. |
| 2642 result_type = BinaryOpIC::INT32; |
| 2643 } |
2613 } | 2644 } |
2614 } | 2645 if (new_overall == BinaryOpIC::INT32 && |
2615 if (new_overall == BinaryOpIC::INT32 && | 2646 previous_overall == BinaryOpIC::INT32) { |
2616 previous_overall == BinaryOpIC::INT32) { | 2647 if (new_left == previous_left && new_right == previous_right) { |
2617 if (new_left == previous_left && new_right == previous_right) { | 2648 result_type = BinaryOpIC::NUMBER; |
2618 result_type = BinaryOpIC::NUMBER; | 2649 } |
2619 } | 2650 } |
2620 } | 2651 } |
2621 | 2652 |
2622 BinaryOpStub stub(key, new_left, new_right, result_type); | 2653 BinaryOpStub stub(key, new_left, new_right, result_type, |
| 2654 new_has_fixed_right_arg, new_fixed_right_arg_value); |
2623 Handle<Code> code = stub.GetCode(isolate); | 2655 Handle<Code> code = stub.GetCode(isolate); |
2624 if (!code.is_null()) { | 2656 if (!code.is_null()) { |
2625 #ifdef DEBUG | 2657 #ifdef DEBUG |
2626 if (FLAG_trace_ic) { | 2658 if (FLAG_trace_ic) { |
2627 PrintF("[BinaryOpIC in "); | 2659 PrintF("[BinaryOpIC in "); |
2628 JavaScriptFrame::PrintTop(isolate, stdout, false, true); | 2660 JavaScriptFrame::PrintTop(isolate, stdout, false, true); |
2629 PrintF(" ((%s+%s)->((%s+%s)->%s))#%s @ %p]\n", | 2661 PrintF(" "); |
2630 BinaryOpIC::GetName(previous_left), | 2662 TraceBinaryOp(previous_left, previous_right, previous_has_fixed_right_arg, |
2631 BinaryOpIC::GetName(previous_right), | 2663 previous_fixed_right_arg_value, previous_result); |
2632 BinaryOpIC::GetName(new_left), | 2664 PrintF(" => "); |
2633 BinaryOpIC::GetName(new_right), | 2665 TraceBinaryOp(new_left, new_right, new_has_fixed_right_arg, |
2634 BinaryOpIC::GetName(result_type), | 2666 new_fixed_right_arg_value, result_type); |
2635 Token::Name(op), | 2667 PrintF(" #%s @ %p]\n", Token::Name(op), static_cast<void*>(*code)); |
2636 static_cast<void*>(*code)); | |
2637 } | 2668 } |
2638 #endif | 2669 #endif |
2639 BinaryOpIC ic(isolate); | 2670 BinaryOpIC ic(isolate); |
2640 ic.patch(*code); | 2671 ic.patch(*code); |
2641 | 2672 |
2642 // Activate inlined smi code. | 2673 // Activate inlined smi code. |
2643 if (previous_overall == BinaryOpIC::UNINITIALIZED) { | 2674 if (previous_overall == BinaryOpIC::UNINITIALIZED) { |
2644 PatchInlinedSmiCode(ic.address(), ENABLE_INLINED_SMI_CHECK); | 2675 PatchInlinedSmiCode(ic.address(), ENABLE_INLINED_SMI_CHECK); |
2645 } | 2676 } |
2646 } | 2677 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2992 #undef ADDR | 3023 #undef ADDR |
2993 }; | 3024 }; |
2994 | 3025 |
2995 | 3026 |
2996 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 3027 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
2997 return IC_utilities[id]; | 3028 return IC_utilities[id]; |
2998 } | 3029 } |
2999 | 3030 |
3000 | 3031 |
3001 } } // namespace v8::internal | 3032 } } // namespace v8::internal |
OLD | NEW |