comparison graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java @ 2866:7f14e6b48a9c

added dead code elimination added ValueAnchor (temp workaround) more inlining logic (now uses DCE) IdealGraphPrinter: print even if Scheduler fails added inlining and DCE tracing options to C1XOptions
author Lukas Stadler <lukas.stadler@jku.at>
date Tue, 07 Jun 2011 16:27:08 +0200
parents 7596ae867a7b
children 5c545fef2c81
comparison
equal deleted inserted replaced
2845:e55543ff91fd 2866:7f14e6b48a9c
76 } 76 }
77 77
78 public Phi(CiKind kind, Merge block, int maxValues, Graph graph) { 78 public Phi(CiKind kind, Merge block, int maxValues, Graph graph) {
79 super(kind, INPUT_COUNT + maxValues, SUCCESSOR_COUNT, graph); 79 super(kind, INPUT_COUNT + maxValues, SUCCESSOR_COUNT, graph);
80 this.maxValues = maxValues; 80 this.maxValues = maxValues;
81 usedInputCount = 1; 81 usedInputCount = 0;
82 setBlock(block); 82 setBlock(block);
83 } 83 }
84 84
85 /** 85 /**
86 * Get the instruction that produces the value associated with the i'th predecessor 86 * Get the instruction that produces the value associated with the i'th predecessor
87 * of the join block. 87 * of the join block.
88 * @param i the index of the predecessor 88 * @param i the index of the predecessor
89 * @return the instruction that produced the value in the i'th predecessor 89 * @return the instruction that produced the value in the i'th predecessor
90 */ 90 */
91 public Value valueAt(int i) { 91 public Value valueAt(int i) {
92 return (Value) inputs().get(i + INPUT_COUNT); 92 return (Value) inputs().get(INPUT_COUNT + i);
93 }
94
95 public Node setValueAt(int i, Node x) {
96 return inputs().set(INPUT_COUNT + i, x);
93 } 97 }
94 98
95 /** 99 /**
96 * Get the number of inputs to this phi (i.e. the number of predecessors to the join block). 100 * Get the number of inputs to this phi (i.e. the number of predecessors to the join block).
97 * @return the number of inputs in this phi 101 * @return the number of inputs in this phi
98 */ 102 */
99 public int valueCount() { 103 public int valueCount() {
100 return usedInputCount - 1; 104 return usedInputCount;
101 } 105 }
102 106
103 @Override 107 @Override
104 public void accept(ValueVisitor v) { 108 public void accept(ValueVisitor v) {
105 v.visitPhi(this); 109 v.visitPhi(this);
117 } 121 }
118 122
119 @Override 123 @Override
120 public void print(LogStream out) { 124 public void print(LogStream out) {
121 out.print("phi function ("); 125 out.print("phi function (");
122 for (int i = 0; i < inputs().size(); ++i) { 126 for (int i = 0; i < valueCount(); ++i) {
123 if (i != 0) { 127 if (i != 0) {
124 out.print(' '); 128 out.print(' ');
125 } 129 }
126 out.print((Value) inputs().get(i)); 130 out.print(valueAt(i));
127 } 131 }
128 out.print(')'); 132 out.print(')');
129 } 133 }
130 134
131 @Override 135 @Override
141 } 145 }
142 146
143 public Phi addInput(Node y) { 147 public Phi addInput(Node y) {
144 assert !this.isDeleted() && !y.isDeleted(); 148 assert !this.isDeleted() && !y.isDeleted();
145 Phi phi = this; 149 Phi phi = this;
146 if (usedInputCount == inputs().size()) { 150 if (usedInputCount == maxValues) {
147 phi = new Phi(kind, block(), usedInputCount * 2, graph()); 151 phi = new Phi(kind, block(), maxValues * 2, graph());
148 for (int i = 0; i < valueCount(); ++i) { 152 for (int i = 0; i < valueCount(); ++i) {
149 phi.addInput(valueAt(i)); 153 phi.addInput(valueAt(i));
150 } 154 }
151 phi.addInput(y); 155 phi.addInput(y);
152 this.replace(phi); 156 this.replace(phi);
153 } else { 157 } else {
154 phi.inputs().set(usedInputCount++, y); 158 setValueAt(usedInputCount++, y);
155 } 159 }
156 return phi; 160 return phi;
157 } 161 }
158 162
159 public void removeInput(int index) { 163 public void removeInput(int index) {
160 inputs().set(index, null); 164 assert index < valueCount() : "index: " + index + ", valueCount: " + valueCount() + "@phi " + id();
161 for (int i = index + 1; i < usedInputCount; ++i) { 165 setValueAt(index, Node.Null);
162 inputs().set(i - 1, inputs().get(i)); 166 for (int i = index + 1; i < valueCount(); ++i) {
167 setValueAt(i - 1, valueAt(i));
163 } 168 }
164 usedInputCount--; 169 usedInputCount--;
165 } 170 }
166 171
167 @Override 172 @Override