blob: 6adacc163d0f896d744a241b3b2bc51965aea696 [file] [log] [blame]
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001// 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
3// found in the LICENSE file.
4
5#include "test/unittests/compiler/node-test-utils.h"
6
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00007#include <vector>
8
Emily Bernierd0a1eb72015-03-24 16:35:39 -04009#include "src/assembler.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000010#include "src/compiler/common-operator.h"
11#include "src/compiler/js-operator.h"
12#include "src/compiler/node-properties.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040013#include "src/compiler/simplified-operator.h"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000014#include "src/handles-inl.h"
15#include "src/objects.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040016
17using testing::_;
18using testing::MakeMatcher;
19using testing::MatcherInterface;
20using testing::MatchResultListener;
21using testing::StringMatchResultListener;
22
23namespace v8 {
24namespace internal {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000025
26bool operator==(Handle<HeapObject> const& lhs, Handle<HeapObject> const& rhs) {
27 return lhs.is_identical_to(rhs);
28}
29
Emily Bernierd0a1eb72015-03-24 16:35:39 -040030namespace compiler {
31
32namespace {
33
34template <typename T>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035bool PrintMatchAndExplain(const T& value, const std::string& value_name,
Emily Bernierd0a1eb72015-03-24 16:35:39 -040036 const Matcher<T>& value_matcher,
37 MatchResultListener* listener) {
38 StringMatchResultListener value_listener;
39 if (!value_matcher.MatchAndExplain(value, &value_listener)) {
40 *listener << "whose " << value_name << " " << value << " doesn't match";
41 if (value_listener.str() != "") {
42 *listener << ", " << value_listener.str();
43 }
44 return false;
45 }
46 return true;
47}
48
49
50class NodeMatcher : public MatcherInterface<Node*> {
51 public:
52 explicit NodeMatcher(IrOpcode::Value opcode) : opcode_(opcode) {}
53
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000054 void DescribeTo(std::ostream* os) const override {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040055 *os << "is a " << IrOpcode::Mnemonic(opcode_) << " node";
56 }
57
58 bool MatchAndExplain(Node* node,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000059 MatchResultListener* listener) const override {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040060 if (node == NULL) {
61 *listener << "which is NULL";
62 return false;
63 }
64 if (node->opcode() != opcode_) {
65 *listener << "whose opcode is " << IrOpcode::Mnemonic(node->opcode())
66 << " but should have been " << IrOpcode::Mnemonic(opcode_);
67 return false;
68 }
69 return true;
70 }
71
72 private:
73 const IrOpcode::Value opcode_;
74};
75
76
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000077class IsBranchMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040078 public:
79 IsBranchMatcher(const Matcher<Node*>& value_matcher,
80 const Matcher<Node*>& control_matcher)
81 : NodeMatcher(IrOpcode::kBranch),
82 value_matcher_(value_matcher),
83 control_matcher_(control_matcher) {}
84
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000085 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040086 NodeMatcher::DescribeTo(os);
87 *os << " whose value (";
88 value_matcher_.DescribeTo(os);
89 *os << ") and control (";
90 control_matcher_.DescribeTo(os);
91 *os << ")";
92 }
93
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000094 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -040095 return (NodeMatcher::MatchAndExplain(node, listener) &&
96 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
97 "value", value_matcher_, listener) &&
98 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
99 "control", control_matcher_, listener));
100 }
101
102 private:
103 const Matcher<Node*> value_matcher_;
104 const Matcher<Node*> control_matcher_;
105};
106
107
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000108class IsSwitchMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400109 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000110 IsSwitchMatcher(const Matcher<Node*>& value_matcher,
111 const Matcher<Node*>& control_matcher)
112 : NodeMatcher(IrOpcode::kSwitch),
113 value_matcher_(value_matcher),
114 control_matcher_(control_matcher) {}
115
116 void DescribeTo(std::ostream* os) const final {
117 NodeMatcher::DescribeTo(os);
118 *os << " whose value (";
119 value_matcher_.DescribeTo(os);
120 *os << ") and control (";
121 control_matcher_.DescribeTo(os);
122 *os << ")";
123 }
124
125 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
126 return (NodeMatcher::MatchAndExplain(node, listener) &&
127 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
128 "value", value_matcher_, listener) &&
129 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
130 "control", control_matcher_, listener));
131 }
132
133 private:
134 const Matcher<Node*> value_matcher_;
135 const Matcher<Node*> control_matcher_;
136};
137
138
139class IsIfValueMatcher final : public NodeMatcher {
140 public:
141 IsIfValueMatcher(const Matcher<int32_t>& value_matcher,
142 const Matcher<Node*>& control_matcher)
143 : NodeMatcher(IrOpcode::kIfValue),
144 value_matcher_(value_matcher),
145 control_matcher_(control_matcher) {}
146
147 void DescribeTo(std::ostream* os) const final {
148 NodeMatcher::DescribeTo(os);
149 *os << " whose value (";
150 value_matcher_.DescribeTo(os);
151 *os << ") and control (";
152 control_matcher_.DescribeTo(os);
153 *os << ")";
154 }
155
156 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
157 return (NodeMatcher::MatchAndExplain(node, listener) &&
158 PrintMatchAndExplain(OpParameter<int32_t>(node->op()), "value",
159 value_matcher_, listener) &&
160 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
161 "control", control_matcher_, listener));
162 }
163
164 private:
165 const Matcher<int32_t> value_matcher_;
166 const Matcher<Node*> control_matcher_;
167};
168
169
170class IsControl1Matcher final : public NodeMatcher {
171 public:
172 IsControl1Matcher(IrOpcode::Value opcode,
173 const Matcher<Node*>& control_matcher)
174 : NodeMatcher(opcode), control_matcher_(control_matcher) {}
175
176 void DescribeTo(std::ostream* os) const final {
177 NodeMatcher::DescribeTo(os);
178 *os << " whose control (";
179 control_matcher_.DescribeTo(os);
180 *os << ")";
181 }
182
183 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
184 return (NodeMatcher::MatchAndExplain(node, listener) &&
185 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
186 "control", control_matcher_, listener));
187 }
188
189 private:
190 const Matcher<Node*> control_matcher_;
191};
192
193
194class IsControl2Matcher final : public NodeMatcher {
195 public:
196 IsControl2Matcher(IrOpcode::Value opcode,
197 const Matcher<Node*>& control0_matcher,
198 const Matcher<Node*>& control1_matcher)
199 : NodeMatcher(opcode),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400200 control0_matcher_(control0_matcher),
201 control1_matcher_(control1_matcher) {}
202
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000203 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400204 NodeMatcher::DescribeTo(os);
205 *os << " whose control0 (";
206 control0_matcher_.DescribeTo(os);
207 *os << ") and control1 (";
208 control1_matcher_.DescribeTo(os);
209 *os << ")";
210 }
211
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000212 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400213 return (NodeMatcher::MatchAndExplain(node, listener) &&
214 PrintMatchAndExplain(NodeProperties::GetControlInput(node, 0),
215 "control0", control0_matcher_, listener) &&
216 PrintMatchAndExplain(NodeProperties::GetControlInput(node, 1),
217 "control1", control1_matcher_, listener));
218 }
219
220 private:
221 const Matcher<Node*> control0_matcher_;
222 const Matcher<Node*> control1_matcher_;
223};
224
225
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000226class IsControl3Matcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400227 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000228 IsControl3Matcher(IrOpcode::Value opcode,
229 const Matcher<Node*>& control0_matcher,
230 const Matcher<Node*>& control1_matcher,
231 const Matcher<Node*>& control2_matcher)
232 : NodeMatcher(opcode),
233 control0_matcher_(control0_matcher),
234 control1_matcher_(control1_matcher),
235 control2_matcher_(control2_matcher) {}
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400236
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000237 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400238 NodeMatcher::DescribeTo(os);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000239 *os << " whose control0 (";
240 control0_matcher_.DescribeTo(os);
241 *os << ") and control1 (";
242 control1_matcher_.DescribeTo(os);
243 *os << ") and control2 (";
244 control2_matcher_.DescribeTo(os);
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400245 *os << ")";
246 }
247
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000248 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400249 return (NodeMatcher::MatchAndExplain(node, listener) &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000250 PrintMatchAndExplain(NodeProperties::GetControlInput(node, 0),
251 "control0", control0_matcher_, listener) &&
252 PrintMatchAndExplain(NodeProperties::GetControlInput(node, 1),
253 "control1", control1_matcher_, listener) &&
254 PrintMatchAndExplain(NodeProperties::GetControlInput(node, 2),
255 "control2", control2_matcher_, listener));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400256 }
257
258 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000259 const Matcher<Node*> control0_matcher_;
260 const Matcher<Node*> control1_matcher_;
261 const Matcher<Node*> control2_matcher_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400262};
263
264
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000265class IsBeginRegionMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400266 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000267 explicit IsBeginRegionMatcher(const Matcher<Node*>& effect_matcher)
268 : NodeMatcher(IrOpcode::kBeginRegion), effect_matcher_(effect_matcher) {}
269
270 void DescribeTo(std::ostream* os) const final {
271 NodeMatcher::DescribeTo(os);
272 *os << " whose effect (";
273 effect_matcher_.DescribeTo(os);
274 *os << ")";
275 }
276
277 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
278 return (NodeMatcher::MatchAndExplain(node, listener) &&
279 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
280 effect_matcher_, listener));
281 }
282
283 private:
284 const Matcher<Node*> effect_matcher_;
285};
286
287
288class IsFinishRegionMatcher final : public NodeMatcher {
289 public:
290 IsFinishRegionMatcher(const Matcher<Node*>& value_matcher,
291 const Matcher<Node*>& effect_matcher)
292 : NodeMatcher(IrOpcode::kFinishRegion),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400293 value_matcher_(value_matcher),
294 effect_matcher_(effect_matcher) {}
295
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000296 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400297 NodeMatcher::DescribeTo(os);
298 *os << " whose value (";
299 value_matcher_.DescribeTo(os);
300 *os << ") and effect (";
301 effect_matcher_.DescribeTo(os);
302 *os << ")";
303 }
304
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000305 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400306 return (NodeMatcher::MatchAndExplain(node, listener) &&
307 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
308 "value", value_matcher_, listener) &&
309 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
310 effect_matcher_, listener));
311 }
312
313 private:
314 const Matcher<Node*> value_matcher_;
315 const Matcher<Node*> effect_matcher_;
316};
317
318
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000319class IsReturnMatcher final : public NodeMatcher {
320 public:
321 IsReturnMatcher(const Matcher<Node*>& value_matcher,
322 const Matcher<Node*>& effect_matcher,
323 const Matcher<Node*>& control_matcher)
324 : NodeMatcher(IrOpcode::kReturn),
325 value_matcher_(value_matcher),
Ben Murdoch097c5b22016-05-18 11:27:45 +0100326 value2_matcher_(_),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000327 effect_matcher_(effect_matcher),
Ben Murdoch097c5b22016-05-18 11:27:45 +0100328 control_matcher_(control_matcher),
329 has_second_return_value_(false) {}
330
331 IsReturnMatcher(const Matcher<Node*>& value_matcher,
332 const Matcher<Node*>& value2_matcher,
333 const Matcher<Node*>& effect_matcher,
334 const Matcher<Node*>& control_matcher)
335 : NodeMatcher(IrOpcode::kReturn),
336 value_matcher_(value_matcher),
337 value2_matcher_(value2_matcher),
338 effect_matcher_(effect_matcher),
339 control_matcher_(control_matcher),
340 has_second_return_value_(true) {}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000341
342 void DescribeTo(std::ostream* os) const final {
343 NodeMatcher::DescribeTo(os);
344 *os << " whose value (";
345 value_matcher_.DescribeTo(os);
Ben Murdoch097c5b22016-05-18 11:27:45 +0100346 if (has_second_return_value_) {
347 *os << ") and second value (";
348 value2_matcher_.DescribeTo(os);
349 }
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000350 *os << ") and effect (";
351 effect_matcher_.DescribeTo(os);
352 *os << ") and control (";
353 control_matcher_.DescribeTo(os);
354 *os << ")";
355 }
356
357 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
358 return (NodeMatcher::MatchAndExplain(node, listener) &&
359 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
360 "value", value_matcher_, listener) &&
Ben Murdoch097c5b22016-05-18 11:27:45 +0100361 (!has_second_return_value_ ||
362 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
363 "value2", value2_matcher_, listener)) &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000364 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
365 effect_matcher_, listener) &&
366 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
367 "control", control_matcher_, listener));
368 }
369
370 private:
371 const Matcher<Node*> value_matcher_;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100372 const Matcher<Node*> value2_matcher_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000373 const Matcher<Node*> effect_matcher_;
374 const Matcher<Node*> control_matcher_;
Ben Murdoch097c5b22016-05-18 11:27:45 +0100375 bool has_second_return_value_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000376};
377
378
379class IsTerminateMatcher final : public NodeMatcher {
380 public:
381 IsTerminateMatcher(const Matcher<Node*>& effect_matcher,
382 const Matcher<Node*>& control_matcher)
383 : NodeMatcher(IrOpcode::kTerminate),
384 effect_matcher_(effect_matcher),
385 control_matcher_(control_matcher) {}
386
387 void DescribeTo(std::ostream* os) const final {
388 NodeMatcher::DescribeTo(os);
389 *os << " whose effect (";
390 effect_matcher_.DescribeTo(os);
391 *os << ") and control (";
392 control_matcher_.DescribeTo(os);
393 *os << ")";
394 }
395
396 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
397 return (NodeMatcher::MatchAndExplain(node, listener) &&
398 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
399 effect_matcher_, listener) &&
400 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
401 "control", control_matcher_, listener));
402 }
403
404 private:
405 const Matcher<Node*> effect_matcher_;
406 const Matcher<Node*> control_matcher_;
407};
408
409
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400410template <typename T>
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000411class IsConstantMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400412 public:
413 IsConstantMatcher(IrOpcode::Value opcode, const Matcher<T>& value_matcher)
414 : NodeMatcher(opcode), value_matcher_(value_matcher) {}
415
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000416 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400417 NodeMatcher::DescribeTo(os);
418 *os << " whose value (";
419 value_matcher_.DescribeTo(os);
420 *os << ")";
421 }
422
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000423 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400424 return (NodeMatcher::MatchAndExplain(node, listener) &&
425 PrintMatchAndExplain(OpParameter<T>(node), "value", value_matcher_,
426 listener));
427 }
428
429 private:
430 const Matcher<T> value_matcher_;
431};
432
433
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000434class IsSelectMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400435 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000436 IsSelectMatcher(const Matcher<MachineRepresentation>& type_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400437 const Matcher<Node*>& value0_matcher,
438 const Matcher<Node*>& value1_matcher,
439 const Matcher<Node*>& value2_matcher)
440 : NodeMatcher(IrOpcode::kSelect),
441 type_matcher_(type_matcher),
442 value0_matcher_(value0_matcher),
443 value1_matcher_(value1_matcher),
444 value2_matcher_(value2_matcher) {}
445
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000446 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400447 NodeMatcher::DescribeTo(os);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000448 *os << " whose representation (";
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400449 type_matcher_.DescribeTo(os);
450 *os << "), value0 (";
451 value0_matcher_.DescribeTo(os);
452 *os << "), value1 (";
453 value1_matcher_.DescribeTo(os);
454 *os << ") and value2 (";
455 value2_matcher_.DescribeTo(os);
456 *os << ")";
457 }
458
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000459 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
460 return (
461 NodeMatcher::MatchAndExplain(node, listener) &&
462 PrintMatchAndExplain(SelectParametersOf(node->op()).representation(),
463 "representation", type_matcher_, listener) &&
464 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "value0",
465 value0_matcher_, listener) &&
466 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "value1",
467 value1_matcher_, listener) &&
468 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), "value2",
469 value2_matcher_, listener));
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400470 }
471
472 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000473 const Matcher<MachineRepresentation> type_matcher_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400474 const Matcher<Node*> value0_matcher_;
475 const Matcher<Node*> value1_matcher_;
476 const Matcher<Node*> value2_matcher_;
477};
478
479
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000480class IsPhiMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400481 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000482 IsPhiMatcher(const Matcher<MachineRepresentation>& type_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400483 const Matcher<Node*>& value0_matcher,
484 const Matcher<Node*>& value1_matcher,
485 const Matcher<Node*>& control_matcher)
486 : NodeMatcher(IrOpcode::kPhi),
487 type_matcher_(type_matcher),
488 value0_matcher_(value0_matcher),
489 value1_matcher_(value1_matcher),
490 control_matcher_(control_matcher) {}
491
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000492 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400493 NodeMatcher::DescribeTo(os);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000494 *os << " whose representation (";
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400495 type_matcher_.DescribeTo(os);
496 *os << "), value0 (";
497 value0_matcher_.DescribeTo(os);
498 *os << "), value1 (";
499 value1_matcher_.DescribeTo(os);
500 *os << ") and control (";
501 control_matcher_.DescribeTo(os);
502 *os << ")";
503 }
504
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000505 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400506 return (NodeMatcher::MatchAndExplain(node, listener) &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000507 PrintMatchAndExplain(PhiRepresentationOf(node->op()),
508 "representation", type_matcher_, listener) &&
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400509 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
510 "value0", value0_matcher_, listener) &&
511 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
512 "value1", value1_matcher_, listener) &&
513 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
514 "control", control_matcher_, listener));
515 }
516
517 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000518 const Matcher<MachineRepresentation> type_matcher_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400519 const Matcher<Node*> value0_matcher_;
520 const Matcher<Node*> value1_matcher_;
521 const Matcher<Node*> control_matcher_;
522};
523
524
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000525class IsPhi2Matcher final : public NodeMatcher {
526 public:
527 IsPhi2Matcher(const Matcher<MachineRepresentation>& type_matcher,
528 const Matcher<Node*>& value0_matcher,
529 const Matcher<Node*>& value1_matcher,
530 const Matcher<Node*>& value2_matcher,
531 const Matcher<Node*>& control_matcher)
532 : NodeMatcher(IrOpcode::kPhi),
533 type_matcher_(type_matcher),
534 value0_matcher_(value0_matcher),
535 value1_matcher_(value1_matcher),
536 value2_matcher_(value2_matcher),
537 control_matcher_(control_matcher) {}
538
539 void DescribeTo(std::ostream* os) const final {
540 NodeMatcher::DescribeTo(os);
541 *os << " whose representation (";
542 type_matcher_.DescribeTo(os);
543 *os << "), value0 (";
544 value0_matcher_.DescribeTo(os);
545 *os << "), value1 (";
546 value1_matcher_.DescribeTo(os);
547 *os << "), value2 (";
548 value2_matcher_.DescribeTo(os);
549 *os << ") and control (";
550 control_matcher_.DescribeTo(os);
551 *os << ")";
552 }
553
554 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
555 return (NodeMatcher::MatchAndExplain(node, listener) &&
556 PrintMatchAndExplain(PhiRepresentationOf(node->op()),
557 "representation", type_matcher_, listener) &&
558 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
559 "value0", value0_matcher_, listener) &&
560 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
561 "value1", value1_matcher_, listener) &&
562 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2),
563 "value2", value2_matcher_, listener) &&
564 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
565 "control", control_matcher_, listener));
566 }
567
568 private:
569 const Matcher<MachineRepresentation> type_matcher_;
570 const Matcher<Node*> value0_matcher_;
571 const Matcher<Node*> value1_matcher_;
572 const Matcher<Node*> value2_matcher_;
573 const Matcher<Node*> control_matcher_;
574};
575
576
577class IsEffectPhiMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400578 public:
579 IsEffectPhiMatcher(const Matcher<Node*>& effect0_matcher,
580 const Matcher<Node*>& effect1_matcher,
581 const Matcher<Node*>& control_matcher)
582 : NodeMatcher(IrOpcode::kEffectPhi),
583 effect0_matcher_(effect0_matcher),
584 effect1_matcher_(effect1_matcher),
585 control_matcher_(control_matcher) {}
586
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000587 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400588 NodeMatcher::DescribeTo(os);
589 *os << "), effect0 (";
590 effect0_matcher_.DescribeTo(os);
591 *os << "), effect1 (";
592 effect1_matcher_.DescribeTo(os);
593 *os << ") and control (";
594 control_matcher_.DescribeTo(os);
595 *os << ")";
596 }
597
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000598 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400599 return (NodeMatcher::MatchAndExplain(node, listener) &&
600 PrintMatchAndExplain(NodeProperties::GetEffectInput(node, 0),
601 "effect0", effect0_matcher_, listener) &&
602 PrintMatchAndExplain(NodeProperties::GetEffectInput(node, 1),
603 "effect1", effect1_matcher_, listener) &&
604 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
605 "control", control_matcher_, listener));
606 }
607
608 private:
609 const Matcher<Node*> effect0_matcher_;
610 const Matcher<Node*> effect1_matcher_;
611 const Matcher<Node*> control_matcher_;
612};
613
614
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000615class IsProjectionMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400616 public:
617 IsProjectionMatcher(const Matcher<size_t>& index_matcher,
618 const Matcher<Node*>& base_matcher)
619 : NodeMatcher(IrOpcode::kProjection),
620 index_matcher_(index_matcher),
621 base_matcher_(base_matcher) {}
622
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000623 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400624 NodeMatcher::DescribeTo(os);
625 *os << " whose index (";
626 index_matcher_.DescribeTo(os);
627 *os << ") and base (";
628 base_matcher_.DescribeTo(os);
629 *os << ")";
630 }
631
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000632 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400633 return (NodeMatcher::MatchAndExplain(node, listener) &&
634 PrintMatchAndExplain(OpParameter<size_t>(node), "index",
635 index_matcher_, listener) &&
636 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
637 base_matcher_, listener));
638 }
639
640 private:
641 const Matcher<size_t> index_matcher_;
642 const Matcher<Node*> base_matcher_;
643};
644
645
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000646class IsCallMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400647 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000648 IsCallMatcher(const Matcher<const CallDescriptor*>& descriptor_matcher,
649 const std::vector<Matcher<Node*>>& value_matchers,
650 const Matcher<Node*>& effect_matcher,
651 const Matcher<Node*>& control_matcher)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400652 : NodeMatcher(IrOpcode::kCall),
653 descriptor_matcher_(descriptor_matcher),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000654 value_matchers_(value_matchers),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400655 effect_matcher_(effect_matcher),
656 control_matcher_(control_matcher) {}
657
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000658 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400659 NodeMatcher::DescribeTo(os);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000660 for (size_t i = 0; i < value_matchers_.size(); ++i) {
661 if (i == 0) {
662 *os << " whose value0 (";
663 } else {
664 *os << "), value" << i << " (";
665 }
666 value_matchers_[i].DescribeTo(os);
667 }
668 *os << "), effect (";
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400669 effect_matcher_.DescribeTo(os);
670 *os << ") and control (";
671 control_matcher_.DescribeTo(os);
672 *os << ")";
673 }
674
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000675 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
676 if (!NodeMatcher::MatchAndExplain(node, listener) ||
677 !PrintMatchAndExplain(OpParameter<const CallDescriptor*>(node),
678 "descriptor", descriptor_matcher_, listener)) {
679 return false;
680 }
681 for (size_t i = 0; i < value_matchers_.size(); ++i) {
682 std::ostringstream ost;
683 ost << "value" << i;
684 if (!PrintMatchAndExplain(
685 NodeProperties::GetValueInput(node, static_cast<int>(i)),
686 ost.str(), value_matchers_[i], listener)) {
687 return false;
688 }
689 }
690 Node* effect_node = nullptr;
691 Node* control_node = nullptr;
692 if (NodeProperties::FirstEffectIndex(node) < node->InputCount()) {
693 effect_node = NodeProperties::GetEffectInput(node);
694 }
695 if (NodeProperties::FirstControlIndex(node) < node->InputCount()) {
696 control_node = NodeProperties::GetControlInput(node);
697 }
698 return (PrintMatchAndExplain(effect_node, "effect", effect_matcher_,
699 listener) &&
700 PrintMatchAndExplain(control_node, "control", control_matcher_,
701 listener));
702 }
703
704 private:
705 const Matcher<const CallDescriptor*> descriptor_matcher_;
706 const std::vector<Matcher<Node*>> value_matchers_;
707 const Matcher<Node*> effect_matcher_;
708 const Matcher<Node*> control_matcher_;
709};
710
711
712class IsTailCallMatcher final : public NodeMatcher {
713 public:
714 IsTailCallMatcher(const Matcher<CallDescriptor const*>& descriptor_matcher,
715 const std::vector<Matcher<Node*>>& value_matchers,
716 const Matcher<Node*>& effect_matcher,
717 const Matcher<Node*>& control_matcher)
718 : NodeMatcher(IrOpcode::kTailCall),
719 descriptor_matcher_(descriptor_matcher),
720 value_matchers_(value_matchers),
721 effect_matcher_(effect_matcher),
722 control_matcher_(control_matcher) {}
723
724 void DescribeTo(std::ostream* os) const final {
725 NodeMatcher::DescribeTo(os);
726 for (size_t i = 0; i < value_matchers_.size(); ++i) {
727 if (i == 0) {
728 *os << " whose value0 (";
729 } else {
730 *os << "), value" << i << " (";
731 }
732 value_matchers_[i].DescribeTo(os);
733 }
734 *os << "), effect (";
735 effect_matcher_.DescribeTo(os);
736 *os << ") and control (";
737 control_matcher_.DescribeTo(os);
738 *os << ")";
739 }
740
741 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
742 if (!NodeMatcher::MatchAndExplain(node, listener) ||
743 !PrintMatchAndExplain(OpParameter<CallDescriptor const*>(node),
744 "descriptor", descriptor_matcher_, listener)) {
745 return false;
746 }
747 for (size_t i = 0; i < value_matchers_.size(); ++i) {
748 std::ostringstream ost;
749 ost << "value" << i;
750 if (!PrintMatchAndExplain(
751 NodeProperties::GetValueInput(node, static_cast<int>(i)),
752 ost.str(), value_matchers_[i], listener)) {
753 return false;
754 }
755 }
756 Node* effect_node = nullptr;
757 Node* control_node = nullptr;
758 if (NodeProperties::FirstEffectIndex(node) < node->InputCount()) {
759 effect_node = NodeProperties::GetEffectInput(node);
760 }
761 if (NodeProperties::FirstControlIndex(node) < node->InputCount()) {
762 control_node = NodeProperties::GetControlInput(node);
763 }
764 return (PrintMatchAndExplain(effect_node, "effect", effect_matcher_,
765 listener) &&
766 PrintMatchAndExplain(control_node, "control", control_matcher_,
767 listener));
768 }
769
770 private:
771 const Matcher<CallDescriptor const*> descriptor_matcher_;
772 const std::vector<Matcher<Node*>> value_matchers_;
773 const Matcher<Node*> effect_matcher_;
774 const Matcher<Node*> control_matcher_;
775};
776
777
778class IsReferenceEqualMatcher final : public NodeMatcher {
779 public:
780 IsReferenceEqualMatcher(const Matcher<Type*>& type_matcher,
781 const Matcher<Node*>& lhs_matcher,
782 const Matcher<Node*>& rhs_matcher)
783 : NodeMatcher(IrOpcode::kReferenceEqual),
784 type_matcher_(type_matcher),
785 lhs_matcher_(lhs_matcher),
786 rhs_matcher_(rhs_matcher) {}
787
788 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400789 return (NodeMatcher::MatchAndExplain(node, listener) &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000790 // TODO(bmeurer): The type parameter is currently ignored.
791 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "lhs",
792 lhs_matcher_, listener) &&
793 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "rhs",
794 rhs_matcher_, listener));
795 }
796
797 private:
798 const Matcher<Type*> type_matcher_;
799 const Matcher<Node*> lhs_matcher_;
800 const Matcher<Node*> rhs_matcher_;
801};
802
803
804class IsAllocateMatcher final : public NodeMatcher {
805 public:
806 IsAllocateMatcher(const Matcher<Node*>& size_matcher,
807 const Matcher<Node*>& effect_matcher,
808 const Matcher<Node*>& control_matcher)
809 : NodeMatcher(IrOpcode::kAllocate),
810 size_matcher_(size_matcher),
811 effect_matcher_(effect_matcher),
812 control_matcher_(control_matcher) {}
813
814 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
815 return (NodeMatcher::MatchAndExplain(node, listener) &&
816 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "size",
817 size_matcher_, listener) &&
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400818 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
819 effect_matcher_, listener) &&
820 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
821 "control", control_matcher_, listener));
822 }
823
824 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000825 const Matcher<Node*> size_matcher_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400826 const Matcher<Node*> effect_matcher_;
827 const Matcher<Node*> control_matcher_;
828};
829
830
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000831class IsLoadFieldMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400832 public:
833 IsLoadFieldMatcher(const Matcher<FieldAccess>& access_matcher,
834 const Matcher<Node*>& base_matcher,
835 const Matcher<Node*>& effect_matcher,
836 const Matcher<Node*>& control_matcher)
837 : NodeMatcher(IrOpcode::kLoadField),
838 access_matcher_(access_matcher),
839 base_matcher_(base_matcher),
840 effect_matcher_(effect_matcher),
841 control_matcher_(control_matcher) {}
842
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000843 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400844 NodeMatcher::DescribeTo(os);
845 *os << " whose access (";
846 access_matcher_.DescribeTo(os);
847 *os << "), base (";
848 base_matcher_.DescribeTo(os);
849 *os << "), effect (";
850 effect_matcher_.DescribeTo(os);
851 *os << ") and control (";
852 control_matcher_.DescribeTo(os);
853 *os << ")";
854 }
855
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000856 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400857 return (NodeMatcher::MatchAndExplain(node, listener) &&
858 PrintMatchAndExplain(OpParameter<FieldAccess>(node), "access",
859 access_matcher_, listener) &&
860 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
861 base_matcher_, listener) &&
862 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
863 effect_matcher_, listener) &&
864 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
865 "control", control_matcher_, listener));
866 }
867
868 private:
869 const Matcher<FieldAccess> access_matcher_;
870 const Matcher<Node*> base_matcher_;
871 const Matcher<Node*> effect_matcher_;
872 const Matcher<Node*> control_matcher_;
873};
874
875
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000876class IsStoreFieldMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400877 public:
878 IsStoreFieldMatcher(const Matcher<FieldAccess>& access_matcher,
879 const Matcher<Node*>& base_matcher,
880 const Matcher<Node*>& value_matcher,
881 const Matcher<Node*>& effect_matcher,
882 const Matcher<Node*>& control_matcher)
883 : NodeMatcher(IrOpcode::kStoreField),
884 access_matcher_(access_matcher),
885 base_matcher_(base_matcher),
886 value_matcher_(value_matcher),
887 effect_matcher_(effect_matcher),
888 control_matcher_(control_matcher) {}
889
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000890 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400891 NodeMatcher::DescribeTo(os);
892 *os << " whose access (";
893 access_matcher_.DescribeTo(os);
894 *os << "), base (";
895 base_matcher_.DescribeTo(os);
896 *os << "), value (";
897 value_matcher_.DescribeTo(os);
898 *os << "), effect (";
899 effect_matcher_.DescribeTo(os);
900 *os << ") and control (";
901 control_matcher_.DescribeTo(os);
902 *os << ")";
903 }
904
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000905 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400906 return (NodeMatcher::MatchAndExplain(node, listener) &&
907 PrintMatchAndExplain(OpParameter<FieldAccess>(node), "access",
908 access_matcher_, listener) &&
909 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
910 base_matcher_, listener) &&
911 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
912 "value", value_matcher_, listener) &&
913 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
914 effect_matcher_, listener) &&
915 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
916 "control", control_matcher_, listener));
917 }
918
919 private:
920 const Matcher<FieldAccess> access_matcher_;
921 const Matcher<Node*> base_matcher_;
922 const Matcher<Node*> value_matcher_;
923 const Matcher<Node*> effect_matcher_;
924 const Matcher<Node*> control_matcher_;
925};
926
927
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000928class IsLoadBufferMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400929 public:
930 IsLoadBufferMatcher(const Matcher<BufferAccess>& access_matcher,
931 const Matcher<Node*>& buffer_matcher,
932 const Matcher<Node*>& offset_matcher,
933 const Matcher<Node*>& length_matcher,
934 const Matcher<Node*>& effect_matcher,
935 const Matcher<Node*>& control_matcher)
936 : NodeMatcher(IrOpcode::kLoadBuffer),
937 access_matcher_(access_matcher),
938 buffer_matcher_(buffer_matcher),
939 offset_matcher_(offset_matcher),
940 length_matcher_(length_matcher),
941 effect_matcher_(effect_matcher),
942 control_matcher_(control_matcher) {}
943
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000944 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400945 NodeMatcher::DescribeTo(os);
946 *os << " whose access (";
947 access_matcher_.DescribeTo(os);
948 *os << "), buffer (";
949 buffer_matcher_.DescribeTo(os);
950 *os << "), offset (";
951 offset_matcher_.DescribeTo(os);
952 *os << "), length (";
953 length_matcher_.DescribeTo(os);
954 *os << "), effect (";
955 effect_matcher_.DescribeTo(os);
956 *os << ") and control (";
957 control_matcher_.DescribeTo(os);
958 *os << ")";
959 }
960
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000961 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400962 return (NodeMatcher::MatchAndExplain(node, listener) &&
963 PrintMatchAndExplain(BufferAccessOf(node->op()), "access",
964 access_matcher_, listener) &&
965 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
966 "buffer", buffer_matcher_, listener) &&
967 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
968 "offset", offset_matcher_, listener) &&
969 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2),
970 "length", length_matcher_, listener) &&
971 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
972 effect_matcher_, listener) &&
973 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
974 "control", control_matcher_, listener));
975 }
976
977 private:
978 const Matcher<BufferAccess> access_matcher_;
979 const Matcher<Node*> buffer_matcher_;
980 const Matcher<Node*> offset_matcher_;
981 const Matcher<Node*> length_matcher_;
982 const Matcher<Node*> effect_matcher_;
983 const Matcher<Node*> control_matcher_;
984};
985
986
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000987class IsStoreBufferMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400988 public:
989 IsStoreBufferMatcher(const Matcher<BufferAccess>& access_matcher,
990 const Matcher<Node*>& buffer_matcher,
991 const Matcher<Node*>& offset_matcher,
992 const Matcher<Node*>& length_matcher,
993 const Matcher<Node*>& value_matcher,
994 const Matcher<Node*>& effect_matcher,
995 const Matcher<Node*>& control_matcher)
996 : NodeMatcher(IrOpcode::kStoreBuffer),
997 access_matcher_(access_matcher),
998 buffer_matcher_(buffer_matcher),
999 offset_matcher_(offset_matcher),
1000 length_matcher_(length_matcher),
1001 value_matcher_(value_matcher),
1002 effect_matcher_(effect_matcher),
1003 control_matcher_(control_matcher) {}
1004
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001005 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001006 NodeMatcher::DescribeTo(os);
1007 *os << " whose access (";
1008 access_matcher_.DescribeTo(os);
1009 *os << "), buffer (";
1010 buffer_matcher_.DescribeTo(os);
1011 *os << "), offset (";
1012 offset_matcher_.DescribeTo(os);
1013 *os << "), length (";
1014 length_matcher_.DescribeTo(os);
1015 *os << "), value (";
1016 value_matcher_.DescribeTo(os);
1017 *os << "), effect (";
1018 effect_matcher_.DescribeTo(os);
1019 *os << ") and control (";
1020 control_matcher_.DescribeTo(os);
1021 *os << ")";
1022 }
1023
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001024 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001025 return (NodeMatcher::MatchAndExplain(node, listener) &&
1026 PrintMatchAndExplain(BufferAccessOf(node->op()), "access",
1027 access_matcher_, listener) &&
1028 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
1029 "buffer", buffer_matcher_, listener) &&
1030 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1031 "offset", offset_matcher_, listener) &&
1032 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2),
1033 "length", length_matcher_, listener) &&
1034 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 3),
1035 "value", value_matcher_, listener) &&
1036 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
1037 effect_matcher_, listener) &&
1038 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
1039 "control", control_matcher_, listener));
1040 }
1041
1042 private:
1043 const Matcher<BufferAccess> access_matcher_;
1044 const Matcher<Node*> buffer_matcher_;
1045 const Matcher<Node*> offset_matcher_;
1046 const Matcher<Node*> length_matcher_;
1047 const Matcher<Node*> value_matcher_;
1048 const Matcher<Node*> effect_matcher_;
1049 const Matcher<Node*> control_matcher_;
1050};
1051
1052
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001053class IsLoadElementMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001054 public:
1055 IsLoadElementMatcher(const Matcher<ElementAccess>& access_matcher,
1056 const Matcher<Node*>& base_matcher,
1057 const Matcher<Node*>& index_matcher,
1058 const Matcher<Node*>& effect_matcher,
1059 const Matcher<Node*>& control_matcher)
1060 : NodeMatcher(IrOpcode::kLoadElement),
1061 access_matcher_(access_matcher),
1062 base_matcher_(base_matcher),
1063 index_matcher_(index_matcher),
1064 effect_matcher_(effect_matcher),
1065 control_matcher_(control_matcher) {}
1066
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001067 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001068 NodeMatcher::DescribeTo(os);
1069 *os << " whose access (";
1070 access_matcher_.DescribeTo(os);
1071 *os << "), base (";
1072 base_matcher_.DescribeTo(os);
1073 *os << "), index (";
1074 index_matcher_.DescribeTo(os);
1075 *os << "), effect (";
1076 effect_matcher_.DescribeTo(os);
1077 *os << ") and control (";
1078 control_matcher_.DescribeTo(os);
1079 *os << ")";
1080 }
1081
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001082 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001083 return (NodeMatcher::MatchAndExplain(node, listener) &&
1084 PrintMatchAndExplain(OpParameter<ElementAccess>(node), "access",
1085 access_matcher_, listener) &&
1086 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1087 base_matcher_, listener) &&
1088 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1089 "index", index_matcher_, listener) &&
1090 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
1091 effect_matcher_, listener) &&
1092 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
1093 "control", control_matcher_, listener));
1094 }
1095
1096 private:
1097 const Matcher<ElementAccess> access_matcher_;
1098 const Matcher<Node*> base_matcher_;
1099 const Matcher<Node*> index_matcher_;
1100 const Matcher<Node*> effect_matcher_;
1101 const Matcher<Node*> control_matcher_;
1102};
1103
1104
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001105class IsStoreElementMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001106 public:
1107 IsStoreElementMatcher(const Matcher<ElementAccess>& access_matcher,
1108 const Matcher<Node*>& base_matcher,
1109 const Matcher<Node*>& index_matcher,
1110 const Matcher<Node*>& value_matcher,
1111 const Matcher<Node*>& effect_matcher,
1112 const Matcher<Node*>& control_matcher)
1113 : NodeMatcher(IrOpcode::kStoreElement),
1114 access_matcher_(access_matcher),
1115 base_matcher_(base_matcher),
1116 index_matcher_(index_matcher),
1117 value_matcher_(value_matcher),
1118 effect_matcher_(effect_matcher),
1119 control_matcher_(control_matcher) {}
1120
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001121 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001122 NodeMatcher::DescribeTo(os);
1123 *os << " whose access (";
1124 access_matcher_.DescribeTo(os);
1125 *os << "), base (";
1126 base_matcher_.DescribeTo(os);
1127 *os << "), index (";
1128 index_matcher_.DescribeTo(os);
1129 *os << "), value (";
1130 value_matcher_.DescribeTo(os);
1131 *os << "), effect (";
1132 effect_matcher_.DescribeTo(os);
1133 *os << ") and control (";
1134 control_matcher_.DescribeTo(os);
1135 *os << ")";
1136 }
1137
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001138 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001139 return (NodeMatcher::MatchAndExplain(node, listener) &&
1140 PrintMatchAndExplain(OpParameter<ElementAccess>(node), "access",
1141 access_matcher_, listener) &&
1142 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1143 base_matcher_, listener) &&
1144 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1145 "index", index_matcher_, listener) &&
1146 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2),
1147 "value", value_matcher_, listener) &&
1148 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
1149 effect_matcher_, listener) &&
1150 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
1151 "control", control_matcher_, listener));
1152 }
1153
1154 private:
1155 const Matcher<ElementAccess> access_matcher_;
1156 const Matcher<Node*> base_matcher_;
1157 const Matcher<Node*> index_matcher_;
1158 const Matcher<Node*> value_matcher_;
1159 const Matcher<Node*> effect_matcher_;
1160 const Matcher<Node*> control_matcher_;
1161};
1162
1163
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001164class IsLoadMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001165 public:
1166 IsLoadMatcher(const Matcher<LoadRepresentation>& rep_matcher,
1167 const Matcher<Node*>& base_matcher,
1168 const Matcher<Node*>& index_matcher,
1169 const Matcher<Node*>& effect_matcher,
1170 const Matcher<Node*>& control_matcher)
1171 : NodeMatcher(IrOpcode::kLoad),
1172 rep_matcher_(rep_matcher),
1173 base_matcher_(base_matcher),
1174 index_matcher_(index_matcher),
1175 effect_matcher_(effect_matcher),
1176 control_matcher_(control_matcher) {}
1177
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001178 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001179 NodeMatcher::DescribeTo(os);
1180 *os << " whose rep (";
1181 rep_matcher_.DescribeTo(os);
1182 *os << "), base (";
1183 base_matcher_.DescribeTo(os);
1184 *os << "), index (";
1185 index_matcher_.DescribeTo(os);
1186 *os << "), effect (";
1187 effect_matcher_.DescribeTo(os);
1188 *os << ") and control (";
1189 control_matcher_.DescribeTo(os);
1190 *os << ")";
1191 }
1192
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001193 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1194 Node* effect_node = nullptr;
1195 Node* control_node = nullptr;
1196 if (NodeProperties::FirstEffectIndex(node) < node->InputCount()) {
1197 effect_node = NodeProperties::GetEffectInput(node);
1198 }
1199 if (NodeProperties::FirstControlIndex(node) < node->InputCount()) {
1200 control_node = NodeProperties::GetControlInput(node);
1201 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001202 return (NodeMatcher::MatchAndExplain(node, listener) &&
1203 PrintMatchAndExplain(OpParameter<LoadRepresentation>(node), "rep",
1204 rep_matcher_, listener) &&
1205 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1206 base_matcher_, listener) &&
1207 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1208 "index", index_matcher_, listener) &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001209 PrintMatchAndExplain(effect_node, "effect", effect_matcher_,
1210 listener) &&
1211 PrintMatchAndExplain(control_node, "control", control_matcher_,
1212 listener));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001213 }
1214
1215 private:
1216 const Matcher<LoadRepresentation> rep_matcher_;
1217 const Matcher<Node*> base_matcher_;
1218 const Matcher<Node*> index_matcher_;
1219 const Matcher<Node*> effect_matcher_;
1220 const Matcher<Node*> control_matcher_;
1221};
1222
1223
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001224class IsStoreMatcher final : public NodeMatcher {
1225 public:
1226 IsStoreMatcher(const Matcher<StoreRepresentation>& rep_matcher,
1227 const Matcher<Node*>& base_matcher,
1228 const Matcher<Node*>& index_matcher,
1229 const Matcher<Node*>& value_matcher,
1230 const Matcher<Node*>& effect_matcher,
1231 const Matcher<Node*>& control_matcher)
1232 : NodeMatcher(IrOpcode::kStore),
1233 rep_matcher_(rep_matcher),
1234 base_matcher_(base_matcher),
1235 index_matcher_(index_matcher),
1236 value_matcher_(value_matcher),
1237 effect_matcher_(effect_matcher),
1238 control_matcher_(control_matcher) {}
1239
1240 void DescribeTo(std::ostream* os) const final {
1241 NodeMatcher::DescribeTo(os);
1242 *os << " whose rep (";
1243 rep_matcher_.DescribeTo(os);
1244 *os << "), base (";
1245 base_matcher_.DescribeTo(os);
1246 *os << "), index (";
1247 index_matcher_.DescribeTo(os);
1248 *os << "), value (";
1249 value_matcher_.DescribeTo(os);
1250 *os << "), effect (";
1251 effect_matcher_.DescribeTo(os);
1252 *os << ") and control (";
1253 control_matcher_.DescribeTo(os);
1254 *os << ")";
1255 }
1256
1257 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1258 Node* effect_node = nullptr;
1259 Node* control_node = nullptr;
1260 if (NodeProperties::FirstEffectIndex(node) < node->InputCount()) {
1261 effect_node = NodeProperties::GetEffectInput(node);
1262 }
1263 if (NodeProperties::FirstControlIndex(node) < node->InputCount()) {
1264 control_node = NodeProperties::GetControlInput(node);
1265 }
1266 return (NodeMatcher::MatchAndExplain(node, listener) &&
1267 PrintMatchAndExplain(OpParameter<StoreRepresentation>(node), "rep",
1268 rep_matcher_, listener) &&
1269 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1270 base_matcher_, listener) &&
1271 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1272 "index", index_matcher_, listener) &&
1273 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2),
1274 "value", value_matcher_, listener) &&
1275 PrintMatchAndExplain(effect_node, "effect", effect_matcher_,
1276 listener) &&
1277 PrintMatchAndExplain(control_node, "control", control_matcher_,
1278 listener));
1279 }
1280
1281 private:
1282 const Matcher<StoreRepresentation> rep_matcher_;
1283 const Matcher<Node*> base_matcher_;
1284 const Matcher<Node*> index_matcher_;
1285 const Matcher<Node*> value_matcher_;
1286 const Matcher<Node*> effect_matcher_;
1287 const Matcher<Node*> control_matcher_;
1288};
1289
Ben Murdochda12d292016-06-02 14:46:10 +01001290class IsStackSlotMatcher final : public NodeMatcher {
1291 public:
1292 explicit IsStackSlotMatcher(const Matcher<MachineRepresentation>& rep_matcher)
1293 : NodeMatcher(IrOpcode::kStackSlot), rep_matcher_(rep_matcher) {}
1294
1295 void DescribeTo(std::ostream* os) const final {
1296 NodeMatcher::DescribeTo(os);
1297 *os << " whose rep (";
1298 rep_matcher_.DescribeTo(os);
1299 *os << ")";
1300 }
1301
1302 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1303 return (NodeMatcher::MatchAndExplain(node, listener) &&
1304 PrintMatchAndExplain(OpParameter<MachineRepresentation>(node),
1305 "rep", rep_matcher_, listener));
1306 }
1307
1308 private:
1309 const Matcher<MachineRepresentation> rep_matcher_;
1310};
1311
Ben Murdochc5610432016-08-08 18:44:38 +01001312class IsTypeGuardMatcher final : public NodeMatcher {
Ben Murdochda12d292016-06-02 14:46:10 +01001313 public:
Ben Murdochc5610432016-08-08 18:44:38 +01001314 IsTypeGuardMatcher(const Matcher<Type*>& type_matcher,
1315 const Matcher<Node*>& value_matcher,
1316 const Matcher<Node*>& control_matcher)
1317 : NodeMatcher(IrOpcode::kTypeGuard),
Ben Murdochda12d292016-06-02 14:46:10 +01001318 type_matcher_(type_matcher),
1319 value_matcher_(value_matcher),
1320 control_matcher_(control_matcher) {}
1321
1322 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1323 return (NodeMatcher::MatchAndExplain(node, listener) &&
1324 PrintMatchAndExplain(OpParameter<Type*>(node->op()), "type",
1325 type_matcher_, listener) &&
1326 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
1327 "value", value_matcher_, listener) &&
1328 PrintMatchAndExplain(NodeProperties::GetControlInput(node, 0),
1329 "control", control_matcher_, listener));
1330 }
1331
1332 private:
1333 const Matcher<Type*> type_matcher_;
1334 const Matcher<Node*> value_matcher_;
1335 const Matcher<Node*> control_matcher_;
1336};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001337
1338class IsToNumberMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001339 public:
1340 IsToNumberMatcher(const Matcher<Node*>& base_matcher,
1341 const Matcher<Node*>& context_matcher,
1342 const Matcher<Node*>& effect_matcher,
1343 const Matcher<Node*>& control_matcher)
1344 : NodeMatcher(IrOpcode::kJSToNumber),
1345 base_matcher_(base_matcher),
1346 context_matcher_(context_matcher),
1347 effect_matcher_(effect_matcher),
1348 control_matcher_(control_matcher) {}
1349
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001350 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001351 NodeMatcher::DescribeTo(os);
1352 *os << " whose base (";
1353 base_matcher_.DescribeTo(os);
1354 *os << "), context (";
1355 context_matcher_.DescribeTo(os);
1356 *os << "), effect (";
1357 effect_matcher_.DescribeTo(os);
1358 *os << ") and control (";
1359 control_matcher_.DescribeTo(os);
1360 *os << ")";
1361 }
1362
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001363 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001364 return (NodeMatcher::MatchAndExplain(node, listener) &&
1365 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1366 base_matcher_, listener) &&
1367 PrintMatchAndExplain(NodeProperties::GetContextInput(node),
1368 "context", context_matcher_, listener) &&
1369 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
1370 effect_matcher_, listener) &&
1371 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
1372 "control", control_matcher_, listener));
1373 }
1374
1375 private:
1376 const Matcher<Node*> base_matcher_;
1377 const Matcher<Node*> context_matcher_;
1378 const Matcher<Node*> effect_matcher_;
1379 const Matcher<Node*> control_matcher_;
1380};
1381
1382
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001383class IsLoadContextMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001384 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001385 IsLoadContextMatcher(const Matcher<ContextAccess>& access_matcher,
1386 const Matcher<Node*>& context_matcher)
1387 : NodeMatcher(IrOpcode::kJSLoadContext),
1388 access_matcher_(access_matcher),
1389 context_matcher_(context_matcher) {}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001390
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001391 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001392 NodeMatcher::DescribeTo(os);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001393 *os << " whose access (";
1394 access_matcher_.DescribeTo(os);
1395 *os << ") and context (";
1396 context_matcher_.DescribeTo(os);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001397 *os << ")";
1398 }
1399
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001400 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001401 return (NodeMatcher::MatchAndExplain(node, listener) &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001402 PrintMatchAndExplain(OpParameter<ContextAccess>(node), "access",
1403 access_matcher_, listener) &&
1404 PrintMatchAndExplain(NodeProperties::GetContextInput(node),
1405 "context", context_matcher_, listener));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001406 }
1407
1408 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001409 const Matcher<ContextAccess> access_matcher_;
1410 const Matcher<Node*> context_matcher_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001411};
1412
Ben Murdochda12d292016-06-02 14:46:10 +01001413class IsQuadopMatcher final : public NodeMatcher {
1414 public:
1415 IsQuadopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& a_matcher,
1416 const Matcher<Node*>& b_matcher,
1417 const Matcher<Node*>& c_matcher,
1418 const Matcher<Node*>& d_matcher)
1419 : NodeMatcher(opcode),
1420 a_matcher_(a_matcher),
1421 b_matcher_(b_matcher),
1422 c_matcher_(c_matcher),
1423 d_matcher_(d_matcher) {}
1424
1425 void DescribeTo(std::ostream* os) const final {
1426 NodeMatcher::DescribeTo(os);
1427 *os << " whose a (";
1428 a_matcher_.DescribeTo(os);
1429 *os << ") and b (";
1430 b_matcher_.DescribeTo(os);
1431 *os << ") and c (";
1432 c_matcher_.DescribeTo(os);
1433 *os << ") and d (";
1434 d_matcher_.DescribeTo(os);
1435 *os << ")";
1436 }
1437
1438 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1439 return (NodeMatcher::MatchAndExplain(node, listener) &&
1440 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "a",
1441 a_matcher_, listener) &&
1442 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "b",
1443 b_matcher_, listener) &&
1444 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), "c",
1445 c_matcher_, listener) &&
1446 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 3), "d",
1447 d_matcher_, listener));
1448 }
1449
1450 private:
1451 const Matcher<Node*> a_matcher_;
1452 const Matcher<Node*> b_matcher_;
1453 const Matcher<Node*> c_matcher_;
1454 const Matcher<Node*> d_matcher_;
1455};
1456
1457class IsTernopMatcher final : public NodeMatcher {
1458 public:
1459 IsTernopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& lhs_matcher,
1460 const Matcher<Node*>& mid_matcher,
1461 const Matcher<Node*>& rhs_matcher)
1462 : NodeMatcher(opcode),
1463 lhs_matcher_(lhs_matcher),
1464 mid_matcher_(mid_matcher),
1465 rhs_matcher_(rhs_matcher) {}
1466
1467 void DescribeTo(std::ostream* os) const final {
1468 NodeMatcher::DescribeTo(os);
1469 *os << " whose lhs (";
1470 lhs_matcher_.DescribeTo(os);
1471 *os << ") and mid (";
1472 mid_matcher_.DescribeTo(os);
1473 *os << ") and rhs (";
1474 rhs_matcher_.DescribeTo(os);
1475 *os << ")";
1476 }
1477
1478 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1479 return (NodeMatcher::MatchAndExplain(node, listener) &&
1480 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "lhs",
1481 lhs_matcher_, listener) &&
1482 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "mid",
1483 mid_matcher_, listener) &&
1484 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), "rhs",
1485 rhs_matcher_, listener));
1486 }
1487
1488 private:
1489 const Matcher<Node*> lhs_matcher_;
1490 const Matcher<Node*> mid_matcher_;
1491 const Matcher<Node*> rhs_matcher_;
1492};
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001493
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001494class IsBinopMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001495 public:
1496 IsBinopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& lhs_matcher,
1497 const Matcher<Node*>& rhs_matcher)
1498 : NodeMatcher(opcode),
1499 lhs_matcher_(lhs_matcher),
1500 rhs_matcher_(rhs_matcher) {}
1501
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001502 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001503 NodeMatcher::DescribeTo(os);
1504 *os << " whose lhs (";
1505 lhs_matcher_.DescribeTo(os);
1506 *os << ") and rhs (";
1507 rhs_matcher_.DescribeTo(os);
1508 *os << ")";
1509 }
1510
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001511 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001512 return (NodeMatcher::MatchAndExplain(node, listener) &&
1513 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "lhs",
1514 lhs_matcher_, listener) &&
1515 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "rhs",
1516 rhs_matcher_, listener));
1517 }
1518
1519 private:
1520 const Matcher<Node*> lhs_matcher_;
1521 const Matcher<Node*> rhs_matcher_;
1522};
1523
1524
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001525class IsUnopMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001526 public:
1527 IsUnopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& input_matcher)
1528 : NodeMatcher(opcode), input_matcher_(input_matcher) {}
1529
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001530 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001531 NodeMatcher::DescribeTo(os);
1532 *os << " whose input (";
1533 input_matcher_.DescribeTo(os);
1534 *os << ")";
1535 }
1536
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001537 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001538 return (NodeMatcher::MatchAndExplain(node, listener) &&
1539 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
1540 "input", input_matcher_, listener));
1541 }
1542
1543 private:
1544 const Matcher<Node*> input_matcher_;
1545};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001546
1547
1548class IsParameterMatcher final : public NodeMatcher {
1549 public:
1550 explicit IsParameterMatcher(const Matcher<int>& index_matcher)
1551 : NodeMatcher(IrOpcode::kParameter), index_matcher_(index_matcher) {}
1552
1553 void DescribeTo(std::ostream* os) const override {
1554 *os << "is a Parameter node with index(";
1555 index_matcher_.DescribeTo(os);
1556 *os << ")";
1557 }
1558
1559 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1560 return (NodeMatcher::MatchAndExplain(node, listener) &&
1561 PrintMatchAndExplain(ParameterIndexOf(node->op()), "index",
1562 index_matcher_, listener));
1563 }
1564
1565 private:
1566 const Matcher<int> index_matcher_;
1567};
1568
1569} // namespace
1570
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001571Matcher<Node*> IsDead() {
1572 return MakeMatcher(new NodeMatcher(IrOpcode::kDead));
1573}
1574
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001575Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher) {
1576 return MakeMatcher(new IsControl1Matcher(IrOpcode::kEnd, control0_matcher));
1577}
1578
1579
1580Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher,
1581 const Matcher<Node*>& control1_matcher) {
1582 return MakeMatcher(new IsControl2Matcher(IrOpcode::kEnd, control0_matcher,
1583 control1_matcher));
1584}
1585
1586
1587Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher,
1588 const Matcher<Node*>& control1_matcher,
1589 const Matcher<Node*>& control2_matcher) {
1590 return MakeMatcher(new IsControl3Matcher(IrOpcode::kEnd, control0_matcher,
1591 control1_matcher, control2_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001592}
1593
1594
1595Matcher<Node*> IsBranch(const Matcher<Node*>& value_matcher,
1596 const Matcher<Node*>& control_matcher) {
1597 return MakeMatcher(new IsBranchMatcher(value_matcher, control_matcher));
1598}
1599
1600
1601Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
1602 const Matcher<Node*>& control1_matcher) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001603 return MakeMatcher(new IsControl2Matcher(IrOpcode::kMerge, control0_matcher,
1604 control1_matcher));
1605}
1606
1607
1608Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
1609 const Matcher<Node*>& control1_matcher,
1610 const Matcher<Node*>& control2_matcher) {
1611 return MakeMatcher(new IsControl3Matcher(IrOpcode::kMerge, control0_matcher,
1612 control1_matcher, control2_matcher));
1613}
1614
1615
1616Matcher<Node*> IsLoop(const Matcher<Node*>& control0_matcher,
1617 const Matcher<Node*>& control1_matcher) {
1618 return MakeMatcher(new IsControl2Matcher(IrOpcode::kLoop, control0_matcher,
1619 control1_matcher));
1620}
1621
1622
1623Matcher<Node*> IsLoop(const Matcher<Node*>& control0_matcher,
1624 const Matcher<Node*>& control1_matcher,
1625 const Matcher<Node*>& control2_matcher) {
1626 return MakeMatcher(new IsControl3Matcher(IrOpcode::kLoop, control0_matcher,
1627 control1_matcher, control2_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001628}
1629
1630
1631Matcher<Node*> IsIfTrue(const Matcher<Node*>& control_matcher) {
1632 return MakeMatcher(new IsControl1Matcher(IrOpcode::kIfTrue, control_matcher));
1633}
1634
1635
1636Matcher<Node*> IsIfFalse(const Matcher<Node*>& control_matcher) {
1637 return MakeMatcher(
1638 new IsControl1Matcher(IrOpcode::kIfFalse, control_matcher));
1639}
1640
1641
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001642Matcher<Node*> IsIfSuccess(const Matcher<Node*>& control_matcher) {
1643 return MakeMatcher(
1644 new IsControl1Matcher(IrOpcode::kIfSuccess, control_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001645}
1646
1647
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001648Matcher<Node*> IsSwitch(const Matcher<Node*>& value_matcher,
1649 const Matcher<Node*>& control_matcher) {
1650 return MakeMatcher(new IsSwitchMatcher(value_matcher, control_matcher));
1651}
1652
1653
1654Matcher<Node*> IsIfValue(const Matcher<int32_t>& value_matcher,
1655 const Matcher<Node*>& control_matcher) {
1656 return MakeMatcher(new IsIfValueMatcher(value_matcher, control_matcher));
1657}
1658
1659
1660Matcher<Node*> IsIfDefault(const Matcher<Node*>& control_matcher) {
1661 return MakeMatcher(
1662 new IsControl1Matcher(IrOpcode::kIfDefault, control_matcher));
1663}
1664
1665
1666Matcher<Node*> IsBeginRegion(const Matcher<Node*>& effect_matcher) {
1667 return MakeMatcher(new IsBeginRegionMatcher(effect_matcher));
1668}
1669
1670
1671Matcher<Node*> IsFinishRegion(const Matcher<Node*>& value_matcher,
1672 const Matcher<Node*>& effect_matcher) {
1673 return MakeMatcher(new IsFinishRegionMatcher(value_matcher, effect_matcher));
1674}
1675
1676
1677Matcher<Node*> IsReturn(const Matcher<Node*>& value_matcher,
1678 const Matcher<Node*>& effect_matcher,
1679 const Matcher<Node*>& control_matcher) {
1680 return MakeMatcher(
1681 new IsReturnMatcher(value_matcher, effect_matcher, control_matcher));
1682}
1683
Ben Murdoch097c5b22016-05-18 11:27:45 +01001684Matcher<Node*> IsReturn2(const Matcher<Node*>& value_matcher,
1685 const Matcher<Node*>& value2_matcher,
1686 const Matcher<Node*>& effect_matcher,
1687 const Matcher<Node*>& control_matcher) {
1688 return MakeMatcher(new IsReturnMatcher(value_matcher, value2_matcher,
1689 effect_matcher, control_matcher));
1690}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001691
1692Matcher<Node*> IsTerminate(const Matcher<Node*>& effect_matcher,
1693 const Matcher<Node*>& control_matcher) {
1694 return MakeMatcher(new IsTerminateMatcher(effect_matcher, control_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001695}
1696
1697
1698Matcher<Node*> IsExternalConstant(
1699 const Matcher<ExternalReference>& value_matcher) {
1700 return MakeMatcher(new IsConstantMatcher<ExternalReference>(
1701 IrOpcode::kExternalConstant, value_matcher));
1702}
1703
1704
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001705Matcher<Node*> IsHeapConstant(Handle<HeapObject> value) {
1706 return MakeMatcher(new IsConstantMatcher<Handle<HeapObject>>(
1707 IrOpcode::kHeapConstant, value));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001708}
1709
1710
1711Matcher<Node*> IsInt32Constant(const Matcher<int32_t>& value_matcher) {
1712 return MakeMatcher(
1713 new IsConstantMatcher<int32_t>(IrOpcode::kInt32Constant, value_matcher));
1714}
1715
1716
1717Matcher<Node*> IsInt64Constant(const Matcher<int64_t>& value_matcher) {
1718 return MakeMatcher(
1719 new IsConstantMatcher<int64_t>(IrOpcode::kInt64Constant, value_matcher));
1720}
1721
1722
1723Matcher<Node*> IsFloat32Constant(const Matcher<float>& value_matcher) {
1724 return MakeMatcher(
1725 new IsConstantMatcher<float>(IrOpcode::kFloat32Constant, value_matcher));
1726}
1727
1728
1729Matcher<Node*> IsFloat64Constant(const Matcher<double>& value_matcher) {
1730 return MakeMatcher(
1731 new IsConstantMatcher<double>(IrOpcode::kFloat64Constant, value_matcher));
1732}
1733
1734
1735Matcher<Node*> IsNumberConstant(const Matcher<double>& value_matcher) {
1736 return MakeMatcher(
1737 new IsConstantMatcher<double>(IrOpcode::kNumberConstant, value_matcher));
1738}
1739
1740
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001741Matcher<Node*> IsSelect(const Matcher<MachineRepresentation>& type_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001742 const Matcher<Node*>& value0_matcher,
1743 const Matcher<Node*>& value1_matcher,
1744 const Matcher<Node*>& value2_matcher) {
1745 return MakeMatcher(new IsSelectMatcher(type_matcher, value0_matcher,
1746 value1_matcher, value2_matcher));
1747}
1748
1749
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001750Matcher<Node*> IsPhi(const Matcher<MachineRepresentation>& type_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001751 const Matcher<Node*>& value0_matcher,
1752 const Matcher<Node*>& value1_matcher,
1753 const Matcher<Node*>& merge_matcher) {
1754 return MakeMatcher(new IsPhiMatcher(type_matcher, value0_matcher,
1755 value1_matcher, merge_matcher));
1756}
1757
1758
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001759Matcher<Node*> IsPhi(const Matcher<MachineRepresentation>& type_matcher,
1760 const Matcher<Node*>& value0_matcher,
1761 const Matcher<Node*>& value1_matcher,
1762 const Matcher<Node*>& value2_matcher,
1763 const Matcher<Node*>& merge_matcher) {
1764 return MakeMatcher(new IsPhi2Matcher(type_matcher, value0_matcher,
1765 value1_matcher, value2_matcher,
1766 merge_matcher));
1767}
1768
1769
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001770Matcher<Node*> IsEffectPhi(const Matcher<Node*>& effect0_matcher,
1771 const Matcher<Node*>& effect1_matcher,
1772 const Matcher<Node*>& merge_matcher) {
1773 return MakeMatcher(
1774 new IsEffectPhiMatcher(effect0_matcher, effect1_matcher, merge_matcher));
1775}
1776
1777
1778Matcher<Node*> IsProjection(const Matcher<size_t>& index_matcher,
1779 const Matcher<Node*>& base_matcher) {
1780 return MakeMatcher(new IsProjectionMatcher(index_matcher, base_matcher));
1781}
1782
Ben Murdoch097c5b22016-05-18 11:27:45 +01001783Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
1784 const Matcher<Node*>& value0_matcher,
1785 const Matcher<Node*>& effect_matcher,
1786 const Matcher<Node*>& control_matcher) {
1787 std::vector<Matcher<Node*>> value_matchers;
1788 value_matchers.push_back(value0_matcher);
1789 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1790 effect_matcher, control_matcher));
1791}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001792
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001793Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001794 const Matcher<Node*>& value0_matcher,
1795 const Matcher<Node*>& value1_matcher,
1796 const Matcher<Node*>& effect_matcher,
1797 const Matcher<Node*>& control_matcher) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001798 std::vector<Matcher<Node*>> value_matchers;
1799 value_matchers.push_back(value0_matcher);
1800 value_matchers.push_back(value1_matcher);
1801 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1802 effect_matcher, control_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001803}
1804
1805
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001806Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
1807 const Matcher<Node*>& value0_matcher,
1808 const Matcher<Node*>& value1_matcher,
1809 const Matcher<Node*>& value2_matcher,
1810 const Matcher<Node*>& effect_matcher,
1811 const Matcher<Node*>& control_matcher) {
1812 std::vector<Matcher<Node*>> value_matchers;
1813 value_matchers.push_back(value0_matcher);
1814 value_matchers.push_back(value1_matcher);
1815 value_matchers.push_back(value2_matcher);
1816 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1817 effect_matcher, control_matcher));
1818}
1819
1820
1821Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001822 const Matcher<Node*>& value0_matcher,
1823 const Matcher<Node*>& value1_matcher,
1824 const Matcher<Node*>& value2_matcher,
1825 const Matcher<Node*>& value3_matcher,
1826 const Matcher<Node*>& effect_matcher,
1827 const Matcher<Node*>& control_matcher) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001828 std::vector<Matcher<Node*>> value_matchers;
1829 value_matchers.push_back(value0_matcher);
1830 value_matchers.push_back(value1_matcher);
1831 value_matchers.push_back(value2_matcher);
1832 value_matchers.push_back(value3_matcher);
1833 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1834 effect_matcher, control_matcher));
1835}
1836
1837
1838Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
1839 const Matcher<Node*>& value0_matcher,
1840 const Matcher<Node*>& value1_matcher,
1841 const Matcher<Node*>& value2_matcher,
1842 const Matcher<Node*>& value3_matcher,
1843 const Matcher<Node*>& value4_matcher,
1844 const Matcher<Node*>& effect_matcher,
1845 const Matcher<Node*>& control_matcher) {
1846 std::vector<Matcher<Node*>> value_matchers;
1847 value_matchers.push_back(value0_matcher);
1848 value_matchers.push_back(value1_matcher);
1849 value_matchers.push_back(value2_matcher);
1850 value_matchers.push_back(value3_matcher);
1851 value_matchers.push_back(value4_matcher);
1852 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1853 effect_matcher, control_matcher));
1854}
1855
1856
1857Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
1858 const Matcher<Node*>& value0_matcher,
1859 const Matcher<Node*>& value1_matcher,
1860 const Matcher<Node*>& value2_matcher,
1861 const Matcher<Node*>& value3_matcher,
1862 const Matcher<Node*>& value4_matcher,
1863 const Matcher<Node*>& value5_matcher,
1864 const Matcher<Node*>& effect_matcher,
1865 const Matcher<Node*>& control_matcher) {
1866 std::vector<Matcher<Node*>> value_matchers;
1867 value_matchers.push_back(value0_matcher);
1868 value_matchers.push_back(value1_matcher);
1869 value_matchers.push_back(value2_matcher);
1870 value_matchers.push_back(value3_matcher);
1871 value_matchers.push_back(value4_matcher);
1872 value_matchers.push_back(value5_matcher);
1873 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1874 effect_matcher, control_matcher));
1875}
1876
1877
1878Matcher<Node*> IsCall(
1879 const Matcher<const CallDescriptor*>& descriptor_matcher,
1880 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1881 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
1882 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& value5_matcher,
1883 const Matcher<Node*>& value6_matcher, const Matcher<Node*>& effect_matcher,
1884 const Matcher<Node*>& control_matcher) {
1885 std::vector<Matcher<Node*>> value_matchers;
1886 value_matchers.push_back(value0_matcher);
1887 value_matchers.push_back(value1_matcher);
1888 value_matchers.push_back(value2_matcher);
1889 value_matchers.push_back(value3_matcher);
1890 value_matchers.push_back(value4_matcher);
1891 value_matchers.push_back(value5_matcher);
1892 value_matchers.push_back(value6_matcher);
1893 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1894 effect_matcher, control_matcher));
1895}
1896
1897
1898Matcher<Node*> IsTailCall(
1899 const Matcher<CallDescriptor const*>& descriptor_matcher,
1900 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1901 const Matcher<Node*>& effect_matcher,
1902 const Matcher<Node*>& control_matcher) {
1903 std::vector<Matcher<Node*>> value_matchers;
1904 value_matchers.push_back(value0_matcher);
1905 value_matchers.push_back(value1_matcher);
1906 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
1907 effect_matcher, control_matcher));
1908}
1909
1910
1911Matcher<Node*> IsTailCall(
1912 const Matcher<CallDescriptor const*>& descriptor_matcher,
1913 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1914 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& effect_matcher,
1915 const Matcher<Node*>& control_matcher) {
1916 std::vector<Matcher<Node*>> value_matchers;
1917 value_matchers.push_back(value0_matcher);
1918 value_matchers.push_back(value1_matcher);
1919 value_matchers.push_back(value2_matcher);
1920 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
1921 effect_matcher, control_matcher));
1922}
1923
1924
1925Matcher<Node*> IsTailCall(
1926 const Matcher<CallDescriptor const*>& descriptor_matcher,
1927 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1928 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
1929 const Matcher<Node*>& effect_matcher,
1930 const Matcher<Node*>& control_matcher) {
1931 std::vector<Matcher<Node*>> value_matchers;
1932 value_matchers.push_back(value0_matcher);
1933 value_matchers.push_back(value1_matcher);
1934 value_matchers.push_back(value2_matcher);
1935 value_matchers.push_back(value3_matcher);
1936 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
1937 effect_matcher, control_matcher));
1938}
1939
1940
1941Matcher<Node*> IsTailCall(
1942 const Matcher<CallDescriptor const*>& descriptor_matcher,
1943 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1944 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
1945 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& effect_matcher,
1946 const Matcher<Node*>& control_matcher) {
1947 std::vector<Matcher<Node*>> value_matchers;
1948 value_matchers.push_back(value0_matcher);
1949 value_matchers.push_back(value1_matcher);
1950 value_matchers.push_back(value2_matcher);
1951 value_matchers.push_back(value3_matcher);
1952 value_matchers.push_back(value4_matcher);
1953 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
1954 effect_matcher, control_matcher));
1955}
1956
1957
1958Matcher<Node*> IsTailCall(
1959 const Matcher<CallDescriptor const*>& descriptor_matcher,
1960 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1961 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
1962 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& value5_matcher,
1963 const Matcher<Node*>& effect_matcher,
1964 const Matcher<Node*>& control_matcher) {
1965 std::vector<Matcher<Node*>> value_matchers;
1966 value_matchers.push_back(value0_matcher);
1967 value_matchers.push_back(value1_matcher);
1968 value_matchers.push_back(value2_matcher);
1969 value_matchers.push_back(value3_matcher);
1970 value_matchers.push_back(value4_matcher);
1971 value_matchers.push_back(value5_matcher);
1972 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
1973 effect_matcher, control_matcher));
1974}
1975
1976
1977Matcher<Node*> IsTailCall(
1978 const Matcher<CallDescriptor const*>& descriptor_matcher,
1979 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1980 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
1981 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& value5_matcher,
1982 const Matcher<Node*>& value6_matcher, const Matcher<Node*>& effect_matcher,
1983 const Matcher<Node*>& control_matcher) {
1984 std::vector<Matcher<Node*>> value_matchers;
1985 value_matchers.push_back(value0_matcher);
1986 value_matchers.push_back(value1_matcher);
1987 value_matchers.push_back(value2_matcher);
1988 value_matchers.push_back(value3_matcher);
1989 value_matchers.push_back(value4_matcher);
1990 value_matchers.push_back(value5_matcher);
1991 value_matchers.push_back(value6_matcher);
1992 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
1993 effect_matcher, control_matcher));
1994}
1995
1996
1997Matcher<Node*> IsTailCall(
1998 const Matcher<CallDescriptor const*>& descriptor_matcher,
1999 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
2000 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
2001 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& value5_matcher,
2002 const Matcher<Node*>& value6_matcher, const Matcher<Node*>& value7_matcher,
2003 const Matcher<Node*>& effect_matcher,
2004 const Matcher<Node*>& control_matcher) {
2005 std::vector<Matcher<Node*>> value_matchers;
2006 value_matchers.push_back(value0_matcher);
2007 value_matchers.push_back(value1_matcher);
2008 value_matchers.push_back(value2_matcher);
2009 value_matchers.push_back(value3_matcher);
2010 value_matchers.push_back(value4_matcher);
2011 value_matchers.push_back(value5_matcher);
2012 value_matchers.push_back(value6_matcher);
2013 value_matchers.push_back(value7_matcher);
2014 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
2015 effect_matcher, control_matcher));
2016}
2017
Ben Murdochc5610432016-08-08 18:44:38 +01002018Matcher<Node*> IsTypeGuard(const Matcher<Type*>& type_matcher,
2019 const Matcher<Node*>& value_matcher,
2020 const Matcher<Node*>& control_matcher) {
Ben Murdochda12d292016-06-02 14:46:10 +01002021 return MakeMatcher(
Ben Murdochc5610432016-08-08 18:44:38 +01002022 new IsTypeGuardMatcher(type_matcher, value_matcher, control_matcher));
Ben Murdochda12d292016-06-02 14:46:10 +01002023}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002024
2025Matcher<Node*> IsReferenceEqual(const Matcher<Type*>& type_matcher,
2026 const Matcher<Node*>& lhs_matcher,
2027 const Matcher<Node*>& rhs_matcher) {
2028 return MakeMatcher(
2029 new IsReferenceEqualMatcher(type_matcher, lhs_matcher, rhs_matcher));
2030}
2031
2032
2033Matcher<Node*> IsAllocate(const Matcher<Node*>& size_matcher,
2034 const Matcher<Node*>& effect_matcher,
2035 const Matcher<Node*>& control_matcher) {
2036 return MakeMatcher(
2037 new IsAllocateMatcher(size_matcher, effect_matcher, control_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002038}
2039
2040
2041Matcher<Node*> IsLoadField(const Matcher<FieldAccess>& access_matcher,
2042 const Matcher<Node*>& base_matcher,
2043 const Matcher<Node*>& effect_matcher,
2044 const Matcher<Node*>& control_matcher) {
2045 return MakeMatcher(new IsLoadFieldMatcher(access_matcher, base_matcher,
2046 effect_matcher, control_matcher));
2047}
2048
2049
2050Matcher<Node*> IsStoreField(const Matcher<FieldAccess>& access_matcher,
2051 const Matcher<Node*>& base_matcher,
2052 const Matcher<Node*>& value_matcher,
2053 const Matcher<Node*>& effect_matcher,
2054 const Matcher<Node*>& control_matcher) {
2055 return MakeMatcher(new IsStoreFieldMatcher(access_matcher, base_matcher,
2056 value_matcher, effect_matcher,
2057 control_matcher));
2058}
2059
2060
2061Matcher<Node*> IsLoadBuffer(const Matcher<BufferAccess>& access_matcher,
2062 const Matcher<Node*>& buffer_matcher,
2063 const Matcher<Node*>& offset_matcher,
2064 const Matcher<Node*>& length_matcher,
2065 const Matcher<Node*>& effect_matcher,
2066 const Matcher<Node*>& control_matcher) {
2067 return MakeMatcher(new IsLoadBufferMatcher(access_matcher, buffer_matcher,
2068 offset_matcher, length_matcher,
2069 effect_matcher, control_matcher));
2070}
2071
2072
2073Matcher<Node*> IsStoreBuffer(const Matcher<BufferAccess>& access_matcher,
2074 const Matcher<Node*>& buffer_matcher,
2075 const Matcher<Node*>& offset_matcher,
2076 const Matcher<Node*>& length_matcher,
2077 const Matcher<Node*>& value_matcher,
2078 const Matcher<Node*>& effect_matcher,
2079 const Matcher<Node*>& control_matcher) {
2080 return MakeMatcher(new IsStoreBufferMatcher(
2081 access_matcher, buffer_matcher, offset_matcher, length_matcher,
2082 value_matcher, effect_matcher, control_matcher));
2083}
2084
2085
2086Matcher<Node*> IsLoadElement(const Matcher<ElementAccess>& access_matcher,
2087 const Matcher<Node*>& base_matcher,
2088 const Matcher<Node*>& index_matcher,
2089 const Matcher<Node*>& effect_matcher,
2090 const Matcher<Node*>& control_matcher) {
2091 return MakeMatcher(new IsLoadElementMatcher(access_matcher, base_matcher,
2092 index_matcher, effect_matcher,
2093 control_matcher));
2094}
2095
2096
2097Matcher<Node*> IsStoreElement(const Matcher<ElementAccess>& access_matcher,
2098 const Matcher<Node*>& base_matcher,
2099 const Matcher<Node*>& index_matcher,
2100 const Matcher<Node*>& value_matcher,
2101 const Matcher<Node*>& effect_matcher,
2102 const Matcher<Node*>& control_matcher) {
2103 return MakeMatcher(new IsStoreElementMatcher(
2104 access_matcher, base_matcher, index_matcher, value_matcher,
2105 effect_matcher, control_matcher));
2106}
2107
2108
2109Matcher<Node*> IsLoad(const Matcher<LoadRepresentation>& rep_matcher,
2110 const Matcher<Node*>& base_matcher,
2111 const Matcher<Node*>& index_matcher,
2112 const Matcher<Node*>& effect_matcher,
2113 const Matcher<Node*>& control_matcher) {
2114 return MakeMatcher(new IsLoadMatcher(rep_matcher, base_matcher, index_matcher,
2115 effect_matcher, control_matcher));
2116}
2117
2118
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002119Matcher<Node*> IsStore(const Matcher<StoreRepresentation>& rep_matcher,
2120 const Matcher<Node*>& base_matcher,
2121 const Matcher<Node*>& index_matcher,
2122 const Matcher<Node*>& value_matcher,
2123 const Matcher<Node*>& effect_matcher,
2124 const Matcher<Node*>& control_matcher) {
2125 return MakeMatcher(new IsStoreMatcher(rep_matcher, base_matcher,
2126 index_matcher, value_matcher,
2127 effect_matcher, control_matcher));
2128}
2129
Ben Murdochda12d292016-06-02 14:46:10 +01002130Matcher<Node*> IsStackSlot(const Matcher<MachineRepresentation>& rep_matcher) {
2131 return MakeMatcher(new IsStackSlotMatcher(rep_matcher));
2132}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002133
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002134Matcher<Node*> IsToNumber(const Matcher<Node*>& base_matcher,
2135 const Matcher<Node*>& context_matcher,
2136 const Matcher<Node*>& effect_matcher,
2137 const Matcher<Node*>& control_matcher) {
2138 return MakeMatcher(new IsToNumberMatcher(base_matcher, context_matcher,
2139 effect_matcher, control_matcher));
2140}
2141
2142
2143Matcher<Node*> IsLoadContext(const Matcher<ContextAccess>& access_matcher,
2144 const Matcher<Node*>& context_matcher) {
2145 return MakeMatcher(new IsLoadContextMatcher(access_matcher, context_matcher));
2146}
2147
2148
2149Matcher<Node*> IsParameter(const Matcher<int> index_matcher) {
2150 return MakeMatcher(new IsParameterMatcher(index_matcher));
2151}
2152
2153
2154Matcher<Node*> IsLoadFramePointer() {
2155 return MakeMatcher(new NodeMatcher(IrOpcode::kLoadFramePointer));
2156}
2157
Ben Murdochc5610432016-08-08 18:44:38 +01002158Matcher<Node*> IsLoadParentFramePointer() {
2159 return MakeMatcher(new NodeMatcher(IrOpcode::kLoadParentFramePointer));
2160}
2161
Ben Murdochda12d292016-06-02 14:46:10 +01002162#define IS_QUADOP_MATCHER(Name) \
2163 Matcher<Node*> Is##Name( \
2164 const Matcher<Node*>& a_matcher, const Matcher<Node*>& b_matcher, \
2165 const Matcher<Node*>& c_matcher, const Matcher<Node*>& d_matcher) { \
2166 return MakeMatcher(new IsQuadopMatcher(IrOpcode::k##Name, a_matcher, \
2167 b_matcher, c_matcher, d_matcher)); \
2168 }
2169
2170IS_QUADOP_MATCHER(Int32PairAdd)
2171IS_QUADOP_MATCHER(Int32PairSub)
2172IS_QUADOP_MATCHER(Int32PairMul)
2173
2174#define IS_TERNOP_MATCHER(Name) \
2175 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \
2176 const Matcher<Node*>& mid_matcher, \
2177 const Matcher<Node*>& rhs_matcher) { \
2178 return MakeMatcher(new IsTernopMatcher(IrOpcode::k##Name, lhs_matcher, \
2179 mid_matcher, rhs_matcher)); \
2180 }
2181
2182IS_TERNOP_MATCHER(Word32PairShl)
2183IS_TERNOP_MATCHER(Word32PairShr)
2184IS_TERNOP_MATCHER(Word32PairSar)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002185
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002186#define IS_BINOP_MATCHER(Name) \
2187 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \
2188 const Matcher<Node*>& rhs_matcher) { \
2189 return MakeMatcher( \
2190 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \
2191 }
2192IS_BINOP_MATCHER(NumberEqual)
2193IS_BINOP_MATCHER(NumberLessThan)
2194IS_BINOP_MATCHER(NumberSubtract)
2195IS_BINOP_MATCHER(NumberMultiply)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002196IS_BINOP_MATCHER(NumberShiftLeft)
2197IS_BINOP_MATCHER(NumberShiftRight)
2198IS_BINOP_MATCHER(NumberShiftRightLogical)
Ben Murdochda12d292016-06-02 14:46:10 +01002199IS_BINOP_MATCHER(NumberImul)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002200IS_BINOP_MATCHER(Word32And)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002201IS_BINOP_MATCHER(Word32Or)
Ben Murdochda12d292016-06-02 14:46:10 +01002202IS_BINOP_MATCHER(Word32Xor)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002203IS_BINOP_MATCHER(Word32Sar)
2204IS_BINOP_MATCHER(Word32Shl)
2205IS_BINOP_MATCHER(Word32Shr)
2206IS_BINOP_MATCHER(Word32Ror)
2207IS_BINOP_MATCHER(Word32Equal)
2208IS_BINOP_MATCHER(Word64And)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002209IS_BINOP_MATCHER(Word64Or)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002210IS_BINOP_MATCHER(Word64Sar)
2211IS_BINOP_MATCHER(Word64Shl)
2212IS_BINOP_MATCHER(Word64Equal)
2213IS_BINOP_MATCHER(Int32AddWithOverflow)
2214IS_BINOP_MATCHER(Int32Add)
2215IS_BINOP_MATCHER(Int32Sub)
2216IS_BINOP_MATCHER(Int32Mul)
2217IS_BINOP_MATCHER(Int32MulHigh)
2218IS_BINOP_MATCHER(Int32LessThan)
2219IS_BINOP_MATCHER(Uint32LessThan)
2220IS_BINOP_MATCHER(Uint32LessThanOrEqual)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002221IS_BINOP_MATCHER(Int64Add)
2222IS_BINOP_MATCHER(Int64Sub)
2223IS_BINOP_MATCHER(JSAdd)
2224IS_BINOP_MATCHER(Float32Max)
2225IS_BINOP_MATCHER(Float32Min)
2226IS_BINOP_MATCHER(Float32Equal)
2227IS_BINOP_MATCHER(Float32LessThan)
2228IS_BINOP_MATCHER(Float32LessThanOrEqual)
2229IS_BINOP_MATCHER(Float64Max)
2230IS_BINOP_MATCHER(Float64Min)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002231IS_BINOP_MATCHER(Float64Sub)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002232IS_BINOP_MATCHER(Float64InsertLowWord32)
2233IS_BINOP_MATCHER(Float64InsertHighWord32)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002234#undef IS_BINOP_MATCHER
2235
2236
2237#define IS_UNOP_MATCHER(Name) \
2238 Matcher<Node*> Is##Name(const Matcher<Node*>& input_matcher) { \
2239 return MakeMatcher(new IsUnopMatcher(IrOpcode::k##Name, input_matcher)); \
2240 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002241IS_UNOP_MATCHER(BooleanNot)
Ben Murdochc5610432016-08-08 18:44:38 +01002242IS_UNOP_MATCHER(TruncateFloat64ToWord32)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002243IS_UNOP_MATCHER(ChangeFloat64ToInt32)
2244IS_UNOP_MATCHER(ChangeFloat64ToUint32)
2245IS_UNOP_MATCHER(ChangeInt32ToFloat64)
2246IS_UNOP_MATCHER(ChangeInt32ToInt64)
2247IS_UNOP_MATCHER(ChangeUint32ToFloat64)
2248IS_UNOP_MATCHER(ChangeUint32ToUint64)
2249IS_UNOP_MATCHER(TruncateFloat64ToFloat32)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002250IS_UNOP_MATCHER(TruncateInt64ToInt32)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002251IS_UNOP_MATCHER(Float32Abs)
2252IS_UNOP_MATCHER(Float64Abs)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002253IS_UNOP_MATCHER(Float64Sqrt)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002254IS_UNOP_MATCHER(Float64RoundDown)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002255IS_UNOP_MATCHER(Float64RoundTruncate)
2256IS_UNOP_MATCHER(Float64RoundTiesAway)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002257IS_UNOP_MATCHER(Float64ExtractLowWord32)
2258IS_UNOP_MATCHER(Float64ExtractHighWord32)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002259IS_UNOP_MATCHER(NumberToInt32)
2260IS_UNOP_MATCHER(NumberToUint32)
Ben Murdoch097c5b22016-05-18 11:27:45 +01002261IS_UNOP_MATCHER(ObjectIsReceiver)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002262IS_UNOP_MATCHER(ObjectIsSmi)
2263IS_UNOP_MATCHER(Word32Clz)
Ben Murdochda12d292016-06-02 14:46:10 +01002264IS_UNOP_MATCHER(Word32Ctz)
2265IS_UNOP_MATCHER(Word32Popcnt)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002266#undef IS_UNOP_MATCHER
2267
2268} // namespace compiler
2269} // namespace internal
2270} // namespace v8