# HG changeset patch # User Michael Haupt # Date 1366114005 -7200 # Node ID 5cabfd00241ef6df47219221e3822b1b5ab88f66 # Parent 0a8d5ca4379c967258896189032c84afa6d02a7f# Parent cf3c89ef00f7bd34edbd4aa05f1650451dce9d31 merge diff -r 0a8d5ca4379c -r 5cabfd00241e 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 Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Tue Apr 16 14:06:45 2013 +0200 @@ -132,7 +132,7 @@ if (GraalOptions.ConditionalElimination && GraalOptions.OptCanonicalizer) { new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); - new IterativeConditionalEliminationPhase(runtime, assumptions).apply(graph); + new IterativeConditionalEliminationPhase().apply(graph, highTierContext); } } } @@ -143,42 +143,8 @@ new LoweringPhase(target, runtime, replacements, assumptions).apply(graph); - if (GraalOptions.OptPushThroughPi) { - new PushThroughPiPhase().apply(graph); - if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); - } - } - - if (GraalOptions.OptFloatingReads) { - int mark = graph.getMark(); - new FloatingReadPhase().apply(graph); - new CanonicalizerPhase.Instance(runtime, assumptions, mark, null).apply(graph); - if (GraalOptions.OptReadElimination) { - new ReadEliminationPhase().apply(graph); - } - } - new RemoveValueProxyPhase().apply(graph); - - if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); - } - - if (GraalOptions.OptEliminatePartiallyRedundantGuards) { - new EliminatePartiallyRedundantGuardsPhase(false, true).apply(graph); - } - - if (GraalOptions.ConditionalElimination && GraalOptions.OptCanonicalizer) { - new IterativeConditionalEliminationPhase(runtime, assumptions).apply(graph); - } - - if (GraalOptions.OptEliminatePartiallyRedundantGuards) { - new EliminatePartiallyRedundantGuardsPhase(true, true).apply(graph); - } - - if (GraalOptions.OptCanonicalizer) { - new CanonicalizerPhase.Instance(runtime, assumptions).apply(graph); - } + MidTierContext midTierContext = new MidTierContext(runtime, assumptions); + Suites.DEFAULT.midTier.apply(graph, midTierContext); plan.runPhases(PhasePosition.MID_LEVEL, graph); diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/BasicConfiguration.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/BasicConfiguration.java Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/BasicConfiguration.java Tue Apr 16 14:06:45 2013 +0200 @@ -32,4 +32,8 @@ public PhaseSuite createHighTier() { return new HighTier(); } + + public PhaseSuite createMidTier() { + return new MidTier(); + } } diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/phases/MidTier.java Tue Apr 16 14:06:45 2013 +0200 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 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.compiler.phases; + +import com.oracle.graal.phases.*; +import com.oracle.graal.phases.common.*; +import com.oracle.graal.phases.tiers.*; + +public class MidTier extends PhaseSuite { + + public MidTier() { + if (GraalOptions.OptPushThroughPi) { + addPhase(new PushThroughPiPhase()); + if (GraalOptions.OptCanonicalizer) { + addPhase(new CanonicalizerPhase()); + } + } + + if (GraalOptions.OptFloatingReads) { + PartialCanonicalizerPhase canonicalizer = new PartialCanonicalizerPhase<>(); + canonicalizer.addPhase(new FloatingReadPhase()); + addPhase(canonicalizer); + if (GraalOptions.OptReadElimination) { + addPhase(new ReadEliminationPhase()); + } + } + addPhase(new RemoveValueProxyPhase()); + + if (GraalOptions.OptCanonicalizer) { + addPhase(new CanonicalizerPhase()); + } + + if (GraalOptions.OptEliminatePartiallyRedundantGuards) { + addPhase(new EliminatePartiallyRedundantGuardsPhase(false, true)); + } + + if (GraalOptions.ConditionalElimination && GraalOptions.OptCanonicalizer) { + addPhase(new IterativeConditionalEliminationPhase()); + } + + if (GraalOptions.OptEliminatePartiallyRedundantGuards) { + addPhase(new EliminatePartiallyRedundantGuardsPhase(true, true)); + } + + if (GraalOptions.OptCanonicalizer) { + addPhase(new CanonicalizerPhase()); + } + } +} diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java Tue Apr 16 14:06:45 2013 +0200 @@ -48,14 +48,24 @@ private static final DebugMetric METRIC_SIMPLIFICATION_CONSIDERED_NODES = Debug.metric("SimplificationConsideredNodes"); public static final DebugMetric METRIC_GLOBAL_VALUE_NUMBERING_HITS = Debug.metric("GlobalValueNumberingHits"); + private final CustomCanonicalizer customCanonicalizer; + public interface CustomCanonicalizer { ValueNode canonicalize(ValueNode node); } + public CanonicalizerPhase() { + this(null); + } + + public CanonicalizerPhase(CustomCanonicalizer customCanonicalizer) { + this.customCanonicalizer = customCanonicalizer; + } + @Override protected void run(StructuredGraph graph, PhaseContext context) { - new Instance(context.getRuntime(), context.getAssumptions()).run(graph); + new Instance(context.getRuntime(), context.getAssumptions(), null, customCanonicalizer).run(graph); } public static class Instance extends Phase { diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java Tue Apr 16 14:06:45 2013 +0200 @@ -71,15 +71,20 @@ } } - private final Map> modifiedInLoops = new IdentityHashMap<>(); - @Override protected void run(StructuredGraph graph) { - ReentrantNodeIterator.apply(new CollectMemoryCheckpointsClosure(), graph.start(), new HashSet<>(), null); - ReentrantNodeIterator.apply(new FloatingReadClosure(), graph.start(), new MemoryMap(graph.start()), null); + Map> modifiedInLoops = new IdentityHashMap<>(); + ReentrantNodeIterator.apply(new CollectMemoryCheckpointsClosure(modifiedInLoops), graph.start(), new HashSet<>(), null); + ReentrantNodeIterator.apply(new FloatingReadClosure(modifiedInLoops), graph.start(), new MemoryMap(graph.start()), null); } - private class CollectMemoryCheckpointsClosure extends NodeIteratorClosure> { + private static class CollectMemoryCheckpointsClosure extends NodeIteratorClosure> { + + private final Map> modifiedInLoops; + + public CollectMemoryCheckpointsClosure(Map> modifiedInLoops) { + this.modifiedInLoops = modifiedInLoops; + } @Override protected void processNode(FixedNode node, Set currentState) { @@ -122,7 +127,13 @@ } - private class FloatingReadClosure extends NodeIteratorClosure { + private static class FloatingReadClosure extends NodeIteratorClosure { + + private final Map> modifiedInLoops; + + public FloatingReadClosure(Map> modifiedInLoops) { + this.modifiedInLoops = modifiedInLoops; + } @Override protected void processNode(FixedNode node, MemoryMap state) { @@ -133,7 +144,7 @@ } } - private void processCheckpoint(MemoryCheckpoint checkpoint, MemoryMap state) { + private static void processCheckpoint(MemoryCheckpoint checkpoint, MemoryMap state) { for (Object identity : checkpoint.getLocationIdentities()) { if (identity == LocationNode.ANY_LOCATION) { state.lastMemorySnapshot.clear(); @@ -142,7 +153,7 @@ } } - private void processFloatable(FloatableAccessNode accessNode, MemoryMap state) { + private static void processFloatable(FloatableAccessNode accessNode, MemoryMap state) { StructuredGraph graph = (StructuredGraph) accessNode.graph(); assert accessNode.getNullCheck() == false; Object locationIdentity = accessNode.location().locationIdentity(); diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java Tue Apr 16 14:06:45 2013 +0200 @@ -24,27 +24,18 @@ import java.util.*; -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.Graph.InputChangedListener; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; import com.oracle.graal.phases.*; - -public class IterativeConditionalEliminationPhase extends Phase { +import com.oracle.graal.phases.tiers.*; - private final MetaAccessProvider runtime; - private final Assumptions assumptions; - - public IterativeConditionalEliminationPhase(MetaAccessProvider runtime, Assumptions assumptions) { - this.runtime = runtime; - this.assumptions = assumptions; - } +public class IterativeConditionalEliminationPhase extends BasePhase { @Override - protected void run(StructuredGraph graph) { + protected void run(StructuredGraph graph, PhaseContext context) { Set canonicalizationRoots = new HashSet<>(); - ConditionalEliminationPhase eliminate = new ConditionalEliminationPhase(runtime); + ConditionalEliminationPhase eliminate = new ConditionalEliminationPhase(context.getRuntime()); Listener listener = new Listener(canonicalizationRoots); while (true) { graph.trackInputChange(listener); @@ -53,7 +44,7 @@ if (canonicalizationRoots.isEmpty()) { break; } - new CanonicalizerPhase.Instance(runtime, assumptions, canonicalizationRoots, null).apply(graph); + new CanonicalizerPhase.Instance(context.getRuntime(), context.getAssumptions(), canonicalizationRoots, null).apply(graph); canonicalizationRoots.clear(); } } diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/PartialCanonicalizerPhase.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/PartialCanonicalizerPhase.java Tue Apr 16 14:06:45 2013 +0200 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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 com.oracle.graal.nodes.*; +import com.oracle.graal.phases.*; +import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer; +import com.oracle.graal.phases.tiers.*; + +public class PartialCanonicalizerPhase extends PhaseSuite { + + private final CustomCanonicalizer customCanonicalizer; + + public PartialCanonicalizerPhase() { + this(null); + } + + public PartialCanonicalizerPhase(CustomCanonicalizer customCanonicalizer) { + this.customCanonicalizer = customCanonicalizer; + } + + @Override + protected void run(StructuredGraph graph, C context) { + int mark = graph.getMark(); + super.run(graph, context); + new CanonicalizerPhase.Instance(context.getRuntime(), context.getAssumptions(), mark, customCanonicalizer).apply(graph); + } +} diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ReadEliminationPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ReadEliminationPhase.java Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ReadEliminationPhase.java Tue Apr 16 14:06:45 2013 +0200 @@ -22,8 +22,6 @@ */ package com.oracle.graal.phases.common; -import java.util.*; - import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; @@ -32,11 +30,8 @@ public class ReadEliminationPhase extends Phase { - private Queue newPhis; - @Override protected void run(StructuredGraph graph) { - newPhis = new LinkedList<>(); for (FloatingReadNode n : graph.getNodes(FloatingReadNode.class)) { if (isReadEliminable(n)) { NodeMap nodeMap = n.graph().createNodeMap(); @@ -47,11 +42,11 @@ } } - private boolean isReadEliminable(FloatingReadNode n) { + private static boolean isReadEliminable(FloatingReadNode n) { return isWrites(n, n.lastLocationAccess(), n.graph().createNodeBitMap()); } - private boolean isWrites(FloatingReadNode n, Node lastLocationAccess, NodeBitMap visited) { + private static boolean isWrites(FloatingReadNode n, Node lastLocationAccess, NodeBitMap visited) { if (lastLocationAccess == null) { return false; } @@ -77,7 +72,7 @@ return false; } - private ValueNode getValue(FloatingReadNode n, Node lastLocationAccess, NodeMap nodeMap) { + private static ValueNode getValue(FloatingReadNode n, Node lastLocationAccess, NodeMap nodeMap) { ValueNode exisiting = nodeMap.get(lastLocationAccess); if (exisiting != null) { return exisiting; @@ -97,7 +92,6 @@ for (ValueNode value : phi.values()) { newPhi.addInput(getValue(n, value, nodeMap)); } - newPhis.add(newPhi); return newPhi; } throw GraalInternalError.shouldNotReachHere(); diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.phases/src/com/oracle/graal/phases/PhaseSuite.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/PhaseSuite.java Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/PhaseSuite.java Tue Apr 16 14:06:45 2013 +0200 @@ -34,17 +34,17 @@ this.phases = new ArrayList<>(); } - protected final void addPhase(BasePhase phase) { + public final void addPhase(BasePhase phase) { phases.add(phase); } - protected final ListIterator> findPhase(Class> phaseClass) { + public final ListIterator> findPhase(Class> phaseClass) { ListIterator> it = phases.listIterator(); findNextPhase(it, phaseClass); return it; } - protected static void findNextPhase(ListIterator> it, Class> phaseClass) { + public static void findNextPhase(ListIterator> it, Class> phaseClass) { while (it.hasNext()) { BasePhase phase = it.next(); if (phaseClass.isInstance(phase)) { diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/CompilerConfiguration.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/CompilerConfiguration.java Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/CompilerConfiguration.java Tue Apr 16 14:06:45 2013 +0200 @@ -27,4 +27,6 @@ public interface CompilerConfiguration { PhaseSuite createHighTier(); + + PhaseSuite createMidTier(); } diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/MidTierContext.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/MidTierContext.java Tue Apr 16 14:06:45 2013 +0200 @@ -0,0 +1,33 @@ +/* + * Copyright (c) 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.tiers; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; + +public class MidTierContext extends PhaseContext { + + public MidTierContext(MetaAccessProvider runtime, Assumptions assumptions) { + super(runtime, assumptions); + } +} diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/Suites.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/Suites.java Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/tiers/Suites.java Tue Apr 16 14:06:45 2013 +0200 @@ -30,6 +30,7 @@ public final class Suites { public final PhaseSuite highTier; + public final PhaseSuite midTier; public static final Suites DEFAULT; @@ -50,6 +51,7 @@ private Suites(CompilerConfiguration config) { highTier = config.createHighTier(); + midTier = config.createMidTier(); } public static Suites createDefaultSuites() { diff -r 0a8d5ca4379c -r 5cabfd00241e graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/IterativeInliningPhase.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/IterativeInliningPhase.java Tue Apr 16 14:05:16 2013 +0200 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/IterativeInliningPhase.java Tue Apr 16 14:06:45 2013 +0200 @@ -84,7 +84,7 @@ if (GraalOptions.ConditionalElimination && GraalOptions.OptCanonicalizer) { new CanonicalizerPhase().apply(graph, context); - new IterativeConditionalEliminationPhase(context.getRuntime(), context.getAssumptions()).apply(graph); + new IterativeConditionalEliminationPhase().apply(graph, context); } return progress;