Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/flow_graph_optimizer.h" | 5 #include "vm/flow_graph_optimizer.h" |
| 6 | 6 |
| 7 #include "vm/flow_graph_builder.h" | 7 #include "vm/flow_graph_builder.h" |
| 8 #include "vm/il_printer.h" | 8 #include "vm/il_printer.h" |
| 9 #include "vm/object_store.h" | 9 #include "vm/object_store.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 DECLARE_FLAG(bool, print_flow_graph); | 13 DECLARE_FLAG(bool, print_flow_graph); |
| 14 DECLARE_FLAG(bool, trace_optimization); | 14 DECLARE_FLAG(bool, trace_optimization); |
| 15 | 15 |
| 16 void FlowGraphOptimizer::ApplyICData() { | 16 void FlowGraphOptimizer::ApplyICData() { |
| 17 VisitBlocks(); | 17 VisitBlocks(); |
| 18 if (FLAG_print_flow_graph) { | 18 if (FLAG_print_flow_graph) { |
| 19 OS::Print("After Optimizations:\n"); | 19 OS::Print("After Optimizations:\n"); |
| 20 FlowGraphPrinter printer(Function::Handle(), block_order_); | 20 FlowGraphPrinter printer(Function::Handle(), block_order_); |
| 21 printer.PrintBlocks(); | 21 printer.PrintBlocks(); |
| 22 } | 22 } |
| 23 } | 23 } |
| 24 | 24 |
| 25 | 25 |
| 26 void FlowGraphOptimizer::VisitBlocks() { | 26 void FlowGraphOptimizer::VisitBlocks() { |
| 27 for (intptr_t i = 0; i < block_order_.length(); ++i) { | 27 for (intptr_t i = 0; i < block_order_.length(); ++i) { |
| 28 Instruction* instr = block_order_[i]->Accept(this); | 28 Instruction* instr = block_order_[i]->Accept(this); |
| 29 // Compile all successors until an exit, branch, or a block entry. | 29 // Optimize all successors until an exit, branch, or a block entry. |
| 30 while ((instr != NULL) && !instr->IsBlockEntry()) { | 30 while ((instr != NULL) && !instr->IsBlockEntry()) { |
| 31 instr = instr->Accept(this); | 31 instr = instr->Accept(this); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 | 36 |
| 37 static bool ICDataHasReceiverClass(const ICData& ic_data, const Class& cls) { | 37 static bool ICDataHasReceiverClass(const ICData& ic_data, const Class& cls) { |
| 38 ASSERT(!cls.IsNull()); | 38 ASSERT(!cls.IsNull()); |
| 39 ASSERT(ic_data.num_args_tested() > 0); | 39 ASSERT(ic_data.num_args_tested() > 0); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 } | 85 } |
| 86 | 86 |
| 87 | 87 |
| 88 static bool HasOneDouble(const ICData& ic_data) { | 88 static bool HasOneDouble(const ICData& ic_data) { |
| 89 const Class& double_class = | 89 const Class& double_class = |
| 90 Class::Handle(Isolate::Current()->object_store()->double_class()); | 90 Class::Handle(Isolate::Current()->object_store()->double_class()); |
| 91 return ICDataHasReceiverClass(ic_data, double_class); | 91 return ICDataHasReceiverClass(ic_data, double_class); |
| 92 } | 92 } |
| 93 | 93 |
| 94 | 94 |
| 95 static bool HasTwoDouble(const ICData& ic_data) { | |
| 96 const Class& double_class = | |
| 97 Class::Handle(Isolate::Current()->object_store()->double_class()); | |
| 98 return ICDataHasTwoReceiverClasses(ic_data, double_class, double_class); | |
| 99 } | |
| 100 | |
| 95 | 101 |
| 96 void FlowGraphOptimizer::TryReplaceWithBinaryOp(InstanceCallComp* comp, | 102 void FlowGraphOptimizer::TryReplaceWithBinaryOp(InstanceCallComp* comp, |
| 97 Token::Kind op_kind) { | 103 Token::Kind op_kind) { |
| 98 if (comp->ic_data()->NumberOfChecks() != 1) { | 104 if (comp->ic_data()->NumberOfChecks() != 1) { |
| 99 // TODO(srdjan): Not yet supported. | 105 // TODO(srdjan): Not yet supported. |
| 100 return; | 106 return; |
| 101 } | 107 } |
| 102 if (!HasTwoSmi(*comp->ic_data())) { | 108 |
| 109 BinaryOpComp::OperandsType operands_type; | |
| 110 | |
| 111 if (HasTwoSmi(*comp->ic_data())) { | |
| 112 if (op_kind == Token::kDIV || | |
| 113 op_kind == Token::kMOD) { | |
| 114 // TODO(srdjan): Not yet supported. | |
| 115 return; | |
| 116 } | |
| 117 | |
| 118 operands_type = BinaryOpComp::kSmiOperands; | |
| 119 } else if (HasTwoDouble(*comp->ic_data())) { | |
| 120 if (op_kind != Token::kADD && | |
| 121 op_kind != Token::kSUB && | |
| 122 op_kind != Token::kMUL && | |
| 123 op_kind != Token::kDIV) { | |
|
srdjan
2012/06/08 05:18:22
TODO(vegorov) ;-)?
Vyacheslav Egorov (Google)
2012/06/08 11:11:13
Done.
I think they are not supported even by ia32
| |
| 124 return; | |
| 125 } | |
| 126 | |
| 127 operands_type = BinaryOpComp::kDoubleOperands; | |
| 128 } else { | |
| 103 // TODO(srdjan): Not yet supported. | 129 // TODO(srdjan): Not yet supported. |
| 104 return; | 130 return; |
| 105 } | 131 } |
| 132 | |
| 106 ASSERT(comp->instr() != NULL); | 133 ASSERT(comp->instr() != NULL); |
| 107 ASSERT(comp->InputCount() == 2); | 134 ASSERT(comp->InputCount() == 2); |
| 135 Value* left = comp->InputAt(0); | |
| 136 Value* right = comp->InputAt(1); | |
| 108 BinaryOpComp* bin_op = | 137 BinaryOpComp* bin_op = |
| 109 new BinaryOpComp(op_kind, comp, comp->InputAt(0), comp->InputAt(1)); | 138 new BinaryOpComp(op_kind, |
| 139 operands_type, | |
| 140 comp, | |
| 141 left, | |
| 142 right); | |
| 110 ASSERT(bin_op->ic_data() == NULL); | 143 ASSERT(bin_op->ic_data() == NULL); |
| 111 bin_op->set_ic_data(comp->ic_data()); | 144 bin_op->set_ic_data(comp->ic_data()); |
| 112 bin_op->set_instr(comp->instr()); | 145 bin_op->set_instr(comp->instr()); |
| 113 comp->instr()->replace_computation(bin_op); | 146 comp->instr()->replace_computation(bin_op); |
| 114 } | 147 } |
| 115 | 148 |
| 116 | 149 |
| 117 void FlowGraphOptimizer::TryReplaceWithUnaryOp(InstanceCallComp* comp, | 150 void FlowGraphOptimizer::TryReplaceWithUnaryOp(InstanceCallComp* comp, |
| 118 Token::Kind op_kind) { | 151 Token::Kind op_kind) { |
| 119 if (comp->ic_data()->NumberOfChecks() != 1) { | 152 if (comp->ic_data()->NumberOfChecks() != 1) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 instr->computation()->Accept(this); | 190 instr->computation()->Accept(this); |
| 158 } | 191 } |
| 159 | 192 |
| 160 | 193 |
| 161 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { | 194 void FlowGraphOptimizer::VisitBind(BindInstr* instr) { |
| 162 instr->computation()->Accept(this); | 195 instr->computation()->Accept(this); |
| 163 } | 196 } |
| 164 | 197 |
| 165 | 198 |
| 166 } // namespace dart | 199 } // namespace dart |
| OLD | NEW |