Mercurial > hg > truffle
comparison graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/SwitchNode.java @ 18993:480bd3b1adcd
Rename BeginNode => AbstractBeginNode.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Wed, 28 Jan 2015 00:50:31 +0100 |
parents | e04d70a4d3ae |
children | 7e2c87dae93e |
comparison
equal
deleted
inserted
replaced
18992:b1c03c2bfa40 | 18993:480bd3b1adcd |
---|---|
35 * The {@code SwitchNode} class is the base of both lookup and table switches. | 35 * The {@code SwitchNode} class is the base of both lookup and table switches. |
36 */ | 36 */ |
37 @NodeInfo | 37 @NodeInfo |
38 public abstract class SwitchNode extends ControlSplitNode { | 38 public abstract class SwitchNode extends ControlSplitNode { |
39 | 39 |
40 @Successor protected NodeSuccessorList<BeginNode> successors; | 40 @Successor protected NodeSuccessorList<AbstractBeginNode> successors; |
41 @Input protected ValueNode value; | 41 @Input protected ValueNode value; |
42 | 42 |
43 // do not change the contents of these arrays: | 43 // do not change the contents of these arrays: |
44 protected final double[] keyProbabilities; | 44 protected final double[] keyProbabilities; |
45 protected final int[] keySuccessors; | 45 protected final int[] keySuccessors; |
48 * Constructs a new Switch. | 48 * Constructs a new Switch. |
49 * | 49 * |
50 * @param value the instruction that provides the value to be switched over | 50 * @param value the instruction that provides the value to be switched over |
51 * @param successors the list of successors of this switch | 51 * @param successors the list of successors of this switch |
52 */ | 52 */ |
53 public SwitchNode(ValueNode value, BeginNode[] successors, int[] keySuccessors, double[] keyProbabilities) { | 53 public SwitchNode(ValueNode value, AbstractBeginNode[] successors, int[] keySuccessors, double[] keyProbabilities) { |
54 super(StampFactory.forVoid()); | 54 super(StampFactory.forVoid()); |
55 assert value.stamp().getStackKind().isNumericInteger() || value.stamp() instanceof AbstractPointerStamp : value.stamp() + " key not supported by SwitchNode"; | 55 assert value.stamp().getStackKind().isNumericInteger() || value.stamp() instanceof AbstractPointerStamp : value.stamp() + " key not supported by SwitchNode"; |
56 assert keySuccessors.length == keyProbabilities.length; | 56 assert keySuccessors.length == keyProbabilities.length; |
57 this.successors = new NodeSuccessorList<>(this, successors); | 57 this.successors = new NodeSuccessorList<>(this, successors); |
58 this.value = value; | 58 this.value = value; |
70 assert total > 0.999 && total < 1.001 : "Total " + total; | 70 assert total > 0.999 && total < 1.001 : "Total " + total; |
71 return true; | 71 return true; |
72 } | 72 } |
73 | 73 |
74 @Override | 74 @Override |
75 public double probability(BeginNode successor) { | 75 public double probability(AbstractBeginNode successor) { |
76 double sum = 0; | 76 double sum = 0; |
77 for (int i = 0; i < keySuccessors.length; i++) { | 77 for (int i = 0; i < keySuccessors.length; i++) { |
78 if (successors.get(keySuccessors[i]) == successor) { | 78 if (successors.get(keySuccessors[i]) == successor) { |
79 sum += keyProbabilities[i]; | 79 sum += keyProbabilities[i]; |
80 } | 80 } |
115 } | 115 } |
116 | 116 |
117 /** | 117 /** |
118 * Returns the successor for the key at the given index. | 118 * Returns the successor for the key at the given index. |
119 */ | 119 */ |
120 public BeginNode keySuccessor(int i) { | 120 public AbstractBeginNode keySuccessor(int i) { |
121 return successors.get(keySuccessors[i]); | 121 return successors.get(keySuccessors[i]); |
122 } | 122 } |
123 | 123 |
124 /** | 124 /** |
125 * Returns the probability of the key at the given index. | 125 * Returns the probability of the key at the given index. |
133 */ | 133 */ |
134 public int defaultSuccessorIndex() { | 134 public int defaultSuccessorIndex() { |
135 return keySuccessors[keySuccessors.length - 1]; | 135 return keySuccessors[keySuccessors.length - 1]; |
136 } | 136 } |
137 | 137 |
138 public BeginNode blockSuccessor(int i) { | 138 public AbstractBeginNode blockSuccessor(int i) { |
139 return successors.get(i); | 139 return successors.get(i); |
140 } | 140 } |
141 | 141 |
142 public void setBlockSuccessor(int i, BeginNode s) { | 142 public void setBlockSuccessor(int i, AbstractBeginNode s) { |
143 successors.set(i, s); | 143 successors.set(i, s); |
144 } | 144 } |
145 | 145 |
146 public int blockSuccessorCount() { | 146 public int blockSuccessorCount() { |
147 return successors.count(); | 147 return successors.count(); |
150 /** | 150 /** |
151 * Gets the successor corresponding to the default (fall through) case. | 151 * Gets the successor corresponding to the default (fall through) case. |
152 * | 152 * |
153 * @return the default successor | 153 * @return the default successor |
154 */ | 154 */ |
155 public BeginNode defaultSuccessor() { | 155 public AbstractBeginNode defaultSuccessor() { |
156 if (defaultSuccessorIndex() == -1) { | 156 if (defaultSuccessorIndex() == -1) { |
157 throw new GraalInternalError("unexpected"); | 157 throw new GraalInternalError("unexpected"); |
158 } | 158 } |
159 return successors.get(defaultSuccessorIndex()); | 159 return successors.get(defaultSuccessorIndex()); |
160 } | 160 } |