# HG changeset patch # User Gilles Duboscq # Date 1306771375 -7200 # Node ID d54ea877a30226db6849cc40c6f749818abc4221 # Parent 9ba6a8abe894d1ae2159079f38c09182dfaf1add# Parent 015be60afcf35796679aa59ebc4c2bf694ec0a46 Merge diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java --- a/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/LIRGenerator.java Mon May 30 18:02:55 2011 +0200 @@ -1280,7 +1280,7 @@ Phi phi = (Phi) suxVal; // curVal can be null without phi being null in conjunction with inlining - if (!phi.isDeadPhi() && curVal != null && curVal != phi) { + if (!phi.isDead() && curVal != null && curVal != phi) { assert phis.contains(phi); if (phi.valueAt(predIndex) != curVal) { @@ -1288,7 +1288,7 @@ } assert phi.valueAt(predIndex) == curVal : "curVal=" + curVal + "valueAt(" + predIndex + ")=" + phi.valueAt(predIndex); - assert !phi.isIllegal() : "illegal phi cannot be marked as live"; + assert !phi.isDead() : "illegal phi cannot be marked as live"; if (curVal instanceof Phi) { operandForPhi((Phi) curVal); } @@ -1343,7 +1343,7 @@ PhiResolver resolver = new PhiResolver(this); for (Phi phi : phis) { - if (!phi.isDeadPhi()) { + if (!phi.isDead()) { Value curVal = phi.valueAt(predIndex); if (curVal != null && curVal != phi) { if (curVal instanceof Phi) { @@ -1389,7 +1389,7 @@ } private CiValue operandForPhi(Phi phi) { - assert !phi.isDeadPhi(); + assert !phi.isDead(); if (phi.operand().isIllegal()) { // allocate a variable for this phi CiVariable operand = newVariable(phi.kind); @@ -1459,7 +1459,7 @@ for (int index = 0; index < state.localsSize(); index++) { final Value value = state.localAt(index); if (value != null) { - if (!value.isIllegal()) { + if (!(value instanceof Phi && ((Phi) value).isDead())) { walkStateValue(value); } } @@ -1468,7 +1468,7 @@ private void walkStateValue(Value value) { if (value != null) { - if (value instanceof Phi && !value.isIllegal()) { + if (value instanceof Phi && !((Phi) value).isDead()) { // phi's are special operandForPhi((Phi) value); } else if (value.operand().isIllegal()) { diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/gen/PhiSimplifier.java --- a/graal/GraalCompiler/src/com/sun/c1x/gen/PhiSimplifier.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/gen/PhiSimplifier.java Mon May 30 18:02:55 2011 +0200 @@ -31,8 +31,15 @@ */ public final class PhiSimplifier { + private NodeBitMap visited; + private NodeBitMap cannotSimplify; + public PhiSimplifier(IR ir) { - for (Node n : ir.compilation.graph.getNodes()) { + Graph graph = ir.compilation.graph; + visited = graph.createNodeBitMap(); + cannotSimplify = graph.createNodeBitMap(); + + for (Node n : graph.getNodes()) { if (n instanceof Phi) { simplify((Phi) n); } @@ -45,41 +52,41 @@ } Phi phi = (Phi) x; - if (phi.valueCount() == 1 && !phi.checkFlag(Value.Flag.PhiCannotSimplify)) { + if (phi.valueCount() == 1 && !cannotSimplify.isMarked(phi)) { return (Value) phi.replace(phi.valueAt(0)); } - if (phi.checkFlag(Value.Flag.PhiCannotSimplify)) { + if (cannotSimplify.isMarked(phi)) { // already tried, cannot simplify this phi return phi; - } else if (phi.checkFlag(Value.Flag.PhiVisited)) { + } else if (visited.isMarked(phi)) { // break cycles in phis return phi; - } else if (phi.isIllegal()) { + } else if (phi.isDead()) { // don't bother with illegals return phi; } else { // attempt to simplify the phi by recursively simplifying its operands - phi.setFlag(Value.Flag.PhiVisited); + visited.mark(phi); Value phiSubst = null; int max = phi.valueCount(); boolean cannotSimplify = false; for (int i = 0; i < max; i++) { Value oldInstr = phi.valueAt(i); - if (oldInstr == null || oldInstr.isIllegal() || oldInstr.isDeadPhi()) { + if (oldInstr == null || (oldInstr instanceof Phi && ((Phi) oldInstr).isDead())) { // if one operand is illegal, make the entire phi illegal phi.makeDead(); - phi.clearFlag(Value.Flag.PhiVisited); + visited.clear(phi); return phi; } Value newInstr = simplify(oldInstr); - if (newInstr == null || newInstr.isIllegal() || newInstr.isDeadPhi()) { + if (newInstr == null || (newInstr instanceof Phi && ((Phi) newInstr).isDead())) { // if the subst instruction is illegal, make the entire phi illegal phi.makeDead(); - phi.clearFlag(Value.Flag.PhiVisited); + visited.clear(phi); return phi; } @@ -97,17 +104,16 @@ } } if (cannotSimplify) { - phi.setFlag(Value.Flag.PhiCannotSimplify); - phi.clearFlag(Value.Flag.PhiVisited); + this.cannotSimplify.mark(phi); + visited.clear(phi); return phi; } // successfully simplified the phi assert phiSubst != null : "illegal phi function"; - phi.clearFlag(Value.Flag.PhiVisited); + visited.clear(phi); phi.replace(phiSubst); -// System.out.printf("replaced phi with %d inputs\n", max); return phiSubst; } diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/CheckCast.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/CheckCast.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/CheckCast.java Mon May 30 18:02:55 2011 +0200 @@ -46,7 +46,7 @@ */ public CheckCast(RiType targetClass, Value targetClassInstruction, Value object, Graph graph) { super(targetClass, targetClassInstruction, object, CiKind.Object, INPUT_COUNT, SUCCESSOR_COUNT, graph); - initFlag(Flag.NonNull, object.isNonNull()); + setNonNull(true); } /** diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/Constant.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Constant.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Constant.java Mon May 30 18:02:55 2011 +0200 @@ -48,7 +48,7 @@ public Constant(CiConstant value, Graph graph) { super(value.kind.stackKind(), INPUT_COUNT, SUCCESSOR_COUNT, graph); this.value = value; - initFlag(Value.Flag.NonNull, value.isNonNull()); + setNonNull(true); } @Override diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionObject.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionObject.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/ExceptionObject.java Mon May 30 18:02:55 2011 +0200 @@ -41,7 +41,7 @@ */ public ExceptionObject(Graph graph) { super(CiKind.Object, INPUT_COUNT, SUCCESSOR_COUNT, graph); - setFlag(Flag.NonNull); + setNonNull(true); } @Override diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/Local.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Local.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Local.java Mon May 30 18:02:55 2011 +0200 @@ -90,4 +90,13 @@ protected int successorCount() { return super.successorCount() + SUCCESSOR_COUNT; } + + @Override + public Node copy(Graph into) { + Local x = new Local(kind, index, into); + x.setDeclaredType(declaredType()); + return x; + } + + } diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/Merge.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Merge.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Merge.java Mon May 30 18:02:55 2011 +0200 @@ -150,7 +150,7 @@ while (!hasPhisOnStack && i < state.stackSize()) { Value value = state.stackAt(i); hasPhisOnStack = isPhiAtBlock(value); - if (value != null && !value.isIllegal()) { + if (value != null && !(value instanceof Phi && ((Phi) value).isDead())) { i += value.kind.sizeInSlots(); } else { i++; @@ -161,7 +161,7 @@ Value value = state.localAt(i); hasPhisInLocals = isPhiAtBlock(value); // also ignore illegal HiWords - if (value != null && !value.isIllegal()) { + if (value != null && !(value instanceof Phi && ((Phi) value).isDead())) { i += value.kind.sizeInSlots(); } else { i++; @@ -180,7 +180,11 @@ if (value != null) { out.println(stateString(j, value)); // also ignore illegal HiWords - j += value.isIllegal() ? 1 : value.kind.sizeInSlots(); + if (value instanceof Phi && ((Phi) value).isDead()) { + j += 1; + } else { + j += value.kind.sizeInSlots(); + } } else { j++; } diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/MonitorAddress.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/MonitorAddress.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/MonitorAddress.java Mon May 30 18:02:55 2011 +0200 @@ -39,7 +39,7 @@ public MonitorAddress(int monitor, Graph graph) { super(CiKind.Word, INPUT_COUNT, SUCCESSOR_COUNT, graph); this.monitor = monitor; - setFlag(Flag.NonNull); + setNonNull(true); } @Override diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/NewArray.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/NewArray.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/NewArray.java Mon May 30 18:02:55 2011 +0200 @@ -66,7 +66,7 @@ */ NewArray(Value length, int inputCount, int successorCount, Graph graph) { super(CiKind.Object, inputCount + INPUT_COUNT, successorCount + SUCCESSOR_COUNT, graph); - setFlag(Flag.NonNull); + setNonNull(true); setLength(length); } } diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/NewInstance.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/NewInstance.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/NewInstance.java Mon May 30 18:02:55 2011 +0200 @@ -51,7 +51,7 @@ this.instanceClass = type; this.cpi = cpi; this.constantPool = constantPool; - setFlag(Flag.NonNull); + setNonNull(true); } /** diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/NullCheck.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/NullCheck.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/NullCheck.java Mon May 30 18:02:55 2011 +0200 @@ -67,7 +67,7 @@ */ public NullCheck(Value object, Graph graph) { super(object.kind, INPUT_COUNT, SUCCESSOR_COUNT, graph); - setFlag(Flag.NonNull); + setNonNull(true); setObject(object); } diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Phi.java Mon May 30 18:02:55 2011 +0200 @@ -40,6 +40,7 @@ private static final int SUCCESSOR_COUNT = 0; private int usedInputCount; + private boolean isDead; @Override protected int successorCount() { @@ -101,8 +102,11 @@ * Make this phi illegal if types were not merged correctly. */ public void makeDead() { - setFlag(Flag.PhiCannotSimplify); - setFlag(Flag.PhiDead); + isDead = true; + } + + public boolean isDead() { + return isDead; } @Override diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/ir/Value.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Value.java Mon May 30 18:02:55 2011 +0200 @@ -33,26 +33,13 @@ */ public abstract class Value extends Node { - public enum Flag { - NonNull, // this value is non-null - - PhiDead, // phi is illegal because local is dead - PhiCannotSimplify, // phi cannot be simplified - PhiVisited; // phi has been visited during simplification - - public final int mask = 1 << ordinal(); - } - /** * The kind of this value. This is {@link CiKind#Void} for instructions that produce no value. * This kind is guaranteed to be a {@linkplain CiKind#stackKind() stack kind}. */ public final CiKind kind; - /** - * A mask of {@linkplain Flag flags} denoting extra properties of this value. - */ - private int flags; + private boolean isNonNull; protected CiValue operand = CiValue.IllegalValue; @@ -83,61 +70,15 @@ } /** - * Check whether this instruction has the specified flag set. - * @param flag the flag to test - * @return {@code true} if this instruction has the flag - */ - public final boolean checkFlag(Flag flag) { - return (flags & flag.mask) != 0; - } - - /** - * Set a flag on this instruction. - * @param flag the flag to set - */ - public final void setFlag(Flag flag) { - flags |= flag.mask; - } - - /** - * Clear a flag on this instruction. - * @param flag the flag to set - */ - public final void clearFlag(Flag flag) { - flags &= ~flag.mask; - } - - /** - * Set or clear a flag on this instruction. - * @param flag the flag to set - * @param val if {@code true}, set the flag, otherwise clear it - */ - public final void setFlag(Flag flag, boolean val) { - if (val) { - setFlag(flag); - } else { - clearFlag(flag); - } - } - - /** - * Initialize a flag on this instruction. Assumes the flag is not initially set, - * e.g. in the constructor of an instruction. - * @param flag the flag to set - * @param val if {@code true}, set the flag, otherwise do nothing - */ - public final void initFlag(Flag flag, boolean val) { - if (val) { - setFlag(flag); - } - } - - /** * Checks whether this instruction produces a value which is guaranteed to be non-null. * @return {@code true} if this instruction's value is not null */ - public final boolean isNonNull() { - return checkFlag(Flag.NonNull); + public boolean isNonNull() { + return isNonNull; + } + + public void setNonNull(boolean isNonNull) { + this.isNonNull = isNonNull; } /** @@ -157,15 +98,6 @@ } /** - * Checks whether this instruction "is illegal"--i.e. it represents a dead - * phi or an instruction which does not produce a value. - * @return {@code true} if this instruction is illegal as an input value to another instruction - */ - public final boolean isIllegal() { - return checkFlag(Flag.PhiDead); - } - - /** * Convert this value to a constant if it is a constant, otherwise return null. * @return the {@link CiConstant} represented by this value if it is a constant; {@code null} * otherwise @@ -248,21 +180,12 @@ public String flagsToString() { StringBuilder sb = new StringBuilder(); - for (Flag f : Flag.values()) { - if (checkFlag(f)) { - if (sb.length() != 0) { - sb.append(' '); - } - sb.append(f.name()); - } + if (isNonNull()) { + sb.append("NonNull"); } return sb.toString(); } - public final boolean isDeadPhi() { - return checkFlag(Flag.PhiDead); - } - /** * Compute the value number of this Instruction. Local and global value numbering * optimizations use a hash map, and the value number provides a hash code. diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/value/FrameStateBuilder.java Mon May 30 18:02:55 2011 +0200 @@ -54,7 +54,7 @@ if (!isStatic(method.accessFlags())) { // add the receiver and assume it is non null Local local = new Local(method.holder().kind(), javaIndex, graph); - local.setFlag(Value.Flag.NonNull, true); + local.setNonNull(true); local.setDeclaredType(method.holder()); storeLocal(javaIndex, local); javaIndex = 1; @@ -322,7 +322,7 @@ public Value loadLocal(int i) { Value x = locals[i]; if (x != null) { - if (x.isIllegal()) { + if (x instanceof Phi && ((Phi) x).isDead()) { return null; } assert x.kind.isSingleWord() || locals[i + 1] == null || locals[i + 1] instanceof Phi; diff -r 9ba6a8abe894 -r d54ea877a302 graal/GraalGraph/src/com/oracle/graal/graph/NodeBitMap.java --- a/graal/GraalGraph/src/com/oracle/graal/graph/NodeBitMap.java Mon May 30 18:01:32 2011 +0200 +++ b/graal/GraalGraph/src/com/oracle/graal/graph/NodeBitMap.java Mon May 30 18:02:55 2011 +0200 @@ -53,6 +53,11 @@ bitMap.set(node.id()); } + public void clear(Node node) { + check(node); + bitMap.clear(node.id()); + } + private void check(Node node) { assert node.graph == graph : "this node is not part of the graph"; assert node.id() < bitMap.size() : "this node (" + node.id() + ") was added to the graph after creating the node bitmap (" + bitMap.length() + ")";