# HG changeset patch # User Gilles Duboscq # Date 1362663369 -3600 # Node ID ed880b9992b4e0be522bccd7570e411c6b9df791 # Parent 22429580c7a8866c4461f11753c9e4efabbfa88c Add GuardLoweringPhase which transforms floating guards into fixed if+deopt Minor cleanup in SchedulePhase diff -r 22429580c7a8 -r ed880b9992b4 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 07 14:35:03 2013 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Mar 07 14:36:09 2013 +0100 @@ -193,6 +193,8 @@ plan.runPhases(PhasePosition.LOW_LEVEL, graph); + new GuardLoweringPhase().apply(graph); + // Add safepoints to loops new SafepointInsertionPhase().apply(graph); diff -r 22429580c7a8 -r ed880b9992b4 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/GuardLoweringPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/GuardLoweringPhase.java Thu Mar 07 14:36:09 2013 +0100 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2013, 2013, 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.phases.common; + +import java.util.*; + +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.cfg.*; +import com.oracle.graal.phases.*; +import com.oracle.graal.phases.schedule.*; + +public class GuardLoweringPhase extends Phase { + + @Override + protected void run(StructuredGraph graph) { + SchedulePhase schedule = new SchedulePhase(); + schedule.apply(graph); + + for (Block block : schedule.getCFG().getBlocks()) { + processBlock(block, schedule, graph); + } + } + + private static void processBlock(Block block, SchedulePhase schedule, StructuredGraph graph) { + List nodes = schedule.nodesFor(block); + FixedWithNextNode lastFixed = block.getBeginNode(); + BeginNode lastFastPath = null; + for (Node node : nodes) { + if (lastFastPath != null && node instanceof FixedNode) { + lastFastPath.setNext((FixedNode) node); + lastFastPath = null; + } + if (node instanceof FixedWithNextNode) { + lastFixed = (FixedWithNextNode) node; + } else if (node instanceof GuardNode) { + GuardNode guard = (GuardNode) node; + BeginNode fastPath = graph.add(new BeginNode()); + BeginNode trueSuccessor; + BeginNode falseSuccessor; + DeoptimizeNode deopt = graph.add(new DeoptimizeNode(guard.action(), guard.reason())); + if (guard.negated()) { + trueSuccessor = BeginNode.begin(deopt); + falseSuccessor = fastPath; + } else { + trueSuccessor = fastPath; + falseSuccessor = BeginNode.begin(deopt); + } + IfNode ifNode = graph.add(new IfNode(guard.condition(), trueSuccessor, falseSuccessor, trueSuccessor == fastPath ? 1 : 0)); + guard.replaceAndDelete(fastPath); + lastFixed.setNext(ifNode); + lastFixed = fastPath; + lastFastPath = fastPath; + } + } + } +} diff -r 22429580c7a8 -r ed880b9992b4 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Thu Mar 07 14:35:03 2013 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Thu Mar 07 14:36:09 2013 +0100 @@ -45,7 +45,7 @@ /** * This closure iterates over all nodes of a scheduled graph (it expects a - * {@link SchedulingStrategy#EARLIEST} schedule) and keeps a list of "actuve" reads. Whenever it + * {@link SchedulingStrategy#EARLIEST} schedule) and keeps a list of "active" reads. Whenever it * encounters a read, it adds it to the active reads. Whenever it encounters a memory * checkpoint, it adds all reads that need to be committed before this checkpoint to the * "phantom" usages and inputs, so that the read is scheduled before the checkpoint afterwards. @@ -135,10 +135,6 @@ private final Map> phantomUsages = new IdentityHashMap<>(); private final Map> phantomInputs = new IdentityHashMap<>(); - public SchedulePhase() { - super("Schedule"); - } - @Override protected void run(StructuredGraph graph) { SchedulingStrategy strategy = GraalOptions.OptScheduleOutOfLoops ? SchedulingStrategy.LATEST_OUT_OF_LOOPS : SchedulingStrategy.LATEST;