OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_XXX. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_XXX. |
6 | 6 |
7 #include "vm/flow_graph_compiler.h" | 7 #include "vm/flow_graph_compiler.h" |
8 | 8 |
9 #include "vm/cha.h" | 9 #include "vm/cha.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 const AbstractTypeArguments& type_arguments = | 1118 const AbstractTypeArguments& type_arguments = |
1119 AbstractTypeArguments::Handle(type.arguments()); | 1119 AbstractTypeArguments::Handle(type.arguments()); |
1120 const bool is_raw_type = type_arguments.IsNull() || | 1120 const bool is_raw_type = type_arguments.IsNull() || |
1121 type_arguments.IsRaw(type_arguments.Length()); | 1121 type_arguments.IsRaw(type_arguments.Length()); |
1122 return is_raw_type; | 1122 return is_raw_type; |
1123 } | 1123 } |
1124 return true; | 1124 return true; |
1125 } | 1125 } |
1126 | 1126 |
1127 | 1127 |
| 1128 static int HighestCountFirst(const CidTarget* a, const CidTarget* b) { |
| 1129 // Negative if 'a' should sort before 'b'. |
| 1130 return b->count - a->count; |
| 1131 } |
| 1132 |
| 1133 |
1128 // Returns 'sorted' array in decreasing count order. | 1134 // Returns 'sorted' array in decreasing count order. |
1129 // The expected number of elements to sort is less than 10. | 1135 // The expected number of elements to sort is less than 10. |
1130 void FlowGraphCompiler::SortICDataByCount(const ICData& ic_data, | 1136 void FlowGraphCompiler::SortICDataByCount(const ICData& ic_data, |
1131 GrowableArray<CidTarget>* sorted) { | 1137 GrowableArray<CidTarget>* sorted) { |
1132 ASSERT(ic_data.num_args_tested() == 1); | 1138 ASSERT(ic_data.num_args_tested() == 1); |
1133 const intptr_t len = ic_data.NumberOfChecks(); | 1139 const intptr_t len = ic_data.NumberOfChecks(); |
1134 sorted->Clear(); | 1140 sorted->Clear(); |
1135 | 1141 |
1136 for (int i = 0; i < len; i++) { | 1142 for (int i = 0; i < len; i++) { |
1137 sorted->Add(CidTarget(ic_data.GetReceiverClassIdAt(i), | 1143 sorted->Add(CidTarget(ic_data.GetReceiverClassIdAt(i), |
1138 &Function::ZoneHandle(ic_data.GetTargetAt(i)), | 1144 &Function::ZoneHandle(ic_data.GetTargetAt(i)), |
1139 ic_data.GetCountAt(i))); | 1145 ic_data.GetCountAt(i))); |
1140 } | 1146 } |
1141 for (int i = 0; i < len; i++) { | 1147 sorted->Sort(HighestCountFirst); |
1142 intptr_t largest_ix = i; | |
1143 for (int k = i + 1; k < len; k++) { | |
1144 if ((*sorted)[largest_ix].count < (*sorted)[k].count) { | |
1145 largest_ix = k; | |
1146 } | |
1147 } | |
1148 if (i != largest_ix) { | |
1149 // Swap. | |
1150 CidTarget temp = (*sorted)[i]; | |
1151 (*sorted)[i] = (*sorted)[largest_ix]; | |
1152 (*sorted)[largest_ix] = temp; | |
1153 } | |
1154 } | |
1155 } | 1148 } |
1156 | 1149 |
1157 } // namespace dart | 1150 } // namespace dart |
OLD | NEW |