# HG changeset patch # User Doug Simon # Date 1335169637 -7200 # Node ID a44b5ebb28a022b1800c3d411213bf367ca3a153 # Parent e7f3f05414291e5b4f10b39e1f03011808c8e23b moved loop safepoint insertion from graph building to just before scheduling, removing the need for safepoint elimination diff -r e7f3f0541429 -r a44b5ebb28a0 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 Fri Apr 20 15:12:10 2012 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Mon Apr 23 10:27:17 2012 +0200 @@ -170,9 +170,6 @@ if (GraalOptions.OptLoopTransform) { new LoopTransformPhase().apply(graph); } - if (GraalOptions.OptSafepointElimination) { - new SafepointPollingEliminationPhase().apply(graph); - } } new RemoveValueProxyPhase().apply(graph); if (GraalOptions.OptCanonicalizer) { @@ -211,6 +208,11 @@ plan.runPhases(PhasePosition.LOW_LEVEL, graph); + // Add safepoints to loops + if (GraalOptions.GenLoopSafepoints) { + new LoopSafepointInsertionPhase().apply(graph); + } + final SchedulePhase schedule = new SchedulePhase(); schedule.apply(graph); Debug.dump(schedule, "final schedule"); diff -r e7f3f0541429 -r a44b5ebb28a0 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopSafepointInsertionPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/LoopSafepointInsertionPhase.java Mon Apr 23 10:27:17 2012 +0200 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.compiler.phases; + +import com.oracle.graal.compiler.*; +import com.oracle.graal.graph.iterators.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.util.*; + +/** + * Adds safepoints to loops. + */ +public class LoopSafepointInsertionPhase extends Phase { + + @Override + protected void run(StructuredGraph graph) { + nextLoop: + for (LoopEndNode loopEnd : graph.getNodes(LoopEndNode.class)) { + if (GraalOptions.OptSafepointElimination) { + // We 'eliminate' safepoints by simply never placing them into loops that have at least one call + NodeIterable it = NodeIterators.dominators(loopEnd).until(loopEnd.loopBegin()); + for (FixedNode n : it) { + if (n instanceof Invoke) { + continue nextLoop; + } + } + } + SafepointNode safepoint = graph.add(new SafepointNode()); + graph.addBeforeFixed(loopEnd, safepoint); + } + } +} diff -r e7f3f0541429 -r a44b5ebb28a0 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/SafepointPollingEliminationPhase.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/SafepointPollingEliminationPhase.java Fri Apr 20 15:12:10 2012 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.graal.compiler.phases; - -import com.oracle.graal.graph.iterators.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.util.*; - -/** - * Removes safepoints from loops that include calls. - * This optimization is conservative; it does not try to remove safepoints from outer loops. - */ -public class SafepointPollingEliminationPhase extends Phase { - - @Override - protected void run(StructuredGraph graph) { - for (SafepointNode safepoint : graph.getNodes(SafepointNode.class)) { - LoopEndNode loopEnd = safepoint.loopEnd(); - if (loopEnd != null) { - NodeIterable it = NodeIterators.dominators(loopEnd).until(loopEnd.loopBegin()); - for (FixedNode n : it) { - if (n instanceof Invoke) { - graph.removeFixed(safepoint); - break; - } - } - } - } - } -} diff -r e7f3f0541429 -r a44b5ebb28a0 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Fri Apr 20 15:12:10 2012 +0200 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Mon Apr 23 10:27:17 2012 +0200 @@ -186,14 +186,6 @@ currentGraph.removeFixed(n); } - // Add safepoints to loop ends - if (GraalOptions.GenLoopSafepoints) { - for (LoopEndNode loopEnd : currentGraph.getNodes(LoopEndNode.class)) { - SafepointNode safepoint = currentGraph.add(new SafepointNode()); - currentGraph.addBeforeFixed(loopEnd, safepoint); - } - } - // remove dead FrameStates for (Node n : currentGraph.getNodes(FrameState.class)) { if (n.usages().size() == 0 && n.predecessor() == null) {