comparison graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java @ 2768:43ffa0e47a46

Towards removing stateAfter on BlockEnd.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Mon, 23 May 2011 19:21:53 +0200
parents cc2b98e2b832
children dd6419f4bfe2
comparison
equal deleted inserted replaced
2767:cc2b98e2b832 2768:43ffa0e47a46
27 import static com.sun.cri.ci.CiCallingConvention.Type.*; 27 import static com.sun.cri.ci.CiCallingConvention.Type.*;
28 import static com.sun.cri.ci.CiValue.*; 28 import static com.sun.cri.ci.CiValue.*;
29 29
30 import java.util.*; 30 import java.util.*;
31 31
32 import com.oracle.graal.graph.*;
32 import com.oracle.max.asm.*; 33 import com.oracle.max.asm.*;
33 import com.sun.c1x.*; 34 import com.sun.c1x.*;
34 import com.sun.c1x.alloc.*; 35 import com.sun.c1x.alloc.*;
35 import com.sun.c1x.alloc.OperandPool.*; 36 import com.sun.c1x.alloc.OperandPool.*;
36 import com.sun.c1x.debug.*; 37 import com.sun.c1x.debug.*;
1261 protected void moveToPhi() { 1262 protected void moveToPhi() {
1262 assert lastState != null; 1263 assert lastState != null;
1263 this.moveToPhi(lastState); 1264 this.moveToPhi(lastState);
1264 } 1265 }
1265 1266
1267 private List<Phi> getPhis(LIRBlock block) {
1268 if (block.getInstructions().size() > 0) {
1269 Instruction i = block.getInstructions().get(0);
1270 if (i instanceof BlockBegin) {
1271 List<Phi> result = new ArrayList<Phi>();
1272 for (Node n : i.usages()) {
1273 if (n instanceof Phi) {
1274 result.add((Phi) n);
1275 }
1276 }
1277 return result;
1278 }
1279 }
1280 return null;
1281 }
1282
1266 protected void moveToPhi(FrameState curState) { 1283 protected void moveToPhi(FrameState curState) {
1267 // Moves all stack values into their phi position 1284 // Moves all stack values into their phi position
1268 LIRBlock bb = currentBlock; 1285 LIRBlock bb = currentBlock;
1269 if (bb.numberOfSux() == 1) { 1286 if (bb.numberOfSux() == 1) {
1270 LIRBlock sux = bb.suxAt(0); 1287 LIRBlock sux = bb.suxAt(0);
1271 assert sux.numberOfPreds() > 0 : "invalid CFG"; 1288 assert sux.numberOfPreds() > 0 : "invalid CFG";
1272 1289
1273 // a block with only one predecessor never has phi functions 1290 // a block with only one predecessor never has phi functions
1274 if (sux.numberOfPreds() > 1) { 1291 if (sux.numberOfPreds() > 1) {
1275 PhiResolver resolver = new PhiResolver(this);
1276
1277 FrameState suxState = sux.stateBefore(); 1292 FrameState suxState = sux.stateBefore();
1293
1294
1295 List<Phi> phis = getPhis(sux);
1296 if (phis != null) {
1297 int predIndex = 0;
1298 for (; predIndex < sux.numberOfPreds(); ++predIndex) {
1299 if (sux.predAt(predIndex) == bb) {
1300 break;
1301 }
1302 }
1303 assert predIndex < sux.numberOfPreds();
1304
1305 // TTY.println("predIndex=" + predIndex + ", bb" + bb.blockID() + ", sux=" + sux.blockID());
1306 // for (int i = 0; i < sux.numberOfPreds(); ++i) {
1307 // TTY.println("pred[" + i + "]=" + sux.predAt(i).blockID());
1308 // }
1309
1310 PhiResolver resolver = new PhiResolver(this);
1311 for (Phi phi : phis) {
1312 if (!phi.isDeadPhi() && phi.valueCount() > predIndex) {
1313 Value curVal = phi.valueAt(predIndex);
1314 if (curVal != null) {
1315 if (curVal instanceof Phi) {
1316 operandForPhi((Phi) curVal);
1317 }
1318 CiValue operand = curVal.operand();
1319 if (operand.isIllegal()) {
1320 // phi.print(TTY.out());
1321 assert curVal instanceof Constant || curVal instanceof Local : "these can be produced lazily" + curVal + "/" + phi;
1322 operand = operandForInstruction(curVal);
1323 }
1324 resolver.move(operand, operandForPhi(phi));
1325 }
1326 }
1327 }
1328 resolver.dispose();
1329 }
1330
1331 /* PhiResolver resolver = new PhiResolver(this);
1278 1332
1279 for (int index = 0; index < suxState.stackSize(); index++) { 1333 for (int index = 0; index < suxState.stackSize(); index++) {
1280 moveToPhi(resolver, curState.stackAt(index), suxState.stackAt(index)); 1334 moveToPhi(resolver, curState.stackAt(index), suxState.stackAt(index));
1281 } 1335 }
1282 1336
1283 for (int index = 0; index < suxState.localsSize(); index++) { 1337 for (int index = 0; index < suxState.localsSize(); index++) {
1284 moveToPhi(resolver, curState.localAt(index), suxState.localAt(index)); 1338 moveToPhi(resolver, curState.localAt(index), suxState.localAt(index));
1285 } 1339 }
1286 resolver.dispose(); 1340 resolver.dispose();*/
1287 } 1341 }
1288 } 1342 }
1289 } 1343 }
1290 1344
1291 /** 1345 /**