| 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/cha.h" | 7 #include "vm/cha.h" |
| 8 #include "vm/flow_graph_builder.h" | 8 #include "vm/flow_graph_builder.h" |
| 9 #include "vm/hash_map.h" | 9 #include "vm/hash_map.h" |
| 10 #include "vm/il_printer.h" | 10 #include "vm/il_printer.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 } | 245 } |
| 246 default: | 246 default: |
| 247 return false; | 247 return false; |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 bool FlowGraphOptimizer::TryReplaceWithBinaryOp(BindInstr* instr, | 252 bool FlowGraphOptimizer::TryReplaceWithBinaryOp(BindInstr* instr, |
| 253 InstanceCallComp* comp, | 253 InstanceCallComp* comp, |
| 254 Token::Kind op_kind) { | 254 Token::Kind op_kind) { |
| 255 BinaryOpComp::OperandsType operands_type = BinaryOpComp::kDynamicOperands; | 255 intptr_t operands_type = kIllegalCid; |
| 256 ASSERT(comp->HasICData()); | 256 ASSERT(comp->HasICData()); |
| 257 const ICData& ic_data = *comp->ic_data(); | 257 const ICData& ic_data = *comp->ic_data(); |
| 258 switch (op_kind) { | 258 switch (op_kind) { |
| 259 case Token::kADD: | 259 case Token::kADD: |
| 260 case Token::kSUB: | 260 case Token::kSUB: |
| 261 case Token::kMUL: | 261 case Token::kMUL: |
| 262 if (HasOnlyTwoSmi(ic_data)) { | 262 if (HasOnlyTwoSmi(ic_data)) { |
| 263 operands_type = BinaryOpComp::kSmiOperands; | 263 operands_type = kSmiCid; |
| 264 } else if (HasOnlyTwoDouble(ic_data)) { | 264 } else if (HasOnlyTwoDouble(ic_data)) { |
| 265 operands_type = BinaryOpComp::kDoubleOperands; | 265 operands_type = kDoubleCid; |
| 266 } else { | 266 } else { |
| 267 return false; | 267 return false; |
| 268 } | 268 } |
| 269 break; | 269 break; |
| 270 case Token::kDIV: | 270 case Token::kDIV: |
| 271 case Token::kMOD: | 271 case Token::kMOD: |
| 272 if (HasOnlyTwoDouble(ic_data)) { | 272 if (HasOnlyTwoDouble(ic_data)) { |
| 273 operands_type = BinaryOpComp::kDoubleOperands; | 273 operands_type = kDoubleCid; |
| 274 } else { | 274 } else { |
| 275 return false; | 275 return false; |
| 276 } | 276 } |
| 277 case Token::kBIT_AND: | 277 case Token::kBIT_AND: |
| 278 if (HasOnlyTwoSmi(ic_data)) { | 278 if (HasOnlyTwoSmi(ic_data)) { |
| 279 operands_type = BinaryOpComp::kSmiOperands; | 279 operands_type = kSmiCid; |
| 280 } else if (HasTwoMintOrSmi(ic_data)) { | 280 } else if (HasTwoMintOrSmi(ic_data)) { |
| 281 operands_type = BinaryOpComp::kMintOperands; | 281 operands_type = kMintCid; |
| 282 } else { | 282 } else { |
| 283 return false; | 283 return false; |
| 284 } | 284 } |
| 285 break; | 285 break; |
| 286 case Token::kBIT_OR: | 286 case Token::kBIT_OR: |
| 287 case Token::kBIT_XOR: | 287 case Token::kBIT_XOR: |
| 288 case Token::kTRUNCDIV: | 288 case Token::kTRUNCDIV: |
| 289 case Token::kSHR: | 289 case Token::kSHR: |
| 290 case Token::kSHL: | 290 case Token::kSHL: |
| 291 if (HasOnlyTwoSmi(ic_data)) { | 291 if (HasOnlyTwoSmi(ic_data)) { |
| 292 operands_type = BinaryOpComp::kSmiOperands; | 292 operands_type = kSmiCid; |
| 293 } else { | 293 } else { |
| 294 return false; | 294 return false; |
| 295 } | 295 } |
| 296 break; | 296 break; |
| 297 default: | 297 default: |
| 298 UNREACHABLE(); | 298 UNREACHABLE(); |
| 299 }; | 299 }; |
| 300 | 300 |
| 301 ASSERT(comp->ArgumentCount() == 2); | 301 ASSERT(comp->ArgumentCount() == 2); |
| 302 if (operands_type == BinaryOpComp::kDoubleOperands) { | 302 if (operands_type == kDoubleCid) { |
| 303 DoubleBinaryOpComp* double_bin_op = new DoubleBinaryOpComp(op_kind, comp); | 303 BinaryDoubleOpComp* double_bin_op = new BinaryDoubleOpComp(op_kind, comp); |
| 304 double_bin_op->set_ic_data(comp->ic_data()); | 304 double_bin_op->set_ic_data(comp->ic_data()); |
| 305 instr->set_computation(double_bin_op); | 305 instr->set_computation(double_bin_op); |
| 306 } else { | 306 } else if (operands_type == kMintCid) { |
| 307 Value* left = comp->ArgumentAt(0)->value(); | 307 Value* left = comp->ArgumentAt(0)->value(); |
| 308 Value* right = comp->ArgumentAt(1)->value(); | 308 Value* right = comp->ArgumentAt(1)->value(); |
| 309 BinaryOpComp* bin_op = | 309 BinaryMintOpComp* bin_op = new BinaryMintOpComp(op_kind, |
| 310 new BinaryOpComp(op_kind, | 310 comp, |
| 311 operands_type, | 311 left, |
| 312 comp, | 312 right); |
| 313 left, | |
| 314 right); | |
| 315 bin_op->set_ic_data(comp->ic_data()); | 313 bin_op->set_ic_data(comp->ic_data()); |
| 316 instr->set_computation(bin_op); | 314 instr->set_computation(bin_op); |
| 317 RemovePushArguments(comp); | 315 RemovePushArguments(comp); |
| 316 } else { |
| 317 ASSERT(operands_type == kSmiCid); |
| 318 Value* left = comp->ArgumentAt(0)->value(); |
| 319 Value* right = comp->ArgumentAt(1)->value(); |
| 320 BinarySmiOpComp* bin_op = new BinarySmiOpComp(op_kind, |
| 321 comp, |
| 322 left, |
| 323 right); |
| 324 bin_op->set_ic_data(comp->ic_data()); |
| 325 instr->set_computation(bin_op); |
| 326 RemovePushArguments(comp); |
| 318 } | 327 } |
| 319 return true; | 328 return true; |
| 320 } | 329 } |
| 321 | 330 |
| 322 | 331 |
| 323 bool FlowGraphOptimizer::TryReplaceWithUnaryOp(BindInstr* instr, | 332 bool FlowGraphOptimizer::TryReplaceWithUnaryOp(BindInstr* instr, |
| 324 InstanceCallComp* comp, | 333 InstanceCallComp* comp, |
| 325 Token::Kind op_kind) { | 334 Token::Kind op_kind) { |
| 326 if (comp->ic_data()->NumberOfChecks() != 1) { | 335 if (comp->ic_data()->NumberOfChecks() != 1) { |
| 327 // TODO(srdjan): Not yet supported. | 336 // TODO(srdjan): Not yet supported. |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 944 OS::Print("Replacing v%d with v%d\n", | 953 OS::Print("Replacing v%d with v%d\n", |
| 945 instr->ssa_temp_index(), | 954 instr->ssa_temp_index(), |
| 946 result->ssa_temp_index()); | 955 result->ssa_temp_index()); |
| 947 } | 956 } |
| 948 } | 957 } |
| 949 } | 958 } |
| 950 } | 959 } |
| 951 | 960 |
| 952 | 961 |
| 953 } // namespace dart | 962 } // namespace dart |
| OLD | NEW |