Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_NODE_MATCHERS_H_ | 5 #ifndef V8_COMPILER_NODE_MATCHERS_H_ |
| 6 #define V8_COMPILER_NODE_MATCHERS_H_ | 6 #define V8_COMPILER_NODE_MATCHERS_H_ |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 // TODO(turbofan): Move ExternalReference out of assembler.h | 10 // TODO(turbofan): Move ExternalReference out of assembler.h |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 | 387 |
| 388 typedef AddMatcher<Int32BinopMatcher, IrOpcode::kInt32Add, IrOpcode::kInt32Sub, | 388 typedef AddMatcher<Int32BinopMatcher, IrOpcode::kInt32Add, IrOpcode::kInt32Sub, |
| 389 IrOpcode::kInt32Mul, IrOpcode::kWord32Shl> | 389 IrOpcode::kInt32Mul, IrOpcode::kWord32Shl> |
| 390 Int32AddMatcher; | 390 Int32AddMatcher; |
| 391 typedef AddMatcher<Int64BinopMatcher, IrOpcode::kInt64Add, IrOpcode::kInt64Sub, | 391 typedef AddMatcher<Int64BinopMatcher, IrOpcode::kInt64Add, IrOpcode::kInt64Sub, |
| 392 IrOpcode::kInt64Mul, IrOpcode::kWord64Shl> | 392 IrOpcode::kInt64Mul, IrOpcode::kWord64Shl> |
| 393 Int64AddMatcher; | 393 Int64AddMatcher; |
| 394 | 394 |
| 395 enum DisplacementMode { kPositiveDisplacement, kNegativeDisplacement }; | 395 enum DisplacementMode { kPositiveDisplacement, kNegativeDisplacement }; |
| 396 | 396 |
| 397 template <class AddMatcher> | 397 template <class AddMatcher> |
|
Benedikt Meurer
2016/08/15 06:29:20
You need to move this enum out of the template cla
| |
| 398 struct BaseWithIndexAndDisplacementMatcher { | 398 struct BaseWithIndexAndDisplacementMatcher { |
| 399 BaseWithIndexAndDisplacementMatcher(Node* node, bool allow_input_swap) | 399 enum Flag { |
| 400 kAllowNone = 0u, | |
| 401 kAllowInputSwap = 1u << 0, | |
| 402 kAllowScale = 1u << 1, | |
| 403 kAllowAll = kAllowInputSwap | kAllowScale | |
| 404 }; | |
| 405 | |
| 406 typedef base::Flags<Flag, uint8_t> Flags; | |
| 407 BaseWithIndexAndDisplacementMatcher(Node* node, Flags flags) | |
| 400 : matches_(false), | 408 : matches_(false), |
| 401 index_(nullptr), | 409 index_(nullptr), |
| 402 scale_(0), | 410 scale_(0), |
| 403 base_(nullptr), | 411 base_(nullptr), |
| 404 displacement_(nullptr), | 412 displacement_(nullptr), |
| 405 displacement_mode_(kPositiveDisplacement) { | 413 displacement_mode_(kPositiveDisplacement) { |
| 406 Initialize(node, allow_input_swap); | 414 Initialize(node, flags); |
| 407 } | 415 } |
| 408 | 416 |
| 409 explicit BaseWithIndexAndDisplacementMatcher(Node* node) | 417 explicit BaseWithIndexAndDisplacementMatcher(Node* node) |
| 410 : matches_(false), | 418 : matches_(false), |
| 411 index_(nullptr), | 419 index_(nullptr), |
| 412 scale_(0), | 420 scale_(0), |
| 413 base_(nullptr), | 421 base_(nullptr), |
| 414 displacement_(nullptr), | 422 displacement_(nullptr), |
| 415 displacement_mode_(kPositiveDisplacement) { | 423 displacement_mode_(kPositiveDisplacement) { |
| 416 Initialize(node, node->op()->HasProperty(Operator::kCommutative)); | 424 Initialize(node, Flags(kAllowScale) | |
| 425 (node->op()->HasProperty(Operator::kCommutative) | |
| 426 ? kAllowInputSwap | |
| 427 : kAllowNone)); | |
| 417 } | 428 } |
| 418 | 429 |
| 419 bool matches() const { return matches_; } | 430 bool matches() const { return matches_; } |
| 420 Node* index() const { return index_; } | 431 Node* index() const { return index_; } |
| 421 int scale() const { return scale_; } | 432 int scale() const { return scale_; } |
| 422 Node* base() const { return base_; } | 433 Node* base() const { return base_; } |
| 423 Node* displacement() const { return displacement_; } | 434 Node* displacement() const { return displacement_; } |
| 424 DisplacementMode displacement_mode() const { return displacement_mode_; } | 435 DisplacementMode displacement_mode() const { return displacement_mode_; } |
| 425 | 436 |
| 426 private: | 437 private: |
| 427 bool matches_; | 438 bool matches_; |
| 428 Node* index_; | 439 Node* index_; |
| 429 int scale_; | 440 int scale_; |
| 430 Node* base_; | 441 Node* base_; |
| 431 Node* displacement_; | 442 Node* displacement_; |
| 432 DisplacementMode displacement_mode_; | 443 DisplacementMode displacement_mode_; |
| 433 | 444 |
| 434 void Initialize(Node* node, bool allow_input_swap) { | 445 void Initialize(Node* node, Flags flags) { |
| 435 // The BaseWithIndexAndDisplacementMatcher canonicalizes the order of | 446 // The BaseWithIndexAndDisplacementMatcher canonicalizes the order of |
| 436 // displacements and scale factors that are used as inputs, so instead of | 447 // displacements and scale factors that are used as inputs, so instead of |
| 437 // enumerating all possible patterns by brute force, checking for node | 448 // enumerating all possible patterns by brute force, checking for node |
| 438 // clusters using the following templates in the following order suffices to | 449 // clusters using the following templates in the following order suffices to |
| 439 // find all of the interesting cases (S = index * scale, B = base input, D = | 450 // find all of the interesting cases (S = index * scale, B = base input, D = |
| 440 // displacement input): | 451 // displacement input): |
| 441 // (S + (B + D)) | 452 // (S + (B + D)) |
| 442 // (S + (B + B)) | 453 // (S + (B + B)) |
| 443 // (S + D) | 454 // (S + D) |
| 444 // (S + B) | 455 // (S + B) |
| 445 // ((S + D) + B) | 456 // ((S + D) + B) |
| 446 // ((S + B) + D) | 457 // ((S + B) + D) |
| 447 // ((B + D) + B) | 458 // ((B + D) + B) |
| 448 // ((B + B) + D) | 459 // ((B + B) + D) |
| 449 // (B + D) | 460 // (B + D) |
| 450 // (B + B) | 461 // (B + B) |
| 451 if (node->InputCount() < 2) return; | 462 if (node->InputCount() < 2) return; |
| 452 AddMatcher m(node, allow_input_swap); | 463 AddMatcher m(node, flags & kAllowInputSwap); |
| 453 Node* left = m.left().node(); | 464 Node* left = m.left().node(); |
| 454 Node* right = m.right().node(); | 465 Node* right = m.right().node(); |
| 455 Node* displacement = nullptr; | 466 Node* displacement = nullptr; |
| 456 Node* base = nullptr; | 467 Node* base = nullptr; |
| 457 Node* index = nullptr; | 468 Node* index = nullptr; |
| 458 Node* scale_expression = nullptr; | 469 Node* scale_expression = nullptr; |
| 459 bool power_of_two_plus_one = false; | 470 bool power_of_two_plus_one = false; |
| 460 DisplacementMode displacement_mode = kPositiveDisplacement; | 471 DisplacementMode displacement_mode = kPositiveDisplacement; |
| 461 int scale = 0; | 472 int scale = 0; |
| 462 if (m.HasIndexInput() && left->OwnedBy(node)) { | 473 if (m.HasIndexInput() && left->OwnedBy(node)) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 // If the scale requires explicitly using the index as the base, but a | 612 // If the scale requires explicitly using the index as the base, but a |
| 602 // base is already part of the match, then the (1 << N + 1) scale factor | 613 // base is already part of the match, then the (1 << N + 1) scale factor |
| 603 // can't be folded into the match and the entire index * scale | 614 // can't be folded into the match and the entire index * scale |
| 604 // calculation must be computed separately. | 615 // calculation must be computed separately. |
| 605 index = scale_expression; | 616 index = scale_expression; |
| 606 scale = 0; | 617 scale = 0; |
| 607 } else { | 618 } else { |
| 608 base = index; | 619 base = index; |
| 609 } | 620 } |
| 610 } | 621 } |
| 622 if (!(flags & kAllowScale) && scale != 0) { | |
| 623 index = scale_expression; | |
| 624 scale = 0; | |
| 625 } | |
| 611 base_ = base; | 626 base_ = base; |
| 612 displacement_ = displacement; | 627 displacement_ = displacement; |
| 613 displacement_mode_ = displacement_mode; | 628 displacement_mode_ = displacement_mode; |
| 614 index_ = index; | 629 index_ = index; |
| 615 scale_ = scale; | 630 scale_ = scale; |
| 616 matches_ = true; | 631 matches_ = true; |
| 617 } | 632 } |
| 618 }; | 633 }; |
| 619 | 634 |
| 620 typedef BaseWithIndexAndDisplacementMatcher<Int32AddMatcher> | 635 typedef BaseWithIndexAndDisplacementMatcher<Int32AddMatcher> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 668 Node* branch_; | 683 Node* branch_; |
| 669 Node* if_true_; | 684 Node* if_true_; |
| 670 Node* if_false_; | 685 Node* if_false_; |
| 671 }; | 686 }; |
| 672 | 687 |
| 673 } // namespace compiler | 688 } // namespace compiler |
| 674 } // namespace internal | 689 } // namespace internal |
| 675 } // namespace v8 | 690 } // namespace v8 |
| 676 | 691 |
| 677 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 692 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
| OLD | NEW |