Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: runtime/vm/constant_propagator.cc

Issue 2074533002: Simplify and improve optimization of is-tests in the precompiler. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1496 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 // Remove uses from branch and all the empty blocks that 1507 // Remove uses from branch and all the empty blocks that
1508 // are now unreachable. 1508 // are now unreachable.
1509 branch->UnuseAllInputs(); 1509 branch->UnuseAllInputs();
1510 for (BitVector::Iterator it(empty_blocks); !it.Done(); it.Advance()) { 1510 for (BitVector::Iterator it(empty_blocks); !it.Done(); it.Advance()) {
1511 BlockEntryInstr* empty_block = graph_->preorder()[it.Current()]; 1511 BlockEntryInstr* empty_block = graph_->preorder()[it.Current()];
1512 empty_block->ClearAllInstructions(); 1512 empty_block->ClearAllInstructions();
1513 } 1513 }
1514 1514
1515 changed = true; 1515 changed = true;
1516 1516
1517 if (FLAG_trace_constant_propagation) { 1517 if (FLAG_trace_constant_propagation &&
1518 OS::Print("Eliminated branch in B%" Pd " common target B%" Pd "\n", 1518 FlowGraphPrinter::ShouldPrint(graph_->function())) {
1519 THR_Print("Eliminated branch in B%" Pd " common target B%" Pd "\n",
1519 block->block_id(), join->block_id()); 1520 block->block_id(), join->block_id());
1520 } 1521 }
1521 } 1522 }
1522 } 1523 }
1523 } 1524 }
1524 } 1525 }
1525 1526
1526 if (changed) { 1527 if (changed) {
1527 graph_->DiscoverBlocks(); 1528 graph_->DiscoverBlocks();
1528 // TODO(fschneider): Update dominator tree in place instead of recomputing. 1529 // TODO(fschneider): Update dominator tree in place instead of recomputing.
1529 GrowableArray<BitVector*> dominance_frontier; 1530 GrowableArray<BitVector*> dominance_frontier;
1530 graph_->ComputeDominators(&dominance_frontier); 1531 graph_->ComputeDominators(&dominance_frontier);
1531 } 1532 }
1532 } 1533 }
1533 1534
1534 1535
1535 void ConstantPropagator::Transform() { 1536 void ConstantPropagator::Transform() {
1536 if (FLAG_trace_constant_propagation) { 1537 if (FLAG_trace_constant_propagation &&
1538 FlowGraphPrinter::ShouldPrint(graph_->function())) {
1537 FlowGraphPrinter::PrintGraph("Before CP", graph_); 1539 FlowGraphPrinter::PrintGraph("Before CP", graph_);
1538 } 1540 }
1539 1541
1540 // We will recompute dominators, block ordering, block ids, block last 1542 // We will recompute dominators, block ordering, block ids, block last
1541 // instructions, previous pointers, predecessors, etc. after eliminating 1543 // instructions, previous pointers, predecessors, etc. after eliminating
1542 // unreachable code. We do not maintain those properties during the 1544 // unreachable code. We do not maintain those properties during the
1543 // transformation. 1545 // transformation.
1544 for (BlockIterator b = graph_->reverse_postorder_iterator(); 1546 for (BlockIterator b = graph_->reverse_postorder_iterator();
1545 !b.Done(); 1547 !b.Done();
1546 b.Advance()) { 1548 b.Advance()) {
1547 BlockEntryInstr* block = b.Current(); 1549 BlockEntryInstr* block = b.Current();
1548 if (!reachable_->Contains(block->preorder_number())) { 1550 if (!reachable_->Contains(block->preorder_number())) {
1549 if (FLAG_trace_constant_propagation) { 1551 if (FLAG_trace_constant_propagation &&
1550 OS::Print("Unreachable B%" Pd "\n", block->block_id()); 1552 FlowGraphPrinter::ShouldPrint(graph_->function())) {
1553 THR_Print("Unreachable B%" Pd "\n", block->block_id());
1551 } 1554 }
1552 // Remove all uses in unreachable blocks. 1555 // Remove all uses in unreachable blocks.
1553 block->ClearAllInstructions(); 1556 block->ClearAllInstructions();
1554 continue; 1557 continue;
1555 } 1558 }
1556 1559
1557 JoinEntryInstr* join = block->AsJoinEntry(); 1560 JoinEntryInstr* join = block->AsJoinEntry();
1558 if (join != NULL) { 1561 if (join != NULL) {
1559 // Remove phi inputs corresponding to unreachable predecessor blocks. 1562 // Remove phi inputs corresponding to unreachable predecessor blocks.
1560 // Predecessors will be recomputed (in block id order) after removing 1563 // Predecessors will be recomputed (in block id order) after removing
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 // effects. Do this for smis only to avoid having to copy other 1614 // effects. Do this for smis only to avoid having to copy other
1612 // objects into the heap's old generation. 1615 // objects into the heap's old generation.
1613 if ((defn != NULL) && 1616 if ((defn != NULL) &&
1614 IsConstant(defn->constant_value()) && 1617 IsConstant(defn->constant_value()) &&
1615 (defn->constant_value().IsSmi() || defn->constant_value().IsOld()) && 1618 (defn->constant_value().IsSmi() || defn->constant_value().IsOld()) &&
1616 !defn->IsConstant() && 1619 !defn->IsConstant() &&
1617 !defn->IsPushArgument() && 1620 !defn->IsPushArgument() &&
1618 !defn->IsStoreIndexed() && 1621 !defn->IsStoreIndexed() &&
1619 !defn->IsStoreInstanceField() && 1622 !defn->IsStoreInstanceField() &&
1620 !defn->IsStoreStaticField()) { 1623 !defn->IsStoreStaticField()) {
1621 if (FLAG_trace_constant_propagation) { 1624 if (FLAG_trace_constant_propagation &&
1622 OS::Print("Constant v%" Pd " = %s\n", 1625 FlowGraphPrinter::ShouldPrint(graph_->function())) {
1626 THR_Print("Constant v%" Pd " = %s\n",
1623 defn->ssa_temp_index(), 1627 defn->ssa_temp_index(),
1624 defn->constant_value().ToCString()); 1628 defn->constant_value().ToCString());
1625 } 1629 }
1626 ConstantInstr* constant = graph_->GetConstant(defn->constant_value()); 1630 ConstantInstr* constant = graph_->GetConstant(defn->constant_value());
1627 defn->ReplaceUsesWith(constant); 1631 defn->ReplaceUsesWith(constant);
1628 i.RemoveCurrentFromGraph(); 1632 i.RemoveCurrentFromGraph();
1629 } 1633 }
1630 } 1634 }
1631 1635
1632 // Replace branches where one target is unreachable with jumps. 1636 // Replace branches where one target is unreachable with jumps.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1674 branch->UnuseAllInputs(); 1678 branch->UnuseAllInputs();
1675 } 1679 }
1676 } 1680 }
1677 } 1681 }
1678 1682
1679 graph_->DiscoverBlocks(); 1683 graph_->DiscoverBlocks();
1680 graph_->MergeBlocks(); 1684 graph_->MergeBlocks();
1681 GrowableArray<BitVector*> dominance_frontier; 1685 GrowableArray<BitVector*> dominance_frontier;
1682 graph_->ComputeDominators(&dominance_frontier); 1686 graph_->ComputeDominators(&dominance_frontier);
1683 1687
1684 if (FLAG_trace_constant_propagation) { 1688 if (FLAG_trace_constant_propagation &&
1689 FlowGraphPrinter::ShouldPrint(graph_->function())) {
1685 FlowGraphPrinter::PrintGraph("After CP", graph_); 1690 FlowGraphPrinter::PrintGraph("After CP", graph_);
1686 } 1691 }
1687 } 1692 }
1688 1693
1689 } // namespace dart 1694 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698