| 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/js-operator.h" |
| 10 #include "src/compiler/node-properties.h" | 11 #include "src/compiler/node-properties.h" |
| 11 #include "src/compiler/simplified-operator.h" | 12 #include "src/compiler/simplified-operator.h" |
| 12 #include "src/unique.h" | 13 #include "src/unique.h" |
| 13 | 14 |
| 14 using testing::_; | 15 using testing::_; |
| 15 using testing::MakeMatcher; | 16 using testing::MakeMatcher; |
| 16 using testing::MatcherInterface; | 17 using testing::MatcherInterface; |
| 17 using testing::MatchResultListener; | 18 using testing::MatchResultListener; |
| 18 using testing::StringMatchResultListener; | 19 using testing::StringMatchResultListener; |
| 19 | 20 |
| (...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 | 1180 |
| 1180 private: | 1181 private: |
| 1181 const Matcher<LoadRepresentation> rep_matcher_; | 1182 const Matcher<LoadRepresentation> rep_matcher_; |
| 1182 const Matcher<Node*> base_matcher_; | 1183 const Matcher<Node*> base_matcher_; |
| 1183 const Matcher<Node*> index_matcher_; | 1184 const Matcher<Node*> index_matcher_; |
| 1184 const Matcher<Node*> effect_matcher_; | 1185 const Matcher<Node*> effect_matcher_; |
| 1185 const Matcher<Node*> control_matcher_; | 1186 const Matcher<Node*> control_matcher_; |
| 1186 }; | 1187 }; |
| 1187 | 1188 |
| 1188 | 1189 |
| 1189 class IsToNumberMatcher final : public NodeMatcher { | 1190 class IsStoreMatcher final : public NodeMatcher { |
| 1190 public: | 1191 public: |
| 1191 IsToNumberMatcher(const Matcher<Node*>& base_matcher, | 1192 IsStoreMatcher(const Matcher<StoreRepresentation>& rep_matcher, |
| 1192 const Matcher<Node*>& context_matcher, | 1193 const Matcher<Node*>& base_matcher, |
| 1193 const Matcher<Node*>& effect_matcher, | 1194 const Matcher<Node*>& index_matcher, |
| 1194 const Matcher<Node*>& control_matcher) | 1195 const Matcher<Node*>& value_matcher, |
| 1195 : NodeMatcher(IrOpcode::kJSToNumber), | 1196 const Matcher<Node*>& effect_matcher, |
| 1197 const Matcher<Node*>& control_matcher) |
| 1198 : NodeMatcher(IrOpcode::kStore), |
| 1199 rep_matcher_(rep_matcher), |
| 1196 base_matcher_(base_matcher), | 1200 base_matcher_(base_matcher), |
| 1197 context_matcher_(context_matcher), | 1201 index_matcher_(index_matcher), |
| 1202 value_matcher_(value_matcher), |
| 1198 effect_matcher_(effect_matcher), | 1203 effect_matcher_(effect_matcher), |
| 1199 control_matcher_(control_matcher) {} | 1204 control_matcher_(control_matcher) {} |
| 1200 | 1205 |
| 1201 void DescribeTo(std::ostream* os) const final { | 1206 void DescribeTo(std::ostream* os) const final { |
| 1202 NodeMatcher::DescribeTo(os); | 1207 NodeMatcher::DescribeTo(os); |
| 1203 *os << " whose base ("; | 1208 *os << " whose rep ("; |
| 1209 rep_matcher_.DescribeTo(os); |
| 1210 *os << "), base ("; |
| 1204 base_matcher_.DescribeTo(os); | 1211 base_matcher_.DescribeTo(os); |
| 1205 *os << "), context ("; | 1212 *os << "), index ("; |
| 1206 context_matcher_.DescribeTo(os); | 1213 index_matcher_.DescribeTo(os); |
| 1214 *os << "), value ("; |
| 1215 value_matcher_.DescribeTo(os); |
| 1207 *os << "), effect ("; | 1216 *os << "), effect ("; |
| 1208 effect_matcher_.DescribeTo(os); | 1217 effect_matcher_.DescribeTo(os); |
| 1209 *os << ") and control ("; | 1218 *os << ") and control ("; |
| 1210 control_matcher_.DescribeTo(os); | 1219 control_matcher_.DescribeTo(os); |
| 1211 *os << ")"; | 1220 *os << ")"; |
| 1212 } | 1221 } |
| 1213 | 1222 |
| 1214 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { | 1223 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { |
| 1215 return (NodeMatcher::MatchAndExplain(node, listener) && | 1224 return (NodeMatcher::MatchAndExplain(node, listener) && |
| 1225 PrintMatchAndExplain(OpParameter<StoreRepresentation>(node), "rep", |
| 1226 rep_matcher_, listener) && |
| 1216 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base", | 1227 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base", |
| 1217 base_matcher_, listener) && | 1228 base_matcher_, listener) && |
| 1218 PrintMatchAndExplain(NodeProperties::GetContextInput(node), | 1229 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), |
| 1219 "context", context_matcher_, listener) && | 1230 "index", index_matcher_, listener) && |
| 1231 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), |
| 1232 "value", value_matcher_, listener) && |
| 1220 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", | 1233 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", |
| 1221 effect_matcher_, listener) && | 1234 effect_matcher_, listener) && |
| 1222 PrintMatchAndExplain(NodeProperties::GetControlInput(node), | 1235 PrintMatchAndExplain(NodeProperties::GetControlInput(node), |
| 1223 "control", control_matcher_, listener)); | 1236 "control", control_matcher_, listener)); |
| 1224 } | 1237 } |
| 1225 | 1238 |
| 1226 private: | 1239 private: |
| 1240 const Matcher<StoreRepresentation> rep_matcher_; |
| 1227 const Matcher<Node*> base_matcher_; | 1241 const Matcher<Node*> base_matcher_; |
| 1228 const Matcher<Node*> context_matcher_; | 1242 const Matcher<Node*> index_matcher_; |
| 1243 const Matcher<Node*> value_matcher_; |
| 1229 const Matcher<Node*> effect_matcher_; | 1244 const Matcher<Node*> effect_matcher_; |
| 1230 const Matcher<Node*> control_matcher_; | 1245 const Matcher<Node*> control_matcher_; |
| 1231 }; | 1246 }; |
| 1232 | 1247 |
| 1233 | 1248 |
| 1234 class IsStoreMatcher final : public NodeMatcher { | 1249 class IsToNumberMatcher final : public NodeMatcher { |
| 1235 public: | 1250 public: |
| 1236 IsStoreMatcher(const Matcher<StoreRepresentation>& rep_matcher, | 1251 IsToNumberMatcher(const Matcher<Node*>& base_matcher, |
| 1237 const Matcher<Node*>& base_matcher, | 1252 const Matcher<Node*>& context_matcher, |
| 1238 const Matcher<Node*>& index_matcher, | 1253 const Matcher<Node*>& effect_matcher, |
| 1239 const Matcher<Node*>& value_matcher, | 1254 const Matcher<Node*>& control_matcher) |
| 1240 const Matcher<Node*>& effect_matcher, | 1255 : NodeMatcher(IrOpcode::kJSToNumber), |
| 1241 const Matcher<Node*>& control_matcher) | |
| 1242 : NodeMatcher(IrOpcode::kStore), | |
| 1243 rep_matcher_(rep_matcher), | |
| 1244 base_matcher_(base_matcher), | 1256 base_matcher_(base_matcher), |
| 1245 index_matcher_(index_matcher), | 1257 context_matcher_(context_matcher), |
| 1246 value_matcher_(value_matcher), | |
| 1247 effect_matcher_(effect_matcher), | 1258 effect_matcher_(effect_matcher), |
| 1248 control_matcher_(control_matcher) {} | 1259 control_matcher_(control_matcher) {} |
| 1249 | 1260 |
| 1250 void DescribeTo(std::ostream* os) const final { | 1261 void DescribeTo(std::ostream* os) const final { |
| 1251 NodeMatcher::DescribeTo(os); | 1262 NodeMatcher::DescribeTo(os); |
| 1252 *os << " whose rep ("; | 1263 *os << " whose base ("; |
| 1253 rep_matcher_.DescribeTo(os); | |
| 1254 *os << "), base ("; | |
| 1255 base_matcher_.DescribeTo(os); | 1264 base_matcher_.DescribeTo(os); |
| 1256 *os << "), index ("; | 1265 *os << "), context ("; |
| 1257 index_matcher_.DescribeTo(os); | 1266 context_matcher_.DescribeTo(os); |
| 1258 *os << "), value ("; | |
| 1259 value_matcher_.DescribeTo(os); | |
| 1260 *os << "), effect ("; | 1267 *os << "), effect ("; |
| 1261 effect_matcher_.DescribeTo(os); | 1268 effect_matcher_.DescribeTo(os); |
| 1262 *os << ") and control ("; | 1269 *os << ") and control ("; |
| 1263 control_matcher_.DescribeTo(os); | 1270 control_matcher_.DescribeTo(os); |
| 1264 *os << ")"; | 1271 *os << ")"; |
| 1265 } | 1272 } |
| 1266 | 1273 |
| 1267 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { | 1274 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { |
| 1268 return (NodeMatcher::MatchAndExplain(node, listener) && | 1275 return (NodeMatcher::MatchAndExplain(node, listener) && |
| 1269 PrintMatchAndExplain(OpParameter<StoreRepresentation>(node), "rep", | |
| 1270 rep_matcher_, listener) && | |
| 1271 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base", | 1276 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base", |
| 1272 base_matcher_, listener) && | 1277 base_matcher_, listener) && |
| 1273 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), | 1278 PrintMatchAndExplain(NodeProperties::GetContextInput(node), |
| 1274 "index", index_matcher_, listener) && | 1279 "context", context_matcher_, listener) && |
| 1275 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), | |
| 1276 "value", value_matcher_, listener) && | |
| 1277 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", | 1280 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect", |
| 1278 effect_matcher_, listener) && | 1281 effect_matcher_, listener) && |
| 1279 PrintMatchAndExplain(NodeProperties::GetControlInput(node), | 1282 PrintMatchAndExplain(NodeProperties::GetControlInput(node), |
| 1280 "control", control_matcher_, listener)); | 1283 "control", control_matcher_, listener)); |
| 1281 } | 1284 } |
| 1282 | 1285 |
| 1283 private: | 1286 private: |
| 1284 const Matcher<StoreRepresentation> rep_matcher_; | |
| 1285 const Matcher<Node*> base_matcher_; | 1287 const Matcher<Node*> base_matcher_; |
| 1286 const Matcher<Node*> index_matcher_; | 1288 const Matcher<Node*> context_matcher_; |
| 1287 const Matcher<Node*> value_matcher_; | |
| 1288 const Matcher<Node*> effect_matcher_; | 1289 const Matcher<Node*> effect_matcher_; |
| 1289 const Matcher<Node*> control_matcher_; | 1290 const Matcher<Node*> control_matcher_; |
| 1290 }; | 1291 }; |
| 1291 | 1292 |
| 1292 | 1293 |
| 1294 class IsLoadContextMatcher final : public NodeMatcher { |
| 1295 public: |
| 1296 IsLoadContextMatcher(const Matcher<ContextAccess>& access_matcher, |
| 1297 const Matcher<Node*>& context_matcher) |
| 1298 : NodeMatcher(IrOpcode::kJSLoadContext), |
| 1299 access_matcher_(access_matcher), |
| 1300 context_matcher_(context_matcher) {} |
| 1301 |
| 1302 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final { |
| 1303 return (NodeMatcher::MatchAndExplain(node, listener) && |
| 1304 PrintMatchAndExplain(OpParameter<ContextAccess>(node), "access", |
| 1305 access_matcher_, listener) && |
| 1306 PrintMatchAndExplain(NodeProperties::GetContextInput(node), |
| 1307 "context", context_matcher_, listener)); |
| 1308 } |
| 1309 |
| 1310 private: |
| 1311 const Matcher<ContextAccess> access_matcher_; |
| 1312 const Matcher<Node*> context_matcher_; |
| 1313 }; |
| 1314 |
| 1315 |
| 1293 class IsBinopMatcher final : public NodeMatcher { | 1316 class IsBinopMatcher final : public NodeMatcher { |
| 1294 public: | 1317 public: |
| 1295 IsBinopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& lhs_matcher, | 1318 IsBinopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& lhs_matcher, |
| 1296 const Matcher<Node*>& rhs_matcher) | 1319 const Matcher<Node*>& rhs_matcher) |
| 1297 : NodeMatcher(opcode), | 1320 : NodeMatcher(opcode), |
| 1298 lhs_matcher_(lhs_matcher), | 1321 lhs_matcher_(lhs_matcher), |
| 1299 rhs_matcher_(rhs_matcher) {} | 1322 rhs_matcher_(rhs_matcher) {} |
| 1300 | 1323 |
| 1301 void DescribeTo(std::ostream* os) const final { | 1324 void DescribeTo(std::ostream* os) const final { |
| 1302 NodeMatcher::DescribeTo(os); | 1325 NodeMatcher::DescribeTo(os); |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 Matcher<Node*> IsLoad(const Matcher<LoadRepresentation>& rep_matcher, | 1743 Matcher<Node*> IsLoad(const Matcher<LoadRepresentation>& rep_matcher, |
| 1721 const Matcher<Node*>& base_matcher, | 1744 const Matcher<Node*>& base_matcher, |
| 1722 const Matcher<Node*>& index_matcher, | 1745 const Matcher<Node*>& index_matcher, |
| 1723 const Matcher<Node*>& effect_matcher, | 1746 const Matcher<Node*>& effect_matcher, |
| 1724 const Matcher<Node*>& control_matcher) { | 1747 const Matcher<Node*>& control_matcher) { |
| 1725 return MakeMatcher(new IsLoadMatcher(rep_matcher, base_matcher, index_matcher, | 1748 return MakeMatcher(new IsLoadMatcher(rep_matcher, base_matcher, index_matcher, |
| 1726 effect_matcher, control_matcher)); | 1749 effect_matcher, control_matcher)); |
| 1727 } | 1750 } |
| 1728 | 1751 |
| 1729 | 1752 |
| 1730 Matcher<Node*> IsToNumber(const Matcher<Node*>& base_matcher, | |
| 1731 const Matcher<Node*>& context_matcher, | |
| 1732 const Matcher<Node*>& effect_matcher, | |
| 1733 const Matcher<Node*>& control_matcher) { | |
| 1734 return MakeMatcher(new IsToNumberMatcher(base_matcher, context_matcher, | |
| 1735 effect_matcher, control_matcher)); | |
| 1736 } | |
| 1737 | |
| 1738 | |
| 1739 Matcher<Node*> IsStore(const Matcher<StoreRepresentation>& rep_matcher, | 1753 Matcher<Node*> IsStore(const Matcher<StoreRepresentation>& rep_matcher, |
| 1740 const Matcher<Node*>& base_matcher, | 1754 const Matcher<Node*>& base_matcher, |
| 1741 const Matcher<Node*>& index_matcher, | 1755 const Matcher<Node*>& index_matcher, |
| 1742 const Matcher<Node*>& value_matcher, | 1756 const Matcher<Node*>& value_matcher, |
| 1743 const Matcher<Node*>& effect_matcher, | 1757 const Matcher<Node*>& effect_matcher, |
| 1744 const Matcher<Node*>& control_matcher) { | 1758 const Matcher<Node*>& control_matcher) { |
| 1745 return MakeMatcher(new IsStoreMatcher(rep_matcher, base_matcher, | 1759 return MakeMatcher(new IsStoreMatcher(rep_matcher, base_matcher, |
| 1746 index_matcher, value_matcher, | 1760 index_matcher, value_matcher, |
| 1747 effect_matcher, control_matcher)); | 1761 effect_matcher, control_matcher)); |
| 1748 } | 1762 } |
| 1749 | 1763 |
| 1750 | 1764 |
| 1765 Matcher<Node*> IsToNumber(const Matcher<Node*>& base_matcher, |
| 1766 const Matcher<Node*>& context_matcher, |
| 1767 const Matcher<Node*>& effect_matcher, |
| 1768 const Matcher<Node*>& control_matcher) { |
| 1769 return MakeMatcher(new IsToNumberMatcher(base_matcher, context_matcher, |
| 1770 effect_matcher, control_matcher)); |
| 1771 } |
| 1772 |
| 1773 |
| 1774 Matcher<Node*> IsLoadContext(const Matcher<ContextAccess>& access_matcher, |
| 1775 const Matcher<Node*>& context_matcher) { |
| 1776 return MakeMatcher(new IsLoadContextMatcher(access_matcher, context_matcher)); |
| 1777 } |
| 1778 |
| 1779 |
| 1751 #define IS_BINOP_MATCHER(Name) \ | 1780 #define IS_BINOP_MATCHER(Name) \ |
| 1752 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \ | 1781 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \ |
| 1753 const Matcher<Node*>& rhs_matcher) { \ | 1782 const Matcher<Node*>& rhs_matcher) { \ |
| 1754 return MakeMatcher( \ | 1783 return MakeMatcher( \ |
| 1755 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \ | 1784 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \ |
| 1756 } | 1785 } |
| 1757 IS_BINOP_MATCHER(NumberEqual) | 1786 IS_BINOP_MATCHER(NumberEqual) |
| 1758 IS_BINOP_MATCHER(NumberLessThan) | 1787 IS_BINOP_MATCHER(NumberLessThan) |
| 1759 IS_BINOP_MATCHER(NumberSubtract) | 1788 IS_BINOP_MATCHER(NumberSubtract) |
| 1760 IS_BINOP_MATCHER(NumberMultiply) | 1789 IS_BINOP_MATCHER(NumberMultiply) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1811 IS_UNOP_MATCHER(NumberToInt32) | 1840 IS_UNOP_MATCHER(NumberToInt32) |
| 1812 IS_UNOP_MATCHER(NumberToUint32) | 1841 IS_UNOP_MATCHER(NumberToUint32) |
| 1813 IS_UNOP_MATCHER(ObjectIsSmi) | 1842 IS_UNOP_MATCHER(ObjectIsSmi) |
| 1814 IS_UNOP_MATCHER(ObjectIsNonNegativeSmi) | 1843 IS_UNOP_MATCHER(ObjectIsNonNegativeSmi) |
| 1815 IS_UNOP_MATCHER(Word32Clz) | 1844 IS_UNOP_MATCHER(Word32Clz) |
| 1816 #undef IS_UNOP_MATCHER | 1845 #undef IS_UNOP_MATCHER |
| 1817 | 1846 |
| 1818 } // namespace compiler | 1847 } // namespace compiler |
| 1819 } // namespace internal | 1848 } // namespace internal |
| 1820 } // namespace v8 | 1849 } // namespace v8 |
| OLD | NEW |