Mercurial > hg > truffle
annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IntegerSwitchNode.java @ 17450:45b45f902bed
removed Node generation (GRAAL-857)
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 15 Oct 2014 15:35:33 +0200 |
parents | c9bb0da795d4 |
children | 9619ba4daf4c |
rev | line source |
---|---|
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
1 /* |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
2 * Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
4 * |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
8 * |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
13 * accompanied this code). |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
14 * |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
18 * |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
21 * questions. |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
22 */ |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
23 package com.oracle.graal.nodes.extended; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
24 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
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:
diff
changeset
|
26 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
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.*; |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
31 import com.oracle.graal.nodes.*; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
32 import com.oracle.graal.nodes.spi.*; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
33 import com.oracle.graal.nodes.util.*; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
34 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
35 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
36 * The {@code IntegerSwitchNode} represents a switch on integer keys, with a sorted array of key |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
37 * values. The actual implementation of the switch will be decided by the backend. |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
38 */ |
16822
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16617
diff
changeset
|
39 @NodeInfo |
5d468add216f
added @NodeInfo annotations to all Node classes
Doug Simon <doug.simon@oracle.com>
parents:
16617
diff
changeset
|
40 public class IntegerSwitchNode extends SwitchNode implements LIRLowerable, Simplifiable { |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
41 |
17328
c9bb0da795d4
Backed out of changeset 17322:655f3e6b467b
Doug Simon <doug.simon@oracle.com>
parents:
17327
diff
changeset
|
42 protected final int[] keys; |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
43 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
44 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
45 * Constructs a integer switch instruction. The keyProbabilities and keySuccessors array contain |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
46 * key.length + 1 entries, the last entry describes the default (fall through) case. |
16617
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
47 * |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
48 * @param value the instruction producing the value being switched on |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
49 * @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:
diff
changeset
|
50 * @param keys the sorted list of keys |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
51 * @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
|
52 * @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:
diff
changeset
|
53 */ |
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
|
54 public static IntegerSwitchNode create(ValueNode value, BeginNode[] successors, int[] keys, double[] keyProbabilities, int[] keySuccessors) { |
17450
45b45f902bed
removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
55 return new IntegerSwitchNode(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
|
56 } |
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 |
17309
845e881ce054
constructors in a Node class must be protected
Doug Simon <doug.simon@oracle.com>
parents:
17276
diff
changeset
|
58 protected IntegerSwitchNode(ValueNode value, BeginNode[] successors, int[] keys, double[] keyProbabilities, int[] keySuccessors) { |
7705
96a596d751ab
remove successorProbabilities from SwitchNode
Lukas Stadler <lukas.stadler@jku.at>
parents:
7530
diff
changeset
|
59 super(value, successors, keySuccessors, keyProbabilities); |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
60 assert keySuccessors.length == keys.length + 1; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
61 assert keySuccessors.length == keyProbabilities.length; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
62 this.keys = keys; |
13294
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
63 assert assertValues(); |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
64 assert assertSorted(); |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
65 } |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
66 |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
67 private boolean assertSorted() { |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
68 for (int i = 1; i < keys.length; i++) { |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
69 assert keys[i - 1] < keys[i]; |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
70 } |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
71 return true; |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
72 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
73 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
74 /** |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
75 * Constructs a integer switch instruction. The keyProbabilities and keySuccessors array contain |
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
76 * key.length + 1 entries, the last entry describes the default (fall through) case. |
16617
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
77 * |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
78 * @param value the instruction producing the value being switched on |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
79 * @param successorCount the number of successors |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
80 * @param keys the sorted list of keys |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
81 * @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
|
82 * @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:
diff
changeset
|
83 */ |
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
|
84 public static IntegerSwitchNode create(ValueNode value, int successorCount, int[] keys, double[] keyProbabilities, int[] keySuccessors) { |
17450
45b45f902bed
removed Node generation (GRAAL-857)
Doug Simon <doug.simon@oracle.com>
parents:
17328
diff
changeset
|
85 return new IntegerSwitchNode(value, successorCount, 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
|
86 } |
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
|
87 |
17309
845e881ce054
constructors in a Node class must be protected
Doug Simon <doug.simon@oracle.com>
parents:
17276
diff
changeset
|
88 protected IntegerSwitchNode(ValueNode value, int successorCount, int[] keys, double[] keyProbabilities, int[] keySuccessors) { |
15145
df2ef5204f2b
Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14950
diff
changeset
|
89 this(value, new BeginNode[successorCount], keys, keyProbabilities, keySuccessors); |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
90 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
91 |
13294
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
92 @Override |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
93 public boolean isSorted() { |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
94 return true; |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
95 } |
29907e69ae8d
rework of switch generation: move code into platform independent SwitchStrategy, add boolean switch strategy
Lukas Stadler <lukas.stadler@jku.at>
parents:
11881
diff
changeset
|
96 |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
97 /** |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
98 * Gets the key at the specified index. |
16617
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
99 * |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
100 * @param i the index |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
101 * @return the key at that index |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
102 */ |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
103 @Override |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
104 public Constant keyAt(int i) { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
105 return Constant.forInt(keys[i]); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
106 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
107 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
108 @Override |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
109 public int keyCount() { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
110 return keys.length; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
111 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
112 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
113 @Override |
16617
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
114 public boolean equalKeys(SwitchNode switchNode) { |
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
115 if (!(switchNode instanceof IntegerSwitchNode)) { |
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
116 return false; |
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
117 } |
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
118 IntegerSwitchNode other = (IntegerSwitchNode) switchNode; |
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
119 return Arrays.equals(keys, other.keys); |
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
120 } |
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
121 |
c164a505fc23
Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15261
diff
changeset
|
122 @Override |
14950
d5a1206e1923
NodeLIRBuilderTool: fix typo in interface name.
Josef Eisl <josef.eisl@jku.at>
parents:
14888
diff
changeset
|
123 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:
diff
changeset
|
124 gen.emitSwitch(this); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
125 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
126 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
127 @Override |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
128 public void simplify(SimplifierTool tool) { |
6359
f8416485a37f
canonicalize IntegerSwitchNode with only a default successor
Lukas Stadler <lukas.stadler@jku.at>
parents:
5711
diff
changeset
|
129 if (blockSuccessorCount() == 1) { |
f8416485a37f
canonicalize IntegerSwitchNode with only a default successor
Lukas Stadler <lukas.stadler@jku.at>
parents:
5711
diff
changeset
|
130 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
|
131 graph().removeSplitPropagate(this, defaultSuccessor()); |
6359
f8416485a37f
canonicalize IntegerSwitchNode with only a default successor
Lukas Stadler <lukas.stadler@jku.at>
parents:
5711
diff
changeset
|
132 } else if (value() instanceof ConstantNode) { |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
133 int constant = value().asConstant().asInt(); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
134 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
135 int survivingEdge = keySuccessorIndex(keyCount()); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
136 for (int i = 0; i < keyCount(); i++) { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
137 if (keys[i] == constant) { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
138 survivingEdge = keySuccessorIndex(i); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
139 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
140 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
141 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:
diff
changeset
|
142 if (i != survivingEdge) { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
143 tool.deleteBranch(blockSuccessor(i)); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
144 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
145 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
146 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
|
147 graph().removeSplit(this, blockSuccessor(survivingEdge)); |
11265 | 148 } else if (value().stamp() instanceof IntegerStamp) { |
17276
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16920
diff
changeset
|
149 IntegerStamp integerStamp = (IntegerStamp) value().stamp(); |
ffb974bef674
moved Node valueNumber and valueEquals logic (optionally) to generated nodes
Doug Simon <doug.simon@oracle.com>
parents:
16920
diff
changeset
|
150 if (!integerStamp.isUnrestricted()) { |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
151 int validKeys = 0; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
152 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:
16920
diff
changeset
|
153 if (integerStamp.contains(keys[i])) { |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
154 validKeys++; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
155 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
156 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
157 if (validKeys == 0) { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
158 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
|
159 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:
diff
changeset
|
160 } else if (validKeys != keys.length) { |
15145
df2ef5204f2b
Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14950
diff
changeset
|
161 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:
diff
changeset
|
162 int[] newKeys = new int[validKeys]; |
7530
5e3d1a68664e
applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents:
7257
diff
changeset
|
163 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:
diff
changeset
|
164 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:
diff
changeset
|
165 double totalProbability = 0; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
166 int current = 0; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
167 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:
16920
diff
changeset
|
168 if (i == keyCount() || integerStamp.contains(keys[i])) { |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
169 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:
diff
changeset
|
170 if (index == -1) { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
171 index = newSuccessors.size(); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
172 newSuccessors.add(keySuccessor(i)); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
173 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
174 newKeySuccessors[current] = index; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
175 if (i < keyCount()) { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
176 newKeys[current] = keys[i]; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
177 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
178 newKeyProbabilities[current] = keyProbability(i); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
179 totalProbability += keyProbability(i); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
180 current++; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
181 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
182 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
183 if (totalProbability > 0) { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
184 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:
diff
changeset
|
185 newKeyProbabilities[i] /= totalProbability; |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
186 } |
11262
c4703de83626
Fix Switch probability if simplification leaves no non-zero probability successor
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
187 } else { |
c4703de83626
Fix Switch probability if simplification leaves no non-zero probability successor
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
9602
diff
changeset
|
188 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
|
189 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
|
190 } |
5698
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
191 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
192 |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
193 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:
14950
diff
changeset
|
194 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:
diff
changeset
|
195 if (!newSuccessors.contains(successor)) { |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
196 tool.deleteBranch(successor); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
197 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
198 setBlockSuccessor(i, null); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
199 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
200 |
15145
df2ef5204f2b
Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
14950
diff
changeset
|
201 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
|
202 IntegerSwitchNode newSwitch = graph().add(IntegerSwitchNode.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:
diff
changeset
|
203 ((FixedWithNextNode) predecessor()).setNext(newSwitch); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
204 GraphUtil.killWithUnusedFloatingInputs(this); |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
205 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
206 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
207 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
208 } |
764db9ada24f
rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff
changeset
|
209 } |