Chromium Code Reviews| 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/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 2092 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2103 comp->set_receiver_class_id(kSmiCid); | 2103 comp->set_receiver_class_id(kSmiCid); |
| 2104 } | 2104 } |
| 2105 } | 2105 } |
| 2106 | 2106 |
| 2107 | 2107 |
| 2108 void FlowGraphOptimizer::VisitEqualityCompare(EqualityCompareInstr* instr) { | 2108 void FlowGraphOptimizer::VisitEqualityCompare(EqualityCompareInstr* instr) { |
| 2109 HandleEqualityCompare(instr, instr); | 2109 HandleEqualityCompare(instr, instr); |
| 2110 } | 2110 } |
| 2111 | 2111 |
| 2112 | 2112 |
| 2113 | |
| 2114 // Check if this StrictCompare can be merged with its input: | |
| 2115 // x = (a === b); y = (x !== true) -> y = a !== b. | |
| 2116 // This is a common occurence for !identical(a, b). | |
| 2117 void FlowGraphOptimizer::HandleStrictCompare(StrictCompareInstr* comp, | |
| 2118 BranchInstr* instr) { | |
| 2119 if ((comp->kind() != Token::kNE_STRICT) || | |
| 2120 !comp->right()->BindsToConstant() || | |
| 2121 (comp->right()->BoundConstant().raw() != Bool::True().raw())) { | |
| 2122 return; | |
| 2123 } | |
| 2124 StrictCompareInstr* left = comp->left()->definition()->AsStrictCompare(); | |
| 2125 if (left == NULL) { | |
| 2126 return; | |
| 2127 } | |
| 2128 Token::Kind reverted_kind = (left->kind() == Token::kNE_STRICT) ? | |
| 2129 Token::kEQ_STRICT : Token::kNE_STRICT; | |
|
Kevin Millikin (Google)
2013/03/25 09:58:08
We should probably have a generic way to do this,
srdjan
2013/03/25 21:12:11
Extended NegateComparison and moved that functiona
| |
| 2130 StrictCompareInstr* reverted_comp = | |
| 2131 new StrictCompareInstr(reverted_kind, | |
| 2132 left->left()->Copy(), | |
| 2133 left->right()->Copy()); | |
| 2134 instr->ReplaceWith(reverted_comp, current_iterator()); | |
|
Kevin Millikin (Google)
2013/03/25 09:58:08
I still think it's nuts that BranchInstr::ReplaceW
srdjan
2013/03/25 21:12:11
Done.
| |
| 2135 left->RemoveFromGraph(); | |
|
Kevin Millikin (Google)
2013/03/25 09:58:08
You can't remove this if it has uses, even environ
srdjan
2013/03/25 21:12:11
Thanks. Adding tests to catch that. Would it be us
| |
| 2136 } | |
| 2137 | |
| 2138 | |
| 2113 void FlowGraphOptimizer::VisitBranch(BranchInstr* instr) { | 2139 void FlowGraphOptimizer::VisitBranch(BranchInstr* instr) { |
| 2114 ComparisonInstr* comparison = instr->comparison(); | 2140 ComparisonInstr* comparison = instr->comparison(); |
| 2115 if (comparison->IsRelationalOp()) { | 2141 if (comparison->IsRelationalOp()) { |
| 2116 HandleRelationalOp(comparison->AsRelationalOp()); | 2142 HandleRelationalOp(comparison->AsRelationalOp()); |
| 2117 } else if (comparison->IsEqualityCompare()) { | 2143 } else if (comparison->IsEqualityCompare()) { |
| 2118 HandleEqualityCompare(comparison->AsEqualityCompare(), instr); | 2144 HandleEqualityCompare(comparison->AsEqualityCompare(), instr); |
| 2119 } else { | 2145 } else { |
| 2120 ASSERT(comparison->IsStrictCompare()); | 2146 ASSERT(comparison->IsStrictCompare()); |
| 2121 // Nothing to do. | 2147 HandleStrictCompare(comparison->AsStrictCompare(), instr); |
|
Kevin Millikin (Google)
2013/03/25 09:58:08
I feel that this belongs better in the canonicaliz
srdjan
2013/03/25 21:12:11
I agree, moved.
| |
| 2122 } | 2148 } |
| 2123 } | 2149 } |
| 2124 | 2150 |
| 2125 | 2151 |
| 2126 static bool MayBeBoxableNumber(intptr_t cid) { | 2152 static bool MayBeBoxableNumber(intptr_t cid) { |
| 2127 return (cid == kDynamicCid) || | 2153 return (cid == kDynamicCid) || |
| 2128 (cid == kMintCid) || | 2154 (cid == kMintCid) || |
| 2129 (cid == kBigintCid) || | 2155 (cid == kBigintCid) || |
| 2130 (cid == kDoubleCid); | 2156 (cid == kDoubleCid); |
| 2131 } | 2157 } |
| (...skipping 2495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4627 if (changed) { | 4653 if (changed) { |
| 4628 // We may have changed the block order and the dominator tree. | 4654 // We may have changed the block order and the dominator tree. |
| 4629 flow_graph->DiscoverBlocks(); | 4655 flow_graph->DiscoverBlocks(); |
| 4630 GrowableArray<BitVector*> dominance_frontier; | 4656 GrowableArray<BitVector*> dominance_frontier; |
| 4631 flow_graph->ComputeDominators(&dominance_frontier); | 4657 flow_graph->ComputeDominators(&dominance_frontier); |
| 4632 } | 4658 } |
| 4633 } | 4659 } |
| 4634 | 4660 |
| 4635 | 4661 |
| 4636 } // namespace dart | 4662 } // namespace dart |
| OLD | NEW |