Mercurial > hg > graal-jvmci-8
annotate graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchRuleRegistry.java @ 17210:ef64e2682bb6
added Edges class to consolidate code operating on set of input or successor edges and to better isolate magic used to access edges
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 25 Sep 2014 10:27:17 +0200 |
parents | 9cf849d5b3f9 |
children | c88ab4f1f04a |
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.*; |
17210
ef64e2682bb6
added Edges class to consolidate code operating on set of input or successor edges and to better isolate magic used to access edges
Doug Simon <doug.simon@oracle.com>
parents:
16994
diff
changeset
|
26 import static com.oracle.graal.graph.Edges.Type.*; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
27 |
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.*; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
29 import java.util.Map.Entry; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
30 |
15966
27ff0792b048
made more services implement com.oracle.graal.api.runtime.Service for faster loading
Doug Simon <doug.simon@oracle.com>
parents:
15826
diff
changeset
|
31 import com.oracle.graal.api.runtime.*; |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
32 import com.oracle.graal.compiler.common.*; |
15370
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.debug.*; |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15456
diff
changeset
|
35 import com.oracle.graal.debug.Debug.Scope; |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
36 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
|
37 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
|
38 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
39 public class MatchRuleRegistry { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
40 |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
41 /** |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
42 * Helper interface for mapping between Class and NodeClass. In static compilation environments, |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
43 * the current NodeClass might not be the same NodeClass used in the target so this provides a |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
44 * level of indirection. |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
45 */ |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
46 public static interface NodeClassLookup { |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
47 NodeClass get(Class<?> theClass); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
48 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
49 |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
50 static class DefaultNodeClassLookup implements NodeClassLookup { |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
51 public NodeClass get(Class<?> theClass) { |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
52 return NodeClass.get(theClass); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
53 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
54 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
55 |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
56 /** |
16899
6f245b6d2936
fixed eclipseformat issue
Doug Simon <doug.simon@oracle.com>
parents:
16897
diff
changeset
|
57 * Convert a list of field names into {@link com.oracle.graal.graph.Position} objects that can |
6f245b6d2936
fixed eclipseformat issue
Doug Simon <doug.simon@oracle.com>
parents:
16897
diff
changeset
|
58 * be used to read them during a match. The names should already have been confirmed to exist in |
6f245b6d2936
fixed eclipseformat issue
Doug Simon <doug.simon@oracle.com>
parents:
16897
diff
changeset
|
59 * the type. |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
60 * |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
61 * @param theClass |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
62 * @param names |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
63 * @return an array of Position objects corresponding to the named fields. |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
64 */ |
16897
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16154
diff
changeset
|
65 public static Position[] findPositions(NodeClassLookup lookup, Class<? extends ValueNode> theClass, String[] names) { |
f90dcdbbb75e
switched to using new NodeFieldIterator and NodeFieldIterable for traversing Node inputs and successors
Doug Simon <doug.simon@oracle.com>
parents:
16154
diff
changeset
|
66 Position[] result = new Position[names.length]; |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
67 NodeClass nodeClass = lookup.get(theClass); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
68 for (int i = 0; i < names.length; i++) { |
17210
ef64e2682bb6
added Edges class to consolidate code operating on set of input or successor edges and to better isolate magic used to access edges
Doug Simon <doug.simon@oracle.com>
parents:
16994
diff
changeset
|
69 Edges edges = nodeClass.getEdges(Inputs); |
ef64e2682bb6
added Edges class to consolidate code operating on set of input or successor edges and to better isolate magic used to access edges
Doug Simon <doug.simon@oracle.com>
parents:
16994
diff
changeset
|
70 for (int e = 0; e < edges.getDirectCount(); e++) { |
ef64e2682bb6
added Edges class to consolidate code operating on set of input or successor edges and to better isolate magic used to access edges
Doug Simon <doug.simon@oracle.com>
parents:
16994
diff
changeset
|
71 if (names[i].equals(edges.getName(e))) { |
ef64e2682bb6
added Edges class to consolidate code operating on set of input or successor edges and to better isolate magic used to access edges
Doug Simon <doug.simon@oracle.com>
parents:
16994
diff
changeset
|
72 result[i] = new Position(edges, e, Node.NOT_ITERABLE); |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
73 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
74 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
75 if (result[i] == null) { |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
76 throw new GraalInternalError("unknown field \"%s\" in class %s", names[i], theClass); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
77 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
78 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
79 return result; |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
80 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
81 |
16994
9cf849d5b3f9
reverted matcher to use Class keys instead of NodeClass keys
Doug Simon <doug.simon@oracle.com>
parents:
16981
diff
changeset
|
82 private static final HashMap<Class<? extends NodeLIRBuilder>, Map<Class<? extends ValueNode>, List<MatchStatement>>> registry = new HashMap<>(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
83 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
84 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
85 * Collect all the {@link MatchStatement}s defined by the superclass chain of theClass. |
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 * @param theClass |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
88 * @return the set of {@link MatchStatement}s applicable to theClass. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
89 */ |
16994
9cf849d5b3f9
reverted matcher to use Class keys instead of NodeClass keys
Doug Simon <doug.simon@oracle.com>
parents:
16981
diff
changeset
|
90 public synchronized static Map<Class<? extends ValueNode>, List<MatchStatement>> lookup(Class<? extends NodeLIRBuilder> theClass) { |
9cf849d5b3f9
reverted matcher to use Class keys instead of NodeClass keys
Doug Simon <doug.simon@oracle.com>
parents:
16981
diff
changeset
|
91 Map<Class<? extends ValueNode>, List<MatchStatement>> result = registry.get(theClass); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
92 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
93 if (result == null) { |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
94 NodeClassLookup lookup = new DefaultNodeClassLookup(); |
16994
9cf849d5b3f9
reverted matcher to use Class keys instead of NodeClass keys
Doug Simon <doug.simon@oracle.com>
parents:
16981
diff
changeset
|
95 Map<Class<? extends ValueNode>, List<MatchStatement>> rules = createRules(theClass, lookup); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
96 registry.put(theClass, rules); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
97 assert registry.get(theClass) == rules; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
98 result = rules; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
99 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
100 if (LogVerbose.getValue()) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
101 try (Scope s = Debug.scope("MatchComplexExpressions")) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
102 Debug.log("Match rules for %s", theClass.getSimpleName()); |
16994
9cf849d5b3f9
reverted matcher to use Class keys instead of NodeClass keys
Doug Simon <doug.simon@oracle.com>
parents:
16981
diff
changeset
|
103 for (Entry<Class<? extends ValueNode>, List<MatchStatement>> entry : result.entrySet()) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
104 Debug.log(" For node class: %s", entry.getKey()); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
105 for (MatchStatement statement : entry.getValue()) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
106 Debug.log(" %s", statement.getPattern()); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
107 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
108 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
109 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
110 } |
15370
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 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
113 if (result.size() == 0) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
114 return null; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
115 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
116 return result; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
117 } |
15826
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
118 |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
119 /* |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
120 * This is a separate, public method so that external clients can create rules with a custom |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
121 * lookup and without the default caching behavior. |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
122 */ |
16994
9cf849d5b3f9
reverted matcher to use Class keys instead of NodeClass keys
Doug Simon <doug.simon@oracle.com>
parents:
16981
diff
changeset
|
123 public static Map<Class<? extends ValueNode>, List<MatchStatement>> createRules(Class<? extends NodeLIRBuilder> theClass, NodeClassLookup lookup) { |
15826
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
124 HashMap<Class<? extends NodeLIRBuilder>, MatchStatementSet> matchSets = new HashMap<>(); |
15966
27ff0792b048
made more services implement com.oracle.graal.api.runtime.Service for faster loading
Doug Simon <doug.simon@oracle.com>
parents:
15826
diff
changeset
|
125 Iterable<MatchStatementSet> sl = Services.load(MatchStatementSet.class); |
15826
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
126 for (MatchStatementSet rules : sl) { |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
127 matchSets.put(rules.forClass(), rules); |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
128 } |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
129 |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
130 // Walk the class hierarchy collecting lists and merge them together. The subclass |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
131 // rules are first which gives them preference over earlier rules. |
16994
9cf849d5b3f9
reverted matcher to use Class keys instead of NodeClass keys
Doug Simon <doug.simon@oracle.com>
parents:
16981
diff
changeset
|
132 Map<Class<? extends ValueNode>, List<MatchStatement>> rules = new HashMap<>(); |
15826
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
133 Class<?> currentClass = theClass; |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
134 do { |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
135 MatchStatementSet matchSet = matchSets.get(currentClass); |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
136 if (matchSet != null) { |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
137 List<MatchStatement> statements = matchSet.statements(lookup); |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
138 for (MatchStatement statement : statements) { |
16994
9cf849d5b3f9
reverted matcher to use Class keys instead of NodeClass keys
Doug Simon <doug.simon@oracle.com>
parents:
16981
diff
changeset
|
139 Class<? extends ValueNode> nodeClass = statement.getPattern().nodeClass(); |
15826
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
140 List<MatchStatement> current = rules.get(nodeClass); |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
141 if (current == null) { |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
142 current = new ArrayList<>(); |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
143 rules.put(nodeClass, current); |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
144 } |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
145 current.add(statement); |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
146 } |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
147 } |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
148 currentClass = currentClass.getSuperclass(); |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
149 } while (currentClass != NodeLIRBuilder.class); |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
150 return rules; |
1891bac562d8
Factor out rule creation in its own method
Christian Wimmer <christian.wimmer@oracle.com>
parents:
15700
diff
changeset
|
151 } |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
152 } |