#ifndef V8_COMPILER_NODE_MATCHERS_H_
#define V8_COMPILER_NODE_MATCHERS_H_
-#include "src/compiler/common-operator.h"
+#include "src/compiler/node.h"
+#include "src/compiler/operator.h"
namespace v8 {
namespace internal {
explicit NodeMatcher(Node* node) : node_(node) {}
Node* node() const { return node_; }
- Operator* op() const { return node()->op(); }
+ const Operator* op() const { return node()->op(); }
IrOpcode::Value opcode() const { return node()->opcode(); }
bool HasProperty(Operator::Property property) const {
// A pattern matcher for abitrary value constants.
-template <typename T>
+template <typename T, IrOpcode::Value kOpcode>
struct ValueMatcher : public NodeMatcher {
explicit ValueMatcher(Node* node)
- : NodeMatcher(node),
- value_(),
- has_value_(CommonOperatorTraits<T>::HasValue(node->op())) {
- if (has_value_) value_ = CommonOperatorTraits<T>::ValueOf(node->op());
+ : NodeMatcher(node), value_(), has_value_(opcode() == kOpcode) {
+ if (has_value_) {
+ value_ = OpParameter<T>(node);
+ }
}
bool HasValue() const { return has_value_; }
- T Value() const {
+ const T& Value() const {
DCHECK(HasValue());
return value_;
}
- bool Is(T value) const {
- return HasValue() && CommonOperatorTraits<T>::Equals(Value(), value);
+ bool Is(const T& value) const {
+ return this->HasValue() && this->Value() == value;
}
- bool IsInRange(T low, T high) const {
- return HasValue() && low <= value_ && value_ <= high;
+ bool IsInRange(const T& low, const T& high) const {
+ return this->HasValue() && low <= this->Value() && this->Value() <= high;
}
private:
// A pattern matcher for integer constants.
-template <typename T>
-struct IntMatcher V8_FINAL : public ValueMatcher<T> {
- explicit IntMatcher(Node* node) : ValueMatcher<T>(node) {}
+template <typename T, IrOpcode::Value kOpcode>
+struct IntMatcher FINAL : public ValueMatcher<T, kOpcode> {
+ explicit IntMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {}
bool IsPowerOf2() const {
return this->HasValue() && this->Value() > 0 &&
}
};
-typedef IntMatcher<int32_t> Int32Matcher;
-typedef IntMatcher<uint32_t> Uint32Matcher;
-typedef IntMatcher<int64_t> Int64Matcher;
-typedef IntMatcher<uint64_t> Uint64Matcher;
+typedef IntMatcher<int32_t, IrOpcode::kInt32Constant> Int32Matcher;
+typedef IntMatcher<uint32_t, IrOpcode::kInt32Constant> Uint32Matcher;
+typedef IntMatcher<int64_t, IrOpcode::kInt64Constant> Int64Matcher;
+typedef IntMatcher<uint64_t, IrOpcode::kInt64Constant> Uint64Matcher;
// A pattern matcher for floating point constants.
-template <typename T>
-struct FloatMatcher V8_FINAL : public ValueMatcher<T> {
- explicit FloatMatcher(Node* node) : ValueMatcher<T>(node) {}
+template <typename T, IrOpcode::Value kOpcode>
+struct FloatMatcher FINAL : public ValueMatcher<T, kOpcode> {
+ explicit FloatMatcher(Node* node) : ValueMatcher<T, kOpcode>(node) {}
bool IsNaN() const { return this->HasValue() && std::isnan(this->Value()); }
};
-typedef FloatMatcher<double> Float64Matcher;
+typedef FloatMatcher<float, IrOpcode::kFloat32Constant> Float32Matcher;
+typedef FloatMatcher<double, IrOpcode::kFloat64Constant> Float64Matcher;
+typedef FloatMatcher<double, IrOpcode::kNumberConstant> NumberMatcher;
+
+
+// A pattern matcher for heap object constants.
+template <typename T>
+struct HeapObjectMatcher FINAL
+ : public ValueMatcher<Unique<T>, IrOpcode::kHeapConstant> {
+ explicit HeapObjectMatcher(Node* node)
+ : ValueMatcher<Unique<T>, IrOpcode::kHeapConstant>(node) {}
+};
// For shorter pattern matching code, this struct matches both the left and
// right hand sides of a binary operation and can put constants on the right
// if they appear on the left hand side of a commutative operation.
template <typename Left, typename Right>
-struct BinopMatcher V8_FINAL : public NodeMatcher {
+struct BinopMatcher FINAL : public NodeMatcher {
explicit BinopMatcher(Node* node)
: NodeMatcher(node), left_(InputAt(0)), right_(InputAt(1)) {
if (HasProperty(Operator::kCommutative)) PutConstantOnRight();
typedef BinopMatcher<Int64Matcher, Int64Matcher> Int64BinopMatcher;
typedef BinopMatcher<Uint64Matcher, Uint64Matcher> Uint64BinopMatcher;
typedef BinopMatcher<Float64Matcher, Float64Matcher> Float64BinopMatcher;
-}
-}
-} // namespace v8::internal::compiler
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
#endif // V8_COMPILER_NODE_MATCHERS_H_