# HG changeset patch # User Josef Eisl # Date 1394471935 -3600 # Node ID d2030fa96c228dd16224be324ac11df563b2092a # Parent 452bb6e732984e0d9ccd71f4e24854f51c304d2e Compute LinearScanOrder in emitLIR. diff -r 452bb6e73298 -r d2030fa96c22 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/backend/AllocatorTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/backend/AllocatorTest.java Thu Mar 06 11:00:50 2014 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/backend/AllocatorTest.java Mon Mar 10 18:18:55 2014 +0100 @@ -33,6 +33,7 @@ import com.oracle.graal.api.code.CallingConvention.Type; import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.*; +import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.test.*; import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; @@ -42,6 +43,7 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.cfg.*; import com.oracle.graal.phases.*; +import com.oracle.graal.phases.schedule.*; public class AllocatorTest extends GraalCompilerTest { @@ -109,20 +111,16 @@ private RegisterStats getRegisterStats(final StructuredGraph graph) { final Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); - LIR lir = null; + SchedulePhase schedule = null; try (Scope s = Debug.scope("FrontEnd")) { - lir = GraalCompiler.emitHIR(getProviders(), getBackend().getTarget(), graph, assumptions, null, getDefaultGraphBuilderSuite(), OptimisticOptimizations.NONE, + schedule = GraalCompiler.emitHIR(getProviders(), getBackend().getTarget(), graph, assumptions, null, getDefaultGraphBuilderSuite(), OptimisticOptimizations.NONE, graph.method().getProfilingInfo(), new SpeculationLog(), getSuites()); } catch (Throwable e) { throw Debug.handle(e); } - try (Scope s = Debug.scope("BackEnd", lir)) { - CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false); - GraalCompiler.emitLIR(getBackend(), getBackend().getTarget(), lir, graph, cc); - return new RegisterStats(lir); - } catch (Throwable e) { - throw Debug.handle(e); - } + CallingConvention cc = getCallingConvention(getCodeCache(), Type.JavaCallee, graph.method(), false); + LIRGenerator lirGen = GraalCompiler.emitLIR(getBackend(), getBackend().getTarget(), schedule, graph, cc); + return new RegisterStats(lirGen.lir); } } diff -r 452bb6e73298 -r d2030fa96c22 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Mar 06 11:00:50 2014 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Mon Mar 10 18:18:55 2014 +0100 @@ -141,19 +141,15 @@ assert !graph.isFrozen(); try (Scope s0 = withScope ? Debug.scope("GraalCompiler", graph, providers.getCodeCache()) : null) { Assumptions assumptions = new Assumptions(OptAssumptions.getValue()); - LIR lir = null; + SchedulePhase schedule = null; try (Scope s = Debug.scope("FrontEnd"); TimerCloseable a = FrontEnd.start()) { - lir = emitHIR(providers, target, graph, assumptions, cache, graphBuilderSuite, optimisticOpts, profilingInfo, speculationLog, suites); + schedule = emitHIR(providers, target, graph, assumptions, cache, graphBuilderSuite, optimisticOpts, profilingInfo, speculationLog, suites); } catch (Throwable e) { throw Debug.handle(e); } try (TimerCloseable a = BackEnd.start()) { LIRGenerator lirGen = null; - try (Scope s = Debug.scope("BackEnd", lir)) { - lirGen = emitLIR(backend, target, lir, graph, cc); - } catch (Throwable e) { - throw Debug.handle(e); - } + lirGen = emitLIR(backend, target, schedule, graph, cc); try (Scope s = Debug.scope("CodeGen", lirGen)) { emitCode(backend, getLeafGraphIdArray(graph), assumptions, lirGen, compilationResult, installedCodeOwner, factory); } catch (Throwable e) { @@ -189,7 +185,7 @@ /** * Builds the graph, optimizes it. */ - public static LIR emitHIR(Providers providers, TargetDescription target, StructuredGraph graph, Assumptions assumptions, GraphCache cache, PhaseSuite graphBuilderSuite, + public static SchedulePhase emitHIR(Providers providers, TargetDescription target, StructuredGraph graph, Assumptions assumptions, GraphCache cache, PhaseSuite graphBuilderSuite, OptimisticOptimizations optimisticOpts, ProfilingInfo profilingInfo, SpeculationLog speculationLog, Suites suites) { if (speculationLog != null) { @@ -223,23 +219,7 @@ SchedulePhase schedule = new SchedulePhase(); schedule.apply(graph); Debug.dump(schedule, "final schedule"); - - Block[] blocks = schedule.getCFG().getBlocks(); - Block startBlock = schedule.getCFG().getStartBlock(); - assert startBlock != null; - assert startBlock.getPredecessorCount() == 0; - - try (Scope s = Debug.scope("ComputeLinearScanOrder")) { - NodesToDoubles nodeProbabilities = new ComputeProbabilityClosure(graph).apply(); - List codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock, nodeProbabilities); - List linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock, nodeProbabilities); - - LIR lir = new LIR(schedule.getCFG(), schedule.getBlockToNodesMap(), linearScanOrder, codeEmittingOrder); - Debug.dump(lir, "After linear scan order"); - return lir; - } catch (Throwable e) { - throw Debug.handle(e); - } + return schedule; } @@ -254,42 +234,66 @@ } } - public static LIRGenerator emitLIR(Backend backend, TargetDescription target, LIR lir, StructuredGraph graph, CallingConvention cc) { - FrameMap frameMap = backend.newFrameMap(); - LIRGenerator lirGen = backend.newLIRGenerator(graph, frameMap, cc, lir); + public static LIRGenerator emitLIR(Backend backend, TargetDescription target, SchedulePhase schedule, StructuredGraph graph, CallingConvention cc) { + Block[] blocks = schedule.getCFG().getBlocks(); + Block startBlock = schedule.getCFG().getStartBlock(); + assert startBlock != null; + assert startBlock.getPredecessorCount() == 0; - try (Scope s = Debug.scope("LIRGen", lirGen)) { - for (Block b : lir.linearScanOrder()) { - emitBlock(lirGen, b); - } - lirGen.beforeRegisterAllocation(); + LIR lir = null; + try (Scope ds = Debug.scope("MidEnd")) { + try (Scope s = Debug.scope("ComputeLinearScanOrder")) { + NodesToDoubles nodeProbabilities = new ComputeProbabilityClosure(graph).apply(); + List codeEmittingOrder = ComputeBlockOrder.computeCodeEmittingOrder(blocks.length, startBlock, nodeProbabilities); + List linearScanOrder = ComputeBlockOrder.computeLinearScanOrder(blocks.length, startBlock, nodeProbabilities); - Debug.dump(lir, "After LIR generation"); - } catch (Throwable e) { - throw Debug.handle(e); - } - - try (Scope s = Debug.scope("Allocator", lirGen)) { - if (backend.shouldAllocateRegisters()) { - new LinearScan(target, lir, frameMap).allocate(); + lir = new LIR(schedule.getCFG(), schedule.getBlockToNodesMap(), linearScanOrder, codeEmittingOrder); + Debug.dump(lir, "After linear scan order"); + } catch (Throwable e) { + throw Debug.handle(e); } } catch (Throwable e) { throw Debug.handle(e); } + try (Scope ds = Debug.scope("BackEnd", lir)) { + FrameMap frameMap = backend.newFrameMap(); + LIRGenerator lirGen = backend.newLIRGenerator(graph, frameMap, cc, lir); - try (Scope s = Debug.scope("ControlFlowOptimizations")) { - EdgeMoveOptimizer.optimize(lir); - ControlFlowOptimizer.optimize(lir); - if (lirGen.canEliminateRedundantMoves()) { - RedundantMoveElimination.optimize(lir, frameMap, lirGen.getGraph().method()); + try (Scope s = Debug.scope("LIRGen", lirGen)) { + for (Block b : lir.linearScanOrder()) { + emitBlock(lirGen, b); + } + lirGen.beforeRegisterAllocation(); + + Debug.dump(lir, "After LIR generation"); + } catch (Throwable e) { + throw Debug.handle(e); } - NullCheckOptimizer.optimize(lir, target.implicitNullCheckLimit); + + try (Scope s = Debug.scope("Allocator", lirGen)) { + if (backend.shouldAllocateRegisters()) { + new LinearScan(target, lir, frameMap).allocate(); + } + } catch (Throwable e) { + throw Debug.handle(e); + } - Debug.dump(lir, "After control flow optimization"); + try (Scope s = Debug.scope("ControlFlowOptimizations")) { + EdgeMoveOptimizer.optimize(lir); + ControlFlowOptimizer.optimize(lir); + if (lirGen.canEliminateRedundantMoves()) { + RedundantMoveElimination.optimize(lir, frameMap, lirGen.getGraph().method()); + } + NullCheckOptimizer.optimize(lir, target.implicitNullCheckLimit); + + Debug.dump(lir, "After control flow optimization"); + } catch (Throwable e) { + throw Debug.handle(e); + } + return lirGen; } catch (Throwable e) { throw Debug.handle(e); } - return lirGen; } public static void emitCode(Backend backend, long[] leafGraphIds, Assumptions assumptions, LIRGenerator lirGen, CompilationResult compilationResult, ResolvedJavaMethod installedCodeOwner,