| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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/flow_graph_optimizer.h" | 5 #include "vm/flow_graph_optimizer.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| (...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 RemovePushArguments(instr); | 1244 RemovePushArguments(instr); |
| 1245 return true; | 1245 return true; |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 | 1248 |
| 1249 // TODO(fschneider): Once we get rid of the distinction between Instruction | 1249 // TODO(fschneider): Once we get rid of the distinction between Instruction |
| 1250 // and computation, this helper can go away. | 1250 // and computation, this helper can go away. |
| 1251 static void HandleRelationalOp(FlowGraphOptimizer* optimizer, | 1251 static void HandleRelationalOp(FlowGraphOptimizer* optimizer, |
| 1252 RelationalOpInstr* comp, | 1252 RelationalOpInstr* comp, |
| 1253 Instruction* instr) { | 1253 Instruction* instr) { |
| 1254 if (!comp->HasICData()) return; | 1254 if (!comp->HasICData() || (comp->ic_data()->NumberOfChecks() == 0)) { |
| 1255 | 1255 return; |
| 1256 } |
| 1256 const ICData& ic_data = *comp->ic_data(); | 1257 const ICData& ic_data = *comp->ic_data(); |
| 1257 if (ic_data.NumberOfChecks() == 0) return; | 1258 if (ic_data.NumberOfChecks() == 1) { |
| 1258 // TODO(srdjan): Add multiple receiver type support. | 1259 ASSERT(ic_data.HasOneTarget()); |
| 1259 if (ic_data.NumberOfChecks() != 1) return; | 1260 if (HasOnlyTwoSmis(ic_data)) { |
| 1260 ASSERT(ic_data.HasOneTarget()); | 1261 optimizer->InsertBefore( |
| 1261 | 1262 instr, |
| 1262 if (HasOnlyTwoSmis(ic_data)) { | 1263 new CheckSmiInstr(comp->left()->Copy(), comp->deopt_id()), |
| 1263 optimizer->InsertBefore( | 1264 instr->env(), |
| 1264 instr, | 1265 Definition::kEffect); |
| 1265 new CheckSmiInstr(comp->left()->Copy(), comp->deopt_id()), | 1266 optimizer->InsertBefore( |
| 1266 instr->env(), | 1267 instr, |
| 1267 Definition::kEffect); | 1268 new CheckSmiInstr(comp->right()->Copy(), comp->deopt_id()), |
| 1268 optimizer->InsertBefore( | 1269 instr->env(), |
| 1269 instr, | 1270 Definition::kEffect); |
| 1270 new CheckSmiInstr(comp->right()->Copy(), comp->deopt_id()), | 1271 comp->set_operands_class_id(kSmiCid); |
| 1271 instr->env(), | 1272 } else if (ShouldSpecializeForDouble(ic_data)) { |
| 1272 Definition::kEffect); | 1273 comp->set_operands_class_id(kDoubleCid); |
| 1273 comp->set_operands_class_id(kSmiCid); | 1274 } else if (HasTwoMintOrSmi(*comp->ic_data()) && |
| 1274 } else if (ShouldSpecializeForDouble(ic_data)) { | 1275 FlowGraphCompiler::SupportsUnboxedMints()) { |
| 1275 comp->set_operands_class_id(kDoubleCid); | 1276 comp->set_operands_class_id(kMintCid); |
| 1276 } else if (comp->ic_data()->AllReceiversAreNumbers()) { | 1277 } else { |
| 1277 comp->set_operands_class_id(kNumberCid); | 1278 ASSERT(comp->operands_class_id() == kIllegalCid); |
| 1279 } |
| 1280 } else if (HasTwoMintOrSmi(*comp->ic_data()) && |
| 1281 FlowGraphCompiler::SupportsUnboxedMints()) { |
| 1282 comp->set_operands_class_id(kMintCid); |
| 1278 } | 1283 } |
| 1279 } | 1284 } |
| 1280 | 1285 |
| 1286 |
| 1281 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpInstr* instr) { | 1287 void FlowGraphOptimizer::VisitRelationalOp(RelationalOpInstr* instr) { |
| 1282 HandleRelationalOp(this, instr, instr); | 1288 HandleRelationalOp(this, instr, instr); |
| 1283 } | 1289 } |
| 1284 | 1290 |
| 1285 | 1291 |
| 1286 // TODO(fschneider): Once we get rid of the distinction between Instruction | 1292 // TODO(fschneider): Once we get rid of the distinction between Instruction |
| 1287 // and computation, this helper can go away. | 1293 // and computation, this helper can go away. |
| 1288 template <typename T> | 1294 template <typename T> |
| 1289 static void HandleEqualityCompare(FlowGraphOptimizer* optimizer, | 1295 static void HandleEqualityCompare(FlowGraphOptimizer* optimizer, |
| 1290 EqualityCompareInstr* comp, | 1296 EqualityCompareInstr* comp, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 comp->set_receiver_class_id(kDoubleCid); | 1332 comp->set_receiver_class_id(kDoubleCid); |
| 1327 } else if (HasTwoMintOrSmi(*comp->ic_data()) && | 1333 } else if (HasTwoMintOrSmi(*comp->ic_data()) && |
| 1328 FlowGraphCompiler::SupportsUnboxedMints()) { | 1334 FlowGraphCompiler::SupportsUnboxedMints()) { |
| 1329 comp->set_receiver_class_id(kMintCid); | 1335 comp->set_receiver_class_id(kMintCid); |
| 1330 } else { | 1336 } else { |
| 1331 ASSERT(comp->receiver_class_id() == kIllegalCid); | 1337 ASSERT(comp->receiver_class_id() == kIllegalCid); |
| 1332 } | 1338 } |
| 1333 } else if (HasTwoMintOrSmi(*comp->ic_data()) && | 1339 } else if (HasTwoMintOrSmi(*comp->ic_data()) && |
| 1334 FlowGraphCompiler::SupportsUnboxedMints()) { | 1340 FlowGraphCompiler::SupportsUnboxedMints()) { |
| 1335 comp->set_receiver_class_id(kMintCid); | 1341 comp->set_receiver_class_id(kMintCid); |
| 1336 } else if (comp->ic_data()->AllReceiversAreNumbers()) { | |
| 1337 comp->set_receiver_class_id(kNumberCid); | |
| 1338 } | 1342 } |
| 1339 | 1343 |
| 1340 if (comp->receiver_class_id() != kIllegalCid) { | 1344 if (comp->receiver_class_id() != kIllegalCid) { |
| 1341 // Done. | 1345 // Done. |
| 1342 return; | 1346 return; |
| 1343 } | 1347 } |
| 1344 | 1348 |
| 1345 // Check if ICDData contains checks with Smi/Null combinations. In that case | 1349 // Check if ICDData contains checks with Smi/Null combinations. In that case |
| 1346 // we can still emit the optimized Smi equality operation but need to add | 1350 // we can still emit the optimized Smi equality operation but need to add |
| 1347 // checks for null or Smi. | 1351 // checks for null or Smi. |
| (...skipping 2175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3523 | 3527 |
| 3524 if (FLAG_trace_constant_propagation) { | 3528 if (FLAG_trace_constant_propagation) { |
| 3525 OS::Print("\n==== After constant propagation ====\n"); | 3529 OS::Print("\n==== After constant propagation ====\n"); |
| 3526 FlowGraphPrinter printer(*graph_); | 3530 FlowGraphPrinter printer(*graph_); |
| 3527 printer.PrintBlocks(); | 3531 printer.PrintBlocks(); |
| 3528 } | 3532 } |
| 3529 } | 3533 } |
| 3530 | 3534 |
| 3531 | 3535 |
| 3532 } // namespace dart | 3536 } // namespace dart |
| OLD | NEW |