| Index: src/compiler/node-matchers.cc
|
| diff --git a/src/compiler/node-matchers.cc b/src/compiler/node-matchers.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9227d8a2a8f4ab40be9a2c3908f310dba925da26
|
| --- /dev/null
|
| +++ b/src/compiler/node-matchers.cc
|
| @@ -0,0 +1,100 @@
|
| +// Copyright 2014 the V8 project authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "src/compiler/node-matchers.h"
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +namespace compiler {
|
| +
|
| +const int ScaleFactorMatcher::kMatchedFactors[] = {1, 2, 4, 8};
|
| +
|
| +
|
| +void ScaleFactorMatcher::Match() {
|
| + if (opcode() != IrOpcode::kInt32Mul) return;
|
| + // TODO(dcarney): should test 64 bit ints as well.
|
| + Int32BinopMatcher m(node());
|
| + if (!m.right().HasValue()) return;
|
| + int32_t value = m.right().Value();
|
| + switch (value) {
|
| + case 8:
|
| + power_++; // Fall through.
|
| + case 4:
|
| + power_++; // Fall through.
|
| + case 2:
|
| + power_++; // Fall through.
|
| + case 1:
|
| + break;
|
| + default:
|
| + return;
|
| + }
|
| + left_ = m.left().node();
|
| +}
|
| +
|
| +
|
| +void IndexAndDisplacementMatcher::Match() {
|
| + if (opcode() == IrOpcode::kInt32Add) {
|
| + Int32BinopMatcher m(node());
|
| + if (m.right().HasValue()) {
|
| + displacement_ = m.right().Value();
|
| + index_node_ = m.left().node();
|
| + }
|
| + }
|
| + // Test scale factor.
|
| + ScaleFactorMatcher scale_matcher(index_node_);
|
| + if (scale_matcher.Matches()) {
|
| + index_node_ = scale_matcher.Left();
|
| + power_ = scale_matcher.Power();
|
| + }
|
| +}
|
| +
|
| +
|
| +const int LeaMultiplyMatcher::kMatchedFactors[7] = {1, 2, 3, 4, 5, 8, 9};
|
| +
|
| +
|
| +void LeaMultiplyMatcher::Match() {
|
| + if (opcode() != IrOpcode::kInt32Mul && opcode() != IrOpcode::kInt64Mul) {
|
| + return;
|
| + }
|
| + int64_t value;
|
| + Node* left = NULL;
|
| + {
|
| + Int32BinopMatcher m(node());
|
| + if (m.right().HasValue()) {
|
| + value = m.right().Value();
|
| + left = m.left().node();
|
| + } else {
|
| + Int64BinopMatcher m(node());
|
| + if (m.right().HasValue()) {
|
| + value = m.right().Value();
|
| + left = m.left().node();
|
| + } else {
|
| + return;
|
| + }
|
| + }
|
| + }
|
| + switch (value) {
|
| + case 9:
|
| + case 8:
|
| + power_++; // Fall through.
|
| + case 5:
|
| + case 4:
|
| + power_++; // Fall through.
|
| + case 3:
|
| + case 2:
|
| + power_++; // Fall through.
|
| + case 1:
|
| + break;
|
| + default:
|
| + return;
|
| + }
|
| + if (!base::bits::IsPowerOfTwo64(value)) {
|
| + displacement_ = 1;
|
| + }
|
| + left_ = left;
|
| +}
|
| +
|
| +} // namespace compiler
|
| +} // namespace internal
|
| +} // namespace v8
|
|
|