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 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 worklist->Add(use); | 972 worklist->Add(use); |
973 } | 973 } |
974 } | 974 } |
975 } | 975 } |
976 } | 976 } |
977 } | 977 } |
978 | 978 |
979 | 979 |
980 class HRangeAnalysis BASE_EMBEDDED { | 980 class HRangeAnalysis BASE_EMBEDDED { |
981 public: | 981 public: |
982 explicit HRangeAnalysis(HGraph* graph) : graph_(graph), changed_ranges_(16) {} | 982 explicit HRangeAnalysis(HGraph* graph) : |
| 983 graph_(graph), zone_(graph->isolate()->zone()), changed_ranges_(16) { } |
983 | 984 |
984 void Analyze(); | 985 void Analyze(); |
985 | 986 |
986 private: | 987 private: |
987 void TraceRange(const char* msg, ...); | 988 void TraceRange(const char* msg, ...); |
988 void Analyze(HBasicBlock* block); | 989 void Analyze(HBasicBlock* block); |
989 void InferControlFlowRange(HCompareIDAndBranch* test, HBasicBlock* dest); | 990 void InferControlFlowRange(HCompareIDAndBranch* test, HBasicBlock* dest); |
990 void UpdateControlFlowRange(Token::Value op, HValue* value, HValue* other); | 991 void UpdateControlFlowRange(Token::Value op, HValue* value, HValue* other); |
991 void InferRange(HValue* value); | 992 void InferRange(HValue* value); |
992 void RollBackTo(int index); | 993 void RollBackTo(int index); |
993 void AddRange(HValue* value, Range* range); | 994 void AddRange(HValue* value, Range* range); |
994 | 995 |
995 HGraph* graph_; | 996 HGraph* graph_; |
| 997 Zone* zone_; |
996 ZoneList<HValue*> changed_ranges_; | 998 ZoneList<HValue*> changed_ranges_; |
997 }; | 999 }; |
998 | 1000 |
999 | 1001 |
1000 void HRangeAnalysis::TraceRange(const char* msg, ...) { | 1002 void HRangeAnalysis::TraceRange(const char* msg, ...) { |
1001 if (FLAG_trace_range) { | 1003 if (FLAG_trace_range) { |
1002 va_list arguments; | 1004 va_list arguments; |
1003 va_start(arguments, msg); | 1005 va_start(arguments, msg); |
1004 OS::VPrint(msg, arguments); | 1006 OS::VPrint(msg, arguments); |
1005 va_end(arguments); | 1007 va_end(arguments); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 Range* range = other->range() != NULL ? other->range() : &temp_range; | 1074 Range* range = other->range() != NULL ? other->range() : &temp_range; |
1073 Range* new_range = NULL; | 1075 Range* new_range = NULL; |
1074 | 1076 |
1075 TraceRange("Control flow range infer %d %s %d\n", | 1077 TraceRange("Control flow range infer %d %s %d\n", |
1076 value->id(), | 1078 value->id(), |
1077 Token::Name(op), | 1079 Token::Name(op), |
1078 other->id()); | 1080 other->id()); |
1079 | 1081 |
1080 if (op == Token::EQ || op == Token::EQ_STRICT) { | 1082 if (op == Token::EQ || op == Token::EQ_STRICT) { |
1081 // The same range has to apply for value. | 1083 // The same range has to apply for value. |
1082 new_range = range->Copy(); | 1084 new_range = range->Copy(zone_); |
1083 } else if (op == Token::LT || op == Token::LTE) { | 1085 } else if (op == Token::LT || op == Token::LTE) { |
1084 new_range = range->CopyClearLower(); | 1086 new_range = range->CopyClearLower(zone_); |
1085 if (op == Token::LT) { | 1087 if (op == Token::LT) { |
1086 new_range->AddConstant(-1); | 1088 new_range->AddConstant(-1); |
1087 } | 1089 } |
1088 } else if (op == Token::GT || op == Token::GTE) { | 1090 } else if (op == Token::GT || op == Token::GTE) { |
1089 new_range = range->CopyClearUpper(); | 1091 new_range = range->CopyClearUpper(zone_); |
1090 if (op == Token::GT) { | 1092 if (op == Token::GT) { |
1091 new_range->AddConstant(1); | 1093 new_range->AddConstant(1); |
1092 } | 1094 } |
1093 } | 1095 } |
1094 | 1096 |
1095 if (new_range != NULL && !new_range->IsMostGeneric()) { | 1097 if (new_range != NULL && !new_range->IsMostGeneric()) { |
1096 AddRange(value, new_range); | 1098 AddRange(value, new_range); |
1097 } | 1099 } |
1098 } | 1100 } |
1099 | 1101 |
1100 | 1102 |
1101 void HRangeAnalysis::InferRange(HValue* value) { | 1103 void HRangeAnalysis::InferRange(HValue* value) { |
1102 ASSERT(!value->HasRange()); | 1104 ASSERT(!value->HasRange()); |
1103 if (!value->representation().IsNone()) { | 1105 if (!value->representation().IsNone()) { |
1104 value->ComputeInitialRange(); | 1106 value->ComputeInitialRange(zone_); |
1105 Range* range = value->range(); | 1107 Range* range = value->range(); |
1106 TraceRange("Initial inferred range of %d (%s) set to [%d,%d]\n", | 1108 TraceRange("Initial inferred range of %d (%s) set to [%d,%d]\n", |
1107 value->id(), | 1109 value->id(), |
1108 value->Mnemonic(), | 1110 value->Mnemonic(), |
1109 range->lower(), | 1111 range->lower(), |
1110 range->upper()); | 1112 range->upper()); |
1111 } | 1113 } |
1112 } | 1114 } |
1113 | 1115 |
1114 | 1116 |
1115 void HRangeAnalysis::RollBackTo(int index) { | 1117 void HRangeAnalysis::RollBackTo(int index) { |
1116 for (int i = index + 1; i < changed_ranges_.length(); ++i) { | 1118 for (int i = index + 1; i < changed_ranges_.length(); ++i) { |
1117 changed_ranges_[i]->RemoveLastAddedRange(); | 1119 changed_ranges_[i]->RemoveLastAddedRange(); |
1118 } | 1120 } |
1119 changed_ranges_.Rewind(index + 1); | 1121 changed_ranges_.Rewind(index + 1); |
1120 } | 1122 } |
1121 | 1123 |
1122 | 1124 |
1123 void HRangeAnalysis::AddRange(HValue* value, Range* range) { | 1125 void HRangeAnalysis::AddRange(HValue* value, Range* range) { |
1124 Range* original_range = value->range(); | 1126 Range* original_range = value->range(); |
1125 value->AddNewRange(range); | 1127 value->AddNewRange(range, zone_); |
1126 changed_ranges_.Add(value); | 1128 changed_ranges_.Add(value); |
1127 Range* new_range = value->range(); | 1129 Range* new_range = value->range(); |
1128 TraceRange("Updated range of %d set to [%d,%d]\n", | 1130 TraceRange("Updated range of %d set to [%d,%d]\n", |
1129 value->id(), | 1131 value->id(), |
1130 new_range->lower(), | 1132 new_range->lower(), |
1131 new_range->upper()); | 1133 new_range->upper()); |
1132 if (original_range != NULL) { | 1134 if (original_range != NULL) { |
1133 TraceRange("Original range was [%d,%d]\n", | 1135 TraceRange("Original range was [%d,%d]\n", |
1134 original_range->lower(), | 1136 original_range->lower(), |
1135 original_range->upper()); | 1137 original_range->upper()); |
(...skipping 6883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8019 } | 8021 } |
8020 } | 8022 } |
8021 | 8023 |
8022 #ifdef DEBUG | 8024 #ifdef DEBUG |
8023 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 8025 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
8024 if (allocator_ != NULL) allocator_->Verify(); | 8026 if (allocator_ != NULL) allocator_->Verify(); |
8025 #endif | 8027 #endif |
8026 } | 8028 } |
8027 | 8029 |
8028 } } // namespace v8::internal | 8030 } } // namespace v8::internal |
OLD | NEW |