OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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/branch_optimizer.h" | 5 #include "vm/branch_optimizer.h" |
6 | 6 |
7 #include "vm/flow_graph.h" | 7 #include "vm/flow_graph.h" |
8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
(...skipping 26 matching lines...) Expand all Loading... |
37 // | 37 // |
38 // Branch(Comparison(kind, Phi, Constant)) | 38 // Branch(Comparison(kind, Phi, Constant)) |
39 // | 39 // |
40 // These are the branches produced by inlining in a test context. Also, | 40 // These are the branches produced by inlining in a test context. Also, |
41 // the phi has no other uses so they can simply be eliminated. The block | 41 // the phi has no other uses so they can simply be eliminated. The block |
42 // has no other phis and no instructions intervening between the phi and | 42 // has no other phis and no instructions intervening between the phi and |
43 // branch so the block can simply be eliminated. | 43 // branch so the block can simply be eliminated. |
44 BranchInstr* branch = block->last_instruction()->AsBranch(); | 44 BranchInstr* branch = block->last_instruction()->AsBranch(); |
45 ASSERT(branch != NULL); | 45 ASSERT(branch != NULL); |
46 ComparisonInstr* comparison = branch->comparison(); | 46 ComparisonInstr* comparison = branch->comparison(); |
| 47 if (comparison->InputCount() != 2) { |
| 48 return false; |
| 49 } |
47 Value* left = comparison->left(); | 50 Value* left = comparison->left(); |
48 PhiInstr* phi = left->definition()->AsPhi(); | 51 PhiInstr* phi = left->definition()->AsPhi(); |
49 Value* right = comparison->right(); | 52 Value* right = comparison->right(); |
50 ConstantInstr* constant = | 53 ConstantInstr* constant = |
51 (right == NULL) ? NULL : right->definition()->AsConstant(); | 54 (right == NULL) ? NULL : right->definition()->AsConstant(); |
52 return (phi != NULL) && | 55 return (phi != NULL) && |
53 (constant != NULL) && | 56 (constant != NULL) && |
54 (phi->GetBlock() == block) && | 57 (phi->GetBlock() == block) && |
55 PhiHasSingleUse(phi, left) && | 58 PhiHasSingleUse(phi, left) && |
56 (block->next() == branch) && | 59 (block->next() == branch) && |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 if (changed) { | 349 if (changed) { |
347 // We may have changed the block order and the dominator tree. | 350 // We may have changed the block order and the dominator tree. |
348 flow_graph->DiscoverBlocks(); | 351 flow_graph->DiscoverBlocks(); |
349 GrowableArray<BitVector*> dominance_frontier; | 352 GrowableArray<BitVector*> dominance_frontier; |
350 flow_graph->ComputeDominators(&dominance_frontier); | 353 flow_graph->ComputeDominators(&dominance_frontier); |
351 } | 354 } |
352 } | 355 } |
353 | 356 |
354 | 357 |
355 } // namespace dart | 358 } // namespace dart |
OLD | NEW |