comparison graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java @ 2823:ac4b086cbd72

Merge
author Gilles Duboscq <gilles.duboscq@oracle.com>
date Mon, 30 May 2011 16:35:08 +0200
parents 530366123e46 c3f64b66fc78
children 244921d7cf50
comparison
equal deleted inserted replaced
2822:530366123e46 2823:ac4b086cbd72
286 appendGoto(target); 286 appendGoto(target);
287 } 287 }
288 288
289 public void mergeOrClone(Block target, FrameStateAccess newState) { 289 public void mergeOrClone(Block target, FrameStateAccess newState) {
290 Instruction first = target.firstInstruction; 290 Instruction first = target.firstInstruction;
291 if (target.isLoopHeader && isVisited(target)) {
292 first = ((LoopBegin) first).loopEnd();
293 }
291 assert first instanceof StateSplit; 294 assert first instanceof StateSplit;
292 295
293 int bci = target.startBci; 296 int bci = target.startBci;
294 297
295 FrameState existingState = ((StateSplit) first).stateBefore(); 298 FrameState existingState = ((StateSplit) first).stateBefore();
296 299
297 if (existingState == null) { 300 if (existingState == null) {
298 assert first instanceof Merge ^ !target.isLoopHeader : "isLoopHeader: " + target.isLoopHeader; 301 // assert first instanceof Merge ^ !target.isLoopHeader : "isLoopHeader: " + target.isLoopHeader;
299 302
300 // copy state because it is modified 303 // copy state because it is modified
301 FrameState duplicate = newState.duplicate(bci); 304 FrameState duplicate = newState.duplicate(bci);
302 305
303 // if the block is a loop header, insert all necessary phis 306 // if the block is a loop header, insert all necessary phis
304 if (target.isLoopHeader) { 307 if (first instanceof LoopBegin && target.isLoopHeader) {
305 assert first instanceof Merge; 308 assert first instanceof Merge;
306 insertLoopPhis((Merge) first, duplicate); 309 insertLoopPhis((Merge) first, duplicate);
307 ((Merge) first).setStateBefore(duplicate); 310 ((Merge) first).setStateBefore(duplicate);
308 } else { 311 } else {
309 ((StateSplit) first).setStateBefore(duplicate); 312 ((StateSplit) first).setStateBefore(duplicate);
317 } 320 }
318 assert existingState.localsSize() == newState.localsSize(); 321 assert existingState.localsSize() == newState.localsSize();
319 assert existingState.stackSize() == newState.stackSize(); 322 assert existingState.stackSize() == newState.stackSize();
320 323
321 if (first instanceof Placeholder) { 324 if (first instanceof Placeholder) {
322 Merge merge = new Merge(existingState.bci, target.isLoopHeader, graph); 325 assert !target.isLoopHeader;
326 Merge merge = new Merge(graph);
323 327
324 Placeholder p = (Placeholder) first; 328 Placeholder p = (Placeholder) first;
325 assert p.next() == null; 329 assert p.next() == null;
326 p.replace(merge); 330 p.replace(merge);
327 target.firstInstruction = merge; 331 target.firstInstruction = merge;
328 merge.setStateBefore(existingState); 332 merge.setStateBefore(existingState);
329 } 333 first = merge;
330 334 }
331 existingState.merge((Merge) target.firstInstruction, newState); 335
336 existingState.merge((Merge) first, newState);
332 } 337 }
333 338
334 for (int j = 0; j < frameState.localsSize() + frameState.stackSize(); ++j) { 339 for (int j = 0; j < frameState.localsSize() + frameState.stackSize(); ++j) {
335 if (frameState.valueAt(j) != null) { 340 if (frameState.valueAt(j) != null) {
336 assert !frameState.valueAt(j).isDeleted(); 341 assert !frameState.valueAt(j).isDeleted();
1025 } 1030 }
1026 append(lookupSwitch); 1031 append(lookupSwitch);
1027 } 1032 }
1028 1033
1029 private Value appendConstant(CiConstant constant) { 1034 private Value appendConstant(CiConstant constant) {
1030 return appendWithBCI(new Constant(constant, graph)); 1035 return append(new Constant(constant, graph));
1031 } 1036 }
1032 1037
1033 private Value append(Instruction x) { 1038 private Value append(Instruction x) {
1034 return appendWithBCI(x); 1039 return appendWithBCI(x);
1040 }
1041
1042 private Value append(Value v) {
1043 return v;
1035 } 1044 }
1036 1045
1037 private Value appendWithBCI(Instruction x) { 1046 private Value appendWithBCI(Instruction x) {
1038 if (x.isAppended()) { 1047 if (x.isAppended()) {
1039 // the instruction has already been added 1048 // the instruction has already been added
1055 private Instruction createTargetAt(int bci, FrameStateAccess stateAfter) { 1064 private Instruction createTargetAt(int bci, FrameStateAccess stateAfter) {
1056 return createTarget(blockFromBci[bci], stateAfter); 1065 return createTarget(blockFromBci[bci], stateAfter);
1057 } 1066 }
1058 1067
1059 private Instruction createTarget(Block block, FrameStateAccess stateAfter) { 1068 private Instruction createTarget(Block block, FrameStateAccess stateAfter) {
1060
1061 assert block != null && stateAfter != null; 1069 assert block != null && stateAfter != null;
1062 assert block.isLoopHeader || block.firstInstruction == null || block.firstInstruction.next() == null : "non-loop block must be iterated after all its predecessors"; 1070 assert block.isLoopHeader || block.firstInstruction == null || block.firstInstruction.next() == null : "non-loop block must be iterated after all its predecessors";
1063 1071
1064 if (block.isExceptionEntry) { 1072 if (block.isExceptionEntry) {
1065 assert stateAfter.stackSize() == 1; 1073 assert stateAfter.stackSize() == 1;
1066 } 1074 }
1067 1075
1068 if (block.firstInstruction == null) { 1076 if (block.firstInstruction == null) {
1069 if (block.isLoopHeader) { 1077 if (block.isLoopHeader) {
1070 block.firstInstruction = new Merge(block.startBci, block.isLoopHeader, graph); 1078 // block.firstInstruction = new Merge(block.startBci, graph);
1079
1080 LoopBegin loopBegin = new LoopBegin(graph);
1081 LoopEnd loopEnd = new LoopEnd(graph);
1082 loopEnd.setLoopBegin(loopBegin);
1083 block.firstInstruction = loopBegin;
1071 } else { 1084 } else {
1072 block.firstInstruction = new Placeholder(graph); 1085 block.firstInstruction = new Placeholder(graph);
1073 } 1086 }
1074 } 1087 }
1075 mergeOrClone(block, stateAfter); 1088 mergeOrClone(block, stateAfter);
1076 addToWorkList(block); 1089 addToWorkList(block);
1077 return block.firstInstruction; 1090
1091 if (block.firstInstruction instanceof LoopBegin && isVisited(block)) {
1092 return ((LoopBegin) block.firstInstruction).loopEnd();
1093 } else {
1094 return block.firstInstruction;
1095 }
1078 } 1096 }
1079 1097
1080 private Value synchronizedObject(FrameStateAccess state, RiMethod target) { 1098 private Value synchronizedObject(FrameStateAccess state, RiMethod target) {
1081 if (isStatic(target.accessFlags())) { 1099 if (isStatic(target.accessFlags())) {
1082 Constant classConstant = new Constant(target.holder().getEncoding(Representation.JavaClass), graph); 1100 Constant classConstant = new Constant(target.holder().getEncoding(Representation.JavaClass), graph);
1083 return appendWithBCI(classConstant); 1101 return append(classConstant);
1084 } else { 1102 } else {
1085 return state.localAt(0); 1103 return state.localAt(0);
1086 } 1104 }
1087 } 1105 }
1088 1106
1131 1149
1132 if (block instanceof ExceptionBlock) { 1150 if (block instanceof ExceptionBlock) {
1133 createExceptionDispatch((ExceptionBlock) block); 1151 createExceptionDispatch((ExceptionBlock) block);
1134 } else { 1152 } else {
1135 iterateBytecodesForBlock(block); 1153 iterateBytecodesForBlock(block);
1154 }
1155 }
1156 }
1157 for (Block b : blocksVisited) {
1158 if (b.isLoopHeader) {
1159 LoopBegin begin = (LoopBegin) b.firstInstruction;
1160 LoopEnd end = begin.loopEnd();
1161
1162 // This can happen with degenerated loops like this one:
1163 // for (;;) {
1164 // try {
1165 // break;
1166 // } catch (UnresolvedException iioe) {
1167 // }
1168 // }
1169 if (end.stateBefore() != null) {
1170 begin.stateBefore().merge(begin, end.stateBefore());
1171 } else {
1172 end.delete();
1173 Merge merge = new Merge(graph);
1174 merge.successors().setAndClear(merge.nextIndex(), begin, begin.nextIndex());
1175 begin.replace(merge);
1136 } 1176 }
1137 } 1177 }
1138 } 1178 }
1139 } 1179 }
1140 1180