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

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
« runtime/vm/compiler.cc ('K') | « 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 if (comparison()->IsStrictCompare()) {
1693 Definition* replacement = comparison()->Canonicalize(optimizer);
Kevin Millikin (Google) 2013/01/10 10:35:00 It might be simpler with an early return, and I li
Florian Schneider 2013/01/10 13:18:41 Done.
1694 if ((replacement != comparison()) &&
1695 replacement->IsComparison()) {
1696 ComparisonInstr* comp = replacement->AsComparison();
1697 if ((comp->input_use_list()->instruction() == this) &&
1698 (comp->input_use_list()->next_use() == NULL) &&
1699 (comp->env_use_list() == NULL)) {
1700 // Replace the comparison if the replacement is used at this branch,
1701 // and has exactly one use.
1702 comp->RemoveFromGraph();
1703 ReplaceWith(comp, NULL /* ignored */);
Kevin Millikin (Google) 2013/01/10 10:35:00 You should expand the comment about NULL so the re
Florian Schneider 2013/01/10 13:18:41 Done.
1704 for (intptr_t i = 0; i < comp->InputCount(); ++i) {
1705 Value* operand = comp->InputAt(i);
1706 operand->set_instruction(this);
1707 }
1708 if (FLAG_trace_optimization) {
1709 OS::Print("Merging comparison v%"Pd"\n", comp->ssa_temp_index());
1710 }
1711 }
1712 }
1713 }
1714 return this;
1715 }
1716
1717
1689 Definition* StrictCompareInstr::Canonicalize(FlowGraphOptimizer* optimizer) { 1718 Definition* StrictCompareInstr::Canonicalize(FlowGraphOptimizer* optimizer) {
1690 if (!right()->BindsToConstant()) return this; 1719 if (!right()->BindsToConstant()) return this;
1691 const Object& right_constant = right()->BoundConstant(); 1720 const Object& right_constant = right()->BoundConstant();
1692 Definition* left_defn = left()->definition(); 1721 Definition* left_defn = left()->definition();
1693 // TODO(fschneider): Handle other cases: e === false and e !== true/false. 1722 // TODO(fschneider): Handle other cases: e === false and e !== true/false.
1694 // Handles e === true. 1723 // Handles e === true.
1695 if ((kind() == Token::kEQ_STRICT) && 1724 if ((kind() == Token::kEQ_STRICT) &&
1696 (right_constant.raw() == Bool::True().raw()) && 1725 (right_constant.raw() == Bool::True().raw()) &&
1697 (left()->ResultCid() == kBoolCid)) { 1726 (left()->ResultCid() == kBoolCid)) {
1698 // Return left subexpression as the replacement for this instruction. 1727 // Return left subexpression as the replacement for this instruction.
(...skipping 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2917 default: 2946 default:
2918 UNREACHABLE(); 2947 UNREACHABLE();
2919 return -1; 2948 return -1;
2920 } 2949 }
2921 } 2950 }
2922 2951
2923 2952
2924 #undef __ 2953 #undef __
2925 2954
2926 } // namespace dart 2955 } // namespace dart
OLDNEW
« runtime/vm/compiler.cc ('K') | « runtime/vm/intermediate_language.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698