annotate graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/IntegerSwitchNode.java @ 16617:c164a505fc23

Properly handle multiple copies of the same test when unswitching
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 29 Jul 2014 17:40:22 -0700
parents 882f4cb7cfcf
children 5d468add216f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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.*;
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
30 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
31 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
32 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
33
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
34 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
35 * 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
36 * 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
37 */
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
38 public final class IntegerSwitchNode extends SwitchNode implements LIRLowerable, Simplifiable {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
40 private final int[] keys;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
42 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
43 * 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
44 * 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
45 *
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
46 * @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
47 * @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
48 * @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
49 * @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
50 * @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
51 */
15145
df2ef5204f2b Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14950
diff changeset
52 public 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
53 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
54 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
55 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
56 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
57 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
58 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
59 }
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
60
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
61 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
62 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
63 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
64 }
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 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
66 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
67
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
68 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
69 * 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
70 * 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
71 *
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
72 * @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
73 * @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
74 * @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
75 * @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
76 * @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
77 */
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
78 public 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
79 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
80 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
81
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
82 @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
83 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
84 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
85 }
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
86
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
87 /**
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
88 * 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
89 *
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
90 * @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
91 * @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
92 */
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
93 @Override
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
94 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
95 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
96 }
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 @Override
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
99 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
100 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
101 }
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
16617
c164a505fc23 Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
104 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
105 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
106 return false;
c164a505fc23 Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
107 }
c164a505fc23 Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
108 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
109 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
110 }
c164a505fc23 Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
111
c164a505fc23 Properly handle multiple copies of the same test when unswitching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15261
diff changeset
112 @Override
14950
d5a1206e1923 NodeLIRBuilderTool: fix typo in interface name.
Josef Eisl <josef.eisl@jku.at>
parents: 14888
diff changeset
113 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
114 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
115 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
116
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
117 @Override
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
118 public void simplify(SimplifierTool tool) {
6359
f8416485a37f canonicalize IntegerSwitchNode with only a default successor
Lukas Stadler <lukas.stadler@jku.at>
parents: 5711
diff changeset
119 if (blockSuccessorCount() == 1) {
f8416485a37f canonicalize IntegerSwitchNode with only a default successor
Lukas Stadler <lukas.stadler@jku.at>
parents: 5711
diff changeset
120 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
121 graph().removeSplitPropagate(this, defaultSuccessor());
6359
f8416485a37f canonicalize IntegerSwitchNode with only a default successor
Lukas Stadler <lukas.stadler@jku.at>
parents: 5711
diff changeset
122 } 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
123 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
124
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
125 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
126 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
127 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
128 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
129 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
130 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
131 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
132 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
133 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
134 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
135 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
136 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
137 graph().removeSplit(this, blockSuccessor(survivingEdge));
11265
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11262
diff changeset
138 } else if (value().stamp() instanceof IntegerStamp) {
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11262
diff changeset
139 IntegerStamp stamp = (IntegerStamp) value().stamp();
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
140 if (!stamp.isUnrestricted()) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
141 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
142 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
143 if (stamp.contains(keys[i])) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
144 validKeys++;
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 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
147 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
148 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
149 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
150 } 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
151 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
152 int[] newKeys = new int[validKeys];
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7257
diff changeset
153 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
154 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
155 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
156 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
157 for (int i = 0; i < keyCount() + 1; i++) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
158 if (i == keyCount() || stamp.contains(keys[i])) {
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
159 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
160 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
161 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
162 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
163 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
164 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
165 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
166 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
167 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
168 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
169 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
170 current++;
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
171 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
172 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
173 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
174 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
175 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
176 }
11262
c4703de83626 Fix Switch probability if simplification leaves no non-zero probability successor
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9602
diff changeset
177 } else {
c4703de83626 Fix Switch probability if simplification leaves no non-zero probability successor
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9602
diff changeset
178 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
179 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
180 }
5698
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 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
184 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
185 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
186 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
187 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
188 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
189 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
190
15145
df2ef5204f2b Remove AbstractBeginNode, move the framestate from AbstractBeginNode to BeginStateSplitNode.
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 14950
diff changeset
191 BeginNode[] successorsArray = newSuccessors.toArray(new BeginNode[newSuccessors.size()]);
5698
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
192 IntegerSwitchNode newSwitch = graph().add(new IntegerSwitchNode(value(), successorsArray, newKeys, newKeyProbabilities, newKeySuccessors));
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
193 ((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
194 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
195 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
196 }
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 }
764db9ada24f rework of switch operations: unify lookup- and tableswitch, introduce switch lir instructions
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
199 }