Mercurial > hg > graal-compiler
changeset 9141:5cabfd00241e
merge
author | Michael Haupt <michael.haupt@oracle.com> |
---|---|
date | Tue, 16 Apr 2013 14:06:45 +0200 |
parents | 0a8d5ca4379c (current diff) cf3c89ef00f7 (diff) |
children | e178e4598f85 febfb532ed2f |
files | |
diffstat | 13 files changed, 203 insertions(+), 73 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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<HighTierContext> createHighTier() { return new HighTier(); } + + public PhaseSuite<MidTierContext> createMidTier() { + return new MidTier(); + } }
--- /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<MidTierContext> { + + public MidTier() { + if (GraalOptions.OptPushThroughPi) { + addPhase(new PushThroughPiPhase()); + if (GraalOptions.OptCanonicalizer) { + addPhase(new CanonicalizerPhase()); + } + } + + if (GraalOptions.OptFloatingReads) { + PartialCanonicalizerPhase<MidTierContext> 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()); + } + } +}
--- 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 {
--- 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<LoopBeginNode, Set<Object>> 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<LoopBeginNode, Set<Object>> 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<Set<Object>> { + private static class CollectMemoryCheckpointsClosure extends NodeIteratorClosure<Set<Object>> { + + private final Map<LoopBeginNode, Set<Object>> modifiedInLoops; + + public CollectMemoryCheckpointsClosure(Map<LoopBeginNode, Set<Object>> modifiedInLoops) { + this.modifiedInLoops = modifiedInLoops; + } @Override protected void processNode(FixedNode node, Set<Object> currentState) { @@ -122,7 +127,13 @@ } - private class FloatingReadClosure extends NodeIteratorClosure<MemoryMap> { + private static class FloatingReadClosure extends NodeIteratorClosure<MemoryMap> { + + private final Map<LoopBeginNode, Set<Object>> modifiedInLoops; + + public FloatingReadClosure(Map<LoopBeginNode, Set<Object>> 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();
--- 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<PhaseContext> { @Override - protected void run(StructuredGraph graph) { + protected void run(StructuredGraph graph, PhaseContext context) { Set<Node> 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(); } }
--- /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<C extends PhaseContext> extends PhaseSuite<C> { + + 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); + } +}
--- 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<PhiNode> newPhis; - @Override protected void run(StructuredGraph graph) { - newPhis = new LinkedList<>(); for (FloatingReadNode n : graph.getNodes(FloatingReadNode.class)) { if (isReadEliminable(n)) { NodeMap<ValueNode> 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<ValueNode> nodeMap) { + private static ValueNode getValue(FloatingReadNode n, Node lastLocationAccess, NodeMap<ValueNode> 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();
--- 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<? super C> phase) { + public final void addPhase(BasePhase<? super C> phase) { phases.add(phase); } - protected final ListIterator<BasePhase<? super C>> findPhase(Class<? extends BasePhase<? super C>> phaseClass) { + public final ListIterator<BasePhase<? super C>> findPhase(Class<? extends BasePhase<? super C>> phaseClass) { ListIterator<BasePhase<? super C>> it = phases.listIterator(); findNextPhase(it, phaseClass); return it; } - protected static <C> void findNextPhase(ListIterator<BasePhase<? super C>> it, Class<? extends BasePhase<? super C>> phaseClass) { + public static <C> void findNextPhase(ListIterator<BasePhase<? super C>> it, Class<? extends BasePhase<? super C>> phaseClass) { while (it.hasNext()) { BasePhase<? super C> phase = it.next(); if (phaseClass.isInstance(phase)) {
--- 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<HighTierContext> createHighTier(); + + PhaseSuite<MidTierContext> createMidTier(); }
--- /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); + } +}
--- 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<HighTierContext> highTier; + public final PhaseSuite<MidTierContext> midTier; public static final Suites DEFAULT; @@ -50,6 +51,7 @@ private Suites(CompilerConfiguration config) { highTier = config.createHighTier(); + midTier = config.createMidTier(); } public static Suites createDefaultSuites() {
--- 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;