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 #include "test/unittests/compiler/node-test-utils.h" | 5 #include "test/unittests/compiler/node-test-utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "src/assembler.h" | 9 #include "src/assembler.h" |
10 #include "src/compiler/common-operator.h" | 10 #include "src/compiler/common-operator.h" |
(...skipping 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1397 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { | 1397 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { |
1398 return (NodeMatcher::MatchAndExplain(node, listener) && | 1398 return (NodeMatcher::MatchAndExplain(node, listener) && |
1399 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), | 1399 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), |
1400 "input", input_matcher_, listener)); | 1400 "input", input_matcher_, listener)); |
1401 } | 1401 } |
1402 | 1402 |
1403 private: | 1403 private: |
1404 const Matcher<Node*> input_matcher_; | 1404 const Matcher<Node*> input_matcher_; |
1405 }; | 1405 }; |
1406 | 1406 |
1407 | |
1407 class IsParameterMatcher final : public NodeMatcher { | 1408 class IsParameterMatcher final : public NodeMatcher { |
1408 public: | 1409 public: |
1409 explicit IsParameterMatcher(const Matcher<int>& index_matcher) | 1410 explicit IsParameterMatcher(const Matcher<int>& index_matcher) |
1410 : NodeMatcher(IrOpcode::kParameter), index_matcher_(index_matcher) {} | 1411 : NodeMatcher(IrOpcode::kParameter), index_matcher_(index_matcher) {} |
1411 | 1412 |
1412 void DescribeTo(std::ostream* os) const override { | 1413 void DescribeTo(std::ostream* os) const override { |
1413 *os << "is a Parameter node with index("; | 1414 *os << "is a Parameter node with index("; |
1414 index_matcher_.DescribeTo(os); | 1415 index_matcher_.DescribeTo(os); |
1415 *os << ")"; | 1416 *os << ")"; |
1416 } | 1417 } |
1417 | 1418 |
1418 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { | 1419 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { |
1419 return (NodeMatcher::MatchAndExplain(node, listener) && | 1420 return (NodeMatcher::MatchAndExplain(node, listener) && |
1420 PrintMatchAndExplain(ParameterIndexOf(node->op()), "index", | 1421 PrintMatchAndExplain(ParameterIndexOf(node->op()), "index", |
1421 index_matcher_, listener)); | 1422 index_matcher_, listener)); |
1422 } | 1423 } |
1423 | 1424 |
1424 private: | 1425 private: |
1425 const Matcher<int> index_matcher_; | 1426 const Matcher<int> index_matcher_; |
1426 }; | 1427 }; |
1427 | 1428 |
1429 | |
1430 // TODO(mythria): Check if we can use the same matcher for Load and Store | |
1431 class IsNamedLoadMatcher final : public NodeMatcher { | |
1432 public: | |
1433 IsNamedLoadMatcher(IrOpcode::Value opcode, | |
rmcilroy
2015/11/09 15:23:01
don't pass the opcode to this constructor, just us
mythria
2015/11/10 09:55:35
Done.
| |
1434 const Matcher<NamedAccess>& named_access_matcher, | |
1435 const Matcher<Node*>& object_value_matcher, | |
1436 const Matcher<Node*>& feedback_vector_matcher, | |
1437 const Matcher<Node*>& effect_matcher, | |
1438 const Matcher<Node*>& control_matcher) | |
1439 : NodeMatcher(opcode), | |
1440 named_access_matcher_(named_access_matcher), | |
1441 object_value_matcher_(object_value_matcher), | |
1442 feedback_vector_matcher_(feedback_vector_matcher), | |
1443 effect_matcher_(effect_matcher), | |
1444 control_matcher_(control_matcher) {} | |
1445 | |
1446 void DescribeTo(std::ostream* os) const final { | |
1447 NodeMatcher::DescribeTo(os); | |
1448 *os << " whose object ("; | |
1449 object_value_matcher_.DescribeTo(os); | |
1450 *os << ") feedback vector ("; | |
rmcilroy
2015/11/09 15:23:01
/s/)/),/
mythria
2015/11/10 09:55:35
Done.
| |
1451 feedback_vector_matcher_.DescribeTo(os); | |
1452 *os << "), effect ("; | |
1453 effect_matcher_.DescribeTo(os); | |
1454 *os << ") and control ("; | |
1455 control_matcher_.DescribeTo(os); | |
1456 *os << ")"; | |
1457 } | |
1458 | |
1459 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { | |
1460 if (!NodeMatcher::MatchAndExplain(node, listener) || | |
1461 !PrintMatchAndExplain(OpParameter<const NamedAccess>(node), | |
1462 "descriptor", named_access_matcher_, listener)) { | |
1463 return false; | |
1464 } | |
1465 std::ostringstream ost; | |
1466 ost << "Object "; | |
1467 if (!PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), ost.str(), | |
1468 object_value_matcher_, listener)) { | |
1469 return false; | |
1470 } | |
1471 ost.clear(); | |
1472 ost << "FeedbackVector "; | |
1473 if (!PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), ost.str(), | |
1474 feedback_vector_matcher_, listener)) { | |
1475 return false; | |
1476 } | |
rmcilroy
2015/11/09 15:23:01
Please use the same pattern as the other matchers
mythria
2015/11/10 09:55:36
Done.
| |
1477 return (PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", | |
1478 effect_matcher_, listener) && | |
1479 PrintMatchAndExplain(NodeProperties::GetControlInput(node), | |
1480 "control", control_matcher_, listener)); | |
1481 } | |
1482 | |
1483 private: | |
1484 const Matcher<NamedAccess> named_access_matcher_; | |
1485 const Matcher<Node*> object_value_matcher_; | |
1486 const Matcher<Node*> feedback_vector_matcher_; | |
1487 const Matcher<Node*> effect_matcher_; | |
1488 const Matcher<Node*> control_matcher_; | |
1489 }; | |
1490 | |
1491 | |
1492 class IsNamedAccessMatcher final : public MatcherInterface<NamedAccess> { | |
rmcilroy
2015/11/09 15:23:01
As discussed, remove this.
mythria
2015/11/10 09:55:35
Done.
| |
1493 public: | |
1494 IsNamedAccessMatcher(LanguageMode language_mode, const Handle<Name>& name, | |
1495 const int slot_id) | |
1496 : language_mode_(language_mode), name_(name), slot_id_(slot_id) {} | |
1497 | |
1498 void DescribeTo(std::ostream* os) const final { | |
1499 *os << " NamedAccess with language_mode ("; | |
1500 *os << language_mode_; | |
1501 *os << ") name ("; | |
1502 *os << name_; | |
1503 *os << ") slot ("; | |
1504 *os << slot_id_; | |
1505 *os << ")"; | |
1506 } | |
1507 | |
1508 bool MatchAndExplain(NamedAccess node, | |
1509 MatchResultListener* listener) const final { | |
1510 if (node.language_mode() != language_mode_) { | |
1511 *listener << "whose languagemode is " << node.language_mode() | |
1512 << " but should have been " << language_mode_; | |
1513 return false; | |
1514 } | |
1515 if (!name_->StrictEquals(*node.name())) { | |
1516 *listener << "whose name is " << node.name() << " but should have been " | |
1517 << name_; | |
1518 return false; | |
1519 } | |
1520 if (node.feedback().slot().ToInt() != slot_id_) { | |
1521 *listener << "whose slot is " << node.feedback().slot().ToInt() | |
1522 << " but should have been " << slot_id_; | |
1523 return false; | |
1524 } | |
1525 // TODO(mythria): Check if Handle<TypeFeedbackVector> | |
1526 // (node.feedback().vector()) is equal to expected value | |
1527 return true; | |
1528 } | |
1529 | |
1530 private: | |
1531 const LanguageMode language_mode_; | |
1532 const Handle<Name> name_; | |
1533 const int slot_id_; | |
1534 }; | |
1535 | |
1428 } // namespace | 1536 } // namespace |
1429 | 1537 |
1430 | 1538 |
1431 Matcher<Node*> IsDead() { | 1539 Matcher<Node*> IsDead() { |
1432 return MakeMatcher(new NodeMatcher(IrOpcode::kDead)); | 1540 return MakeMatcher(new NodeMatcher(IrOpcode::kDead)); |
1433 } | 1541 } |
1434 | 1542 |
1435 | 1543 |
1436 Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher) { | 1544 Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher) { |
1437 return MakeMatcher(new IsControl1Matcher(IrOpcode::kEnd, control0_matcher)); | 1545 return MakeMatcher(new IsControl1Matcher(IrOpcode::kEnd, control0_matcher)); |
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1991 Matcher<Node*> IsParameter(const Matcher<int> index_matcher) { | 2099 Matcher<Node*> IsParameter(const Matcher<int> index_matcher) { |
1992 return MakeMatcher(new IsParameterMatcher(index_matcher)); | 2100 return MakeMatcher(new IsParameterMatcher(index_matcher)); |
1993 } | 2101 } |
1994 | 2102 |
1995 | 2103 |
1996 Matcher<Node*> IsLoadFramePointer() { | 2104 Matcher<Node*> IsLoadFramePointer() { |
1997 return MakeMatcher(new NodeMatcher(IrOpcode::kLoadFramePointer)); | 2105 return MakeMatcher(new NodeMatcher(IrOpcode::kLoadFramePointer)); |
1998 } | 2106 } |
1999 | 2107 |
2000 | 2108 |
2109 Matcher<Node*> IsNamedLoad(const Matcher<NamedAccess>& node_access_matcher, | |
rmcilroy
2015/11/09 15:23:01
IsJSLoadNamed (Follow the name of the IrOpcode)
mythria
2015/11/10 09:55:35
Done.
| |
2110 const Matcher<Node*>& object_value_matcher, | |
2111 const Matcher<Node*>& feedback_vector_matcher, | |
2112 const Matcher<Node*>& effect_matcher, | |
2113 const Matcher<Node*>& control_matcher) { | |
2114 return MakeMatcher(new IsNamedLoadMatcher( | |
2115 IrOpcode::kJSLoadNamed, node_access_matcher, object_value_matcher, | |
2116 feedback_vector_matcher, effect_matcher, control_matcher)); | |
2117 } | |
2118 | |
2119 | |
2120 Matcher<NamedAccess> IsNamedAccess(LanguageMode language_mode, | |
rmcilroy
2015/11/09 15:23:00
As discussed offline, let's not add a new NamedAcc
mythria
2015/11/10 09:55:36
As discussed, I pass Handle<Name> instead of match
| |
2121 const Handle<Name>& name, | |
2122 const int slot_id) { | |
2123 return MakeMatcher(new IsNamedAccessMatcher(language_mode, name, slot_id)); | |
2124 } | |
2125 | |
2126 | |
2001 #define IS_BINOP_MATCHER(Name) \ | 2127 #define IS_BINOP_MATCHER(Name) \ |
2002 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \ | 2128 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \ |
2003 const Matcher<Node*>& rhs_matcher) { \ | 2129 const Matcher<Node*>& rhs_matcher) { \ |
2004 return MakeMatcher( \ | 2130 return MakeMatcher( \ |
2005 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \ | 2131 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \ |
2006 } | 2132 } |
2007 IS_BINOP_MATCHER(NumberEqual) | 2133 IS_BINOP_MATCHER(NumberEqual) |
2008 IS_BINOP_MATCHER(NumberLessThan) | 2134 IS_BINOP_MATCHER(NumberLessThan) |
2009 IS_BINOP_MATCHER(NumberSubtract) | 2135 IS_BINOP_MATCHER(NumberSubtract) |
2010 IS_BINOP_MATCHER(NumberMultiply) | 2136 IS_BINOP_MATCHER(NumberMultiply) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2071 IS_UNOP_MATCHER(Float64ExtractHighWord32) | 2197 IS_UNOP_MATCHER(Float64ExtractHighWord32) |
2072 IS_UNOP_MATCHER(NumberToInt32) | 2198 IS_UNOP_MATCHER(NumberToInt32) |
2073 IS_UNOP_MATCHER(NumberToUint32) | 2199 IS_UNOP_MATCHER(NumberToUint32) |
2074 IS_UNOP_MATCHER(ObjectIsSmi) | 2200 IS_UNOP_MATCHER(ObjectIsSmi) |
2075 IS_UNOP_MATCHER(Word32Clz) | 2201 IS_UNOP_MATCHER(Word32Clz) |
2076 #undef IS_UNOP_MATCHER | 2202 #undef IS_UNOP_MATCHER |
2077 | 2203 |
2078 } // namespace compiler | 2204 } // namespace compiler |
2079 } // namespace internal | 2205 } // namespace internal |
2080 } // namespace v8 | 2206 } // namespace v8 |
OLD | NEW |