| OLD | NEW |
| 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/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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 Representation to, | 227 Representation to, |
| 228 Value* use, | 228 Value* use, |
| 229 Instruction* insert_before, | 229 Instruction* insert_before, |
| 230 Instruction* deopt_target) { | 230 Instruction* deopt_target) { |
| 231 Definition* converted = NULL; | 231 Definition* converted = NULL; |
| 232 if ((from == kTagged) && (to == kUnboxedMint)) { | 232 if ((from == kTagged) && (to == kUnboxedMint)) { |
| 233 ASSERT((deopt_target != NULL) || | 233 ASSERT((deopt_target != NULL) || |
| 234 (use->Type()->ToCid() == kDoubleCid)); | 234 (use->Type()->ToCid() == kDoubleCid)); |
| 235 const intptr_t deopt_id = (deopt_target != NULL) ? | 235 const intptr_t deopt_id = (deopt_target != NULL) ? |
| 236 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; | 236 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; |
| 237 converted = new UnboxIntegerInstr(new Value(use->definition()), deopt_id); | 237 converted = new UnboxIntegerInstr(use->CopyWithType(), deopt_id); |
| 238 } else if ((from == kUnboxedMint) && (to == kTagged)) { | 238 } else if ((from == kUnboxedMint) && (to == kTagged)) { |
| 239 converted = new BoxIntegerInstr(new Value(use->definition())); | 239 converted = new BoxIntegerInstr(use->CopyWithType()); |
| 240 } else if (from == kUnboxedMint && to == kUnboxedDouble) { | 240 } else if (from == kUnboxedMint && to == kUnboxedDouble) { |
| 241 // Convert by boxing/unboxing. | 241 // Convert by boxing/unboxing. |
| 242 // TODO(fschneider): Implement direct unboxed mint-to-double conversion. | 242 // TODO(fschneider): Implement direct unboxed mint-to-double conversion. |
| 243 BoxIntegerInstr* boxed = new BoxIntegerInstr(new Value(use->definition())); | 243 BoxIntegerInstr* boxed = new BoxIntegerInstr(use->CopyWithType()); |
| 244 InsertBefore(insert_before, boxed, NULL, Definition::kValue); | 244 InsertBefore(insert_before, boxed, NULL, Definition::kValue); |
| 245 const intptr_t deopt_id = (deopt_target != NULL) ? | 245 const intptr_t deopt_id = (deopt_target != NULL) ? |
| 246 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; | 246 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; |
| 247 converted = new UnboxDoubleInstr(new Value(boxed), deopt_id); | 247 converted = new UnboxDoubleInstr(new Value(boxed), deopt_id); |
| 248 } else if ((from == kUnboxedDouble) && (to == kTagged)) { | 248 } else if ((from == kUnboxedDouble) && (to == kTagged)) { |
| 249 converted = new BoxDoubleInstr(new Value(use->definition()), NULL); | 249 converted = new BoxDoubleInstr(use->CopyWithType(), NULL); |
| 250 } else if ((from == kTagged) && (to == kUnboxedDouble)) { | 250 } else if ((from == kTagged) && (to == kUnboxedDouble)) { |
| 251 const intptr_t deopt_id = (deopt_target != NULL) ? | 251 const intptr_t deopt_id = (deopt_target != NULL) ? |
| 252 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; | 252 deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId; |
| 253 ASSERT((deopt_target != NULL) || | 253 ASSERT((deopt_target != NULL) || |
| 254 (use->Type()->ToCid() == kDoubleCid)); | 254 (use->Type()->ToCid() == kDoubleCid)); |
| 255 ConstantInstr* constant = use->definition()->AsConstant(); | 255 ConstantInstr* constant = use->definition()->AsConstant(); |
| 256 if ((constant != NULL) && constant->value().IsSmi()) { | 256 if ((constant != NULL) && constant->value().IsSmi()) { |
| 257 const double dbl_val = Smi::Cast(constant->value()).AsDoubleValue(); | 257 const double dbl_val = Smi::Cast(constant->value()).AsDoubleValue(); |
| 258 const Double& dbl_obj = | 258 const Double& dbl_obj = |
| 259 Double::ZoneHandle(Double::New(dbl_val, Heap::kOld)); | 259 Double::ZoneHandle(Double::New(dbl_val, Heap::kOld)); |
| 260 ConstantInstr* double_const = new ConstantInstr(dbl_obj); | 260 ConstantInstr* double_const = new ConstantInstr(dbl_obj); |
| 261 InsertBefore(insert_before, double_const, NULL, Definition::kValue); | 261 InsertBefore(insert_before, double_const, NULL, Definition::kValue); |
| 262 converted = new UnboxDoubleInstr(new Value(double_const), deopt_id); | 262 converted = new UnboxDoubleInstr(new Value(double_const), deopt_id); |
| 263 } else { | 263 } else { |
| 264 converted = new UnboxDoubleInstr(new Value(use->definition()), deopt_id); | 264 converted = new UnboxDoubleInstr(use->CopyWithType(), deopt_id); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 ASSERT(converted != NULL); | 267 ASSERT(converted != NULL); |
| 268 InsertBefore(insert_before, converted, use->instruction()->env(), | 268 InsertBefore(insert_before, converted, use->instruction()->env(), |
| 269 Definition::kValue); | 269 Definition::kValue); |
| 270 use->set_definition(converted); | 270 use->set_definition(converted); |
| 271 } | 271 } |
| 272 | 272 |
| 273 | 273 |
| 274 void FlowGraphOptimizer::InsertConversionsFor(Definition* def) { | 274 void FlowGraphOptimizer::InsertConversionsFor(Definition* def) { |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 break; | 926 break; |
| 927 default: | 927 default: |
| 928 UNREACHABLE(); | 928 UNREACHABLE(); |
| 929 }; | 929 }; |
| 930 | 930 |
| 931 ASSERT(call->ArgumentCount() == 2); | 931 ASSERT(call->ArgumentCount() == 2); |
| 932 if (operands_type == kDoubleCid) { | 932 if (operands_type == kDoubleCid) { |
| 933 Value* left = call->ArgumentAt(0)->value(); | 933 Value* left = call->ArgumentAt(0)->value(); |
| 934 Value* right = call->ArgumentAt(1)->value(); | 934 Value* right = call->ArgumentAt(1)->value(); |
| 935 | 935 |
| 936 // Check that either left or right are not a smi. Result or a | 936 // Check that either left or right are not a smi. Result of a |
| 937 // binary operation with two smis is a smi not a double. | 937 // binary operation with two smis is a smi not a double. |
| 938 InsertBefore(call, | 938 InsertBefore(call, |
| 939 new CheckEitherNonSmiInstr(left->Copy(), | 939 new CheckEitherNonSmiInstr(left->Copy(), |
| 940 right->Copy(), | 940 right->Copy(), |
| 941 call), | 941 call), |
| 942 call->env(), | 942 call->env(), |
| 943 Definition::kEffect); | 943 Definition::kEffect); |
| 944 | 944 |
| 945 BinaryDoubleOpInstr* double_bin_op = | 945 BinaryDoubleOpInstr* double_bin_op = |
| 946 new BinaryDoubleOpInstr(op_kind, left->Copy(), right->Copy(), call); | 946 new BinaryDoubleOpInstr(op_kind, left->Copy(), right->Copy(), call); |
| (...skipping 3328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4275 | 4275 |
| 4276 if (FLAG_trace_constant_propagation) { | 4276 if (FLAG_trace_constant_propagation) { |
| 4277 OS::Print("\n==== After constant propagation ====\n"); | 4277 OS::Print("\n==== After constant propagation ====\n"); |
| 4278 FlowGraphPrinter printer(*graph_); | 4278 FlowGraphPrinter printer(*graph_); |
| 4279 printer.PrintBlocks(); | 4279 printer.PrintBlocks(); |
| 4280 } | 4280 } |
| 4281 } | 4281 } |
| 4282 | 4282 |
| 4283 | 4283 |
| 4284 } // namespace dart | 4284 } // namespace dart |
| OLD | NEW |