comparison graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanWalker.java @ 21338:5010ea46630a

LinearScan: move changeSpillState to LinearScanWalker.
author Josef Eisl <josef.eisl@jku.at>
date Tue, 12 May 2015 14:04:40 +0200
parents 9f45587ad8f5
children 4677c5d78ca6 93c50cefb9e8
comparison
equal deleted inserted replaced
21337:583a64c48dda 21338:5010ea46630a
481 481
482 assert interval.firstUsage(RegisterPriority.ShouldHaveRegister) > currentPosition : "interval must not have use position before currentPosition"; 482 assert interval.firstUsage(RegisterPriority.ShouldHaveRegister) > currentPosition : "interval must not have use position before currentPosition";
483 483
484 allocator.assignSpillSlot(interval); 484 allocator.assignSpillSlot(interval);
485 handleSpillSlot(interval); 485 handleSpillSlot(interval);
486 allocator.changeSpillState(interval, minSplitPos); 486 changeSpillState(interval, minSplitPos);
487 487
488 // Also kick parent intervals out of register to memory when they have no use 488 // Also kick parent intervals out of register to memory when they have no use
489 // position. This avoids short interval in register surrounded by intervals in 489 // position. This avoids short interval in register surrounded by intervals in
490 // memory . avoid useless moves from memory to register and back 490 // memory . avoid useless moves from memory to register and back
491 Interval parent = interval; 491 Interval parent = interval;
527 assert !allocator.isBlockBegin(optimalSplitPos) || ((optimalSplitPos & 1) == 0) : "split pos must be even on block boundary"; 527 assert !allocator.isBlockBegin(optimalSplitPos) || ((optimalSplitPos & 1) == 0) : "split pos must be even on block boundary";
528 528
529 Interval spilledPart = interval.split(optimalSplitPos, allocator); 529 Interval spilledPart = interval.split(optimalSplitPos, allocator);
530 allocator.assignSpillSlot(spilledPart); 530 allocator.assignSpillSlot(spilledPart);
531 handleSpillSlot(spilledPart); 531 handleSpillSlot(spilledPart);
532 allocator.changeSpillState(spilledPart, optimalSplitPos); 532 changeSpillState(spilledPart, optimalSplitPos);
533 533
534 if (!allocator.isBlockBegin(optimalSplitPos)) { 534 if (!allocator.isBlockBegin(optimalSplitPos)) {
535 if (Debug.isLogEnabled()) { 535 if (Debug.isLogEnabled()) {
536 Debug.log("inserting move from interval %d to %d", interval.operandNumber, spilledPart.operandNumber); 536 Debug.log("inserting move from interval %d to %d", interval.operandNumber, spilledPart.operandNumber);
537 } 537 }
546 Debug.log("left interval: %s", interval.logString(allocator)); 546 Debug.log("left interval: %s", interval.logString(allocator));
547 Debug.log("spilled interval : %s", spilledPart.logString(allocator)); 547 Debug.log("spilled interval : %s", spilledPart.logString(allocator));
548 } 548 }
549 } 549 }
550 } 550 }
551 }
552 }
553
554 // called during register allocation
555 private void changeSpillState(Interval interval, int spillPos) {
556 switch (interval.spillState()) {
557 case NoSpillStore: {
558 int defLoopDepth = allocator.blockForId(interval.spillDefinitionPos()).getLoopDepth();
559 int spillLoopDepth = allocator.blockForId(spillPos).getLoopDepth();
560
561 if (defLoopDepth < spillLoopDepth) {
562 /*
563 * The loop depth of the spilling position is higher then the loop depth at the
564 * definition of the interval. Move write to memory out of loop.
565 */
566 if (LinearScan.Options.LSRAOptimizeSpillPosition.getValue()) {
567 // find best spill position in dominator the tree
568 interval.setSpillState(SpillState.SpillInDominator);
569 } else {
570 // store at definition of the interval
571 interval.setSpillState(SpillState.StoreAtDefinition);
572 }
573 } else {
574 /*
575 * The interval is currently spilled only once, so for now there is no reason to
576 * store the interval at the definition.
577 */
578 interval.setSpillState(SpillState.OneSpillStore);
579 }
580 break;
581 }
582
583 case OneSpillStore: {
584 if (LinearScan.Options.LSRAOptimizeSpillPosition.getValue()) {
585 // the interval is spilled more then once
586 interval.setSpillState(SpillState.SpillInDominator);
587 } else {
588 // It is better to store it to memory at the definition.
589 interval.setSpillState(SpillState.StoreAtDefinition);
590 }
591 break;
592 }
593
594 case SpillInDominator:
595 case StoreAtDefinition:
596 case StartInMemory:
597 case NoOptimization:
598 case NoDefinitionFound:
599 // nothing to do
600 break;
601
602 default:
603 throw new BailoutException("other states not allowed at this time");
551 } 604 }
552 } 605 }
553 606
554 /** 607 /**
555 * This is called for every interval that is assigned to a stack slot. 608 * This is called for every interval that is assigned to a stack slot.