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/constant_propagator.h" | 5 #include "vm/constant_propagator.h" |
| 6 | 6 |
| 7 #include "vm/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/flow_graph_compiler.h" | 9 #include "vm/flow_graph_compiler.h" |
| 10 #include "vm/flow_graph_range_analysis.h" | 10 #include "vm/flow_graph_range_analysis.h" |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 424 } else if (IsConstant(value)) { | 424 } else if (IsConstant(value)) { |
| 425 ASSERT(!value.IsNull()); | 425 ASSERT(!value.IsNull()); |
| 426 ASSERT(value.IsBool()); | 426 ASSERT(value.IsBool()); |
| 427 bool result = Bool::Cast(value).value(); | 427 bool result = Bool::Cast(value).value(); |
| 428 SetValue(instr, Smi::Handle(Z, Smi::New(result ? instr->if_true() | 428 SetValue(instr, Smi::Handle(Z, Smi::New(result ? instr->if_true() |
| 429 : instr->if_false()))); | 429 : instr->if_false()))); |
| 430 } | 430 } |
| 431 } | 431 } |
| 432 | 432 |
| 433 | 433 |
| 434 void ConstantPropagator::VisitSmiRangeComparison( | |
| 435 SmiRangeComparisonInstr* instr) { | |
| 436 Definition* defn = instr->input()->definition(); | |
| 437 const Object& value = defn->constant_value(); | |
| 438 if (IsConstant(value)) { | |
| 439 ASSERT(value.IsSmi()); | |
| 440 intptr_t number = Smi::Cast(value).Value(); | |
| 441 if (number < instr->from() || instr->to() < number) { | |
|
Vyacheslav Egorov (Google)
2017/06/28 13:53:47
maybe better:
bool result = instr->from() <= numb
erikcorry
2017/07/03 08:59:55
Done, but with <= because to() is inclusive.
| |
| 442 SetValue(instr, Bool::Get(instr->is_negated())); | |
| 443 } else { | |
| 444 SetValue(instr, Bool::Get(!instr->is_negated())); | |
| 445 } | |
| 446 } else if (IsNonConstant(value)) { | |
| 447 SetValue(instr, non_constant_); | |
| 448 } | |
| 449 } | |
| 450 | |
| 451 | |
| 434 void ConstantPropagator::VisitStrictCompare(StrictCompareInstr* instr) { | 452 void ConstantPropagator::VisitStrictCompare(StrictCompareInstr* instr) { |
| 435 Definition* left_defn = instr->left()->definition(); | 453 Definition* left_defn = instr->left()->definition(); |
| 436 Definition* right_defn = instr->right()->definition(); | 454 Definition* right_defn = instr->right()->definition(); |
| 437 | 455 |
| 438 Definition* unwrapped_left_defn = UnwrapPhi(left_defn); | 456 Definition* unwrapped_left_defn = UnwrapPhi(left_defn); |
| 439 Definition* unwrapped_right_defn = UnwrapPhi(right_defn); | 457 Definition* unwrapped_right_defn = UnwrapPhi(right_defn); |
| 440 if (unwrapped_left_defn == unwrapped_right_defn) { | 458 if (unwrapped_left_defn == unwrapped_right_defn) { |
| 441 // Fold x === x, and x !== x to true/false. | 459 // Fold x === x, and x !== x to true/false. |
| 442 SetValue(instr, Bool::Get(instr->kind() == Token::kEQ_STRICT)); | 460 SetValue(instr, Bool::Get(instr->kind() == Token::kEQ_STRICT)); |
| 443 if (unwrapped_left_defn != left_defn) { | 461 if (unwrapped_left_defn != left_defn) { |
| (...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1734 GrowableArray<BitVector*> dominance_frontier; | 1752 GrowableArray<BitVector*> dominance_frontier; |
| 1735 graph_->ComputeDominators(&dominance_frontier); | 1753 graph_->ComputeDominators(&dominance_frontier); |
| 1736 | 1754 |
| 1737 if (FLAG_trace_constant_propagation && | 1755 if (FLAG_trace_constant_propagation && |
| 1738 FlowGraphPrinter::ShouldPrint(graph_->function())) { | 1756 FlowGraphPrinter::ShouldPrint(graph_->function())) { |
| 1739 FlowGraphPrinter::PrintGraph("After CP", graph_); | 1757 FlowGraphPrinter::PrintGraph("After CP", graph_); |
| 1740 } | 1758 } |
| 1741 } | 1759 } |
| 1742 | 1760 |
| 1743 } // namespace dart | 1761 } // namespace dart |
| OLD | NEW |