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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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> |
| 398 struct BaseWithIndexAndDisplacementMatcher { | 398 struct BaseWithIndexAndDisplacementMatcher { |
| 399 BaseWithIndexAndDisplacementMatcher(Node* node, bool allow_input_swap) | 399 BaseWithIndexAndDisplacementMatcher(Node* node, bool allow_input_swap, |
|
Benedikt Meurer
2016/08/12 17:57:06
Can you turn these two booleans into flags? Using
| |
| 400 bool allow_scale = true) | |
| 400 : matches_(false), | 401 : matches_(false), |
| 401 index_(nullptr), | 402 index_(nullptr), |
| 402 scale_(0), | 403 scale_(0), |
| 403 base_(nullptr), | 404 base_(nullptr), |
| 404 displacement_(nullptr), | 405 displacement_(nullptr), |
| 405 displacement_mode_(kPositiveDisplacement) { | 406 displacement_mode_(kPositiveDisplacement) { |
| 406 Initialize(node, allow_input_swap); | 407 Initialize(node, allow_input_swap, allow_scale); |
| 407 } | 408 } |
| 408 | 409 |
| 409 explicit BaseWithIndexAndDisplacementMatcher(Node* node) | 410 explicit BaseWithIndexAndDisplacementMatcher(Node* node) |
| 410 : matches_(false), | 411 : matches_(false), |
| 411 index_(nullptr), | 412 index_(nullptr), |
| 412 scale_(0), | 413 scale_(0), |
| 413 base_(nullptr), | 414 base_(nullptr), |
| 414 displacement_(nullptr), | 415 displacement_(nullptr), |
| 415 displacement_mode_(kPositiveDisplacement) { | 416 displacement_mode_(kPositiveDisplacement) { |
| 416 Initialize(node, node->op()->HasProperty(Operator::kCommutative)); | 417 Initialize(node, node->op()->HasProperty(Operator::kCommutative), true); |
| 417 } | 418 } |
| 418 | 419 |
| 419 bool matches() const { return matches_; } | 420 bool matches() const { return matches_; } |
| 420 Node* index() const { return index_; } | 421 Node* index() const { return index_; } |
| 421 int scale() const { return scale_; } | 422 int scale() const { return scale_; } |
| 422 Node* base() const { return base_; } | 423 Node* base() const { return base_; } |
| 423 Node* displacement() const { return displacement_; } | 424 Node* displacement() const { return displacement_; } |
| 424 DisplacementMode displacement_mode() const { return displacement_mode_; } | 425 DisplacementMode displacement_mode() const { return displacement_mode_; } |
| 425 | 426 |
| 426 private: | 427 private: |
| 427 bool matches_; | 428 bool matches_; |
| 428 Node* index_; | 429 Node* index_; |
| 429 int scale_; | 430 int scale_; |
| 430 Node* base_; | 431 Node* base_; |
| 431 Node* displacement_; | 432 Node* displacement_; |
| 432 DisplacementMode displacement_mode_; | 433 DisplacementMode displacement_mode_; |
| 433 | 434 |
| 434 void Initialize(Node* node, bool allow_input_swap) { | 435 void Initialize(Node* node, bool allow_input_swap, bool allow_scale) { |
| 435 // The BaseWithIndexAndDisplacementMatcher canonicalizes the order of | 436 // The BaseWithIndexAndDisplacementMatcher canonicalizes the order of |
| 436 // displacements and scale factors that are used as inputs, so instead of | 437 // displacements and scale factors that are used as inputs, so instead of |
| 437 // enumerating all possible patterns by brute force, checking for node | 438 // enumerating all possible patterns by brute force, checking for node |
| 438 // clusters using the following templates in the following order suffices to | 439 // 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 = | 440 // find all of the interesting cases (S = index * scale, B = base input, D = |
| 440 // displacement input): | 441 // displacement input): |
| 441 // (S + (B + D)) | 442 // (S + (B + D)) |
| 442 // (S + (B + B)) | 443 // (S + (B + B)) |
| 443 // (S + D) | 444 // (S + D) |
| 444 // (S + B) | 445 // (S + B) |
| (...skipping 156 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 | 602 // 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 | 603 // 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 | 604 // can't be folded into the match and the entire index * scale |
| 604 // calculation must be computed separately. | 605 // calculation must be computed separately. |
| 605 index = scale_expression; | 606 index = scale_expression; |
| 606 scale = 0; | 607 scale = 0; |
| 607 } else { | 608 } else { |
| 608 base = index; | 609 base = index; |
| 609 } | 610 } |
| 610 } | 611 } |
| 612 if (!allow_scale && scale != 0) { | |
| 613 index = scale_expression; | |
| 614 scale = 0; | |
| 615 } | |
| 611 base_ = base; | 616 base_ = base; |
| 612 displacement_ = displacement; | 617 displacement_ = displacement; |
| 613 displacement_mode_ = displacement_mode; | 618 displacement_mode_ = displacement_mode; |
| 614 index_ = index; | 619 index_ = index; |
| 615 scale_ = scale; | 620 scale_ = scale; |
| 616 matches_ = true; | 621 matches_ = true; |
| 617 } | 622 } |
| 618 }; | 623 }; |
| 619 | 624 |
| 620 typedef BaseWithIndexAndDisplacementMatcher<Int32AddMatcher> | 625 typedef BaseWithIndexAndDisplacementMatcher<Int32AddMatcher> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 668 Node* branch_; | 673 Node* branch_; |
| 669 Node* if_true_; | 674 Node* if_true_; |
| 670 Node* if_false_; | 675 Node* if_false_; |
| 671 }; | 676 }; |
| 672 | 677 |
| 673 } // namespace compiler | 678 } // namespace compiler |
| 674 } // namespace internal | 679 } // namespace internal |
| 675 } // namespace v8 | 680 } // namespace v8 |
| 676 | 681 |
| 677 #endif // V8_COMPILER_NODE_MATCHERS_H_ | 682 #endif // V8_COMPILER_NODE_MATCHERS_H_ |
| OLD | NEW |