annotate graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchPattern.java @ 18941:c943ba97b2a7

Remove class ScheduledNode from the node class hierarchy.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Sat, 24 Jan 2015 00:45:12 +0100
parents c88ab4f1f04a
children 14496953435e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.*;
15547
cab432461b8b use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15520
diff changeset
26 import com.oracle.graal.graph.*;
16841
cbd42807a31f moved NodeInfo and friends into separate com.oracle.graal.nodeinfo project so that annotation processor can be applied to the base Node class
Doug Simon <doug.simon@oracle.com>
parents: 16604
diff changeset
27 import com.oracle.graal.nodeinfo.*;
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
18941
c943ba97b2a7 Remove class ScheduledNode from the node class hierarchy.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18163
diff changeset
53 final ValueNode 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
18941
c943ba97b2a7 Remove class ScheduledNode from the node class hierarchy.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18163
diff changeset
57 Result(MatchResultCode result, ValueNode node, MatchPattern matcher) {
15370
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);
16604
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
71 private static final Result CACHED_WRONG_CLASS = new Result(MatchResultCode.WRONG_CLASS, null, null);
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
72 private static final Result CACHED_NAMED_VALUE_MISMATCH = new Result(MatchResultCode.NAMED_VALUE_MISMATCH, null, null);
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
73 private static final Result CACHED_TOO_MANY_USERS = new Result(MatchResultCode.TOO_MANY_USERS, null, null);
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
74 private static final Result CACHED_NOT_IN_BLOCK = new Result(MatchResultCode.NOT_IN_BLOCK, null, null);
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
75 private static final Result CACHED_NOT_SAFE = new Result(MatchResultCode.NOT_SAFE, null, null);
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
76 private static final Result CACHED_ALREADY_USED = new Result(MatchResultCode.ALREADY_USED, null, null);
15370
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
77
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
78 static Result wrongClass(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
79 MatchResult_WRONG_CLASS.increment();
16604
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
80 return Debug.isEnabled() ? new Result(MatchResultCode.WRONG_CLASS, node, matcher) : CACHED_WRONG_CLASS;
15370
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
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
83 static Result namedValueMismatch(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
84 MatchResult_NAMED_VALUE_MISMATCH.increment();
16604
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
85 return Debug.isEnabled() ? new Result(MatchResultCode.NAMED_VALUE_MISMATCH, node, matcher) : CACHED_NAMED_VALUE_MISMATCH;
15370
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
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
88 static Result tooManyUsers(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
89 MatchResult_TOO_MANY_USERS.increment();
16604
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
90 return Debug.isEnabled() ? new Result(MatchResultCode.TOO_MANY_USERS, node, matcher) : CACHED_TOO_MANY_USERS;
15370
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
18941
c943ba97b2a7 Remove class ScheduledNode from the node class hierarchy.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18163
diff changeset
93 static Result notInBlock(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
94 MatchResult_NOT_IN_BLOCK.increment();
16604
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
95 return Debug.isEnabled() ? new Result(MatchResultCode.NOT_IN_BLOCK, node, matcher) : CACHED_NOT_IN_BLOCK;
15370
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
18941
c943ba97b2a7 Remove class ScheduledNode from the node class hierarchy.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18163
diff changeset
98 static Result notSafe(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
99 MatchResult_NOT_SAFE.increment();
16604
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
100 return Debug.isEnabled() ? new Result(MatchResultCode.NOT_SAFE, node, matcher) : CACHED_NOT_SAFE;
15370
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
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
103 static Result alreadyUsed(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
104 MatchResult_ALREADY_USED.increment();
16604
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
105 return Debug.isEnabled() ? new Result(MatchResultCode.ALREADY_USED, node, matcher) : CACHED_ALREADY_USED;
15370
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
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
108 @Override
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
109 public String toString() {
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
110 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
111 return "OK";
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
112 }
16604
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
113 if (node == null) {
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
114 return code.toString();
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
115 } else {
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
116 return code + " " + node.toString(Verbosity.Id) + "|" + node.getClass().getSimpleName() + " " + matcher;
b519954b9daf cached MatchPattern.Result failure constants
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15700
diff changeset
117 }
15370
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
118 }
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
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
121 /**
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
122 * 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
123 */
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
124 private final Class<? extends ValueNode> nodeClass;
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
125
15370
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
126 /**
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
127 * 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
128 * 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
129 */
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
130 private final String name;
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 /**
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
133 * 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
134 */
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
135 private final MatchPattern[] patterns;
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
136
15370
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 * 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
139 */
16897
f90dcdbbb75e switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
140 private final Position[] inputs;
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
141
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 * 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
144 * users.
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
145 */
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
146 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
147
15547
cab432461b8b use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15520
diff changeset
148 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
149
15370
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
150 public MatchPattern(String name, boolean singleUser) {
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
151 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
152 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
153
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
154 public MatchPattern(Class<? extends ValueNode> nodeClass, String name, boolean singleUser) {
17450
45b45f902bed removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents: 17172
diff changeset
155 this.nodeClass = nodeClass;
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
156 this.name = name;
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
157 this.singleUser = singleUser;
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
158 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
159 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
160 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
161
16897
f90dcdbbb75e switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
162 private MatchPattern(Class<? extends ValueNode> nodeClass, String name, boolean singleUser, MatchPattern[] patterns, Position[] inputs) {
15547
cab432461b8b use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15520
diff changeset
163 assert inputs == null || inputs.length == patterns.length;
17450
45b45f902bed removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents: 17172
diff changeset
164 this.nodeClass = nodeClass;
15370
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
165 this.name = name;
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
166 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
167 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
168 this.inputs = inputs;
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
169 }
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
170
16897
f90dcdbbb75e switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
171 public MatchPattern(Class<? extends ValueNode> nodeClass, String name, MatchPattern first, Position[] inputs, boolean 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
172 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
173 }
cab432461b8b use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15520
diff changeset
174
16897
f90dcdbbb75e switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
175 public MatchPattern(Class<? extends ValueNode> nodeClass, String name, MatchPattern first, MatchPattern second, Position[] inputs, boolean 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
176 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
177 }
cab432461b8b use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15520
diff changeset
178
16897
f90dcdbbb75e switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
179 public MatchPattern(Class<? extends ValueNode> nodeClass, String name, MatchPattern first, MatchPattern second, MatchPattern third, Position[] inputs, boolean 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
180 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
181 }
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 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
184 return nodeClass;
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
185 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
186
15453
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
187 private Result matchType(ValueNode node) {
16994
9cf849d5b3f9 reverted matcher to use Class keys instead of NodeClass keys
Doug Simon <doug.simon@oracle.com>
parents: 16990
diff changeset
188 if (nodeClass != null && node.getClass() != nodeClass) {
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
189 return Result.wrongClass(node, this);
15453
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 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
192 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
193
15453
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
194 /**
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
195 * 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
196 *
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
197 * @param node
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
198 * @param context
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
199 * @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
200 */
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
201 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
202 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
203 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
204 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
205 }
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
206 return result;
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
207 }
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
208
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
209 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
210 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
211 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
212 return result;
15370
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 if (singleUser && !atRoot) {
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
215 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
216 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
217 return result;
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
218 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
219 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
220
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
221 if (name != null) {
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
222 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
223 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
224
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
225 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
226 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
227 if (result != Result.OK) {
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
228 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
229 }
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
230 }
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
231
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
232 return result;
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
233 }
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
234
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 * 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
237 * 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
238 *
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
239 * @param node
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
240 * @param statement
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
241 * @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
242 */
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
243 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
244 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
245 }
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 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
248 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
249 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
250 return result;
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
251 }
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
252
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
253 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
254 if (node.usages().count() > 1) {
18163
c88ab4f1f04a re-enabled Checkstyle with the release of 6.0 that supports Java 8; fixed existing Checkstyle warnings
Doug Simon <doug.simon@oracle.com>
parents: 17450
diff changeset
255 return Result.tooManyUsers(node, statement.getPattern());
15453
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
256 }
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
257 }
100306ae985b switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15370
diff changeset
258
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
259 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
260 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
261 if (result != Result.OK) {
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
262 return result;
15370
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 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
265
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
266 return result;
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
267 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
268
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
269 /**
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
270 * 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
271 * 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
272 * 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
273 */
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
274 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
275 String result = String.format("%s", root);
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
276 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
277 return result;
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
278 } else {
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
279 StringBuilder sb = new StringBuilder();
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
280 sb.append("(");
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
281 sb.append(result);
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
282 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
283 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
284 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
285 }
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
286 sb.append(")");
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
287 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
288 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
289 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
290
15547
cab432461b8b use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15520
diff changeset
291 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
292 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
293 }
cab432461b8b use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15520
diff changeset
294
15370
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
295 @Override
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
296 public String toString() {
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
297 if (nodeClass == null) {
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
298 return name;
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
299 } else {
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
300 String nodeName = nodeClass.getSimpleName();
17450
45b45f902bed removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents: 17172
diff changeset
301 if (nodeName.endsWith("Node")) {
45b45f902bed removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents: 17172
diff changeset
302 nodeName = nodeName.substring(0, nodeName.length() - 4);
45b45f902bed removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents: 17172
diff changeset
303 }
15520
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
304 if (patterns.length == 0) {
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
305 return nodeName + (name != null ? "=" + name : "");
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
306 } else {
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
307 StringBuilder sb = new StringBuilder();
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
308 sb.append("(");
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
309 sb.append(nodeName);
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
310 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
311 sb.append(" ");
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
312 sb.append(patterns[index].toString());
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
313 }
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
314 sb.append(")");
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
315 return sb.toString();
4cdc787681d4 add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15453
diff changeset
316 }
15370
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
317 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
318 }
319deee16746 add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff changeset
319 }