| 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/bit_vector.h" | 7 #include "vm/bit_vector.h" |
| 8 #include "vm/cha.h" | 8 #include "vm/cha.h" |
| 9 #include "vm/flow_graph_builder.h" | 9 #include "vm/flow_graph_builder.h" |
| 10 #include "vm/flow_graph_compiler.h" | 10 #include "vm/flow_graph_compiler.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // For non-definitions Canonicalize should return either NULL or | 73 // For non-definitions Canonicalize should return either NULL or |
| 74 // this. | 74 // this. |
| 75 ASSERT((replacement == NULL) || current->IsDefinition()); | 75 ASSERT((replacement == NULL) || current->IsDefinition()); |
| 76 ReplaceCurrentInstruction(&it, current, replacement); | 76 ReplaceCurrentInstruction(&it, current, replacement); |
| 77 } | 77 } |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 | 82 |
| 83 static Definition* CreateConversion(Representation from, | 83 void FlowGraphOptimizer::InsertConversion(Representation from, |
| 84 Representation to, | 84 Representation to, |
| 85 Definition* def, | 85 Instruction* instr, |
| 86 Instruction* deopt_target) { | 86 Value* use, |
| 87 Definition* def, |
| 88 Instruction* deopt_target) { |
| 89 Definition* converted = NULL; |
| 87 if ((from == kTagged) && (to == kUnboxedMint)) { | 90 if ((from == kTagged) && (to == kUnboxedMint)) { |
| 88 const intptr_t deopt_id = (deopt_target != NULL) ? | 91 const intptr_t deopt_id = (deopt_target != NULL) ? |
| 89 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; | 92 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; |
| 90 ASSERT((deopt_target != NULL) || (def->GetPropagatedCid() == kDoubleCid)); | 93 ASSERT((deopt_target != NULL) || (def->GetPropagatedCid() == kDoubleCid)); |
| 91 return new UnboxIntegerInstr(new Value(def), deopt_id); | 94 converted = new UnboxIntegerInstr(new Value(def), deopt_id); |
| 92 } else if ((from == kUnboxedMint) && (to == kTagged)) { | 95 } else if ((from == kUnboxedMint) && (to == kTagged)) { |
| 93 return new BoxIntegerInstr(new Value(def)); | 96 converted = new BoxIntegerInstr(new Value(def)); |
| 97 } else if (from == kUnboxedMint && to == kUnboxedDouble) { |
| 98 // Convert by boxing/unboxing. |
| 99 // TODO(fschneider): Implement direct unboxed mint-to-double conversion. |
| 100 BoxIntegerInstr* boxed = new BoxIntegerInstr(new Value(def)); |
| 101 InsertBefore(instr, boxed, NULL, Definition::kValue); |
| 102 const intptr_t deopt_id = (deopt_target != NULL) ? |
| 103 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; |
| 104 converted = new UnboxDoubleInstr(new Value(boxed), deopt_id); |
| 94 } else if ((from == kUnboxedDouble) && (to == kTagged)) { | 105 } else if ((from == kUnboxedDouble) && (to == kTagged)) { |
| 95 return new BoxDoubleInstr(new Value(def), NULL); | 106 converted = new BoxDoubleInstr(new Value(def), NULL); |
| 96 } else if ((from == kTagged) && (to == kUnboxedDouble)) { | 107 } else if ((from == kTagged) && (to == kUnboxedDouble)) { |
| 97 const intptr_t deopt_id = (deopt_target != NULL) ? | 108 const intptr_t deopt_id = (deopt_target != NULL) ? |
| 98 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; | 109 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; |
| 99 ASSERT((deopt_target != NULL) || (def->GetPropagatedCid() == kDoubleCid)); | 110 ASSERT((deopt_target != NULL) || (def->GetPropagatedCid() == kDoubleCid)); |
| 100 return new UnboxDoubleInstr(new Value(def), deopt_id); | 111 converted = new UnboxDoubleInstr(new Value(def), deopt_id); |
| 101 } else { | |
| 102 UNREACHABLE(); | |
| 103 return NULL; | |
| 104 } | 112 } |
| 113 ASSERT(converted != NULL); |
| 114 InsertBefore(instr, converted, use->instruction()->env(), |
| 115 Definition::kValue); |
| 116 use->set_definition(converted); |
| 105 } | 117 } |
| 106 | 118 |
| 107 | 119 |
| 108 void FlowGraphOptimizer::InsertConversionsFor(Definition* def) { | 120 void FlowGraphOptimizer::InsertConversionsFor(Definition* def) { |
| 109 const Representation from_rep = def->representation(); | 121 const Representation from_rep = def->representation(); |
| 110 | 122 |
| 111 for (Value* use = def->input_use_list(); | 123 for (Value* use = def->input_use_list(); |
| 112 use != NULL; | 124 use != NULL; |
| 113 use = use->next_use()) { | 125 use = use->next_use()) { |
| 114 const Representation to_rep = | 126 const Representation to_rep = |
| 115 use->instruction()->RequiredInputRepresentation(use->use_index()); | 127 use->instruction()->RequiredInputRepresentation(use->use_index()); |
| 116 if (from_rep == to_rep) { | 128 if (from_rep == to_rep) { |
| 117 continue; | 129 continue; |
| 118 } | 130 } |
| 119 | 131 |
| 120 Instruction* deopt_target = NULL; | 132 Instruction* deopt_target = NULL; |
| 121 Instruction* instr = use->instruction(); | 133 Instruction* instr = use->instruction(); |
| 122 if (instr->IsPhi()) { | 134 if (instr->IsPhi()) { |
| 123 if (!instr->AsPhi()->is_alive()) continue; | 135 if (!instr->AsPhi()->is_alive()) continue; |
| 124 | 136 |
| 125 // For phis conversions have to be inserted in the predecessor. | 137 // For phis conversions have to be inserted in the predecessor. |
| 126 const BlockEntryInstr* pred = | 138 const BlockEntryInstr* pred = |
| 127 instr->AsPhi()->block()->PredecessorAt(use->use_index()); | 139 instr->AsPhi()->block()->PredecessorAt(use->use_index()); |
| 128 instr = pred->last_instruction(); | 140 instr = pred->last_instruction(); |
| 129 } else { | 141 } else { |
| 130 deopt_target = instr; | 142 deopt_target = instr; |
| 131 } | 143 } |
| 132 | 144 |
| 133 Definition* converted = | 145 InsertConversion(from_rep, to_rep, instr, use, def, deopt_target); |
| 134 CreateConversion(from_rep, to_rep, def, deopt_target); | |
| 135 InsertBefore(instr, converted, use->instruction()->env(), | |
| 136 Definition::kValue); | |
| 137 use->set_definition(converted); | |
| 138 } | 146 } |
| 139 } | 147 } |
| 140 | 148 |
| 141 | 149 |
| 142 void FlowGraphOptimizer::SelectRepresentations() { | 150 void FlowGraphOptimizer::SelectRepresentations() { |
| 143 // Convervatively unbox all phis that were proven to be of type Double. | 151 // Convervatively unbox all phis that were proven to be of type Double. |
| 144 for (intptr_t i = 0; i < block_order_.length(); ++i) { | 152 for (intptr_t i = 0; i < block_order_.length(); ++i) { |
| 145 JoinEntryInstr* join_entry = block_order_[i]->AsJoinEntry(); | 153 JoinEntryInstr* join_entry = block_order_[i]->AsJoinEntry(); |
| 146 if (join_entry == NULL) continue; | 154 if (join_entry == NULL) continue; |
| 147 | 155 |
| (...skipping 3101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3249 | 3257 |
| 3250 if (FLAG_trace_constant_propagation) { | 3258 if (FLAG_trace_constant_propagation) { |
| 3251 OS::Print("\n==== After constant propagation ====\n"); | 3259 OS::Print("\n==== After constant propagation ====\n"); |
| 3252 FlowGraphPrinter printer(*graph_); | 3260 FlowGraphPrinter printer(*graph_); |
| 3253 printer.PrintBlocks(); | 3261 printer.PrintBlocks(); |
| 3254 } | 3262 } |
| 3255 } | 3263 } |
| 3256 | 3264 |
| 3257 | 3265 |
| 3258 } // namespace dart | 3266 } // namespace dart |
| OLD | NEW |