comparison graal/GraalCompiler/src/com/sun/c1x/gen/PhiSimplifier.java @ 2821:015be60afcf3

removed flags from Value class
author Lukas Stadler <lukas.stadler@jku.at>
date Mon, 30 May 2011 17:05:06 +0200
parents 189ffb7d1d84
children 7f14e6b48a9c
comparison
equal deleted inserted replaced
2820:2b8ef0a06391 2821:015be60afcf3
29 /** 29 /**
30 * The {@code PhiSimplifier} class is a helper class that can reduce phi instructions. 30 * The {@code PhiSimplifier} class is a helper class that can reduce phi instructions.
31 */ 31 */
32 public final class PhiSimplifier { 32 public final class PhiSimplifier {
33 33
34 private NodeBitMap visited;
35 private NodeBitMap cannotSimplify;
36
34 public PhiSimplifier(IR ir) { 37 public PhiSimplifier(IR ir) {
35 for (Node n : ir.compilation.graph.getNodes()) { 38 Graph graph = ir.compilation.graph;
39 visited = graph.createNodeBitMap();
40 cannotSimplify = graph.createNodeBitMap();
41
42 for (Node n : graph.getNodes()) {
36 if (n instanceof Phi) { 43 if (n instanceof Phi) {
37 simplify((Phi) n); 44 simplify((Phi) n);
38 } 45 }
39 } 46 }
40 } 47 }
43 if (x == null || !(x instanceof Phi)) { 50 if (x == null || !(x instanceof Phi)) {
44 return x; 51 return x;
45 } 52 }
46 Phi phi = (Phi) x; 53 Phi phi = (Phi) x;
47 54
48 if (phi.valueCount() == 1 && !phi.checkFlag(Value.Flag.PhiCannotSimplify)) { 55 if (phi.valueCount() == 1 && !cannotSimplify.isMarked(phi)) {
49 return (Value) phi.replace(phi.valueAt(0)); 56 return (Value) phi.replace(phi.valueAt(0));
50 } 57 }
51 58
52 if (phi.checkFlag(Value.Flag.PhiCannotSimplify)) { 59 if (cannotSimplify.isMarked(phi)) {
53 // already tried, cannot simplify this phi 60 // already tried, cannot simplify this phi
54 return phi; 61 return phi;
55 } else if (phi.checkFlag(Value.Flag.PhiVisited)) { 62 } else if (visited.isMarked(phi)) {
56 // break cycles in phis 63 // break cycles in phis
57 return phi; 64 return phi;
58 } else if (phi.isIllegal()) { 65 } else if (phi.isDead()) {
59 // don't bother with illegals 66 // don't bother with illegals
60 return phi; 67 return phi;
61 } else { 68 } else {
62 // attempt to simplify the phi by recursively simplifying its operands 69 // attempt to simplify the phi by recursively simplifying its operands
63 phi.setFlag(Value.Flag.PhiVisited); 70 visited.mark(phi);
64 Value phiSubst = null; 71 Value phiSubst = null;
65 int max = phi.valueCount(); 72 int max = phi.valueCount();
66 boolean cannotSimplify = false; 73 boolean cannotSimplify = false;
67 for (int i = 0; i < max; i++) { 74 for (int i = 0; i < max; i++) {
68 Value oldInstr = phi.valueAt(i); 75 Value oldInstr = phi.valueAt(i);
69 76
70 if (oldInstr == null || oldInstr.isIllegal() || oldInstr.isDeadPhi()) { 77 if (oldInstr == null || (oldInstr instanceof Phi && ((Phi) oldInstr).isDead())) {
71 // if one operand is illegal, make the entire phi illegal 78 // if one operand is illegal, make the entire phi illegal
72 phi.makeDead(); 79 phi.makeDead();
73 phi.clearFlag(Value.Flag.PhiVisited); 80 visited.clear(phi);
74 return phi; 81 return phi;
75 } 82 }
76 83
77 Value newInstr = simplify(oldInstr); 84 Value newInstr = simplify(oldInstr);
78 85
79 if (newInstr == null || newInstr.isIllegal() || newInstr.isDeadPhi()) { 86 if (newInstr == null || (newInstr instanceof Phi && ((Phi) newInstr).isDead())) {
80 // if the subst instruction is illegal, make the entire phi illegal 87 // if the subst instruction is illegal, make the entire phi illegal
81 phi.makeDead(); 88 phi.makeDead();
82 phi.clearFlag(Value.Flag.PhiVisited); 89 visited.clear(phi);
83 return phi; 90 return phi;
84 } 91 }
85 92
86 // attempt to simplify this operand 93 // attempt to simplify this operand
87 if (!cannotSimplify) { 94 if (!cannotSimplify) {
95 cannotSimplify = true; 102 cannotSimplify = true;
96 } 103 }
97 } 104 }
98 } 105 }
99 if (cannotSimplify) { 106 if (cannotSimplify) {
100 phi.setFlag(Value.Flag.PhiCannotSimplify); 107 this.cannotSimplify.mark(phi);
101 phi.clearFlag(Value.Flag.PhiVisited); 108 visited.clear(phi);
102 return phi; 109 return phi;
103 } 110 }
104 111
105 // successfully simplified the phi 112 // successfully simplified the phi
106 assert phiSubst != null : "illegal phi function"; 113 assert phiSubst != null : "illegal phi function";
107 phi.clearFlag(Value.Flag.PhiVisited); 114 visited.clear(phi);
108 115
109 phi.replace(phiSubst); 116 phi.replace(phiSubst);
110 // System.out.printf("replaced phi with %d inputs\n", max);
111 117
112 return phiSubst; 118 return phiSubst;
113 } 119 }
114 } 120 }
115 } 121 }