434 // insert new instruction before instruction at position index
435 moveResolver.moveInsertPosition(instructions, index);
436 moveResolver.addMapping(srcIt, dstIt);
437 }
438
439 private int findOptimalSplitPos(AbstractBlockBase<?> minBlock, AbstractBlockBase<?> maxBlock, int maxSplitPos) {
440 int fromBlockNr = minBlock.getLinearScanNumber();
441 int toBlockNr = maxBlock.getLinearScanNumber();
442
443 assert 0 <= fromBlockNr && fromBlockNr < blockCount() : "out of range";
444 assert 0 <= toBlockNr && toBlockNr < blockCount() : "out of range";
445 assert fromBlockNr < toBlockNr : "must cross block boundary";
446
447 // Try to split at end of maxBlock. If this would be after
448 // maxSplitPos, then use the begin of maxBlock
449 int optimalSplitPos = allocator.getLastLirInstructionId(maxBlock) + 2;
450 if (optimalSplitPos > maxSplitPos) {
451 optimalSplitPos = allocator.getFirstLirInstructionId(maxBlock);
452 }
453
454 // minimal block probability
455 double minProbability = maxBlock.probability();
456 for (int i = toBlockNr - 1; i >= fromBlockNr; i--) {
457 AbstractBlockBase<?> cur = blockAt(i);
458
459 if (cur.probability() < minProbability) {
460 // Block with lower probability found. Split at the end of this block.
461 minProbability = cur.probability();
462 optimalSplitPos = allocator.getLastLirInstructionId(cur) + 2;
463 }
464 }
465 assert optimalSplitPos > allocator.maxOpId() || allocator.isBlockBegin(optimalSplitPos) : "algorithm must move split pos to block boundary";
466
467 return optimalSplitPos;
468 }
469
470 @SuppressWarnings({"unused"})
471 private int findOptimalSplitPos(TraceInterval interval, int minSplitPos, int maxSplitPos, boolean doLoopOptimization) {
472 int optimalSplitPos = findOptimalSplitPos0(minSplitPos, maxSplitPos);
473 if (debug.isLogEnabled()) {
474 debug.log("optimal split position: %d", optimalSplitPos);
475 }
476 return optimalSplitPos;
477 }
478
479 private int findOptimalSplitPos0(int minSplitPos, int maxSplitPos) {
480 if (minSplitPos == maxSplitPos) {
481 // trivial case, no optimization of split position possible
839 }
840
841 private int findOptimalSpillPos(AbstractBlockBase<?> minBlock, AbstractBlockBase<?> maxBlock, int maxSplitPos) {
842 int fromBlockNr = minBlock.getLinearScanNumber();
843 int toBlockNr = maxBlock.getLinearScanNumber();
844
845 assert 0 <= fromBlockNr && fromBlockNr < blockCount() : "out of range";
846 assert 0 <= toBlockNr && toBlockNr < blockCount() : "out of range";
847 assert fromBlockNr < toBlockNr : "must cross block boundary";
848
849 /*
850 * Try to split at end of maxBlock. We use last instruction -2 because we want to insert the
851 * move before the block end op. If this would be after maxSplitPos, then use the
852 * maxSplitPos.
853 */
854 int optimalSplitPos = allocator.getLastLirInstructionId(maxBlock) - 2;
855 if (optimalSplitPos > maxSplitPos) {
856 optimalSplitPos = maxSplitPos;
857 }
858
859 // minimal block probability
860 double minProbability = maxBlock.probability();
861 for (int i = toBlockNr - 1; i >= fromBlockNr; i--) {
862 AbstractBlockBase<?> cur = blockAt(i);
863
864 if (cur.probability() < minProbability) {
865 // Block with lower probability found. Split at the end of this block.
866 int opIdBeforeBlockEnd = allocator.getLastLirInstructionId(cur) - 2;
867 if (allocator.getLIR().getLIRforBlock(cur).size() > 2) {
868 minProbability = cur.probability();
869 optimalSplitPos = opIdBeforeBlockEnd;
870 } else {
871 /*
872 * Skip blocks with only LabelOp and BlockEndOp since they cause move ordering
873 * problems.
874 */
875 assert allocator.isBlockBegin(opIdBeforeBlockEnd);
876 }
877 }
878 }
879 assert optimalSplitPos > allocator.maxOpId() || optimalSplitPos == maxSplitPos || allocator.isBlockEnd(optimalSplitPos + 2) : "algorithm must move split pos to block boundary";
880 assert !allocator.isBlockBegin(optimalSplitPos);
881 return optimalSplitPos;
882 }
883
884 /**
885 * This is called for every interval that is assigned to a stack slot.
886 */
887 private static void handleSpillSlot(TraceInterval interval) {
888 assert interval.location() != null && (interval.canMaterialize() || isStackSlotValue(interval.location())) : "interval not assigned to a stack slot " + interval;
|
434 // insert new instruction before instruction at position index
435 moveResolver.moveInsertPosition(instructions, index);
436 moveResolver.addMapping(srcIt, dstIt);
437 }
438
439 private int findOptimalSplitPos(AbstractBlockBase<?> minBlock, AbstractBlockBase<?> maxBlock, int maxSplitPos) {
440 int fromBlockNr = minBlock.getLinearScanNumber();
441 int toBlockNr = maxBlock.getLinearScanNumber();
442
443 assert 0 <= fromBlockNr && fromBlockNr < blockCount() : "out of range";
444 assert 0 <= toBlockNr && toBlockNr < blockCount() : "out of range";
445 assert fromBlockNr < toBlockNr : "must cross block boundary";
446
447 // Try to split at end of maxBlock. If this would be after
448 // maxSplitPos, then use the begin of maxBlock
449 int optimalSplitPos = allocator.getLastLirInstructionId(maxBlock) + 2;
450 if (optimalSplitPos > maxSplitPos) {
451 optimalSplitPos = allocator.getFirstLirInstructionId(maxBlock);
452 }
453
454 // minimal block frequency
455 double minFrequency = maxBlock.getRelativeFrequency();
456 for (int i = toBlockNr - 1; i >= fromBlockNr; i--) {
457 AbstractBlockBase<?> cur = blockAt(i);
458
459 if (cur.getRelativeFrequency() < minFrequency) {
460 // Block with lower frequency found. Split at the end of this block.
461 minFrequency = cur.getRelativeFrequency();
462 optimalSplitPos = allocator.getLastLirInstructionId(cur) + 2;
463 }
464 }
465 assert optimalSplitPos > allocator.maxOpId() || allocator.isBlockBegin(optimalSplitPos) : "algorithm must move split pos to block boundary";
466
467 return optimalSplitPos;
468 }
469
470 @SuppressWarnings({"unused"})
471 private int findOptimalSplitPos(TraceInterval interval, int minSplitPos, int maxSplitPos, boolean doLoopOptimization) {
472 int optimalSplitPos = findOptimalSplitPos0(minSplitPos, maxSplitPos);
473 if (debug.isLogEnabled()) {
474 debug.log("optimal split position: %d", optimalSplitPos);
475 }
476 return optimalSplitPos;
477 }
478
479 private int findOptimalSplitPos0(int minSplitPos, int maxSplitPos) {
480 if (minSplitPos == maxSplitPos) {
481 // trivial case, no optimization of split position possible
839 }
840
841 private int findOptimalSpillPos(AbstractBlockBase<?> minBlock, AbstractBlockBase<?> maxBlock, int maxSplitPos) {
842 int fromBlockNr = minBlock.getLinearScanNumber();
843 int toBlockNr = maxBlock.getLinearScanNumber();
844
845 assert 0 <= fromBlockNr && fromBlockNr < blockCount() : "out of range";
846 assert 0 <= toBlockNr && toBlockNr < blockCount() : "out of range";
847 assert fromBlockNr < toBlockNr : "must cross block boundary";
848
849 /*
850 * Try to split at end of maxBlock. We use last instruction -2 because we want to insert the
851 * move before the block end op. If this would be after maxSplitPos, then use the
852 * maxSplitPos.
853 */
854 int optimalSplitPos = allocator.getLastLirInstructionId(maxBlock) - 2;
855 if (optimalSplitPos > maxSplitPos) {
856 optimalSplitPos = maxSplitPos;
857 }
858
859 // minimal block frequency
860 double minFrequency = maxBlock.getRelativeFrequency();
861 for (int i = toBlockNr - 1; i >= fromBlockNr; i--) {
862 AbstractBlockBase<?> cur = blockAt(i);
863
864 if (cur.getRelativeFrequency() < minFrequency) {
865 // Block with lower frequency found. Split at the end of this block.
866 int opIdBeforeBlockEnd = allocator.getLastLirInstructionId(cur) - 2;
867 if (allocator.getLIR().getLIRforBlock(cur).size() > 2) {
868 minFrequency = cur.getRelativeFrequency();
869 optimalSplitPos = opIdBeforeBlockEnd;
870 } else {
871 /*
872 * Skip blocks with only LabelOp and BlockEndOp since they cause move ordering
873 * problems.
874 */
875 assert allocator.isBlockBegin(opIdBeforeBlockEnd);
876 }
877 }
878 }
879 assert optimalSplitPos > allocator.maxOpId() || optimalSplitPos == maxSplitPos || allocator.isBlockEnd(optimalSplitPos + 2) : "algorithm must move split pos to block boundary";
880 assert !allocator.isBlockBegin(optimalSplitPos);
881 return optimalSplitPos;
882 }
883
884 /**
885 * This is called for every interval that is assigned to a stack slot.
886 */
887 private static void handleSpillSlot(TraceInterval interval) {
888 assert interval.location() != null && (interval.canMaterialize() || isStackSlotValue(interval.location())) : "interval not assigned to a stack slot " + interval;
|