comparison graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/MemoryScheduleTest.java @ 10920:9802c478a26c

NewMemoryAwareScheduling: fix out of loop scheduling for floating reads (GRAAL-159)
author Bernhard Urban <bernhard.urban@jku.at>
date Thu, 01 Aug 2013 17:23:30 +0200
parents 8106edbdeac9
children f75695de1312
comparison
equal deleted inserted replaced
10919:2cf0785957fb 10920:9802c478a26c
187 assertReadWithinStartBlock(schedule, false); 187 assertReadWithinStartBlock(schedule, false);
188 assertReadWithinReturnBlock(schedule, true); 188 assertReadWithinReturnBlock(schedule, true);
189 } 189 }
190 190
191 /** 191 /**
192 * Here the read should float out of the loop.
193 */
194 public static int testLoop3Snippet(int a) {
195 int j = 0;
196 for (int i = 0; i < a; i++) {
197 if (i - container.a == 0) {
198 break;
199 }
200 j++;
201 }
202 return j;
203 }
204
205 @Test
206 public void testLoop3() {
207 SchedulePhase schedule = getFinalSchedule("testLoop3Snippet", TestMode.WITHOUT_FRAMESTATES, MemoryScheduling.OPTIMAL, false);
208 assertEquals(7, schedule.getCFG().getBlocks().length);
209 assertReadWithinStartBlock(schedule, true);
210 assertReadWithinReturnBlock(schedule, false);
211 }
212
213 /**
192 * Here the read should float to the end (into the same block as the return). 214 * Here the read should float to the end (into the same block as the return).
193 */ 215 */
194 public static int testArrayCopySnippet(Integer intValue, char[] a, char[] b, int len) { 216 public static int testArrayCopySnippet(Integer intValue, char[] a, char[] b, int len) {
195 System.arraycopy(a, 0, b, 0, len); 217 System.arraycopy(a, 0, b, 0, len);
196 return intValue.intValue(); 218 return intValue.intValue();
369 } 391 }
370 392
371 @Test 393 @Test
372 public void testProxy2() { 394 public void testProxy2() {
373 SchedulePhase schedule = getFinalSchedule("testProxy2Snippet", TestMode.WITHOUT_FRAMESTATES, MemoryScheduling.OPTIMAL, false); 395 SchedulePhase schedule = getFinalSchedule("testProxy2Snippet", TestMode.WITHOUT_FRAMESTATES, MemoryScheduling.OPTIMAL, false);
396 assertReadWithinStartBlock(schedule, false);
397 assertReadWithinReturnBlock(schedule, false);
398 }
399
400 private int hash = 0;
401 private final char[] value = new char[3];
402
403 public int testStringHashCodeSnippet() {
404 int h = hash;
405 if (h == 0 && value.length > 0) {
406 char[] val = value;
407
408 for (int i = 0; i < value.length; i++) {
409 h = 31 * h + val[i];
410 }
411 hash = h;
412 }
413 return h;
414 }
415
416 @Test
417 public void testStringHashCode() {
418 SchedulePhase schedule = getFinalSchedule("testStringHashCodeSnippet", TestMode.WITHOUT_FRAMESTATES, MemoryScheduling.OPTIMAL, false);
419 assertReadWithinStartBlock(schedule, true);
420 assertReadWithinReturnBlock(schedule, false);
421
422 hash = 0x1337;
423 value[0] = 'a';
424 value[1] = 'b';
425 value[2] = 'c';
426 test("testStringHashCodeSnippet");
427 }
428
429 public static int testLoop4Snippet(int count) {
430 int[] a = new int[count];
431
432 for (int i = 0; i < a.length; i++) {
433 a[i] = i;
434 }
435
436 int i = 0;
437 int iwrap = count - 1;
438 int sum = 0;
439
440 while (i < count) {
441 sum += (a[i] + a[iwrap]) / 2;
442 iwrap = i;
443 i++;
444 }
445 return sum;
446 }
447
448 @Test
449 public void testLoop4() {
450 SchedulePhase schedule = getFinalSchedule("testLoop4Snippet", TestMode.WITHOUT_FRAMESTATES, MemoryScheduling.OPTIMAL, false);
374 assertReadWithinStartBlock(schedule, false); 451 assertReadWithinStartBlock(schedule, false);
375 assertReadWithinReturnBlock(schedule, false); 452 assertReadWithinReturnBlock(schedule, false);
376 } 453 }
377 454
378 private void assertReadWithinReturnBlock(SchedulePhase schedule, boolean withinReturnBlock) { 455 private void assertReadWithinReturnBlock(SchedulePhase schedule, boolean withinReturnBlock) {
442 Debug.dump(graph, "after removal of framestates"); 519 Debug.dump(graph, "after removal of framestates");
443 520
444 new FloatingReadPhase().apply(graph); 521 new FloatingReadPhase().apply(graph);
445 new RemoveValueProxyPhase().apply(graph); 522 new RemoveValueProxyPhase().apply(graph);
446 523
524 MidTierContext midContext = new MidTierContext(runtime(), assumptions, replacements, runtime().getTarget(), OptimisticOptimizations.ALL);
525 new GuardLoweringPhase().apply(graph, midContext);
526 new LoweringPhase(LoweringType.AFTER_GUARDS).apply(graph, midContext);
527 new LoweringPhase(LoweringType.AFTER_FSA).apply(graph, midContext);
528
447 SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS, memsched, printSchedule); 529 SchedulePhase schedule = new SchedulePhase(SchedulingStrategy.LATEST_OUT_OF_LOOPS, memsched, printSchedule);
448 schedule.apply(graph); 530 schedule.apply(graph);
449 assertEquals(1, graph.getNodes().filter(StartNode.class).count()); 531 assertEquals(1, graph.getNodes().filter(StartNode.class).count());
532 TTY.flush();
450 return schedule; 533 return schedule;
451 } 534 }
452 }); 535 });
453 } 536 }
454 } 537 }