annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/TypeSwitchNode.java @ 18362:ea0fbb571466

Use pointer stamps in LoadHub and LoadMethod. Introduce explicit casts between Word and metaspace pointers.
author Roland Schatz <roland.schatz@oracle.com>
date Thu, 13 Nov 2014 11:12:25 +0100
parents 6ac7e9c85be6
children f57d86eb036f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 /*
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
2 * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 *
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 * published by the Free Software Foundation.
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 *
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 * accompanied this code).
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14 *
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 *
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
21 * questions.
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
22 */
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
23 package com.oracle.graal.nodes.java;
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
24
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
25 import java.util.*;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
26
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
27 import com.oracle.graal.api.meta.*;
15261
882f4cb7cfcf Move Stamps to graal.compiler.common.
Josef Eisl <josef.eisl@jku.at>
parents: 15145
diff changeset
28 import com.oracle.graal.compiler.common.type.*;
11881
da9db8331658 moved Canonicalizable and Simplifiable to the com.oracle.graal.graph project (GRAAL-506)
Doug Simon <doug.simon@oracle.com>
parents: 11265
diff changeset
29 import com.oracle.graal.graph.spi.*;
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: 16822
diff changeset
30 import com.oracle.graal.nodeinfo.*;
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
31 import com.oracle.graal.nodes.*;
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
32 import com.oracle.graal.nodes.extended.*;
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
33 import com.oracle.graal.nodes.spi.*;
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
34 import com.oracle.graal.nodes.util.*;
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
35
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
36 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
37 * The {@code TypeSwitchNode} performs a lookup based on the type of the input value. The type
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
38 * comparison is an exact type comparison, not an instanceof.
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39 */
16822
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16616
diff changeset
40 @NodeInfo
5d468add216f added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents: 16616
diff changeset
41 public class TypeSwitchNode extends SwitchNode implements LIRLowerable, Simplifiable {
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
42
17328
c9bb0da795d4 Backed out of changeset 17322:655f3e6b467b
Doug Simon <doug.simon@oracle.com>
parents: 17327
diff changeset
43 protected final ResolvedJavaType[] keys;
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
44
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
45 /**
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
46 * Constructs a type switch instruction. The keyProbabilities array contain key.length + 1
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
47 * entries. The last entry in every array describes the default case.
16616
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
48 *
7705
96a596d751ab remove successorProbabilities from SwitchNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
49 * @param value the instruction producing the value being switched on, the object hub
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
50 * @param successors the list of successors
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
51 * @param keys the list of types
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
52 * @param keyProbabilities the probabilities of the keys
5711
4d7175cf3526 enabled Eclipse/JDT javadoc checking and fixed resulting warnings
Doug Simon <doug.simon@oracle.com>
parents: 5698
diff changeset
53 * @param keySuccessors the successor index for each key
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
54 */
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
55 public static TypeSwitchNode create(ValueNode value, BeginNode[] successors, ResolvedJavaType[] keys, double[] keyProbabilities, int[] keySuccessors) {
17450
45b45f902bed removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents: 17328
diff changeset
56 return new TypeSwitchNode(value, successors, keys, keyProbabilities, keySuccessors);
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
57 }
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
58
17309
845e881ce054 constructors in a Node class must be protected
Doug Simon <doug.simon@oracle.com>
parents: 17276
diff changeset
59 protected TypeSwitchNode(ValueNode value, BeginNode[] successors, ResolvedJavaType[] keys, double[] keyProbabilities, int[] keySuccessors) {
7705
96a596d751ab remove successorProbabilities from SwitchNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
60 super(value, successors, keySuccessors, keyProbabilities);
7063
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
61 assert successors.length <= keys.length + 1;
0d7dfa5b79e8 merged inlining and intrinsification phases
Christian Haeubl <haeubl@ssw.jku.at>
parents: 6539
diff changeset
62 assert keySuccessors.length == keyProbabilities.length;
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
63 this.keys = keys;
18362
ea0fbb571466 Use pointer stamps in LoadHub and LoadMethod.
Roland Schatz <roland.schatz@oracle.com>
parents: 18361
diff changeset
64 assert value.stamp() instanceof AbstractPointerStamp;
16616
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
65 assert assertKeys();
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
66 }
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
67
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
68 /**
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
69 * Don't allow duplicate keys.
16616
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
70 */
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
71 private boolean assertKeys() {
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
72 for (int i = 0; i < keys.length; i++) {
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
73 for (int j = 0; j < keys.length; j++) {
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
74 if (i == j) {
16616
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
75 continue;
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
76 }
16616
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
77 assert !keys[i].equals(keys[j]);
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
78 }
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
79 }
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
80 return true;
13294
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
81 }
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
82
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
83 @Override
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
84 public boolean isSorted() {
14633
da2431cc1506 Rename ValueNode kind() to getKind().
Josef Eisl <josef.eisl@jku.at>
parents: 13488
diff changeset
85 Kind kind = value().getKind();
13294
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
86 if (kind.isNumericInteger()) {
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
87 JavaConstant lastKey = null;
13294
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
88 for (int i = 0; i < keyCount(); i++) {
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
89 JavaConstant key = keyAt(i);
13294
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
90 if (lastKey != null && key.asLong() <= lastKey.asLong()) {
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
91 return false;
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
92 }
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
93 lastKey = key;
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
94 }
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
95 return true;
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
96 } else {
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
97 return false;
29907e69ae8d rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents: 12052
diff changeset
98 }
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
99 }
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
100
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
101 @Override
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
102 public int keyCount() {
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
103 return keys.length;
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
104 }
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
105
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
106 @Override
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
107 public JavaConstant keyAt(int index) {
18362
ea0fbb571466 Use pointer stamps in LoadHub and LoadMethod.
Roland Schatz <roland.schatz@oracle.com>
parents: 18361
diff changeset
108 return (JavaConstant) keys[index].getObjectHub();
7705
96a596d751ab remove successorProbabilities from SwitchNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
109 }
96a596d751ab remove successorProbabilities from SwitchNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
110
16616
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
111 @Override
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
112 public boolean equalKeys(SwitchNode switchNode) {
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
113 if (!(switchNode instanceof TypeSwitchNode)) {
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
114 return false;
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
115 }
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
116 TypeSwitchNode other = (TypeSwitchNode) switchNode;
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
117 return Arrays.equals(keys, other.keys);
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
118 }
29404eec7ced eliminate duplicate entries from profile data
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16219
diff changeset
119
7705
96a596d751ab remove successorProbabilities from SwitchNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
120 public ResolvedJavaType typeAt(int index) {
96a596d751ab remove successorProbabilities from SwitchNode
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
121 return keys[index];
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
122 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
123
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
124 @Override
14950
d5a1206e1923 NodeLIRBuilderTool: fix typo in interface name.
Josef Eisl <josef.eisl@jku.at>
parents: 14888
diff changeset
125 public void generate(NodeLIRBuilderTool gen) {
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
126 gen.emitSwitch(this);
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
127 }
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
128
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
129 @Override
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
130 public void simplify(SimplifierTool tool) {
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
131 if (value() instanceof ConstantNode) {
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
132 JavaConstant constant = value().asJavaConstant();
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
133
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
134 int survivingEdge = keySuccessorIndex(keyCount());
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
135 for (int i = 0; i < keyCount(); i++) {
18187
9619ba4daf4c Rename Constant to JavaConstant.
Roland Schatz <roland.schatz@oracle.com>
parents: 18163
diff changeset
136 JavaConstant typeHub = keyAt(i);
6329
92bc58dc5b5e More clean up and documentation in api.code and api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5711
diff changeset
137 assert constant.getKind() == typeHub.getKind();
13488
83adefeb8e5c The runtime cannot always compare two constants
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13294
diff changeset
138 Boolean equal = tool.getConstantReflection().constantEquals(constant, typeHub);
83adefeb8e5c The runtime cannot always compare two constants
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13294
diff changeset
139 if (equal == null) {
83adefeb8e5c The runtime cannot always compare two constants
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13294
diff changeset
140 /* We don't know if this key is a match or not, so we cannot simplify. */
83adefeb8e5c The runtime cannot always compare two constants
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13294
diff changeset
141 return;
83adefeb8e5c The runtime cannot always compare two constants
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13294
diff changeset
142 } else if (equal.booleanValue()) {
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
143 survivingEdge = keySuccessorIndex(i);
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
144 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
145 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
146 for (int i = 0; i < blockSuccessorCount(); i++) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
147 if (i != survivingEdge) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
148 tool.deleteBranch(blockSuccessor(i));
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
149 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
150 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
151 tool.addToWorkList(blockSuccessor(survivingEdge));
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9436
diff changeset
152 graph().removeSplit(this, blockSuccessor(survivingEdge));
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
153 }
16219
24c30ecf930f rename object() to getValue() in LoadHubNode
Lukas Stadler <lukas.stadler@oracle.com>
parents: 15261
diff changeset
154 if (value() instanceof LoadHubNode && ((LoadHubNode) value()).getValue().stamp() instanceof ObjectStamp) {
17276
ffb974bef674 moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents: 16919
diff changeset
155 ObjectStamp objectStamp = (ObjectStamp) ((LoadHubNode) value()).getValue().stamp();
ffb974bef674 moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents: 16919
diff changeset
156 if (objectStamp.type() != null) {
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
157 int validKeys = 0;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
158 for (int i = 0; i < keyCount(); i++) {
17276
ffb974bef674 moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents: 16919
diff changeset
159 if (objectStamp.type().isAssignableFrom(keys[i])) {
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
160 validKeys++;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
161 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
162 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
163 if (validKeys == 0) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
164 tool.addToWorkList(defaultSuccessor());
9602
19c5a07c7843 Introduce a graph() method that returns a StructuredGraph, to make many explicit casts unnecessary
Christian Wimmer <christian.wimmer@oracle.com>
parents: 9436
diff changeset
165 graph().removeSplitPropagate(this, defaultSuccessor());
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
166 } else if (validKeys != keys.length) {
15145
df2ef5204f2b Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14991
diff changeset
167 ArrayList<BeginNode> newSuccessors = new ArrayList<>(blockSuccessorCount());
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
168 ResolvedJavaType[] newKeys = new ResolvedJavaType[validKeys];
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
169 int[] newKeySuccessors = new int[validKeys + 1];
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
170 double[] newKeyProbabilities = new double[validKeys + 1];
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
171 double totalProbability = 0;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
172 int current = 0;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
173 for (int i = 0; i < keyCount() + 1; i++) {
17276
ffb974bef674 moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents: 16919
diff changeset
174 if (i == keyCount() || objectStamp.type().isAssignableFrom(keys[i])) {
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
175 int index = newSuccessors.indexOf(keySuccessor(i));
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
176 if (index == -1) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
177 index = newSuccessors.size();
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
178 newSuccessors.add(keySuccessor(i));
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
179 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
180 newKeySuccessors[current] = index;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
181 if (i < keyCount()) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
182 newKeys[current] = keys[i];
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
183 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
184 newKeyProbabilities[current] = keyProbability(i);
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
185 totalProbability += keyProbability(i);
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
186 current++;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
187 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
188 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
189 if (totalProbability > 0) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
190 for (int i = 0; i < current; i++) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
191 newKeyProbabilities[i] /= totalProbability;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
192 }
11262
c4703de83626 Fix Switch probability if simplification leaves no non-zero probability successor
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9602
diff changeset
193 } else {
c4703de83626 Fix Switch probability if simplification leaves no non-zero probability successor
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9602
diff changeset
194 for (int i = 0; i < current; i++) {
c4703de83626 Fix Switch probability if simplification leaves no non-zero probability successor
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9602
diff changeset
195 newKeyProbabilities[i] = 1.0 / current;
c4703de83626 Fix Switch probability if simplification leaves no non-zero probability successor
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9602
diff changeset
196 }
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
197 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
198
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
199 for (int i = 0; i < blockSuccessorCount(); i++) {
15145
df2ef5204f2b Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14991
diff changeset
200 BeginNode successor = blockSuccessor(i);
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
201 if (!newSuccessors.contains(successor)) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
202 tool.deleteBranch(successor);
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
203 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
204 setBlockSuccessor(i, null);
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
205 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
206
15145
df2ef5204f2b Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14991
diff changeset
207 BeginNode[] successorsArray = newSuccessors.toArray(new BeginNode[newSuccessors.size()]);
16895
06c15e88d383 added factory method to all Node classes; replaced Node classes instantiation with calls to factory methods; replaced identity tests on Node classes with ' == <node class>.getGenClass()' idiom
Doug Simon <doug.simon@oracle.com>
parents: 16841
diff changeset
208 TypeSwitchNode newSwitch = graph().add(TypeSwitchNode.create(value(), successorsArray, newKeys, newKeyProbabilities, newKeySuccessors));
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
209 ((FixedWithNextNode) predecessor()).setNext(newSwitch);
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
210 GraphUtil.killWithUnusedFloatingInputs(this);
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
211 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
212 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents: 5662
diff changeset
213 }
5662
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
214 }
13166af0809e added TypeSwitchNode for polymorphic inlining
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
215 }