blob: 6e5d39f68db5d013698e1ce326f2cb6dc562e2b9 [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 IsEffectSetMatcher final : public NodeMatcher {
616 public:
617 IsEffectSetMatcher(const Matcher<Node*>& effect0_matcher,
618 const Matcher<Node*>& effect1_matcher)
619 : NodeMatcher(IrOpcode::kEffectSet),
620 effect0_matcher_(effect0_matcher),
621 effect1_matcher_(effect1_matcher) {}
622
623 void DescribeTo(std::ostream* os) const final {
624 NodeMatcher::DescribeTo(os);
625 *os << "), effect0 (";
626 effect0_matcher_.DescribeTo(os);
627 *os << ") and effect1 (";
628 effect1_matcher_.DescribeTo(os);
629 *os << ")";
630 }
631
632 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
633 if (!NodeMatcher::MatchAndExplain(node, listener)) return false;
634
635 Node* effect0 = NodeProperties::GetEffectInput(node, 0);
636 Node* effect1 = NodeProperties::GetEffectInput(node, 1);
637
638 {
639 // Try matching in the reverse order first.
640 StringMatchResultListener value_listener;
641 if (effect0_matcher_.MatchAndExplain(effect1, &value_listener) &&
642 effect1_matcher_.MatchAndExplain(effect0, &value_listener)) {
643 return true;
644 }
645 }
646
647 return PrintMatchAndExplain(effect0, "effect0", effect0_matcher_,
648 listener) &&
649 PrintMatchAndExplain(effect1, "effect1", effect1_matcher_, listener);
650 }
651
652 private:
653 const Matcher<Node*> effect0_matcher_;
654 const Matcher<Node*> effect1_matcher_;
655};
656
657
658class IsProjectionMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400659 public:
660 IsProjectionMatcher(const Matcher<size_t>& index_matcher,
661 const Matcher<Node*>& base_matcher)
662 : NodeMatcher(IrOpcode::kProjection),
663 index_matcher_(index_matcher),
664 base_matcher_(base_matcher) {}
665
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000666 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400667 NodeMatcher::DescribeTo(os);
668 *os << " whose index (";
669 index_matcher_.DescribeTo(os);
670 *os << ") and base (";
671 base_matcher_.DescribeTo(os);
672 *os << ")";
673 }
674
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000675 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400676 return (NodeMatcher::MatchAndExplain(node, listener) &&
677 PrintMatchAndExplain(OpParameter<size_t>(node), "index",
678 index_matcher_, listener) &&
679 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
680 base_matcher_, listener));
681 }
682
683 private:
684 const Matcher<size_t> index_matcher_;
685 const Matcher<Node*> base_matcher_;
686};
687
688
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000689class IsCallMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400690 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000691 IsCallMatcher(const Matcher<const CallDescriptor*>& descriptor_matcher,
692 const std::vector<Matcher<Node*>>& value_matchers,
693 const Matcher<Node*>& effect_matcher,
694 const Matcher<Node*>& control_matcher)
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400695 : NodeMatcher(IrOpcode::kCall),
696 descriptor_matcher_(descriptor_matcher),
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000697 value_matchers_(value_matchers),
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400698 effect_matcher_(effect_matcher),
699 control_matcher_(control_matcher) {}
700
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000701 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400702 NodeMatcher::DescribeTo(os);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000703 for (size_t i = 0; i < value_matchers_.size(); ++i) {
704 if (i == 0) {
705 *os << " whose value0 (";
706 } else {
707 *os << "), value" << i << " (";
708 }
709 value_matchers_[i].DescribeTo(os);
710 }
711 *os << "), effect (";
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400712 effect_matcher_.DescribeTo(os);
713 *os << ") and control (";
714 control_matcher_.DescribeTo(os);
715 *os << ")";
716 }
717
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000718 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
719 if (!NodeMatcher::MatchAndExplain(node, listener) ||
720 !PrintMatchAndExplain(OpParameter<const CallDescriptor*>(node),
721 "descriptor", descriptor_matcher_, listener)) {
722 return false;
723 }
724 for (size_t i = 0; i < value_matchers_.size(); ++i) {
725 std::ostringstream ost;
726 ost << "value" << i;
727 if (!PrintMatchAndExplain(
728 NodeProperties::GetValueInput(node, static_cast<int>(i)),
729 ost.str(), value_matchers_[i], listener)) {
730 return false;
731 }
732 }
733 Node* effect_node = nullptr;
734 Node* control_node = nullptr;
735 if (NodeProperties::FirstEffectIndex(node) < node->InputCount()) {
736 effect_node = NodeProperties::GetEffectInput(node);
737 }
738 if (NodeProperties::FirstControlIndex(node) < node->InputCount()) {
739 control_node = NodeProperties::GetControlInput(node);
740 }
741 return (PrintMatchAndExplain(effect_node, "effect", effect_matcher_,
742 listener) &&
743 PrintMatchAndExplain(control_node, "control", control_matcher_,
744 listener));
745 }
746
747 private:
748 const Matcher<const CallDescriptor*> descriptor_matcher_;
749 const std::vector<Matcher<Node*>> value_matchers_;
750 const Matcher<Node*> effect_matcher_;
751 const Matcher<Node*> control_matcher_;
752};
753
754
755class IsTailCallMatcher final : public NodeMatcher {
756 public:
757 IsTailCallMatcher(const Matcher<CallDescriptor const*>& descriptor_matcher,
758 const std::vector<Matcher<Node*>>& value_matchers,
759 const Matcher<Node*>& effect_matcher,
760 const Matcher<Node*>& control_matcher)
761 : NodeMatcher(IrOpcode::kTailCall),
762 descriptor_matcher_(descriptor_matcher),
763 value_matchers_(value_matchers),
764 effect_matcher_(effect_matcher),
765 control_matcher_(control_matcher) {}
766
767 void DescribeTo(std::ostream* os) const final {
768 NodeMatcher::DescribeTo(os);
769 for (size_t i = 0; i < value_matchers_.size(); ++i) {
770 if (i == 0) {
771 *os << " whose value0 (";
772 } else {
773 *os << "), value" << i << " (";
774 }
775 value_matchers_[i].DescribeTo(os);
776 }
777 *os << "), effect (";
778 effect_matcher_.DescribeTo(os);
779 *os << ") and control (";
780 control_matcher_.DescribeTo(os);
781 *os << ")";
782 }
783
784 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
785 if (!NodeMatcher::MatchAndExplain(node, listener) ||
786 !PrintMatchAndExplain(OpParameter<CallDescriptor const*>(node),
787 "descriptor", descriptor_matcher_, listener)) {
788 return false;
789 }
790 for (size_t i = 0; i < value_matchers_.size(); ++i) {
791 std::ostringstream ost;
792 ost << "value" << i;
793 if (!PrintMatchAndExplain(
794 NodeProperties::GetValueInput(node, static_cast<int>(i)),
795 ost.str(), value_matchers_[i], listener)) {
796 return false;
797 }
798 }
799 Node* effect_node = nullptr;
800 Node* control_node = nullptr;
801 if (NodeProperties::FirstEffectIndex(node) < node->InputCount()) {
802 effect_node = NodeProperties::GetEffectInput(node);
803 }
804 if (NodeProperties::FirstControlIndex(node) < node->InputCount()) {
805 control_node = NodeProperties::GetControlInput(node);
806 }
807 return (PrintMatchAndExplain(effect_node, "effect", effect_matcher_,
808 listener) &&
809 PrintMatchAndExplain(control_node, "control", control_matcher_,
810 listener));
811 }
812
813 private:
814 const Matcher<CallDescriptor const*> descriptor_matcher_;
815 const std::vector<Matcher<Node*>> value_matchers_;
816 const Matcher<Node*> effect_matcher_;
817 const Matcher<Node*> control_matcher_;
818};
819
820
821class IsReferenceEqualMatcher final : public NodeMatcher {
822 public:
823 IsReferenceEqualMatcher(const Matcher<Type*>& type_matcher,
824 const Matcher<Node*>& lhs_matcher,
825 const Matcher<Node*>& rhs_matcher)
826 : NodeMatcher(IrOpcode::kReferenceEqual),
827 type_matcher_(type_matcher),
828 lhs_matcher_(lhs_matcher),
829 rhs_matcher_(rhs_matcher) {}
830
831 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400832 return (NodeMatcher::MatchAndExplain(node, listener) &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000833 // TODO(bmeurer): The type parameter is currently ignored.
834 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "lhs",
835 lhs_matcher_, listener) &&
836 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "rhs",
837 rhs_matcher_, listener));
838 }
839
840 private:
841 const Matcher<Type*> type_matcher_;
842 const Matcher<Node*> lhs_matcher_;
843 const Matcher<Node*> rhs_matcher_;
844};
845
846
847class IsAllocateMatcher final : public NodeMatcher {
848 public:
849 IsAllocateMatcher(const Matcher<Node*>& size_matcher,
850 const Matcher<Node*>& effect_matcher,
851 const Matcher<Node*>& control_matcher)
852 : NodeMatcher(IrOpcode::kAllocate),
853 size_matcher_(size_matcher),
854 effect_matcher_(effect_matcher),
855 control_matcher_(control_matcher) {}
856
857 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
858 return (NodeMatcher::MatchAndExplain(node, listener) &&
859 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "size",
860 size_matcher_, listener) &&
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400861 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
862 effect_matcher_, listener) &&
863 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
864 "control", control_matcher_, listener));
865 }
866
867 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000868 const Matcher<Node*> size_matcher_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400869 const Matcher<Node*> effect_matcher_;
870 const Matcher<Node*> control_matcher_;
871};
872
873
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000874class IsLoadFieldMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400875 public:
876 IsLoadFieldMatcher(const Matcher<FieldAccess>& access_matcher,
877 const Matcher<Node*>& base_matcher,
878 const Matcher<Node*>& effect_matcher,
879 const Matcher<Node*>& control_matcher)
880 : NodeMatcher(IrOpcode::kLoadField),
881 access_matcher_(access_matcher),
882 base_matcher_(base_matcher),
883 effect_matcher_(effect_matcher),
884 control_matcher_(control_matcher) {}
885
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000886 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400887 NodeMatcher::DescribeTo(os);
888 *os << " whose access (";
889 access_matcher_.DescribeTo(os);
890 *os << "), base (";
891 base_matcher_.DescribeTo(os);
892 *os << "), effect (";
893 effect_matcher_.DescribeTo(os);
894 *os << ") and control (";
895 control_matcher_.DescribeTo(os);
896 *os << ")";
897 }
898
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000899 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400900 return (NodeMatcher::MatchAndExplain(node, listener) &&
901 PrintMatchAndExplain(OpParameter<FieldAccess>(node), "access",
902 access_matcher_, listener) &&
903 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
904 base_matcher_, listener) &&
905 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
906 effect_matcher_, listener) &&
907 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
908 "control", control_matcher_, listener));
909 }
910
911 private:
912 const Matcher<FieldAccess> access_matcher_;
913 const Matcher<Node*> base_matcher_;
914 const Matcher<Node*> effect_matcher_;
915 const Matcher<Node*> control_matcher_;
916};
917
918
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000919class IsStoreFieldMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400920 public:
921 IsStoreFieldMatcher(const Matcher<FieldAccess>& access_matcher,
922 const Matcher<Node*>& base_matcher,
923 const Matcher<Node*>& value_matcher,
924 const Matcher<Node*>& effect_matcher,
925 const Matcher<Node*>& control_matcher)
926 : NodeMatcher(IrOpcode::kStoreField),
927 access_matcher_(access_matcher),
928 base_matcher_(base_matcher),
929 value_matcher_(value_matcher),
930 effect_matcher_(effect_matcher),
931 control_matcher_(control_matcher) {}
932
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000933 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400934 NodeMatcher::DescribeTo(os);
935 *os << " whose access (";
936 access_matcher_.DescribeTo(os);
937 *os << "), base (";
938 base_matcher_.DescribeTo(os);
939 *os << "), value (";
940 value_matcher_.DescribeTo(os);
941 *os << "), effect (";
942 effect_matcher_.DescribeTo(os);
943 *os << ") and control (";
944 control_matcher_.DescribeTo(os);
945 *os << ")";
946 }
947
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000948 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400949 return (NodeMatcher::MatchAndExplain(node, listener) &&
950 PrintMatchAndExplain(OpParameter<FieldAccess>(node), "access",
951 access_matcher_, listener) &&
952 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
953 base_matcher_, listener) &&
954 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
955 "value", value_matcher_, listener) &&
956 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
957 effect_matcher_, listener) &&
958 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
959 "control", control_matcher_, listener));
960 }
961
962 private:
963 const Matcher<FieldAccess> access_matcher_;
964 const Matcher<Node*> base_matcher_;
965 const Matcher<Node*> value_matcher_;
966 const Matcher<Node*> effect_matcher_;
967 const Matcher<Node*> control_matcher_;
968};
969
970
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000971class IsLoadBufferMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400972 public:
973 IsLoadBufferMatcher(const Matcher<BufferAccess>& access_matcher,
974 const Matcher<Node*>& buffer_matcher,
975 const Matcher<Node*>& offset_matcher,
976 const Matcher<Node*>& length_matcher,
977 const Matcher<Node*>& effect_matcher,
978 const Matcher<Node*>& control_matcher)
979 : NodeMatcher(IrOpcode::kLoadBuffer),
980 access_matcher_(access_matcher),
981 buffer_matcher_(buffer_matcher),
982 offset_matcher_(offset_matcher),
983 length_matcher_(length_matcher),
984 effect_matcher_(effect_matcher),
985 control_matcher_(control_matcher) {}
986
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000987 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400988 NodeMatcher::DescribeTo(os);
989 *os << " whose access (";
990 access_matcher_.DescribeTo(os);
991 *os << "), buffer (";
992 buffer_matcher_.DescribeTo(os);
993 *os << "), offset (";
994 offset_matcher_.DescribeTo(os);
995 *os << "), length (";
996 length_matcher_.DescribeTo(os);
997 *os << "), effect (";
998 effect_matcher_.DescribeTo(os);
999 *os << ") and control (";
1000 control_matcher_.DescribeTo(os);
1001 *os << ")";
1002 }
1003
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001004 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001005 return (NodeMatcher::MatchAndExplain(node, listener) &&
1006 PrintMatchAndExplain(BufferAccessOf(node->op()), "access",
1007 access_matcher_, listener) &&
1008 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
1009 "buffer", buffer_matcher_, listener) &&
1010 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1011 "offset", offset_matcher_, listener) &&
1012 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2),
1013 "length", length_matcher_, listener) &&
1014 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
1015 effect_matcher_, listener) &&
1016 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
1017 "control", control_matcher_, listener));
1018 }
1019
1020 private:
1021 const Matcher<BufferAccess> access_matcher_;
1022 const Matcher<Node*> buffer_matcher_;
1023 const Matcher<Node*> offset_matcher_;
1024 const Matcher<Node*> length_matcher_;
1025 const Matcher<Node*> effect_matcher_;
1026 const Matcher<Node*> control_matcher_;
1027};
1028
1029
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001030class IsStoreBufferMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001031 public:
1032 IsStoreBufferMatcher(const Matcher<BufferAccess>& access_matcher,
1033 const Matcher<Node*>& buffer_matcher,
1034 const Matcher<Node*>& offset_matcher,
1035 const Matcher<Node*>& length_matcher,
1036 const Matcher<Node*>& value_matcher,
1037 const Matcher<Node*>& effect_matcher,
1038 const Matcher<Node*>& control_matcher)
1039 : NodeMatcher(IrOpcode::kStoreBuffer),
1040 access_matcher_(access_matcher),
1041 buffer_matcher_(buffer_matcher),
1042 offset_matcher_(offset_matcher),
1043 length_matcher_(length_matcher),
1044 value_matcher_(value_matcher),
1045 effect_matcher_(effect_matcher),
1046 control_matcher_(control_matcher) {}
1047
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001048 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001049 NodeMatcher::DescribeTo(os);
1050 *os << " whose access (";
1051 access_matcher_.DescribeTo(os);
1052 *os << "), buffer (";
1053 buffer_matcher_.DescribeTo(os);
1054 *os << "), offset (";
1055 offset_matcher_.DescribeTo(os);
1056 *os << "), length (";
1057 length_matcher_.DescribeTo(os);
1058 *os << "), value (";
1059 value_matcher_.DescribeTo(os);
1060 *os << "), effect (";
1061 effect_matcher_.DescribeTo(os);
1062 *os << ") and control (";
1063 control_matcher_.DescribeTo(os);
1064 *os << ")";
1065 }
1066
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001067 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001068 return (NodeMatcher::MatchAndExplain(node, listener) &&
1069 PrintMatchAndExplain(BufferAccessOf(node->op()), "access",
1070 access_matcher_, listener) &&
1071 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
1072 "buffer", buffer_matcher_, listener) &&
1073 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1074 "offset", offset_matcher_, listener) &&
1075 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2),
1076 "length", length_matcher_, listener) &&
1077 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 3),
1078 "value", value_matcher_, listener) &&
1079 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
1080 effect_matcher_, listener) &&
1081 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
1082 "control", control_matcher_, listener));
1083 }
1084
1085 private:
1086 const Matcher<BufferAccess> access_matcher_;
1087 const Matcher<Node*> buffer_matcher_;
1088 const Matcher<Node*> offset_matcher_;
1089 const Matcher<Node*> length_matcher_;
1090 const Matcher<Node*> value_matcher_;
1091 const Matcher<Node*> effect_matcher_;
1092 const Matcher<Node*> control_matcher_;
1093};
1094
1095
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001096class IsLoadElementMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001097 public:
1098 IsLoadElementMatcher(const Matcher<ElementAccess>& access_matcher,
1099 const Matcher<Node*>& base_matcher,
1100 const Matcher<Node*>& index_matcher,
1101 const Matcher<Node*>& effect_matcher,
1102 const Matcher<Node*>& control_matcher)
1103 : NodeMatcher(IrOpcode::kLoadElement),
1104 access_matcher_(access_matcher),
1105 base_matcher_(base_matcher),
1106 index_matcher_(index_matcher),
1107 effect_matcher_(effect_matcher),
1108 control_matcher_(control_matcher) {}
1109
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001110 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001111 NodeMatcher::DescribeTo(os);
1112 *os << " whose access (";
1113 access_matcher_.DescribeTo(os);
1114 *os << "), base (";
1115 base_matcher_.DescribeTo(os);
1116 *os << "), index (";
1117 index_matcher_.DescribeTo(os);
1118 *os << "), effect (";
1119 effect_matcher_.DescribeTo(os);
1120 *os << ") and control (";
1121 control_matcher_.DescribeTo(os);
1122 *os << ")";
1123 }
1124
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001125 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001126 return (NodeMatcher::MatchAndExplain(node, listener) &&
1127 PrintMatchAndExplain(OpParameter<ElementAccess>(node), "access",
1128 access_matcher_, listener) &&
1129 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1130 base_matcher_, listener) &&
1131 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1132 "index", index_matcher_, listener) &&
1133 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
1134 effect_matcher_, listener) &&
1135 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
1136 "control", control_matcher_, listener));
1137 }
1138
1139 private:
1140 const Matcher<ElementAccess> access_matcher_;
1141 const Matcher<Node*> base_matcher_;
1142 const Matcher<Node*> index_matcher_;
1143 const Matcher<Node*> effect_matcher_;
1144 const Matcher<Node*> control_matcher_;
1145};
1146
1147
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001148class IsStoreElementMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001149 public:
1150 IsStoreElementMatcher(const Matcher<ElementAccess>& access_matcher,
1151 const Matcher<Node*>& base_matcher,
1152 const Matcher<Node*>& index_matcher,
1153 const Matcher<Node*>& value_matcher,
1154 const Matcher<Node*>& effect_matcher,
1155 const Matcher<Node*>& control_matcher)
1156 : NodeMatcher(IrOpcode::kStoreElement),
1157 access_matcher_(access_matcher),
1158 base_matcher_(base_matcher),
1159 index_matcher_(index_matcher),
1160 value_matcher_(value_matcher),
1161 effect_matcher_(effect_matcher),
1162 control_matcher_(control_matcher) {}
1163
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001164 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001165 NodeMatcher::DescribeTo(os);
1166 *os << " whose access (";
1167 access_matcher_.DescribeTo(os);
1168 *os << "), base (";
1169 base_matcher_.DescribeTo(os);
1170 *os << "), index (";
1171 index_matcher_.DescribeTo(os);
1172 *os << "), value (";
1173 value_matcher_.DescribeTo(os);
1174 *os << "), effect (";
1175 effect_matcher_.DescribeTo(os);
1176 *os << ") and control (";
1177 control_matcher_.DescribeTo(os);
1178 *os << ")";
1179 }
1180
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001181 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001182 return (NodeMatcher::MatchAndExplain(node, listener) &&
1183 PrintMatchAndExplain(OpParameter<ElementAccess>(node), "access",
1184 access_matcher_, listener) &&
1185 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1186 base_matcher_, listener) &&
1187 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1188 "index", index_matcher_, listener) &&
1189 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2),
1190 "value", value_matcher_, listener) &&
1191 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
1192 effect_matcher_, listener) &&
1193 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
1194 "control", control_matcher_, listener));
1195 }
1196
1197 private:
1198 const Matcher<ElementAccess> access_matcher_;
1199 const Matcher<Node*> base_matcher_;
1200 const Matcher<Node*> index_matcher_;
1201 const Matcher<Node*> value_matcher_;
1202 const Matcher<Node*> effect_matcher_;
1203 const Matcher<Node*> control_matcher_;
1204};
1205
1206
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001207class IsLoadMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001208 public:
1209 IsLoadMatcher(const Matcher<LoadRepresentation>& rep_matcher,
1210 const Matcher<Node*>& base_matcher,
1211 const Matcher<Node*>& index_matcher,
1212 const Matcher<Node*>& effect_matcher,
1213 const Matcher<Node*>& control_matcher)
1214 : NodeMatcher(IrOpcode::kLoad),
1215 rep_matcher_(rep_matcher),
1216 base_matcher_(base_matcher),
1217 index_matcher_(index_matcher),
1218 effect_matcher_(effect_matcher),
1219 control_matcher_(control_matcher) {}
1220
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001221 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001222 NodeMatcher::DescribeTo(os);
1223 *os << " whose rep (";
1224 rep_matcher_.DescribeTo(os);
1225 *os << "), base (";
1226 base_matcher_.DescribeTo(os);
1227 *os << "), index (";
1228 index_matcher_.DescribeTo(os);
1229 *os << "), effect (";
1230 effect_matcher_.DescribeTo(os);
1231 *os << ") and control (";
1232 control_matcher_.DescribeTo(os);
1233 *os << ")";
1234 }
1235
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001236 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1237 Node* effect_node = nullptr;
1238 Node* control_node = nullptr;
1239 if (NodeProperties::FirstEffectIndex(node) < node->InputCount()) {
1240 effect_node = NodeProperties::GetEffectInput(node);
1241 }
1242 if (NodeProperties::FirstControlIndex(node) < node->InputCount()) {
1243 control_node = NodeProperties::GetControlInput(node);
1244 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001245 return (NodeMatcher::MatchAndExplain(node, listener) &&
1246 PrintMatchAndExplain(OpParameter<LoadRepresentation>(node), "rep",
1247 rep_matcher_, listener) &&
1248 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1249 base_matcher_, listener) &&
1250 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1251 "index", index_matcher_, listener) &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001252 PrintMatchAndExplain(effect_node, "effect", effect_matcher_,
1253 listener) &&
1254 PrintMatchAndExplain(control_node, "control", control_matcher_,
1255 listener));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001256 }
1257
1258 private:
1259 const Matcher<LoadRepresentation> rep_matcher_;
1260 const Matcher<Node*> base_matcher_;
1261 const Matcher<Node*> index_matcher_;
1262 const Matcher<Node*> effect_matcher_;
1263 const Matcher<Node*> control_matcher_;
1264};
1265
1266
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001267class IsStoreMatcher final : public NodeMatcher {
1268 public:
1269 IsStoreMatcher(const Matcher<StoreRepresentation>& rep_matcher,
1270 const Matcher<Node*>& base_matcher,
1271 const Matcher<Node*>& index_matcher,
1272 const Matcher<Node*>& value_matcher,
1273 const Matcher<Node*>& effect_matcher,
1274 const Matcher<Node*>& control_matcher)
1275 : NodeMatcher(IrOpcode::kStore),
1276 rep_matcher_(rep_matcher),
1277 base_matcher_(base_matcher),
1278 index_matcher_(index_matcher),
1279 value_matcher_(value_matcher),
1280 effect_matcher_(effect_matcher),
1281 control_matcher_(control_matcher) {}
1282
1283 void DescribeTo(std::ostream* os) const final {
1284 NodeMatcher::DescribeTo(os);
1285 *os << " whose rep (";
1286 rep_matcher_.DescribeTo(os);
1287 *os << "), base (";
1288 base_matcher_.DescribeTo(os);
1289 *os << "), index (";
1290 index_matcher_.DescribeTo(os);
1291 *os << "), value (";
1292 value_matcher_.DescribeTo(os);
1293 *os << "), effect (";
1294 effect_matcher_.DescribeTo(os);
1295 *os << ") and control (";
1296 control_matcher_.DescribeTo(os);
1297 *os << ")";
1298 }
1299
1300 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1301 Node* effect_node = nullptr;
1302 Node* control_node = nullptr;
1303 if (NodeProperties::FirstEffectIndex(node) < node->InputCount()) {
1304 effect_node = NodeProperties::GetEffectInput(node);
1305 }
1306 if (NodeProperties::FirstControlIndex(node) < node->InputCount()) {
1307 control_node = NodeProperties::GetControlInput(node);
1308 }
1309 return (NodeMatcher::MatchAndExplain(node, listener) &&
1310 PrintMatchAndExplain(OpParameter<StoreRepresentation>(node), "rep",
1311 rep_matcher_, listener) &&
1312 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1313 base_matcher_, listener) &&
1314 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1),
1315 "index", index_matcher_, listener) &&
1316 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2),
1317 "value", value_matcher_, listener) &&
1318 PrintMatchAndExplain(effect_node, "effect", effect_matcher_,
1319 listener) &&
1320 PrintMatchAndExplain(control_node, "control", control_matcher_,
1321 listener));
1322 }
1323
1324 private:
1325 const Matcher<StoreRepresentation> rep_matcher_;
1326 const Matcher<Node*> base_matcher_;
1327 const Matcher<Node*> index_matcher_;
1328 const Matcher<Node*> value_matcher_;
1329 const Matcher<Node*> effect_matcher_;
1330 const Matcher<Node*> control_matcher_;
1331};
1332
Ben Murdochda12d292016-06-02 14:46:10 +01001333class IsStackSlotMatcher final : public NodeMatcher {
1334 public:
1335 explicit IsStackSlotMatcher(const Matcher<MachineRepresentation>& rep_matcher)
1336 : NodeMatcher(IrOpcode::kStackSlot), rep_matcher_(rep_matcher) {}
1337
1338 void DescribeTo(std::ostream* os) const final {
1339 NodeMatcher::DescribeTo(os);
1340 *os << " whose rep (";
1341 rep_matcher_.DescribeTo(os);
1342 *os << ")";
1343 }
1344
1345 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1346 return (NodeMatcher::MatchAndExplain(node, listener) &&
1347 PrintMatchAndExplain(OpParameter<MachineRepresentation>(node),
1348 "rep", rep_matcher_, listener));
1349 }
1350
1351 private:
1352 const Matcher<MachineRepresentation> rep_matcher_;
1353};
1354
1355class IsGuardMatcher final : public NodeMatcher {
1356 public:
1357 IsGuardMatcher(const Matcher<Type*>& type_matcher,
1358 const Matcher<Node*>& value_matcher,
1359 const Matcher<Node*>& control_matcher)
1360 : NodeMatcher(IrOpcode::kGuard),
1361 type_matcher_(type_matcher),
1362 value_matcher_(value_matcher),
1363 control_matcher_(control_matcher) {}
1364
1365 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1366 return (NodeMatcher::MatchAndExplain(node, listener) &&
1367 PrintMatchAndExplain(OpParameter<Type*>(node->op()), "type",
1368 type_matcher_, listener) &&
1369 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
1370 "value", value_matcher_, listener) &&
1371 PrintMatchAndExplain(NodeProperties::GetControlInput(node, 0),
1372 "control", control_matcher_, listener));
1373 }
1374
1375 private:
1376 const Matcher<Type*> type_matcher_;
1377 const Matcher<Node*> value_matcher_;
1378 const Matcher<Node*> control_matcher_;
1379};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001380
1381class IsToNumberMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001382 public:
1383 IsToNumberMatcher(const Matcher<Node*>& base_matcher,
1384 const Matcher<Node*>& context_matcher,
1385 const Matcher<Node*>& effect_matcher,
1386 const Matcher<Node*>& control_matcher)
1387 : NodeMatcher(IrOpcode::kJSToNumber),
1388 base_matcher_(base_matcher),
1389 context_matcher_(context_matcher),
1390 effect_matcher_(effect_matcher),
1391 control_matcher_(control_matcher) {}
1392
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001393 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001394 NodeMatcher::DescribeTo(os);
1395 *os << " whose base (";
1396 base_matcher_.DescribeTo(os);
1397 *os << "), context (";
1398 context_matcher_.DescribeTo(os);
1399 *os << "), effect (";
1400 effect_matcher_.DescribeTo(os);
1401 *os << ") and control (";
1402 control_matcher_.DescribeTo(os);
1403 *os << ")";
1404 }
1405
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001406 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001407 return (NodeMatcher::MatchAndExplain(node, listener) &&
1408 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "base",
1409 base_matcher_, listener) &&
1410 PrintMatchAndExplain(NodeProperties::GetContextInput(node),
1411 "context", context_matcher_, listener) &&
1412 PrintMatchAndExplain(NodeProperties::GetEffectInput(node), "effect",
1413 effect_matcher_, listener) &&
1414 PrintMatchAndExplain(NodeProperties::GetControlInput(node),
1415 "control", control_matcher_, listener));
1416 }
1417
1418 private:
1419 const Matcher<Node*> base_matcher_;
1420 const Matcher<Node*> context_matcher_;
1421 const Matcher<Node*> effect_matcher_;
1422 const Matcher<Node*> control_matcher_;
1423};
1424
1425
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001426class IsLoadContextMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001427 public:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001428 IsLoadContextMatcher(const Matcher<ContextAccess>& access_matcher,
1429 const Matcher<Node*>& context_matcher)
1430 : NodeMatcher(IrOpcode::kJSLoadContext),
1431 access_matcher_(access_matcher),
1432 context_matcher_(context_matcher) {}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001433
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001434 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001435 NodeMatcher::DescribeTo(os);
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001436 *os << " whose access (";
1437 access_matcher_.DescribeTo(os);
1438 *os << ") and context (";
1439 context_matcher_.DescribeTo(os);
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001440 *os << ")";
1441 }
1442
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001443 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001444 return (NodeMatcher::MatchAndExplain(node, listener) &&
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001445 PrintMatchAndExplain(OpParameter<ContextAccess>(node), "access",
1446 access_matcher_, listener) &&
1447 PrintMatchAndExplain(NodeProperties::GetContextInput(node),
1448 "context", context_matcher_, listener));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001449 }
1450
1451 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001452 const Matcher<ContextAccess> access_matcher_;
1453 const Matcher<Node*> context_matcher_;
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001454};
1455
Ben Murdochda12d292016-06-02 14:46:10 +01001456class IsQuadopMatcher final : public NodeMatcher {
1457 public:
1458 IsQuadopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& a_matcher,
1459 const Matcher<Node*>& b_matcher,
1460 const Matcher<Node*>& c_matcher,
1461 const Matcher<Node*>& d_matcher)
1462 : NodeMatcher(opcode),
1463 a_matcher_(a_matcher),
1464 b_matcher_(b_matcher),
1465 c_matcher_(c_matcher),
1466 d_matcher_(d_matcher) {}
1467
1468 void DescribeTo(std::ostream* os) const final {
1469 NodeMatcher::DescribeTo(os);
1470 *os << " whose a (";
1471 a_matcher_.DescribeTo(os);
1472 *os << ") and b (";
1473 b_matcher_.DescribeTo(os);
1474 *os << ") and c (";
1475 c_matcher_.DescribeTo(os);
1476 *os << ") and d (";
1477 d_matcher_.DescribeTo(os);
1478 *os << ")";
1479 }
1480
1481 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1482 return (NodeMatcher::MatchAndExplain(node, listener) &&
1483 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "a",
1484 a_matcher_, listener) &&
1485 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "b",
1486 b_matcher_, listener) &&
1487 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), "c",
1488 c_matcher_, listener) &&
1489 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 3), "d",
1490 d_matcher_, listener));
1491 }
1492
1493 private:
1494 const Matcher<Node*> a_matcher_;
1495 const Matcher<Node*> b_matcher_;
1496 const Matcher<Node*> c_matcher_;
1497 const Matcher<Node*> d_matcher_;
1498};
1499
1500class IsTernopMatcher final : public NodeMatcher {
1501 public:
1502 IsTernopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& lhs_matcher,
1503 const Matcher<Node*>& mid_matcher,
1504 const Matcher<Node*>& rhs_matcher)
1505 : NodeMatcher(opcode),
1506 lhs_matcher_(lhs_matcher),
1507 mid_matcher_(mid_matcher),
1508 rhs_matcher_(rhs_matcher) {}
1509
1510 void DescribeTo(std::ostream* os) const final {
1511 NodeMatcher::DescribeTo(os);
1512 *os << " whose lhs (";
1513 lhs_matcher_.DescribeTo(os);
1514 *os << ") and mid (";
1515 mid_matcher_.DescribeTo(os);
1516 *os << ") and rhs (";
1517 rhs_matcher_.DescribeTo(os);
1518 *os << ")";
1519 }
1520
1521 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1522 return (NodeMatcher::MatchAndExplain(node, listener) &&
1523 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "lhs",
1524 lhs_matcher_, listener) &&
1525 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "mid",
1526 mid_matcher_, listener) &&
1527 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 2), "rhs",
1528 rhs_matcher_, listener));
1529 }
1530
1531 private:
1532 const Matcher<Node*> lhs_matcher_;
1533 const Matcher<Node*> mid_matcher_;
1534 const Matcher<Node*> rhs_matcher_;
1535};
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001536
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001537class IsBinopMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001538 public:
1539 IsBinopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& lhs_matcher,
1540 const Matcher<Node*>& rhs_matcher)
1541 : NodeMatcher(opcode),
1542 lhs_matcher_(lhs_matcher),
1543 rhs_matcher_(rhs_matcher) {}
1544
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001545 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001546 NodeMatcher::DescribeTo(os);
1547 *os << " whose lhs (";
1548 lhs_matcher_.DescribeTo(os);
1549 *os << ") and rhs (";
1550 rhs_matcher_.DescribeTo(os);
1551 *os << ")";
1552 }
1553
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001554 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001555 return (NodeMatcher::MatchAndExplain(node, listener) &&
1556 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0), "lhs",
1557 lhs_matcher_, listener) &&
1558 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 1), "rhs",
1559 rhs_matcher_, listener));
1560 }
1561
1562 private:
1563 const Matcher<Node*> lhs_matcher_;
1564 const Matcher<Node*> rhs_matcher_;
1565};
1566
1567
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001568class IsUnopMatcher final : public NodeMatcher {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001569 public:
1570 IsUnopMatcher(IrOpcode::Value opcode, const Matcher<Node*>& input_matcher)
1571 : NodeMatcher(opcode), input_matcher_(input_matcher) {}
1572
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001573 void DescribeTo(std::ostream* os) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001574 NodeMatcher::DescribeTo(os);
1575 *os << " whose input (";
1576 input_matcher_.DescribeTo(os);
1577 *os << ")";
1578 }
1579
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001580 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001581 return (NodeMatcher::MatchAndExplain(node, listener) &&
1582 PrintMatchAndExplain(NodeProperties::GetValueInput(node, 0),
1583 "input", input_matcher_, listener));
1584 }
1585
1586 private:
1587 const Matcher<Node*> input_matcher_;
1588};
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001589
1590
1591class IsParameterMatcher final : public NodeMatcher {
1592 public:
1593 explicit IsParameterMatcher(const Matcher<int>& index_matcher)
1594 : NodeMatcher(IrOpcode::kParameter), index_matcher_(index_matcher) {}
1595
1596 void DescribeTo(std::ostream* os) const override {
1597 *os << "is a Parameter node with index(";
1598 index_matcher_.DescribeTo(os);
1599 *os << ")";
1600 }
1601
1602 bool MatchAndExplain(Node* node, MatchResultListener* listener) const final {
1603 return (NodeMatcher::MatchAndExplain(node, listener) &&
1604 PrintMatchAndExplain(ParameterIndexOf(node->op()), "index",
1605 index_matcher_, listener));
1606 }
1607
1608 private:
1609 const Matcher<int> index_matcher_;
1610};
1611
1612} // namespace
1613
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001614Matcher<Node*> IsDead() {
1615 return MakeMatcher(new NodeMatcher(IrOpcode::kDead));
1616}
1617
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001618Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher) {
1619 return MakeMatcher(new IsControl1Matcher(IrOpcode::kEnd, control0_matcher));
1620}
1621
1622
1623Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher,
1624 const Matcher<Node*>& control1_matcher) {
1625 return MakeMatcher(new IsControl2Matcher(IrOpcode::kEnd, control0_matcher,
1626 control1_matcher));
1627}
1628
1629
1630Matcher<Node*> IsEnd(const Matcher<Node*>& control0_matcher,
1631 const Matcher<Node*>& control1_matcher,
1632 const Matcher<Node*>& control2_matcher) {
1633 return MakeMatcher(new IsControl3Matcher(IrOpcode::kEnd, control0_matcher,
1634 control1_matcher, control2_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001635}
1636
1637
1638Matcher<Node*> IsBranch(const Matcher<Node*>& value_matcher,
1639 const Matcher<Node*>& control_matcher) {
1640 return MakeMatcher(new IsBranchMatcher(value_matcher, control_matcher));
1641}
1642
1643
1644Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
1645 const Matcher<Node*>& control1_matcher) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001646 return MakeMatcher(new IsControl2Matcher(IrOpcode::kMerge, control0_matcher,
1647 control1_matcher));
1648}
1649
1650
1651Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
1652 const Matcher<Node*>& control1_matcher,
1653 const Matcher<Node*>& control2_matcher) {
1654 return MakeMatcher(new IsControl3Matcher(IrOpcode::kMerge, control0_matcher,
1655 control1_matcher, control2_matcher));
1656}
1657
1658
1659Matcher<Node*> IsLoop(const Matcher<Node*>& control0_matcher,
1660 const Matcher<Node*>& control1_matcher) {
1661 return MakeMatcher(new IsControl2Matcher(IrOpcode::kLoop, control0_matcher,
1662 control1_matcher));
1663}
1664
1665
1666Matcher<Node*> IsLoop(const Matcher<Node*>& control0_matcher,
1667 const Matcher<Node*>& control1_matcher,
1668 const Matcher<Node*>& control2_matcher) {
1669 return MakeMatcher(new IsControl3Matcher(IrOpcode::kLoop, control0_matcher,
1670 control1_matcher, control2_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001671}
1672
1673
1674Matcher<Node*> IsIfTrue(const Matcher<Node*>& control_matcher) {
1675 return MakeMatcher(new IsControl1Matcher(IrOpcode::kIfTrue, control_matcher));
1676}
1677
1678
1679Matcher<Node*> IsIfFalse(const Matcher<Node*>& control_matcher) {
1680 return MakeMatcher(
1681 new IsControl1Matcher(IrOpcode::kIfFalse, control_matcher));
1682}
1683
1684
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001685Matcher<Node*> IsIfSuccess(const Matcher<Node*>& control_matcher) {
1686 return MakeMatcher(
1687 new IsControl1Matcher(IrOpcode::kIfSuccess, control_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001688}
1689
1690
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001691Matcher<Node*> IsSwitch(const Matcher<Node*>& value_matcher,
1692 const Matcher<Node*>& control_matcher) {
1693 return MakeMatcher(new IsSwitchMatcher(value_matcher, control_matcher));
1694}
1695
1696
1697Matcher<Node*> IsIfValue(const Matcher<int32_t>& value_matcher,
1698 const Matcher<Node*>& control_matcher) {
1699 return MakeMatcher(new IsIfValueMatcher(value_matcher, control_matcher));
1700}
1701
1702
1703Matcher<Node*> IsIfDefault(const Matcher<Node*>& control_matcher) {
1704 return MakeMatcher(
1705 new IsControl1Matcher(IrOpcode::kIfDefault, control_matcher));
1706}
1707
1708
1709Matcher<Node*> IsBeginRegion(const Matcher<Node*>& effect_matcher) {
1710 return MakeMatcher(new IsBeginRegionMatcher(effect_matcher));
1711}
1712
1713
1714Matcher<Node*> IsFinishRegion(const Matcher<Node*>& value_matcher,
1715 const Matcher<Node*>& effect_matcher) {
1716 return MakeMatcher(new IsFinishRegionMatcher(value_matcher, effect_matcher));
1717}
1718
1719
1720Matcher<Node*> IsReturn(const Matcher<Node*>& value_matcher,
1721 const Matcher<Node*>& effect_matcher,
1722 const Matcher<Node*>& control_matcher) {
1723 return MakeMatcher(
1724 new IsReturnMatcher(value_matcher, effect_matcher, control_matcher));
1725}
1726
Ben Murdoch097c5b22016-05-18 11:27:45 +01001727Matcher<Node*> IsReturn2(const Matcher<Node*>& value_matcher,
1728 const Matcher<Node*>& value2_matcher,
1729 const Matcher<Node*>& effect_matcher,
1730 const Matcher<Node*>& control_matcher) {
1731 return MakeMatcher(new IsReturnMatcher(value_matcher, value2_matcher,
1732 effect_matcher, control_matcher));
1733}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001734
1735Matcher<Node*> IsTerminate(const Matcher<Node*>& effect_matcher,
1736 const Matcher<Node*>& control_matcher) {
1737 return MakeMatcher(new IsTerminateMatcher(effect_matcher, control_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001738}
1739
1740
1741Matcher<Node*> IsExternalConstant(
1742 const Matcher<ExternalReference>& value_matcher) {
1743 return MakeMatcher(new IsConstantMatcher<ExternalReference>(
1744 IrOpcode::kExternalConstant, value_matcher));
1745}
1746
1747
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001748Matcher<Node*> IsHeapConstant(Handle<HeapObject> value) {
1749 return MakeMatcher(new IsConstantMatcher<Handle<HeapObject>>(
1750 IrOpcode::kHeapConstant, value));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001751}
1752
1753
1754Matcher<Node*> IsInt32Constant(const Matcher<int32_t>& value_matcher) {
1755 return MakeMatcher(
1756 new IsConstantMatcher<int32_t>(IrOpcode::kInt32Constant, value_matcher));
1757}
1758
1759
1760Matcher<Node*> IsInt64Constant(const Matcher<int64_t>& value_matcher) {
1761 return MakeMatcher(
1762 new IsConstantMatcher<int64_t>(IrOpcode::kInt64Constant, value_matcher));
1763}
1764
1765
1766Matcher<Node*> IsFloat32Constant(const Matcher<float>& value_matcher) {
1767 return MakeMatcher(
1768 new IsConstantMatcher<float>(IrOpcode::kFloat32Constant, value_matcher));
1769}
1770
1771
1772Matcher<Node*> IsFloat64Constant(const Matcher<double>& value_matcher) {
1773 return MakeMatcher(
1774 new IsConstantMatcher<double>(IrOpcode::kFloat64Constant, value_matcher));
1775}
1776
1777
1778Matcher<Node*> IsNumberConstant(const Matcher<double>& value_matcher) {
1779 return MakeMatcher(
1780 new IsConstantMatcher<double>(IrOpcode::kNumberConstant, value_matcher));
1781}
1782
1783
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001784Matcher<Node*> IsSelect(const Matcher<MachineRepresentation>& type_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001785 const Matcher<Node*>& value0_matcher,
1786 const Matcher<Node*>& value1_matcher,
1787 const Matcher<Node*>& value2_matcher) {
1788 return MakeMatcher(new IsSelectMatcher(type_matcher, value0_matcher,
1789 value1_matcher, value2_matcher));
1790}
1791
1792
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001793Matcher<Node*> IsPhi(const Matcher<MachineRepresentation>& type_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001794 const Matcher<Node*>& value0_matcher,
1795 const Matcher<Node*>& value1_matcher,
1796 const Matcher<Node*>& merge_matcher) {
1797 return MakeMatcher(new IsPhiMatcher(type_matcher, value0_matcher,
1798 value1_matcher, merge_matcher));
1799}
1800
1801
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001802Matcher<Node*> IsPhi(const Matcher<MachineRepresentation>& type_matcher,
1803 const Matcher<Node*>& value0_matcher,
1804 const Matcher<Node*>& value1_matcher,
1805 const Matcher<Node*>& value2_matcher,
1806 const Matcher<Node*>& merge_matcher) {
1807 return MakeMatcher(new IsPhi2Matcher(type_matcher, value0_matcher,
1808 value1_matcher, value2_matcher,
1809 merge_matcher));
1810}
1811
1812
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001813Matcher<Node*> IsEffectPhi(const Matcher<Node*>& effect0_matcher,
1814 const Matcher<Node*>& effect1_matcher,
1815 const Matcher<Node*>& merge_matcher) {
1816 return MakeMatcher(
1817 new IsEffectPhiMatcher(effect0_matcher, effect1_matcher, merge_matcher));
1818}
1819
1820
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001821Matcher<Node*> IsEffectSet(const Matcher<Node*>& effect0_matcher,
1822 const Matcher<Node*>& effect1_matcher) {
1823 return MakeMatcher(new IsEffectSetMatcher(effect0_matcher, effect1_matcher));
1824}
1825
1826
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001827Matcher<Node*> IsProjection(const Matcher<size_t>& index_matcher,
1828 const Matcher<Node*>& base_matcher) {
1829 return MakeMatcher(new IsProjectionMatcher(index_matcher, base_matcher));
1830}
1831
Ben Murdoch097c5b22016-05-18 11:27:45 +01001832Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
1833 const Matcher<Node*>& value0_matcher,
1834 const Matcher<Node*>& effect_matcher,
1835 const Matcher<Node*>& control_matcher) {
1836 std::vector<Matcher<Node*>> value_matchers;
1837 value_matchers.push_back(value0_matcher);
1838 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1839 effect_matcher, control_matcher));
1840}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001841
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001842Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001843 const Matcher<Node*>& value0_matcher,
1844 const Matcher<Node*>& value1_matcher,
1845 const Matcher<Node*>& effect_matcher,
1846 const Matcher<Node*>& control_matcher) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001847 std::vector<Matcher<Node*>> value_matchers;
1848 value_matchers.push_back(value0_matcher);
1849 value_matchers.push_back(value1_matcher);
1850 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1851 effect_matcher, control_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001852}
1853
1854
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001855Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
1856 const Matcher<Node*>& value0_matcher,
1857 const Matcher<Node*>& value1_matcher,
1858 const Matcher<Node*>& value2_matcher,
1859 const Matcher<Node*>& effect_matcher,
1860 const Matcher<Node*>& control_matcher) {
1861 std::vector<Matcher<Node*>> value_matchers;
1862 value_matchers.push_back(value0_matcher);
1863 value_matchers.push_back(value1_matcher);
1864 value_matchers.push_back(value2_matcher);
1865 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1866 effect_matcher, control_matcher));
1867}
1868
1869
1870Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
Emily Bernierd0a1eb72015-03-24 16:35:39 -04001871 const Matcher<Node*>& value0_matcher,
1872 const Matcher<Node*>& value1_matcher,
1873 const Matcher<Node*>& value2_matcher,
1874 const Matcher<Node*>& value3_matcher,
1875 const Matcher<Node*>& effect_matcher,
1876 const Matcher<Node*>& control_matcher) {
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001877 std::vector<Matcher<Node*>> value_matchers;
1878 value_matchers.push_back(value0_matcher);
1879 value_matchers.push_back(value1_matcher);
1880 value_matchers.push_back(value2_matcher);
1881 value_matchers.push_back(value3_matcher);
1882 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1883 effect_matcher, control_matcher));
1884}
1885
1886
1887Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
1888 const Matcher<Node*>& value0_matcher,
1889 const Matcher<Node*>& value1_matcher,
1890 const Matcher<Node*>& value2_matcher,
1891 const Matcher<Node*>& value3_matcher,
1892 const Matcher<Node*>& value4_matcher,
1893 const Matcher<Node*>& effect_matcher,
1894 const Matcher<Node*>& control_matcher) {
1895 std::vector<Matcher<Node*>> value_matchers;
1896 value_matchers.push_back(value0_matcher);
1897 value_matchers.push_back(value1_matcher);
1898 value_matchers.push_back(value2_matcher);
1899 value_matchers.push_back(value3_matcher);
1900 value_matchers.push_back(value4_matcher);
1901 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1902 effect_matcher, control_matcher));
1903}
1904
1905
1906Matcher<Node*> IsCall(const Matcher<const CallDescriptor*>& descriptor_matcher,
1907 const Matcher<Node*>& value0_matcher,
1908 const Matcher<Node*>& value1_matcher,
1909 const Matcher<Node*>& value2_matcher,
1910 const Matcher<Node*>& value3_matcher,
1911 const Matcher<Node*>& value4_matcher,
1912 const Matcher<Node*>& value5_matcher,
1913 const Matcher<Node*>& effect_matcher,
1914 const Matcher<Node*>& control_matcher) {
1915 std::vector<Matcher<Node*>> value_matchers;
1916 value_matchers.push_back(value0_matcher);
1917 value_matchers.push_back(value1_matcher);
1918 value_matchers.push_back(value2_matcher);
1919 value_matchers.push_back(value3_matcher);
1920 value_matchers.push_back(value4_matcher);
1921 value_matchers.push_back(value5_matcher);
1922 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1923 effect_matcher, control_matcher));
1924}
1925
1926
1927Matcher<Node*> IsCall(
1928 const Matcher<const CallDescriptor*>& descriptor_matcher,
1929 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1930 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
1931 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& value5_matcher,
1932 const Matcher<Node*>& value6_matcher, const Matcher<Node*>& effect_matcher,
1933 const Matcher<Node*>& control_matcher) {
1934 std::vector<Matcher<Node*>> value_matchers;
1935 value_matchers.push_back(value0_matcher);
1936 value_matchers.push_back(value1_matcher);
1937 value_matchers.push_back(value2_matcher);
1938 value_matchers.push_back(value3_matcher);
1939 value_matchers.push_back(value4_matcher);
1940 value_matchers.push_back(value5_matcher);
1941 value_matchers.push_back(value6_matcher);
1942 return MakeMatcher(new IsCallMatcher(descriptor_matcher, value_matchers,
1943 effect_matcher, control_matcher));
1944}
1945
1946
1947Matcher<Node*> IsTailCall(
1948 const Matcher<CallDescriptor const*>& descriptor_matcher,
1949 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1950 const Matcher<Node*>& effect_matcher,
1951 const Matcher<Node*>& control_matcher) {
1952 std::vector<Matcher<Node*>> value_matchers;
1953 value_matchers.push_back(value0_matcher);
1954 value_matchers.push_back(value1_matcher);
1955 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
1956 effect_matcher, control_matcher));
1957}
1958
1959
1960Matcher<Node*> IsTailCall(
1961 const Matcher<CallDescriptor const*>& descriptor_matcher,
1962 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1963 const Matcher<Node*>& value2_matcher, 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 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
1970 effect_matcher, control_matcher));
1971}
1972
1973
1974Matcher<Node*> IsTailCall(
1975 const Matcher<CallDescriptor const*>& descriptor_matcher,
1976 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1977 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
1978 const Matcher<Node*>& effect_matcher,
1979 const Matcher<Node*>& control_matcher) {
1980 std::vector<Matcher<Node*>> value_matchers;
1981 value_matchers.push_back(value0_matcher);
1982 value_matchers.push_back(value1_matcher);
1983 value_matchers.push_back(value2_matcher);
1984 value_matchers.push_back(value3_matcher);
1985 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
1986 effect_matcher, control_matcher));
1987}
1988
1989
1990Matcher<Node*> IsTailCall(
1991 const Matcher<CallDescriptor const*>& descriptor_matcher,
1992 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
1993 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
1994 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& effect_matcher,
1995 const Matcher<Node*>& control_matcher) {
1996 std::vector<Matcher<Node*>> value_matchers;
1997 value_matchers.push_back(value0_matcher);
1998 value_matchers.push_back(value1_matcher);
1999 value_matchers.push_back(value2_matcher);
2000 value_matchers.push_back(value3_matcher);
2001 value_matchers.push_back(value4_matcher);
2002 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
2003 effect_matcher, control_matcher));
2004}
2005
2006
2007Matcher<Node*> IsTailCall(
2008 const Matcher<CallDescriptor const*>& descriptor_matcher,
2009 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
2010 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
2011 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& value5_matcher,
2012 const Matcher<Node*>& effect_matcher,
2013 const Matcher<Node*>& control_matcher) {
2014 std::vector<Matcher<Node*>> value_matchers;
2015 value_matchers.push_back(value0_matcher);
2016 value_matchers.push_back(value1_matcher);
2017 value_matchers.push_back(value2_matcher);
2018 value_matchers.push_back(value3_matcher);
2019 value_matchers.push_back(value4_matcher);
2020 value_matchers.push_back(value5_matcher);
2021 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
2022 effect_matcher, control_matcher));
2023}
2024
2025
2026Matcher<Node*> IsTailCall(
2027 const Matcher<CallDescriptor const*>& descriptor_matcher,
2028 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
2029 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
2030 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& value5_matcher,
2031 const Matcher<Node*>& value6_matcher, const Matcher<Node*>& effect_matcher,
2032 const Matcher<Node*>& control_matcher) {
2033 std::vector<Matcher<Node*>> value_matchers;
2034 value_matchers.push_back(value0_matcher);
2035 value_matchers.push_back(value1_matcher);
2036 value_matchers.push_back(value2_matcher);
2037 value_matchers.push_back(value3_matcher);
2038 value_matchers.push_back(value4_matcher);
2039 value_matchers.push_back(value5_matcher);
2040 value_matchers.push_back(value6_matcher);
2041 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
2042 effect_matcher, control_matcher));
2043}
2044
2045
2046Matcher<Node*> IsTailCall(
2047 const Matcher<CallDescriptor const*>& descriptor_matcher,
2048 const Matcher<Node*>& value0_matcher, const Matcher<Node*>& value1_matcher,
2049 const Matcher<Node*>& value2_matcher, const Matcher<Node*>& value3_matcher,
2050 const Matcher<Node*>& value4_matcher, const Matcher<Node*>& value5_matcher,
2051 const Matcher<Node*>& value6_matcher, const Matcher<Node*>& value7_matcher,
2052 const Matcher<Node*>& effect_matcher,
2053 const Matcher<Node*>& control_matcher) {
2054 std::vector<Matcher<Node*>> value_matchers;
2055 value_matchers.push_back(value0_matcher);
2056 value_matchers.push_back(value1_matcher);
2057 value_matchers.push_back(value2_matcher);
2058 value_matchers.push_back(value3_matcher);
2059 value_matchers.push_back(value4_matcher);
2060 value_matchers.push_back(value5_matcher);
2061 value_matchers.push_back(value6_matcher);
2062 value_matchers.push_back(value7_matcher);
2063 return MakeMatcher(new IsTailCallMatcher(descriptor_matcher, value_matchers,
2064 effect_matcher, control_matcher));
2065}
2066
Ben Murdochda12d292016-06-02 14:46:10 +01002067Matcher<Node*> IsGuard(const Matcher<Type*>& type_matcher,
2068 const Matcher<Node*>& value_matcher,
2069 const Matcher<Node*>& control_matcher) {
2070 return MakeMatcher(
2071 new IsGuardMatcher(type_matcher, value_matcher, control_matcher));
2072}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002073
2074Matcher<Node*> IsReferenceEqual(const Matcher<Type*>& type_matcher,
2075 const Matcher<Node*>& lhs_matcher,
2076 const Matcher<Node*>& rhs_matcher) {
2077 return MakeMatcher(
2078 new IsReferenceEqualMatcher(type_matcher, lhs_matcher, rhs_matcher));
2079}
2080
2081
2082Matcher<Node*> IsAllocate(const Matcher<Node*>& size_matcher,
2083 const Matcher<Node*>& effect_matcher,
2084 const Matcher<Node*>& control_matcher) {
2085 return MakeMatcher(
2086 new IsAllocateMatcher(size_matcher, effect_matcher, control_matcher));
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002087}
2088
2089
2090Matcher<Node*> IsLoadField(const Matcher<FieldAccess>& access_matcher,
2091 const Matcher<Node*>& base_matcher,
2092 const Matcher<Node*>& effect_matcher,
2093 const Matcher<Node*>& control_matcher) {
2094 return MakeMatcher(new IsLoadFieldMatcher(access_matcher, base_matcher,
2095 effect_matcher, control_matcher));
2096}
2097
2098
2099Matcher<Node*> IsStoreField(const Matcher<FieldAccess>& access_matcher,
2100 const Matcher<Node*>& base_matcher,
2101 const Matcher<Node*>& value_matcher,
2102 const Matcher<Node*>& effect_matcher,
2103 const Matcher<Node*>& control_matcher) {
2104 return MakeMatcher(new IsStoreFieldMatcher(access_matcher, base_matcher,
2105 value_matcher, effect_matcher,
2106 control_matcher));
2107}
2108
2109
2110Matcher<Node*> IsLoadBuffer(const Matcher<BufferAccess>& access_matcher,
2111 const Matcher<Node*>& buffer_matcher,
2112 const Matcher<Node*>& offset_matcher,
2113 const Matcher<Node*>& length_matcher,
2114 const Matcher<Node*>& effect_matcher,
2115 const Matcher<Node*>& control_matcher) {
2116 return MakeMatcher(new IsLoadBufferMatcher(access_matcher, buffer_matcher,
2117 offset_matcher, length_matcher,
2118 effect_matcher, control_matcher));
2119}
2120
2121
2122Matcher<Node*> IsStoreBuffer(const Matcher<BufferAccess>& access_matcher,
2123 const Matcher<Node*>& buffer_matcher,
2124 const Matcher<Node*>& offset_matcher,
2125 const Matcher<Node*>& length_matcher,
2126 const Matcher<Node*>& value_matcher,
2127 const Matcher<Node*>& effect_matcher,
2128 const Matcher<Node*>& control_matcher) {
2129 return MakeMatcher(new IsStoreBufferMatcher(
2130 access_matcher, buffer_matcher, offset_matcher, length_matcher,
2131 value_matcher, effect_matcher, control_matcher));
2132}
2133
2134
2135Matcher<Node*> IsLoadElement(const Matcher<ElementAccess>& access_matcher,
2136 const Matcher<Node*>& base_matcher,
2137 const Matcher<Node*>& index_matcher,
2138 const Matcher<Node*>& effect_matcher,
2139 const Matcher<Node*>& control_matcher) {
2140 return MakeMatcher(new IsLoadElementMatcher(access_matcher, base_matcher,
2141 index_matcher, effect_matcher,
2142 control_matcher));
2143}
2144
2145
2146Matcher<Node*> IsStoreElement(const Matcher<ElementAccess>& access_matcher,
2147 const Matcher<Node*>& base_matcher,
2148 const Matcher<Node*>& index_matcher,
2149 const Matcher<Node*>& value_matcher,
2150 const Matcher<Node*>& effect_matcher,
2151 const Matcher<Node*>& control_matcher) {
2152 return MakeMatcher(new IsStoreElementMatcher(
2153 access_matcher, base_matcher, index_matcher, value_matcher,
2154 effect_matcher, control_matcher));
2155}
2156
2157
2158Matcher<Node*> IsLoad(const Matcher<LoadRepresentation>& rep_matcher,
2159 const Matcher<Node*>& base_matcher,
2160 const Matcher<Node*>& index_matcher,
2161 const Matcher<Node*>& effect_matcher,
2162 const Matcher<Node*>& control_matcher) {
2163 return MakeMatcher(new IsLoadMatcher(rep_matcher, base_matcher, index_matcher,
2164 effect_matcher, control_matcher));
2165}
2166
2167
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002168Matcher<Node*> IsStore(const Matcher<StoreRepresentation>& rep_matcher,
2169 const Matcher<Node*>& base_matcher,
2170 const Matcher<Node*>& index_matcher,
2171 const Matcher<Node*>& value_matcher,
2172 const Matcher<Node*>& effect_matcher,
2173 const Matcher<Node*>& control_matcher) {
2174 return MakeMatcher(new IsStoreMatcher(rep_matcher, base_matcher,
2175 index_matcher, value_matcher,
2176 effect_matcher, control_matcher));
2177}
2178
Ben Murdochda12d292016-06-02 14:46:10 +01002179Matcher<Node*> IsStackSlot(const Matcher<MachineRepresentation>& rep_matcher) {
2180 return MakeMatcher(new IsStackSlotMatcher(rep_matcher));
2181}
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002182
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002183Matcher<Node*> IsToNumber(const Matcher<Node*>& base_matcher,
2184 const Matcher<Node*>& context_matcher,
2185 const Matcher<Node*>& effect_matcher,
2186 const Matcher<Node*>& control_matcher) {
2187 return MakeMatcher(new IsToNumberMatcher(base_matcher, context_matcher,
2188 effect_matcher, control_matcher));
2189}
2190
2191
2192Matcher<Node*> IsLoadContext(const Matcher<ContextAccess>& access_matcher,
2193 const Matcher<Node*>& context_matcher) {
2194 return MakeMatcher(new IsLoadContextMatcher(access_matcher, context_matcher));
2195}
2196
2197
2198Matcher<Node*> IsParameter(const Matcher<int> index_matcher) {
2199 return MakeMatcher(new IsParameterMatcher(index_matcher));
2200}
2201
2202
2203Matcher<Node*> IsLoadFramePointer() {
2204 return MakeMatcher(new NodeMatcher(IrOpcode::kLoadFramePointer));
2205}
2206
Ben Murdochda12d292016-06-02 14:46:10 +01002207#define IS_QUADOP_MATCHER(Name) \
2208 Matcher<Node*> Is##Name( \
2209 const Matcher<Node*>& a_matcher, const Matcher<Node*>& b_matcher, \
2210 const Matcher<Node*>& c_matcher, const Matcher<Node*>& d_matcher) { \
2211 return MakeMatcher(new IsQuadopMatcher(IrOpcode::k##Name, a_matcher, \
2212 b_matcher, c_matcher, d_matcher)); \
2213 }
2214
2215IS_QUADOP_MATCHER(Int32PairAdd)
2216IS_QUADOP_MATCHER(Int32PairSub)
2217IS_QUADOP_MATCHER(Int32PairMul)
2218
2219#define IS_TERNOP_MATCHER(Name) \
2220 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \
2221 const Matcher<Node*>& mid_matcher, \
2222 const Matcher<Node*>& rhs_matcher) { \
2223 return MakeMatcher(new IsTernopMatcher(IrOpcode::k##Name, lhs_matcher, \
2224 mid_matcher, rhs_matcher)); \
2225 }
2226
2227IS_TERNOP_MATCHER(Word32PairShl)
2228IS_TERNOP_MATCHER(Word32PairShr)
2229IS_TERNOP_MATCHER(Word32PairSar)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002230
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002231#define IS_BINOP_MATCHER(Name) \
2232 Matcher<Node*> Is##Name(const Matcher<Node*>& lhs_matcher, \
2233 const Matcher<Node*>& rhs_matcher) { \
2234 return MakeMatcher( \
2235 new IsBinopMatcher(IrOpcode::k##Name, lhs_matcher, rhs_matcher)); \
2236 }
2237IS_BINOP_MATCHER(NumberEqual)
2238IS_BINOP_MATCHER(NumberLessThan)
2239IS_BINOP_MATCHER(NumberSubtract)
2240IS_BINOP_MATCHER(NumberMultiply)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002241IS_BINOP_MATCHER(NumberShiftLeft)
2242IS_BINOP_MATCHER(NumberShiftRight)
2243IS_BINOP_MATCHER(NumberShiftRightLogical)
Ben Murdochda12d292016-06-02 14:46:10 +01002244IS_BINOP_MATCHER(NumberImul)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002245IS_BINOP_MATCHER(Word32And)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002246IS_BINOP_MATCHER(Word32Or)
Ben Murdochda12d292016-06-02 14:46:10 +01002247IS_BINOP_MATCHER(Word32Xor)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002248IS_BINOP_MATCHER(Word32Sar)
2249IS_BINOP_MATCHER(Word32Shl)
2250IS_BINOP_MATCHER(Word32Shr)
2251IS_BINOP_MATCHER(Word32Ror)
2252IS_BINOP_MATCHER(Word32Equal)
2253IS_BINOP_MATCHER(Word64And)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002254IS_BINOP_MATCHER(Word64Or)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002255IS_BINOP_MATCHER(Word64Sar)
2256IS_BINOP_MATCHER(Word64Shl)
2257IS_BINOP_MATCHER(Word64Equal)
2258IS_BINOP_MATCHER(Int32AddWithOverflow)
2259IS_BINOP_MATCHER(Int32Add)
2260IS_BINOP_MATCHER(Int32Sub)
2261IS_BINOP_MATCHER(Int32Mul)
2262IS_BINOP_MATCHER(Int32MulHigh)
2263IS_BINOP_MATCHER(Int32LessThan)
2264IS_BINOP_MATCHER(Uint32LessThan)
2265IS_BINOP_MATCHER(Uint32LessThanOrEqual)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002266IS_BINOP_MATCHER(Int64Add)
2267IS_BINOP_MATCHER(Int64Sub)
2268IS_BINOP_MATCHER(JSAdd)
2269IS_BINOP_MATCHER(Float32Max)
2270IS_BINOP_MATCHER(Float32Min)
2271IS_BINOP_MATCHER(Float32Equal)
2272IS_BINOP_MATCHER(Float32LessThan)
2273IS_BINOP_MATCHER(Float32LessThanOrEqual)
2274IS_BINOP_MATCHER(Float64Max)
2275IS_BINOP_MATCHER(Float64Min)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002276IS_BINOP_MATCHER(Float64Sub)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002277IS_BINOP_MATCHER(Float64InsertLowWord32)
2278IS_BINOP_MATCHER(Float64InsertHighWord32)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002279#undef IS_BINOP_MATCHER
2280
2281
2282#define IS_UNOP_MATCHER(Name) \
2283 Matcher<Node*> Is##Name(const Matcher<Node*>& input_matcher) { \
2284 return MakeMatcher(new IsUnopMatcher(IrOpcode::k##Name, input_matcher)); \
2285 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002286IS_UNOP_MATCHER(BooleanNot)
2287IS_UNOP_MATCHER(ChangeFloat64ToInt32)
2288IS_UNOP_MATCHER(ChangeFloat64ToUint32)
2289IS_UNOP_MATCHER(ChangeInt32ToFloat64)
2290IS_UNOP_MATCHER(ChangeInt32ToInt64)
2291IS_UNOP_MATCHER(ChangeUint32ToFloat64)
2292IS_UNOP_MATCHER(ChangeUint32ToUint64)
2293IS_UNOP_MATCHER(TruncateFloat64ToFloat32)
2294IS_UNOP_MATCHER(TruncateFloat64ToInt32)
2295IS_UNOP_MATCHER(TruncateInt64ToInt32)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002296IS_UNOP_MATCHER(Float32Abs)
2297IS_UNOP_MATCHER(Float64Abs)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002298IS_UNOP_MATCHER(Float64Sqrt)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002299IS_UNOP_MATCHER(Float64RoundDown)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002300IS_UNOP_MATCHER(Float64RoundTruncate)
2301IS_UNOP_MATCHER(Float64RoundTiesAway)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002302IS_UNOP_MATCHER(Float64ExtractLowWord32)
2303IS_UNOP_MATCHER(Float64ExtractHighWord32)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002304IS_UNOP_MATCHER(NumberToInt32)
2305IS_UNOP_MATCHER(NumberToUint32)
Ben Murdoch097c5b22016-05-18 11:27:45 +01002306IS_UNOP_MATCHER(ObjectIsReceiver)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00002307IS_UNOP_MATCHER(ObjectIsSmi)
2308IS_UNOP_MATCHER(Word32Clz)
Ben Murdochda12d292016-06-02 14:46:10 +01002309IS_UNOP_MATCHER(Word32Ctz)
2310IS_UNOP_MATCHER(Word32Popcnt)
Emily Bernierd0a1eb72015-03-24 16:35:39 -04002311#undef IS_UNOP_MATCHER
2312
2313} // namespace compiler
2314} // namespace internal
2315} // namespace v8