# HG changeset patch # User Josef Eisl # Date 1430924671 -7200 # Node ID 8ecb442fc8648c2314cc8423e4087c47342a1c2d # Parent 3bc3865789b16da839597ae6258d4308e591e53d LinearScan: split into sub-phases. diff -r 3bc3865789b1 -r 8ecb442fc864 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java Mon May 11 17:41:46 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScan.java Wed May 06 17:04:31 2015 +0200 @@ -50,6 +50,8 @@ import com.oracle.graal.lir.framemap.*; import com.oracle.graal.lir.gen.*; import com.oracle.graal.lir.gen.LIRGeneratorTool.SpillMoveFactory; +import com.oracle.graal.lir.phases.*; +import com.oracle.graal.lir.phases.AllocationPhase.AllocationContext; import com.oracle.graal.options.*; /** @@ -60,14 +62,13 @@ */ class LinearScan { - final TargetDescription target; final LIRGenerationResult res; final LIR ir; final FrameMapBuilder frameMapBuilder; - final SpillMoveFactory spillMoveFactory; final RegisterAttributes[] registerAttributes; final Register[] registers; final RegisterAllocationConfig regAllocConfig; + private final SpillMoveFactory moveFactory; final boolean callKillsRegisters; @@ -166,10 +167,9 @@ private final int firstVariableNumber; LinearScan(TargetDescription target, LIRGenerationResult res, SpillMoveFactory spillMoveFactory, RegisterAllocationConfig regAllocConfig) { - this.target = target; this.res = res; this.ir = res.getLIR(); - this.spillMoveFactory = spillMoveFactory; + this.moveFactory = spillMoveFactory; this.frameMapBuilder = res.getFrameMapBuilder(); this.sortedBlocks = ir.linearScanOrder(); this.registerAttributes = regAllocConfig.getRegisterConfig().getAttributesMap(); @@ -198,7 +198,7 @@ } SpillMoveFactory getSpillMoveFactory() { - return spillMoveFactory; + return moveFactory; } protected MoveResolver createMoveResolver() { @@ -1829,88 +1829,109 @@ } } - private static final DebugTimer lifetimeTimer = Debug.timer("LinearScan_LifetimeAnalysis"); - private static final DebugTimer registerAllocationTimer = Debug.timer("LinearScan_RegisterAllocation"); - private static final DebugTimer optimizedSpillPositionTimer = Debug.timer("LinearScan_OptimizeSpillPosition"); - private static final DebugTimer resolveDataFlowTimer = Debug.timer("LinearScan_ResolveDataFlow"); - private static final DebugTimer eliminateSpillMoveTimer = Debug.timer("LinearScan_EliminateSpillMove"); - private static final DebugTimer assignLocationsTimer = Debug.timer("LinearScan_AssignLocations"); - - void allocate() { + > void allocate(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, SpillMoveFactory spillMoveFactory) { /* * This is the point to enable debug logging for the whole register allocation. */ try (Indent indent = Debug.logAndIndent("LinearScan allocate")) { - - try (Scope s = Debug.scope("LifetimeAnalysis"); DebugCloseable a = lifetimeTimer.start()) { - numberInstructions(); - printLir("Before register allocation", true); - computeLocalLiveSets(); - computeGlobalLiveSets(); - buildIntervals(); - sortIntervalsBeforeAllocation(); - } catch (Throwable e) { - throw Debug.handle(e); - } + AllocationContext context = new AllocationContext(spillMoveFactory); - try (Scope s = Debug.scope("RegisterAllocation"); DebugCloseable a = registerAllocationTimer.start()) { - printIntervals("Before register allocation"); - allocateRegisters(); - } catch (Throwable e) { - throw Debug.handle(e); + new LifetimeAnalysis().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); + new RegisterAllocation().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); + if (LinearScan.Options.LSRAOptimizeSpillPosition.getValue()) { + new OptimizeSpillPosition().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); } + new ResolveDataFlow().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); - if (Options.LSRAOptimizeSpillPosition.getValue()) { - try (Scope s = Debug.scope("OptimizeSpillPosition"); DebugCloseable a = optimizedSpillPositionTimer.start()) { - optimizeSpillPosition(); - } catch (Throwable e) { - throw Debug.handle(e); - } + printIntervals("After register allocation"); + printLir("After register allocation", true); + + sortIntervalsAfterAllocation(); + + if (DetailedAsserts.getValue()) { + verify(); } - try (Scope s = Debug.scope("ResolveDataFlow"); DebugCloseable a = resolveDataFlowTimer.start()) { - resolveDataFlow(); - } catch (Throwable e) { - throw Debug.handle(e); - } - - try (Scope s = Debug.scope("DebugInfo")) { - printIntervals("After register allocation"); - printLir("After register allocation", true); - - sortIntervalsAfterAllocation(); - - if (DetailedAsserts.getValue()) { - verify(); - } - - beforeSpillMoveElimination(); + new EliminateSpillMove().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); + new AssignLocations().apply(target, lirGenRes, codeEmittingOrder, linearScanOrder, context); - try (Scope s1 = Debug.scope("EliminateSpillMove"); DebugCloseable a = eliminateSpillMoveTimer.start()) { - eliminateSpillMoves(); - } catch (Throwable e) { - throw Debug.handle(e); - } - printLir("After spill move elimination", true); - - try (Scope s1 = Debug.scope("AssignLocations"); DebugCloseable a = assignLocationsTimer.start()) { - assignLocations(); - } catch (Throwable e) { - throw Debug.handle(e); - } - - if (DetailedAsserts.getValue()) { - verifyIntervals(); - } - } catch (Throwable e) { - throw Debug.handle(e); + if (DetailedAsserts.getValue()) { + verifyIntervals(); } printLir("After register number assignment", true); } } + private final class LifetimeAnalysis extends AllocationPhase { + + @Override + protected > void run(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, + SpillMoveFactory spillMoveFactory) { + numberInstructions(); + printLir("Before register allocation", true); + computeLocalLiveSets(); + computeGlobalLiveSets(); + buildIntervals(); + sortIntervalsBeforeAllocation(); + } + + } + + private final class RegisterAllocation extends AllocationPhase { + + @Override + protected > void run(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, + SpillMoveFactory spillMoveFactory) { + printIntervals("Before register allocation"); + allocateRegisters(); + } + + } + + private final class OptimizeSpillPosition extends AllocationPhase { + + @Override + protected > void run(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, + SpillMoveFactory spillMoveFactory) { + optimizeSpillPosition(); + } + + } + + private final class ResolveDataFlow extends AllocationPhase { + + @Override + protected > void run(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, + SpillMoveFactory spillMoveFactory) { + resolveDataFlow(); + } + + } + + private final class EliminateSpillMove extends AllocationPhase { + + @Override + protected > void run(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, + SpillMoveFactory spillMoveFactory) { + beforeSpillMoveElimination(); + eliminateSpillMoves(); + printLir("After spill move elimination", true); + } + + } + + private final class AssignLocations extends AllocationPhase { + + @Override + protected > void run(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, + SpillMoveFactory spillMoveFactory) { + assignLocations(); + } + + } + protected void beforeSpillMoveElimination() { } diff -r 3bc3865789b1 -r 8ecb442fc864 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanPhase.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanPhase.java Mon May 11 17:41:46 2015 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/alloc/lsra/LinearScanPhase.java Wed May 06 17:04:31 2015 +0200 @@ -49,11 +49,13 @@ @Override protected > void run(TargetDescription target, LIRGenerationResult lirGenRes, List codeEmittingOrder, List linearScanOrder, SpillMoveFactory spillMoveFactory) { + final LinearScan allocator; if (LinearScanPhase.SSA_LSRA.getValue()) { - new SSALinearScan(target, lirGenRes, spillMoveFactory, new RegisterAllocationConfig(lirGenRes.getFrameMapBuilder().getRegisterConfig())).allocate(); + allocator = new SSALinearScan(target, lirGenRes, spillMoveFactory, new RegisterAllocationConfig(lirGenRes.getFrameMapBuilder().getRegisterConfig())); } else { - new LinearScan(target, lirGenRes, spillMoveFactory, new RegisterAllocationConfig(lirGenRes.getFrameMapBuilder().getRegisterConfig())).allocate(); + allocator = new LinearScan(target, lirGenRes, spillMoveFactory, new RegisterAllocationConfig(lirGenRes.getFrameMapBuilder().getRegisterConfig())); } + allocator.allocate(target, lirGenRes, codeEmittingOrder, linearScanOrder, spillMoveFactory); } }