Chromium Code Reviews| 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/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" |
| 9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 | 330 |
| 331 | 331 |
| 332 UnboxedConstantInstr::UnboxedConstantInstr(const Object& value) | 332 UnboxedConstantInstr::UnboxedConstantInstr(const Object& value) |
| 333 : ConstantInstr(value), constant_address_(0) { | 333 : ConstantInstr(value), constant_address_(0) { |
| 334 // Only doubles supported for now. | 334 // Only doubles supported for now. |
| 335 ASSERT(value.IsDouble()); | 335 ASSERT(value.IsDouble()); |
| 336 constant_address_ = | 336 constant_address_ = |
| 337 FlowGraphBuilder::FindDoubleConstant(Double::Cast(value).value()); | 337 FlowGraphBuilder::FindDoubleConstant(Double::Cast(value).value()); |
| 338 } | 338 } |
| 339 | 339 |
| 340 | |
| 341 bool Value::BindsTo32BitMaskConstant() const { | |
| 342 if (!definition()->IsUnboxInteger() || !definition()->IsUnboxUint32()) { | |
| 343 return false; | |
| 344 } | |
| 345 // Two cases to consider: UnboxInteger and UnboxUint32. | |
| 346 if (definition()->IsUnboxInteger()) { | |
| 347 UnboxIntegerInstr* instr = definition()->AsUnboxInteger(); | |
| 348 if (!instr->value()->BindsToConstant()) { | |
| 349 return false; | |
| 350 } | |
| 351 const Object& obj = instr->value()->BoundConstant(); | |
| 352 if (!obj.IsMint()) { | |
| 353 return false; | |
| 354 } | |
| 355 Mint& mint = Mint::Handle(); | |
| 356 mint ^= obj.raw(); | |
| 357 return mint.value() == kMaxUint32; | |
| 358 } else if (definition()->IsUnboxUint32()) { | |
| 359 UnboxUint32Instr* instr = definition()->AsUnboxUint32(); | |
| 360 if (!instr->value()->BindsToConstant()) { | |
| 361 return false; | |
| 362 } | |
| 363 const Object& obj = instr->value()->BoundConstant(); | |
| 364 if (!obj.IsMint()) { | |
| 365 return false; | |
| 366 } | |
| 367 Mint& mint = Mint::Handle(); | |
| 368 mint ^= obj.raw(); | |
| 369 return mint.value() == kMaxUint32; | |
| 370 } | |
| 371 return false; | |
| 372 } | |
| 373 | |
| 374 | |
| 340 // Returns true if the value represents a constant. | 375 // Returns true if the value represents a constant. |
| 341 bool Value::BindsToConstant() const { | 376 bool Value::BindsToConstant() const { |
| 342 return definition()->IsConstant(); | 377 return definition()->IsConstant(); |
| 343 } | 378 } |
| 344 | 379 |
| 345 | 380 |
| 346 // Returns true if the value represents constant null. | 381 // Returns true if the value represents constant null. |
| 347 bool Value::BindsToConstantNull() const { | 382 bool Value::BindsToConstantNull() const { |
| 348 ConstantInstr* constant = definition()->AsConstant(); | 383 ConstantInstr* constant = definition()->AsConstant(); |
| 349 return (constant != NULL) && constant->value().IsNull(); | 384 return (constant != NULL) && constant->value().IsNull(); |
| (...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1457 right(), | 1492 right(), |
| 1458 left()); | 1493 left()); |
| 1459 if (result != NULL) { | 1494 if (result != NULL) { |
| 1460 return result; | 1495 return result; |
| 1461 } | 1496 } |
| 1462 | 1497 |
| 1463 return this; | 1498 return this; |
| 1464 } | 1499 } |
| 1465 | 1500 |
| 1466 | 1501 |
| 1502 static bool IsUint32Mask(BinaryUint32OpInstr* defn) { | |
| 1503 ASSERT(defn != NULL); | |
| 1504 if (defn->op_kind() != Token::kBIT_AND) { | |
| 1505 // Not a mask. | |
| 1506 return false; | |
| 1507 } | |
| 1508 Value* left = defn->left(); | |
| 1509 Value* right = defn->right(); | |
| 1510 return left->BindsTo32BitMaskConstant() != right->BindsTo32BitMaskConstant(); | |
| 1511 } | |
| 1512 | |
| 1513 | |
| 1514 Definition* BinaryUint32OpInstr::Canonicalize(FlowGraph* flow_graph) { | |
| 1515 Definition* result = NULL; | |
| 1516 | |
| 1517 result = CanonicalizeCommutativeArithmetic(op_kind(), | |
| 1518 kMintCid, | |
| 1519 left(), | |
| 1520 right()); | |
| 1521 if (result != NULL) { | |
| 1522 return result; | |
| 1523 } | |
| 1524 | |
| 1525 result = CanonicalizeCommutativeArithmetic(op_kind(), | |
| 1526 kMintCid, | |
| 1527 right(), | |
| 1528 left()); | |
| 1529 if (result != NULL) { | |
| 1530 return result; | |
| 1531 } | |
| 1532 | |
| 1533 // If this is (value & 0xFFFFFFFF) the mask operation can be dropped. | |
| 1534 if (IsUint32Mask(this)) { | |
|
Vyacheslav Egorov (Google)
2014/07/08 12:39:31
I would fold it into CanonicalizeCommutativeArithm
Cutch
2014/07/09 17:48:26
This specific case can't be folded into Canonicali
| |
| 1535 return NULL; | |
| 1536 } | |
| 1537 | |
| 1538 return this; | |
| 1539 } | |
| 1540 | |
| 1541 | |
| 1467 // Optimizations that eliminate or simplify individual instructions. | 1542 // Optimizations that eliminate or simplify individual instructions. |
| 1468 Instruction* Instruction::Canonicalize(FlowGraph* flow_graph) { | 1543 Instruction* Instruction::Canonicalize(FlowGraph* flow_graph) { |
| 1469 return this; | 1544 return this; |
| 1470 } | 1545 } |
| 1471 | 1546 |
| 1472 | 1547 |
| 1473 Definition* Definition::Canonicalize(FlowGraph* flow_graph) { | 1548 Definition* Definition::Canonicalize(FlowGraph* flow_graph) { |
| 1474 return this; | 1549 return this; |
| 1475 } | 1550 } |
| 1476 | 1551 |
| (...skipping 2498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3975 case Token::kTRUNCDIV: return 0; | 4050 case Token::kTRUNCDIV: return 0; |
| 3976 case Token::kMOD: return 1; | 4051 case Token::kMOD: return 1; |
| 3977 default: UNIMPLEMENTED(); return -1; | 4052 default: UNIMPLEMENTED(); return -1; |
| 3978 } | 4053 } |
| 3979 } | 4054 } |
| 3980 | 4055 |
| 3981 | 4056 |
| 3982 #undef __ | 4057 #undef __ |
| 3983 | 4058 |
| 3984 } // namespace dart | 4059 } // namespace dart |
| OLD | NEW |