OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 19 matching lines...) Expand all Loading... |
30 #include <algorithm> | 30 #include <algorithm> |
31 | 31 |
32 #include "v8.h" | 32 #include "v8.h" |
33 #include "codegen.h" | 33 #include "codegen.h" |
34 #include "full-codegen.h" | 34 #include "full-codegen.h" |
35 #include "hashmap.h" | 35 #include "hashmap.h" |
36 #include "hydrogen-dce.h" | 36 #include "hydrogen-dce.h" |
37 #include "hydrogen-environment-liveness.h" | 37 #include "hydrogen-environment-liveness.h" |
38 #include "hydrogen-escape-analysis.h" | 38 #include "hydrogen-escape-analysis.h" |
39 #include "hydrogen-infer-representation.h" | 39 #include "hydrogen-infer-representation.h" |
| 40 #include "hydrogen-infer-types.h" |
40 #include "hydrogen-gvn.h" | 41 #include "hydrogen-gvn.h" |
41 #include "hydrogen-osr.h" | 42 #include "hydrogen-osr.h" |
42 #include "hydrogen-range-analysis.h" | 43 #include "hydrogen-range-analysis.h" |
43 #include "hydrogen-redundant-phi.h" | 44 #include "hydrogen-redundant-phi.h" |
44 #include "hydrogen-sce.h" | 45 #include "hydrogen-sce.h" |
45 #include "hydrogen-uint32-analysis.h" | 46 #include "hydrogen-uint32-analysis.h" |
46 #include "lithium-allocator.h" | 47 #include "lithium-allocator.h" |
47 #include "parser.h" | 48 #include "parser.h" |
48 #include "scopeinfo.h" | 49 #include "scopeinfo.h" |
49 #include "scopes.h" | 50 #include "scopes.h" |
(...skipping 2507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2557 phi_list_ = new(zone()) ZoneList<HPhi*>(block_count, zone()); | 2558 phi_list_ = new(zone()) ZoneList<HPhi*>(block_count, zone()); |
2558 for (int i = 0; i < block_count; ++i) { | 2559 for (int i = 0; i < block_count; ++i) { |
2559 for (int j = 0; j < blocks_[i]->phis()->length(); ++j) { | 2560 for (int j = 0; j < blocks_[i]->phis()->length(); ++j) { |
2560 HPhi* phi = blocks_[i]->phis()->at(j); | 2561 HPhi* phi = blocks_[i]->phis()->at(j); |
2561 phi_list_->Add(phi, zone()); | 2562 phi_list_->Add(phi, zone()); |
2562 } | 2563 } |
2563 } | 2564 } |
2564 } | 2565 } |
2565 | 2566 |
2566 | 2567 |
2567 void HGraph::InferTypes(ZoneList<HValue*>* worklist) { | |
2568 BitVector in_worklist(GetMaximumValueID(), zone()); | |
2569 for (int i = 0; i < worklist->length(); ++i) { | |
2570 ASSERT(!in_worklist.Contains(worklist->at(i)->id())); | |
2571 in_worklist.Add(worklist->at(i)->id()); | |
2572 } | |
2573 | |
2574 while (!worklist->is_empty()) { | |
2575 HValue* current = worklist->RemoveLast(); | |
2576 in_worklist.Remove(current->id()); | |
2577 if (current->UpdateInferredType()) { | |
2578 for (HUseIterator it(current->uses()); !it.Done(); it.Advance()) { | |
2579 HValue* use = it.value(); | |
2580 if (!in_worklist.Contains(use->id())) { | |
2581 in_worklist.Add(use->id()); | |
2582 worklist->Add(use, zone()); | |
2583 } | |
2584 } | |
2585 } | |
2586 } | |
2587 } | |
2588 | |
2589 | |
2590 void HGraph::MergeRemovableSimulates() { | 2568 void HGraph::MergeRemovableSimulates() { |
2591 HPhase phase("H_Merge removable simulates", this); | 2569 HPhase phase("H_Merge removable simulates", this); |
2592 ZoneList<HSimulate*> mergelist(2, zone()); | 2570 ZoneList<HSimulate*> mergelist(2, zone()); |
2593 for (int i = 0; i < blocks()->length(); ++i) { | 2571 for (int i = 0; i < blocks()->length(); ++i) { |
2594 HBasicBlock* block = blocks()->at(i); | 2572 HBasicBlock* block = blocks()->at(i); |
2595 // Make sure the merge list is empty at the start of a block. | 2573 // Make sure the merge list is empty at the start of a block. |
2596 ASSERT(mergelist.is_empty()); | 2574 ASSERT(mergelist.is_empty()); |
2597 // Nasty heuristic: Never remove the first simulate in a block. This | 2575 // Nasty heuristic: Never remove the first simulate in a block. This |
2598 // just so happens to have a beneficial effect on register allocation. | 2576 // just so happens to have a beneficial effect on register allocation. |
2599 bool first = true; | 2577 bool first = true; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2643 | 2621 |
2644 if (!mergelist.is_empty()) { | 2622 if (!mergelist.is_empty()) { |
2645 // Merge the accumulated simulates at the end of the block. | 2623 // Merge the accumulated simulates at the end of the block. |
2646 HSimulate* last = mergelist.RemoveLast(); | 2624 HSimulate* last = mergelist.RemoveLast(); |
2647 last->MergeWith(&mergelist); | 2625 last->MergeWith(&mergelist); |
2648 } | 2626 } |
2649 } | 2627 } |
2650 } | 2628 } |
2651 | 2629 |
2652 | 2630 |
2653 void HGraph::InitializeInferredTypes() { | |
2654 HPhase phase("H_Inferring types", this); | |
2655 InitializeInferredTypes(0, this->blocks_.length() - 1); | |
2656 } | |
2657 | |
2658 | |
2659 void HGraph::InitializeInferredTypes(int from_inclusive, int to_inclusive) { | |
2660 for (int i = from_inclusive; i <= to_inclusive; ++i) { | |
2661 HBasicBlock* block = blocks_[i]; | |
2662 | |
2663 const ZoneList<HPhi*>* phis = block->phis(); | |
2664 for (int j = 0; j < phis->length(); j++) { | |
2665 phis->at(j)->UpdateInferredType(); | |
2666 } | |
2667 | |
2668 for (HInstructionIterator it(block); !it.Done(); it.Advance()) { | |
2669 it.Current()->UpdateInferredType(); | |
2670 } | |
2671 | |
2672 if (block->IsLoopHeader()) { | |
2673 HBasicBlock* last_back_edge = | |
2674 block->loop_information()->GetLastBackEdge(); | |
2675 InitializeInferredTypes(i + 1, last_back_edge->block_id()); | |
2676 // Skip all blocks already processed by the recursive call. | |
2677 i = last_back_edge->block_id(); | |
2678 // Update phis of the loop header now after the whole loop body is | |
2679 // guaranteed to be processed. | |
2680 ZoneList<HValue*> worklist(block->phis()->length(), zone()); | |
2681 for (int j = 0; j < block->phis()->length(); ++j) { | |
2682 worklist.Add(block->phis()->at(j), zone()); | |
2683 } | |
2684 InferTypes(&worklist); | |
2685 } | |
2686 } | |
2687 } | |
2688 | |
2689 | |
2690 void HGraph::PropagateMinusZeroChecks(HValue* value, BitVector* visited) { | 2631 void HGraph::PropagateMinusZeroChecks(HValue* value, BitVector* visited) { |
2691 HValue* current = value; | 2632 HValue* current = value; |
2692 while (current != NULL) { | 2633 while (current != NULL) { |
2693 if (visited->Contains(current->id())) return; | 2634 if (visited->Contains(current->id())) return; |
2694 | 2635 |
2695 // For phis, we must propagate the check to all of its inputs. | 2636 // For phis, we must propagate the check to all of its inputs. |
2696 if (current->IsPhi()) { | 2637 if (current->IsPhi()) { |
2697 visited->Add(current->id()); | 2638 visited->Add(current->id()); |
2698 HPhi* phi = HPhi::cast(current); | 2639 HPhi* phi = HPhi::cast(current); |
2699 for (int i = 0; i < phi->OperandCount(); ++i) { | 2640 for (int i = 0; i < phi->OperandCount(); ++i) { |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3387 Run<HInferRepresentationPhase>(); | 3328 Run<HInferRepresentationPhase>(); |
3388 | 3329 |
3389 // Remove HSimulate instructions that have turned out not to be needed | 3330 // Remove HSimulate instructions that have turned out not to be needed |
3390 // after all by folding them into the following HSimulate. | 3331 // after all by folding them into the following HSimulate. |
3391 // This must happen after inferring representations. | 3332 // This must happen after inferring representations. |
3392 MergeRemovableSimulates(); | 3333 MergeRemovableSimulates(); |
3393 | 3334 |
3394 MarkDeoptimizeOnUndefined(); | 3335 MarkDeoptimizeOnUndefined(); |
3395 InsertRepresentationChanges(); | 3336 InsertRepresentationChanges(); |
3396 | 3337 |
3397 InitializeInferredTypes(); | 3338 Run<HInferTypesPhase>(); |
3398 | 3339 |
3399 // Must be performed before canonicalization to ensure that Canonicalize | 3340 // Must be performed before canonicalization to ensure that Canonicalize |
3400 // will not remove semantically meaningful ToInt32 operations e.g. BIT_OR with | 3341 // will not remove semantically meaningful ToInt32 operations e.g. BIT_OR with |
3401 // zero. | 3342 // zero. |
3402 if (FLAG_opt_safe_uint32_operations) Run<HUint32AnalysisPhase>(); | 3343 if (FLAG_opt_safe_uint32_operations) Run<HUint32AnalysisPhase>(); |
3403 | 3344 |
3404 if (FLAG_use_canonicalizing) Canonicalize(); | 3345 if (FLAG_use_canonicalizing) Canonicalize(); |
3405 | 3346 |
3406 if (FLAG_use_escape_analysis) Run<HEscapeAnalysisPhase>(); | 3347 if (FLAG_use_escape_analysis) Run<HEscapeAnalysisPhase>(); |
3407 | 3348 |
(...skipping 7246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10654 if (ShouldProduceTraceOutput()) { | 10595 if (ShouldProduceTraceOutput()) { |
10655 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); | 10596 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); |
10656 } | 10597 } |
10657 | 10598 |
10658 #ifdef DEBUG | 10599 #ifdef DEBUG |
10659 graph_->Verify(false); // No full verify. | 10600 graph_->Verify(false); // No full verify. |
10660 #endif | 10601 #endif |
10661 } | 10602 } |
10662 | 10603 |
10663 } } // namespace v8::internal | 10604 } } // namespace v8::internal |
OLD | NEW |