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

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

Issue 11819031: Add canonicalize optimization for branches. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/intermediate_language.h" 5 #include "vm/intermediate_language.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/dart_entry.h" 8 #include "vm/dart_entry.h"
9 #include "vm/flow_graph_allocator.h" 9 #include "vm/flow_graph_allocator.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
11 #include "vm/flow_graph_compiler.h" 11 #include "vm/flow_graph_compiler.h"
12 #include "vm/flow_graph_optimizer.h" 12 #include "vm/flow_graph_optimizer.h"
13 #include "vm/locations.h" 13 #include "vm/locations.h"
14 #include "vm/object.h" 14 #include "vm/object.h"
15 #include "vm/object_store.h" 15 #include "vm/object_store.h"
16 #include "vm/os.h" 16 #include "vm/os.h"
17 #include "vm/scopes.h" 17 #include "vm/scopes.h"
18 #include "vm/stub_code.h" 18 #include "vm/stub_code.h"
19 #include "vm/symbols.h" 19 #include "vm/symbols.h"
20 20
21 namespace dart { 21 namespace dart {
22 22
23 DEFINE_FLAG(bool, new_identity_spec, true, 23 DEFINE_FLAG(bool, new_identity_spec, true,
24 "Use new identity check rules for numbers."); 24 "Use new identity check rules for numbers.");
25 DEFINE_FLAG(bool, propagate_ic_data, true, 25 DEFINE_FLAG(bool, propagate_ic_data, true,
26 "Propagate IC data from unoptimized to optimized IC calls."); 26 "Propagate IC data from unoptimized to optimized IC calls.");
27 DECLARE_FLAG(bool, enable_type_checks); 27 DECLARE_FLAG(bool, enable_type_checks);
28 DECLARE_FLAG(int, max_polymorphic_checks); 28 DECLARE_FLAG(int, max_polymorphic_checks);
29 DECLARE_FLAG(bool, trace_optimization);
29 30
30 Definition::Definition() 31 Definition::Definition()
31 : range_(NULL), 32 : range_(NULL),
32 temp_index_(-1), 33 temp_index_(-1),
33 ssa_temp_index_(-1), 34 ssa_temp_index_(-1),
34 propagated_type_(AbstractType::Handle()), 35 propagated_type_(AbstractType::Handle()),
35 propagated_cid_(kIllegalCid), 36 propagated_cid_(kIllegalCid),
36 input_use_list_(NULL), 37 input_use_list_(NULL),
37 env_use_list_(NULL), 38 env_use_list_(NULL),
38 use_kind_(kValue), // Phis and parameters rely on this default. 39 use_kind_(kValue), // Phis and parameters rely on this default.
(...skipping 1640 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 // It is ok to insert instructions before the current during 1680 // It is ok to insert instructions before the current during
1680 // forward iteration. 1681 // forward iteration.
1681 optimizer->InsertBefore(this, null_constant, NULL, Definition::kValue); 1682 optimizer->InsertBefore(this, null_constant, NULL, Definition::kValue);
1682 instantiator_type_arguments()->RemoveFromInputUseList(); 1683 instantiator_type_arguments()->RemoveFromInputUseList();
1683 instantiator_type_arguments()->set_definition(null_constant); 1684 instantiator_type_arguments()->set_definition(null_constant);
1684 instantiator_type_arguments()->AddToInputUseList(); 1685 instantiator_type_arguments()->AddToInputUseList();
1685 } 1686 }
1686 return this; 1687 return this;
1687 } 1688 }
1688 1689
1690
1691 Instruction* BranchInstr::Canonicalize(FlowGraphOptimizer* optimizer) {
1692 // Only handle strict-compares.
1693 if (comparison()->IsStrictCompare()) {
1694 Definition* replacement = comparison()->Canonicalize(optimizer);
1695 if (replacement == comparison() || replacement == NULL) return this;
1696 ComparisonInstr* comp = replacement->AsComparison();
1697 if (comp == NULL) return this;
1698
1699 // Replace the comparison if the replacement is used at this branch,
1700 // and has exactly one use.
1701 if ((comp->input_use_list()->instruction() == this) &&
1702 (comp->input_use_list()->next_use() == NULL) &&
1703 (comp->env_use_list() == NULL)) {
1704 comp->RemoveFromGraph();
1705 // It is safe to pass a NULL iterator because we're replacing the
1706 // comparison wrapped in a BranchInstr which does not modify the
1707 // linked list of instructions.
1708 ReplaceWith(comp, NULL /* ignored */);
1709 for (intptr_t i = 0; i < comp->InputCount(); ++i) {
1710 Value* operand = comp->InputAt(i);
1711 operand->set_instruction(this);
1712 }
1713 if (FLAG_trace_optimization) {
1714 OS::Print("Merging comparison v%"Pd"\n", comp->ssa_temp_index());
1715 }
1716 // Clear the comparison's use list, temp index and ssa temp index since
1717 // the value of the comparison is not used outside the branch anymore.
1718 comp->set_input_use_list(NULL);
1719 comp->ClearSSATempIndex();
1720 comp->ClearTempIndex();
1721 }
1722 }
1723 return this;
1724 }
1725
1726
1689 Definition* StrictCompareInstr::Canonicalize(FlowGraphOptimizer* optimizer) { 1727 Definition* StrictCompareInstr::Canonicalize(FlowGraphOptimizer* optimizer) {
1690 if (!right()->BindsToConstant()) return this; 1728 if (!right()->BindsToConstant()) return this;
1691 const Object& right_constant = right()->BoundConstant(); 1729 const Object& right_constant = right()->BoundConstant();
1692 Definition* left_defn = left()->definition(); 1730 Definition* left_defn = left()->definition();
1693 // TODO(fschneider): Handle other cases: e === false and e !== true/false. 1731 // TODO(fschneider): Handle other cases: e === false and e !== true/false.
1694 // Handles e === true. 1732 // Handles e === true.
1695 if ((kind() == Token::kEQ_STRICT) && 1733 if ((kind() == Token::kEQ_STRICT) &&
1696 (right_constant.raw() == Bool::True().raw()) && 1734 (right_constant.raw() == Bool::True().raw()) &&
1697 (left()->ResultCid() == kBoolCid)) { 1735 (left()->ResultCid() == kBoolCid)) {
1698 // Return left subexpression as the replacement for this instruction. 1736 // Return left subexpression as the replacement for this instruction.
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2917 default: 2955 default:
2918 UNREACHABLE(); 2956 UNREACHABLE();
2919 return -1; 2957 return -1;
2920 } 2958 }
2921 } 2959 }
2922 2960
2923 2961
2924 #undef __ 2962 #undef __
2925 2963
2926 } // namespace dart 2964 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698