Mercurial > hg > truffle
annotate graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchStatement.java @ 15453:100306ae985b
switch MatchRule from class to method annotation and fix review feedback
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Wed, 30 Apr 2014 12:27:27 -0700 |
parents | 319deee16746 |
children | bb97b75d1d65 |
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 static com.oracle.graal.compiler.GraalDebugConfig.*; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
26 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
27 import java.lang.reflect.*; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
28 import java.util.*; |
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 import com.oracle.graal.api.meta.*; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
31 import com.oracle.graal.compiler.*; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
32 import com.oracle.graal.compiler.common.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
33 import com.oracle.graal.compiler.gen.*; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
34 import com.oracle.graal.compiler.match.MatchPattern.MatchResultCode; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
35 import com.oracle.graal.compiler.match.MatchPattern.Result; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
36 import com.oracle.graal.debug.*; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
37 import com.oracle.graal.graph.*; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
38 import com.oracle.graal.graph.Node.Verbosity; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
39 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
|
40 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
41 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
42 * A named {@link MatchPattern} along with a {@link MatchGenerator} that can be evaluated to replace |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
43 * one or more {@link ValueNode}s with a single {@link Value}. |
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 public class MatchStatement { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
47 private static final DebugMetric MatchStatementSuccess = Debug.metric("MatchStatementSuccess"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
48 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
49 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
50 * A printable name for this statement. Usually it's just the name of the method doing the |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
51 * emission. |
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 private final String name; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
54 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
55 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
56 * The actual match pattern. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
57 */ |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
58 private final MatchPattern pattern; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
59 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
60 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
61 * The method in the {@link NodeLIRBuilder} subclass that will actually do the code emission. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
62 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
63 private Method generatorMethod; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
64 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
65 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
66 * The name of arguments in the order they are expected to be passed to the generator method. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
67 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
68 private String[] arguments; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
69 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
70 public MatchStatement(String name, MatchPattern pattern, Method generator, String[] arguments) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
71 this.name = name; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
72 this.pattern = pattern; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
73 this.generatorMethod = generator; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
74 this.arguments = arguments; |
15370
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 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
78 * Attempt to match the current statement against a Node. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
79 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
80 * @param builder the current builder instance. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
81 * @param node the node to be matched |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
82 * @param nodes the nodes in the current block |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
83 * @return true if the statement matched something and set a {@link ComplexMatchResult} to be |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
84 * evaluated by the NodeLIRBuilder. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
85 */ |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
86 public boolean generate(NodeLIRBuilder builder, int index, ValueNode node, List<ScheduledNode> nodes) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
87 assert index == nodes.indexOf(node); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
88 // Check that the basic shape matches |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
89 Result result = pattern.matchShape(node, this); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
90 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
|
91 return false; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
92 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
93 // Now ensure that the other safety constraints are matched. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
94 MatchContext context = new MatchContext(builder, this, index, node, nodes); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
95 result = pattern.matchUsage(node, context); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
96 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
|
97 try { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
98 // Invoke the generator method and set the result if it's non null. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
99 ComplexMatchResult value = (ComplexMatchResult) generatorMethod.invoke(builder, buildArgList(context)); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
100 if (value != null) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
101 context.setResult(value); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
102 MatchStatementSuccess.increment(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
103 return true; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
104 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
105 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
106 throw new GraalInternalError(e); |
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 } else { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
109 if (LogVerbose.getValue() && result.code != MatchResultCode.WRONG_CLASS) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
110 Debug.log("while matching %s|%s %s %s", context.getRoot().toString(Verbosity.Id), context.getRoot().getClass().getSimpleName(), getName(), result); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
111 } |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
112 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
113 return false; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
114 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
115 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
116 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
117 * @param context |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
118 * @return the ValueNodes captured by the match rule in the order expected by the |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
119 * generatorMethod |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
120 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
121 private Object[] buildArgList(MatchContext context) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
122 Object[] result = new Object[arguments.length]; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
123 for (int i = 0; i < arguments.length; i++) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
124 if ("root".equals(arguments[i])) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
125 result[i] = context.getRoot(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
126 } else { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
127 result[i] = context.namedNode(arguments[i]); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
128 if (result[i] == null) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
129 throw new GraalGraphInternalError("Can't find named node %s", arguments[i]); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
130 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
131 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
132 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
133 return result; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
134 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
135 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
136 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
|
137 return pattern.formatMatch(root); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
138 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
139 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
140 public MatchPattern getPattern() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
141 return pattern; |
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 String getName() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
145 return name; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
146 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
147 } |