Mercurial > hg > truffle
annotate graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchPattern.java @ 15700:98423229008c
allow overriding the NodeClass lookup when building MatchStatements
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Fri, 16 May 2014 00:12:48 -0700 |
parents | cab432461b8b |
children | b519954b9daf |
rev | line source |
---|---|
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
1 /* |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
4 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
8 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
14 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
18 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
21 * questions. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
22 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.compiler.match; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
24 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
25 import com.oracle.graal.debug.*; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
26 import com.oracle.graal.graph.Node.Verbosity; |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
27 import com.oracle.graal.graph.*; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.nodes.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
29 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
30 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
31 * A simple recursive pattern matcher for a DAG of nodes. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
32 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
33 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
34 public class MatchPattern { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
35 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
36 enum MatchResultCode { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
37 OK, |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
38 WRONG_CLASS, |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
39 NAMED_VALUE_MISMATCH, |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
40 TOO_MANY_USERS, |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
41 NOT_IN_BLOCK, |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
42 NOT_SAFE, |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
43 ALREADY_USED, |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
44 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
45 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
46 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
47 * A descriptive result for match failures. This can be helpful for debugging why a match |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
48 * doesn't work as expected. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
49 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
50 static class Result { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
51 final MatchResultCode code; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
52 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
53 final ScheduledNode node; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
54 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
55 final MatchPattern matcher; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
56 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
57 Result(MatchResultCode result, ScheduledNode node, MatchPattern matcher) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
58 this.code = result; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
59 this.node = node; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
60 this.matcher = matcher; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
61 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
62 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
63 private static final DebugMetric MatchResult_WRONG_CLASS = Debug.metric("MatchResult_WRONG_CLASS"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
64 private static final DebugMetric MatchResult_NAMED_VALUE_MISMATCH = Debug.metric("MatchResult_NAMED_VALUE_MISMATCH"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
65 private static final DebugMetric MatchResult_TOO_MANY_USERS = Debug.metric("MatchResult_TOO_MANY_USERS"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
66 private static final DebugMetric MatchResult_NOT_IN_BLOCK = Debug.metric("MatchResult_NOT_IN_BLOCK"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
67 private static final DebugMetric MatchResult_NOT_SAFE = Debug.metric("MatchResult_NOT_SAFE"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
68 private static final DebugMetric MatchResult_ALREADY_USED = Debug.metric("MatchResult_ALREADY_USED"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
69 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
70 static final Result OK = new Result(MatchResultCode.OK, null, null); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
71 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
72 static Result WRONG_CLASS(ValueNode node, MatchPattern matcher) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
73 MatchResult_WRONG_CLASS.increment(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
74 return new Result(MatchResultCode.WRONG_CLASS, node, matcher); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
75 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
76 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
77 static Result NAMED_VALUE_MISMATCH(ValueNode node, MatchPattern matcher) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
78 MatchResult_NAMED_VALUE_MISMATCH.increment(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
79 return new Result(MatchResultCode.NAMED_VALUE_MISMATCH, node, matcher); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
80 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
81 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
82 static Result TOO_MANY_USERS(ValueNode node, MatchPattern matcher) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
83 MatchResult_TOO_MANY_USERS.increment(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
84 return new Result(MatchResultCode.TOO_MANY_USERS, node, matcher); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
85 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
86 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
87 static Result NOT_IN_BLOCK(ScheduledNode node, MatchPattern matcher) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
88 MatchResult_NOT_IN_BLOCK.increment(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
89 return new Result(MatchResultCode.NOT_IN_BLOCK, node, matcher); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
90 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
91 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
92 static Result NOT_SAFE(ScheduledNode node, MatchPattern matcher) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
93 MatchResult_NOT_SAFE.increment(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
94 return new Result(MatchResultCode.NOT_SAFE, node, matcher); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
95 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
96 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
97 static Result ALREADY_USED(ValueNode node, MatchPattern matcher) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
98 MatchResult_ALREADY_USED.increment(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
99 return new Result(MatchResultCode.ALREADY_USED, node, matcher); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
100 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
101 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
102 @Override |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
103 public String toString() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
104 if (code == MatchResultCode.OK) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
105 return "OK"; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
106 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
107 return code + " " + node.toString(Verbosity.Id) + "|" + node.getClass().getSimpleName() + " " + matcher; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
108 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
109 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
110 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
111 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
112 * The expected type of the node. It must match exactly. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
113 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
114 private final Class<? extends ValueNode> nodeClass; |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
115 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
116 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
117 * An optional name for this node. A name can occur multiple times in a match and that name must |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
118 * always refer to the same node of the match will fail. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
119 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
120 private final String name; |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
121 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
122 /** |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
123 * Patterns to match the inputs. |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
124 */ |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
125 private final MatchPattern[] patterns; |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
126 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
127 /** |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
128 * The inputs to match the patterns against. |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
129 */ |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
130 private final NodeClass.Position[] inputs; |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
131 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
132 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
133 * Can there only be one user of the node. Constant nodes can be matched even if there are other |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
134 * users. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
135 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
136 private final boolean singleUser; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
137 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
138 private static final MatchPattern[] EMPTY_PATTERNS = new MatchPattern[0]; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
139 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
140 public MatchPattern(String name, boolean singleUser) { |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
141 this(null, name, singleUser); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
142 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
143 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
144 public MatchPattern(Class<? extends ValueNode> nodeClass, String name, boolean singleUser) { |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
145 this.nodeClass = nodeClass; |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
146 this.name = name; |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
147 this.singleUser = singleUser; |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
148 this.patterns = EMPTY_PATTERNS; |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
149 this.inputs = null; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
150 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
151 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
152 private MatchPattern(Class<? extends ValueNode> nodeClass, String name, boolean singleUser, MatchPattern[] patterns, NodeClass.Position[] inputs) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
153 assert inputs == null || inputs.length == patterns.length; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
154 this.nodeClass = nodeClass; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
155 this.name = name; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
156 this.singleUser = singleUser; |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
157 this.patterns = patterns; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
158 this.inputs = inputs; |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
159 } |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
160 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
161 public MatchPattern(Class<? extends ValueNode> nodeClass, String name, MatchPattern first, NodeClass.Position[] inputs, boolean singleUser) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
162 this(nodeClass, name, singleUser, new MatchPattern[]{first}, inputs); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
163 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
164 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
165 public MatchPattern(Class<? extends ValueNode> nodeClass, String name, MatchPattern first, MatchPattern second, NodeClass.Position[] inputs, boolean singleUser) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
166 this(nodeClass, name, singleUser, new MatchPattern[]{first, second}, inputs); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
167 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
168 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
169 public MatchPattern(Class<? extends ValueNode> nodeClass, String name, MatchPattern first, MatchPattern second, MatchPattern third, NodeClass.Position[] inputs, boolean singleUser) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
170 this(nodeClass, name, singleUser, new MatchPattern[]{first, second, third}, inputs); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
171 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
172 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
173 Class<? extends ValueNode> nodeClass() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
174 return nodeClass; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
175 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
176 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
177 private Result matchType(ValueNode node) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
178 if (nodeClass != null && node.getClass() != nodeClass) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
179 return Result.WRONG_CLASS(node, this); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
180 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
181 return Result.OK; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
182 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
183 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
184 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
185 * Match any named nodes and ensure that the consumed nodes can be safely merged. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
186 * |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
187 * @param node |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
188 * @param context |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
189 * @return Result.OK is the pattern can be safely matched. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
190 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
191 Result matchUsage(ValueNode node, MatchContext context) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
192 Result result = matchUsage(node, context, true); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
193 if (result == Result.OK) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
194 result = context.validate(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
195 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
196 return result; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
197 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
198 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
199 private Result matchUsage(ValueNode node, MatchContext context, boolean atRoot) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
200 Result result = matchType(node); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
201 if (result != Result.OK) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
202 return result; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
203 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
204 if (singleUser && !atRoot) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
205 result = context.consume(node); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
206 if (result != Result.OK) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
207 return result; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
208 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
209 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
210 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
211 if (name != null) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
212 result = context.captureNamedValue(name, nodeClass, node); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
213 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
214 |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
215 for (int input = 0; input < patterns.length; input++) { |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
216 result = patterns[input].matchUsage(getInput(input, node), context, false); |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
217 if (result != Result.OK) { |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
218 return result; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
219 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
220 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
221 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
222 return result; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
223 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
224 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
225 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
226 * Recursively match the shape of the tree without worry about named values. Most matches fail |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
227 * at this point so it's performed first. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
228 * |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
229 * @param node |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
230 * @param statement |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
231 * @return Result.OK if the shape of the pattern matches. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
232 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
233 public Result matchShape(ValueNode node, MatchStatement statement) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
234 return matchShape(node, statement, true); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
235 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
236 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
237 private Result matchShape(ValueNode node, MatchStatement statement, boolean atRoot) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
238 Result result = matchType(node); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
239 if (result != Result.OK) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
240 return result; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
241 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
242 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
243 if (singleUser && !atRoot) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
244 if (node.usages().count() > 1) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
245 return Result.TOO_MANY_USERS(node, statement.getPattern()); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
246 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
247 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
248 |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
249 for (int input = 0; input < patterns.length; input++) { |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
250 result = patterns[input].matchShape(getInput(input, node), statement, false); |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
251 if (result != Result.OK) { |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
252 return result; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
253 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
254 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
255 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
256 return result; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
257 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
258 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
259 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
260 * For a node starting at root, produce a String showing the inputs that matched against this |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
261 * rule. It's assumed that a match has already succeeded against this rule, otherwise the |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
262 * printing may produce exceptions. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
263 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
264 public String formatMatch(ValueNode root) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
265 String result = String.format("%s", root); |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
266 if (patterns.length == 0) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
267 return result; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
268 } else { |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
269 StringBuilder sb = new StringBuilder(); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
270 sb.append("("); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
271 sb.append(result); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
272 for (int input = 0; input < patterns.length; input++) { |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
273 sb.append(" "); |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
274 sb.append(patterns[input].formatMatch(getInput(input, root))); |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
275 } |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
276 sb.append(")"); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
277 return sb.toString(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
278 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
279 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
280 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
281 private ValueNode getInput(int index, ValueNode node) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
282 return (ValueNode) inputs[index].get(node); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
283 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
284 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
285 @Override |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
286 public String toString() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
287 if (nodeClass == null) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
288 return name; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
289 } else { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
290 String nodeName = nodeClass.getSimpleName(); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
291 nodeName = nodeName.substring(0, nodeName.length() - 4); |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
292 if (patterns.length == 0) { |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
293 return nodeName + (name != null ? "=" + name : ""); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
294 } else { |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
295 StringBuilder sb = new StringBuilder(); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
296 sb.append("("); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
297 sb.append(nodeName); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
298 for (int index = 0; index < patterns.length; index++) { |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
299 sb.append(" "); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
300 sb.append(patterns[index].toString()); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
301 } |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
302 sb.append(")"); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
303 return sb.toString(); |
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15453
diff
changeset
|
304 } |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
305 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
306 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
307 } |