Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/ir/Switch.java @ 2602:0c6564c254af
new node layout: BlockBegin, BlockEnd
-Dc1x.dot=regex for pdf output
escape dot graph labels (<, >, &)
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 06 May 2011 10:25:37 +0200 |
parents | 16b9a8b5ad39 |
children | a0dd2b907806 |
comparison
equal
deleted
inserted
replaced
2601:224e8b4007bd | 2602:0c6564c254af |
---|---|
22 */ | 22 */ |
23 package com.sun.c1x.ir; | 23 package com.sun.c1x.ir; |
24 | 24 |
25 import java.util.*; | 25 import java.util.*; |
26 | 26 |
27 import com.oracle.graal.graph.*; | |
27 import com.sun.c1x.value.*; | 28 import com.sun.c1x.value.*; |
28 import com.sun.cri.ci.*; | 29 import com.sun.cri.ci.*; |
29 | 30 |
30 /** | 31 /** |
31 * The {@code Switch} class is the base of both lookup and table switches. | 32 * The {@code Switch} class is the base of both lookup and table switches. |
32 * | |
33 * @author Ben L. Titzer | |
34 */ | 33 */ |
35 public abstract class Switch extends BlockEnd { | 34 public abstract class Switch extends BlockEnd { |
36 | 35 |
37 Value value; | 36 private static final int INPUT_COUNT = 1; |
37 private static final int INPUT_VALUE = 0; | |
38 | |
39 private static final int SUCCESSOR_COUNT = 0; | |
40 | |
41 @Override | |
42 protected int inputCount() { | |
43 return super.inputCount() + INPUT_COUNT; | |
44 } | |
45 | |
46 @Override | |
47 protected int successorCount() { | |
48 return super.successorCount() + SUCCESSOR_COUNT; | |
49 } | |
50 | |
51 /** | |
52 * The instruction that provides the input value to this switch. | |
53 */ | |
54 public Value value() { | |
55 return (Value) inputs().get(super.inputCount() + INPUT_VALUE); | |
56 } | |
57 | |
58 public Value setValue(Value n) { | |
59 return (Value) inputs().set(super.inputCount() + INPUT_VALUE, n); | |
60 } | |
38 | 61 |
39 /** | 62 /** |
40 * Constructs a new Switch. | 63 * Constructs a new Switch. |
41 * @param value the instruction that provides the value to be switched over | 64 * @param value the instruction that provides the value to be switched over |
42 * @param successors the list of successors of this switch | 65 * @param successors the list of successors of this switch |
43 * @param stateBefore the state before the switch | 66 * @param stateBefore the state before the switch |
44 * @param isSafepoint {@code true} if this switch is a safepoint | 67 * @param isSafepoint {@code true} if this switch is a safepoint |
68 * @param graph | |
45 */ | 69 */ |
46 public Switch(Value value, List<BlockBegin> successors, FrameState stateBefore, boolean isSafepoint) { | 70 public Switch(Value value, List<BlockBegin> successors, FrameState stateBefore, boolean isSafepoint, int inputCount, int successorCount, Graph graph) { |
47 super(CiKind.Illegal, stateBefore, isSafepoint, successors); | 71 super(CiKind.Illegal, stateBefore, isSafepoint, successors, inputCount + INPUT_COUNT, successorCount + SUCCESSOR_COUNT, graph); |
48 this.value = value; | 72 setValue(value); |
49 } | |
50 | |
51 /** | |
52 * Gets the instruction that provides the input value to this switch. | |
53 * @return the instruction producing the input value | |
54 */ | |
55 public Value value() { | |
56 return value; | |
57 } | 73 } |
58 | 74 |
59 /** | 75 /** |
60 * Gets the number of cases that this switch covers (excluding the default case). | 76 * Gets the number of cases that this switch covers (excluding the default case). |
61 * @return the number of cases | 77 * @return the number of cases |
62 */ | 78 */ |
63 public int numberOfCases() { | 79 public int numberOfCases() { |
64 return successors.size() - 1; | 80 return blockSuccessorCount() - 1; |
65 } | 81 } |
66 | 82 |
67 /** | |
68 * Iterates over the inputs to this instruction. | |
69 * @param closure the closure to apply | |
70 */ | |
71 @Override | |
72 public void inputValuesDo(ValueClosure closure) { | |
73 value = closure.apply(value); | |
74 } | |
75 } | 83 } |