Mercurial > hg > graal-jvmci-8
changeset 2742:6e3cc55cf54e
merge
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 20 May 2011 11:15:55 +0200 |
parents | 88123130ede6 (diff) a3cd5eb68837 (current diff) |
children | 55f1db570dfa |
files | |
diffstat | 6 files changed, 188 insertions(+), 131 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Fri May 20 11:11:33 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Fri May 20 11:15:55 2011 +0200 @@ -38,7 +38,6 @@ import com.sun.c1x.graph.*; import com.sun.c1x.ir.*; import com.sun.c1x.lir.*; -import com.sun.c1x.opt.*; import com.sun.c1x.util.*; import com.sun.c1x.value.*; import com.sun.cri.bytecode.*;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/PhiSimplifier.java Fri May 20 11:15:55 2011 +0200 @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2009, 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.sun.c1x.gen; + +import com.sun.c1x.graph.*; +import com.sun.c1x.ir.*; +import com.sun.c1x.value.*; + +/** + * The {@code PhiSimplifier} class is a helper class that can reduce phi instructions. + * + * @author Ben L. Titzer + */ +public final class PhiSimplifier implements BlockClosure { + + final IR ir; + + public PhiSimplifier(IR ir) { + this.ir = ir; + ir.getHIRStartBlock().iterateAnyOrder(this, false); + } + + /** + * This method is called for each block and processes any phi statements in the block. + * @param block the block to apply the simplification to + */ + public void apply(BlockBegin block) { + FrameState state = block.stateBefore(); + for (int i = 0; i < state.stackSize(); i++) { + simplify(state.stackAt(i)); + } + for (int i = 0; i < state.localsSize(); i++) { + simplify(state.localAt(i)); + } + } + + Value simplify(Value x) { + if (x == null || !(x instanceof Phi)) { + return x; + } + Phi phi = (Phi) x; + if (phi.checkFlag(Value.Flag.PhiCannotSimplify)) { + // already tried, cannot simplify this phi + return phi; + } else if (phi.checkFlag(Value.Flag.PhiVisited)) { + // break cycles in phis + return phi; + } else if (phi.isIllegal()) { + // don't bother with illegals + return phi; + } else { + // attempt to simplify the phi by recursively simplifying its operands + phi.setFlag(Value.Flag.PhiVisited); + Value phiSubst = null; + int max = phi.phiInputCount(); + boolean cannotSimplify = false; + for (int i = 0; i < max; i++) { + Value oldInstr = phi.inputAt(i); + + if (oldInstr == null || oldInstr.isIllegal() || oldInstr.isDeadPhi()) { + // if one operand is illegal, make the entire phi illegal + phi.makeDead(); + phi.clearFlag(Value.Flag.PhiVisited); + return phi; + } + + Value newInstr = simplify(oldInstr); + + if (newInstr == null || newInstr.isIllegal() || newInstr.isDeadPhi()) { + // if the subst instruction is illegal, make the entire phi illegal + phi.makeDead(); + phi.clearFlag(Value.Flag.PhiVisited); + return phi; + } + + // attempt to simplify this operand + if (!cannotSimplify) { + + if (newInstr != phi && newInstr != phiSubst) { + if (phiSubst == null) { + phiSubst = newInstr; + continue; + } + // this phi cannot be simplified + cannotSimplify = true; + } + } + } + if (cannotSimplify) { + phi.setFlag(Value.Flag.PhiCannotSimplify); + phi.clearFlag(Value.Flag.PhiVisited); + return phi; + } + + // successfully simplified the phi + assert phiSubst != null : "illegal phi function"; + phi.clearFlag(Value.Flag.PhiVisited); + return phiSubst; + } + } +}
--- a/graal/GraalCompiler/src/com/sun/c1x/opt/PhiSimplifier.java Fri May 20 11:11:33 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2009, 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.sun.c1x.opt; - -import com.sun.c1x.graph.*; -import com.sun.c1x.ir.*; -import com.sun.c1x.value.*; - -/** - * The {@code PhiSimplifier} class is a helper class that can reduce phi instructions. - * - * @author Ben L. Titzer - */ -public final class PhiSimplifier implements BlockClosure { - - final IR ir; - - public PhiSimplifier(IR ir) { - this.ir = ir; - ir.getHIRStartBlock().iterateAnyOrder(this, false); - } - - /** - * This method is called for each block and processes any phi statements in the block. - * @param block the block to apply the simplification to - */ - public void apply(BlockBegin block) { - FrameState state = block.stateBefore(); - for (int i = 0; i < state.stackSize(); i++) { - simplify(state.stackAt(i)); - } - for (int i = 0; i < state.localsSize(); i++) { - simplify(state.localAt(i)); - } - } - - Value simplify(Value x) { - if (x == null || !(x instanceof Phi)) { - return x; - } - Phi phi = (Phi) x; - if (phi.checkFlag(Value.Flag.PhiCannotSimplify)) { - // already tried, cannot simplify this phi - return phi; - } else if (phi.checkFlag(Value.Flag.PhiVisited)) { - // break cycles in phis - return phi; - } else if (phi.isIllegal()) { - // don't bother with illegals - return phi; - } else { - // attempt to simplify the phi by recursively simplifying its operands - phi.setFlag(Value.Flag.PhiVisited); - Value phiSubst = null; - int max = phi.phiInputCount(); - boolean cannotSimplify = false; - for (int i = 0; i < max; i++) { - Value oldInstr = phi.inputAt(i); - - if (oldInstr == null || oldInstr.isIllegal() || oldInstr.isDeadPhi()) { - // if one operand is illegal, make the entire phi illegal - phi.makeDead(); - phi.clearFlag(Value.Flag.PhiVisited); - return phi; - } - - Value newInstr = simplify(oldInstr); - - if (newInstr == null || newInstr.isIllegal() || newInstr.isDeadPhi()) { - // if the subst instruction is illegal, make the entire phi illegal - phi.makeDead(); - phi.clearFlag(Value.Flag.PhiVisited); - return phi; - } - - // attempt to simplify this operand - if (!cannotSimplify) { - - if (newInstr != phi && newInstr != phiSubst) { - if (phiSubst == null) { - phiSubst = newInstr; - continue; - } - // this phi cannot be simplified - cannotSimplify = true; - } - } - } - if (cannotSimplify) { - phi.setFlag(Value.Flag.PhiCannotSimplify); - phi.clearFlag(Value.Flag.PhiVisited); - return phi; - } - - // successfully simplified the phi - assert phiSubst != null : "illegal phi function"; - phi.clearFlag(Value.Flag.PhiVisited); - return phiSubst; - } - } -}
--- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Fri May 20 11:11:33 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameState.java Fri May 20 11:15:55 2011 +0200 @@ -36,7 +36,7 @@ * The {@code FrameState} class encapsulates the frame state (i.e. local variables and * operand stack) at a particular point in the abstract interpretation. */ -public class FrameState extends Value implements FrameStateAccess { +public final class FrameState extends Value implements FrameStateAccess { protected final int localsSize;
--- a/graal/GraalGraph/.classpath Fri May 20 11:11:33 2011 +0200 +++ b/graal/GraalGraph/.classpath Fri May 20 11:15:55 2011 +0200 @@ -1,8 +1,9 @@ -<?xml version="1.0" encoding="UTF-8"?> -<classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="src" path="test"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> - <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> - <classpathentry kind="output" path="bin"/> -</classpath> +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="src" path="test"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> + <classpathentry combineaccessrules="false" kind="src" path="/com.oracle.max.cri"/> + <classpathentry kind="output" path="bin"/> +</classpath>
--- a/graal/GraalGraph/src/com/oracle/graal/graph/Graph.java Fri May 20 11:11:33 2011 +0200 +++ b/graal/GraalGraph/src/com/oracle/graal/graph/Graph.java Fri May 20 11:15:55 2011 +0200 @@ -26,6 +26,8 @@ import java.util.Collection; import java.util.Collections; +import com.sun.cri.ci.CiBitMap; + public class Graph { private final ArrayList<Node> nodes; @@ -54,4 +56,59 @@ public Root root() { return root; } + + public NodeBitMap createNodeBitMap() { + return new NodeBitMap(); + } + + public <T> NodeMap<T> createNodeMap() { + return new NodeMap<T>(); + } + + public final class NodeBitMap { + + private final CiBitMap bitMap = new CiBitMap(nextId); + + private NodeBitMap() { + } + + public boolean isMarked(Node node) { + check(node); + return bitMap.get(node.id()); + } + + public void mark(Node node) { + check(node); + bitMap.set(node.id()); + } + + private void check(Node node) { + assert node.graph == Graph.this : "this node is not part of the graph"; + assert node.id() < bitMap.length() : "this node was added to the graph after creating the node bitmap"; + } + } + + public final class NodeMap<T> { + + private final Object[] values = new Object[nextId]; + + private NodeMap() { + } + + @SuppressWarnings("unchecked") + public T get(Node node) { + check(node); + return (T) values[node.id()]; + } + + public void set(Node node, T value) { + check(node); + values[node.id()] = value; + } + + private void check(Node node) { + assert node.graph == Graph.this : "this node is not part of the graph"; + assert node.id() < values.length : "this node was added to the graph after creating the node map"; + } + } }