| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 | 884 |
| 885 class HRangeAnalysis BASE_EMBEDDED { | 885 class HRangeAnalysis BASE_EMBEDDED { |
| 886 public: | 886 public: |
| 887 explicit HRangeAnalysis(HGraph* graph) : graph_(graph), changed_ranges_(16) {} | 887 explicit HRangeAnalysis(HGraph* graph) : graph_(graph), changed_ranges_(16) {} |
| 888 | 888 |
| 889 void Analyze(); | 889 void Analyze(); |
| 890 | 890 |
| 891 private: | 891 private: |
| 892 void TraceRange(const char* msg, ...); | 892 void TraceRange(const char* msg, ...); |
| 893 void Analyze(HBasicBlock* block); | 893 void Analyze(HBasicBlock* block); |
| 894 void InferControlFlowRange(HCompareIDAndBranch* test, HBasicBlock* dest); | 894 void InferControlFlowRange(HCompareNumbersAndBranch* test, |
| 895 HBasicBlock* dest); |
| 895 void UpdateControlFlowRange(Token::Value op, HValue* value, HValue* other); | 896 void UpdateControlFlowRange(Token::Value op, HValue* value, HValue* other); |
| 896 void InferRange(HValue* value); | 897 void InferRange(HValue* value); |
| 897 void RollBackTo(int index); | 898 void RollBackTo(int index); |
| 898 void AddRange(HValue* value, Range* range); | 899 void AddRange(HValue* value, Range* range); |
| 899 | 900 |
| 900 HGraph* graph_; | 901 HGraph* graph_; |
| 901 ZoneList<HValue*> changed_ranges_; | 902 ZoneList<HValue*> changed_ranges_; |
| 902 }; | 903 }; |
| 903 | 904 |
| 904 | 905 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 919 | 920 |
| 920 | 921 |
| 921 void HRangeAnalysis::Analyze(HBasicBlock* block) { | 922 void HRangeAnalysis::Analyze(HBasicBlock* block) { |
| 922 TraceRange("Analyzing block B%d\n", block->block_id()); | 923 TraceRange("Analyzing block B%d\n", block->block_id()); |
| 923 | 924 |
| 924 int last_changed_range = changed_ranges_.length() - 1; | 925 int last_changed_range = changed_ranges_.length() - 1; |
| 925 | 926 |
| 926 // Infer range based on control flow. | 927 // Infer range based on control flow. |
| 927 if (block->predecessors()->length() == 1) { | 928 if (block->predecessors()->length() == 1) { |
| 928 HBasicBlock* pred = block->predecessors()->first(); | 929 HBasicBlock* pred = block->predecessors()->first(); |
| 929 if (pred->end()->IsCompareIDAndBranch()) { | 930 if (pred->end()->IsCompareNumbersAndBranch()) { |
| 930 InferControlFlowRange(HCompareIDAndBranch::cast(pred->end()), block); | 931 InferControlFlowRange(HCompareNumbersAndBranch::cast(pred->end()), |
| 932 block); |
| 931 } | 933 } |
| 932 } | 934 } |
| 933 | 935 |
| 934 // Process phi instructions. | 936 // Process phi instructions. |
| 935 for (int i = 0; i < block->phis()->length(); ++i) { | 937 for (int i = 0; i < block->phis()->length(); ++i) { |
| 936 HPhi* phi = block->phis()->at(i); | 938 HPhi* phi = block->phis()->at(i); |
| 937 InferRange(phi); | 939 InferRange(phi); |
| 938 } | 940 } |
| 939 | 941 |
| 940 // Go through all instructions of the current block. | 942 // Go through all instructions of the current block. |
| 941 HInstruction* instr = block->first(); | 943 HInstruction* instr = block->first(); |
| 942 while (instr != block->end()) { | 944 while (instr != block->end()) { |
| 943 InferRange(instr); | 945 InferRange(instr); |
| 944 instr = instr->next(); | 946 instr = instr->next(); |
| 945 } | 947 } |
| 946 | 948 |
| 947 // Continue analysis in all dominated blocks. | 949 // Continue analysis in all dominated blocks. |
| 948 for (int i = 0; i < block->dominated_blocks()->length(); ++i) { | 950 for (int i = 0; i < block->dominated_blocks()->length(); ++i) { |
| 949 Analyze(block->dominated_blocks()->at(i)); | 951 Analyze(block->dominated_blocks()->at(i)); |
| 950 } | 952 } |
| 951 | 953 |
| 952 RollBackTo(last_changed_range); | 954 RollBackTo(last_changed_range); |
| 953 } | 955 } |
| 954 | 956 |
| 955 | 957 |
| 956 void HRangeAnalysis::InferControlFlowRange(HCompareIDAndBranch* test, | 958 void HRangeAnalysis::InferControlFlowRange(HCompareNumbersAndBranch* test, |
| 957 HBasicBlock* dest) { | 959 HBasicBlock* dest) { |
| 958 ASSERT((test->FirstSuccessor() == dest) == (test->SecondSuccessor() != dest)); | 960 ASSERT((test->FirstSuccessor() == dest) == (test->SecondSuccessor() != dest)); |
| 959 if (test->GetInputRepresentation().IsInteger32()) { | 961 if (test->GetInputRepresentation().IsInteger32()) { |
| 960 Token::Value op = test->token(); | 962 Token::Value op = test->token(); |
| 961 if (test->SecondSuccessor() == dest) { | 963 if (test->SecondSuccessor() == dest) { |
| 962 op = Token::NegateCompareOp(op); | 964 op = Token::NegateCompareOp(op); |
| 963 } | 965 } |
| 964 Token::Value inverted_op = Token::InvertCompareOp(op); | 966 Token::Value inverted_op = Token::InvertCompareOp(op); |
| 965 UpdateControlFlowRange(op, test->left(), test->right()); | 967 UpdateControlFlowRange(op, test->left(), test->right()); |
| 966 UpdateControlFlowRange(inverted_op, test->right(), test->left()); | 968 UpdateControlFlowRange(inverted_op, test->right(), test->left()); |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1929 RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi::cast(input)); | 1931 RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi::cast(input)); |
| 1930 } | 1932 } |
| 1931 } | 1933 } |
| 1932 } | 1934 } |
| 1933 | 1935 |
| 1934 | 1936 |
| 1935 void HGraph::MarkDeoptimizeOnUndefined() { | 1937 void HGraph::MarkDeoptimizeOnUndefined() { |
| 1936 HPhase phase("MarkDeoptimizeOnUndefined", this); | 1938 HPhase phase("MarkDeoptimizeOnUndefined", this); |
| 1937 // Compute DeoptimizeOnUndefined flag for phis. | 1939 // Compute DeoptimizeOnUndefined flag for phis. |
| 1938 // Any phi that can reach a use with DeoptimizeOnUndefined set must | 1940 // Any phi that can reach a use with DeoptimizeOnUndefined set must |
| 1939 // have DeoptimizeOnUndefined set. Currently only HCompareIDAndBranch, with | 1941 // have DeoptimizeOnUndefined set. Currently only HCompareNumbersAndBranch, |
| 1940 // double input representation, has this flag set. | 1942 // with double input representation, has this flag set. |
| 1941 // The flag is used by HChange tagged->double, which must deoptimize | 1943 // The flag is used by HChange tagged->double, which must deoptimize |
| 1942 // if one of its uses has this flag set. | 1944 // if one of its uses has this flag set. |
| 1943 for (int i = 0; i < phi_list()->length(); i++) { | 1945 for (int i = 0; i < phi_list()->length(); i++) { |
| 1944 HPhi* phi = phi_list()->at(i); | 1946 HPhi* phi = phi_list()->at(i); |
| 1945 if (phi->representation().IsDouble()) { | 1947 if (phi->representation().IsDouble()) { |
| 1946 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { | 1948 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { |
| 1947 if (it.value()->CheckFlag(HValue::kDeoptimizeOnUndefined)) { | 1949 if (it.value()->CheckFlag(HValue::kDeoptimizeOnUndefined)) { |
| 1948 RecursivelyMarkPhiDeoptimizeOnUndefined(phi); | 1950 RecursivelyMarkPhiDeoptimizeOnUndefined(phi); |
| 1949 break; | 1951 break; |
| 1950 } | 1952 } |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2666 // Finish with deoptimize and add uses of enviroment values to | 2668 // Finish with deoptimize and add uses of enviroment values to |
| 2667 // account for invisible uses. | 2669 // account for invisible uses. |
| 2668 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); | 2670 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); |
| 2669 set_current_block(NULL); | 2671 set_current_block(NULL); |
| 2670 break; | 2672 break; |
| 2671 } | 2673 } |
| 2672 | 2674 |
| 2673 // Otherwise generate a compare and branch. | 2675 // Otherwise generate a compare and branch. |
| 2674 CHECK_ALIVE(VisitForValue(clause->label())); | 2676 CHECK_ALIVE(VisitForValue(clause->label())); |
| 2675 HValue* label_value = Pop(); | 2677 HValue* label_value = Pop(); |
| 2676 HCompareIDAndBranch* compare = | 2678 HCompareNumbersAndBranch* compare = |
| 2677 new(zone()) HCompareIDAndBranch(tag_value, | 2679 new(zone()) HCompareNumbersAndBranch(tag_value, |
| 2678 label_value, | 2680 label_value, |
| 2679 Token::EQ_STRICT); | 2681 Token::EQ_STRICT); |
| 2680 compare->SetInputRepresentation(Representation::Integer32()); | 2682 compare->SetInputRepresentation(Representation::Integer32()); |
| 2681 HBasicBlock* body_block = graph()->CreateBasicBlock(); | 2683 HBasicBlock* body_block = graph()->CreateBasicBlock(); |
| 2682 HBasicBlock* next_test_block = graph()->CreateBasicBlock(); | 2684 HBasicBlock* next_test_block = graph()->CreateBasicBlock(); |
| 2683 compare->SetSuccessorAt(0, body_block); | 2685 compare->SetSuccessorAt(0, body_block); |
| 2684 compare->SetSuccessorAt(1, next_test_block); | 2686 compare->SetSuccessorAt(1, next_test_block); |
| 2685 current_block()->Finish(compare); | 2687 current_block()->Finish(compare); |
| 2686 set_current_block(next_test_block); | 2688 set_current_block(next_test_block); |
| 2687 } | 2689 } |
| 2688 | 2690 |
| 2689 // Save the current block to use for the default or to join with the | 2691 // Save the current block to use for the default or to join with the |
| (...skipping 3059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5749 result->set_position(expr->position()); | 5751 result->set_position(expr->position()); |
| 5750 return ast_context()->ReturnControl(result, expr->id()); | 5752 return ast_context()->ReturnControl(result, expr->id()); |
| 5751 } else { | 5753 } else { |
| 5752 Representation r = ToRepresentation(type_info); | 5754 Representation r = ToRepresentation(type_info); |
| 5753 if (r.IsTagged()) { | 5755 if (r.IsTagged()) { |
| 5754 HCompareGeneric* result = | 5756 HCompareGeneric* result = |
| 5755 new(zone()) HCompareGeneric(context, left, right, op); | 5757 new(zone()) HCompareGeneric(context, left, right, op); |
| 5756 result->set_position(expr->position()); | 5758 result->set_position(expr->position()); |
| 5757 return ast_context()->ReturnInstruction(result, expr->id()); | 5759 return ast_context()->ReturnInstruction(result, expr->id()); |
| 5758 } else { | 5760 } else { |
| 5759 HCompareIDAndBranch* result = | 5761 HCompareNumbersAndBranch* result = |
| 5760 new(zone()) HCompareIDAndBranch(left, right, op); | 5762 new(zone()) HCompareNumbersAndBranch(left, right, op); |
| 5761 result->set_position(expr->position()); | 5763 result->set_position(expr->position()); |
| 5762 result->SetInputRepresentation(r); | 5764 result->SetInputRepresentation(r); |
| 5763 return ast_context()->ReturnControl(result, expr->id()); | 5765 return ast_context()->ReturnControl(result, expr->id()); |
| 5764 } | 5766 } |
| 5765 } | 5767 } |
| 5766 } | 5768 } |
| 5767 | 5769 |
| 5768 | 5770 |
| 5769 void HGraphBuilder::VisitCompareToNull(CompareToNull* expr) { | 5771 void HGraphBuilder::VisitCompareToNull(CompareToNull* expr) { |
| 5770 ASSERT(!HasStackOverflow()); | 5772 ASSERT(!HasStackOverflow()); |
| (...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6731 } | 6733 } |
| 6732 } | 6734 } |
| 6733 | 6735 |
| 6734 #ifdef DEBUG | 6736 #ifdef DEBUG |
| 6735 if (graph_ != NULL) graph_->Verify(); | 6737 if (graph_ != NULL) graph_->Verify(); |
| 6736 if (allocator_ != NULL) allocator_->Verify(); | 6738 if (allocator_ != NULL) allocator_->Verify(); |
| 6737 #endif | 6739 #endif |
| 6738 } | 6740 } |
| 6739 | 6741 |
| 6740 } } // namespace v8::internal | 6742 } } // namespace v8::internal |
| OLD | NEW |