# HG changeset patch # User Lukas Stadler # Date 1307467283 -7200 # Node ID fc75fd3fa5e4e97540fffe6b5c2c114f41166f1e # Parent 6d24c27902a27017e1e0d6bf86682a99215915d9# Parent 7a4e6e11877f14291c43872493bae4e9447ed25d merge (inlining broken) diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/oracle/max/graal/opt/CanonicalizerPhase.java --- a/graal/GraalCompiler/src/com/oracle/max/graal/opt/CanonicalizerPhase.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/oracle/max/graal/opt/CanonicalizerPhase.java Tue Jun 07 19:21:23 2011 +0200 @@ -22,15 +22,47 @@ */ package com.oracle.max.graal.opt; +import java.util.*; + import com.oracle.graal.graph.*; +import com.sun.c1x.*; public class CanonicalizerPhase extends Phase { @Override protected void run(Graph graph) { - // TODO Auto-generated method stub + NodeBitMap visited = graph.createNodeBitMap(); + List nodes = new ArrayList(graph.getNodes()); + for (Node n : nodes) { + if (n == null) { + continue; + } + if (!visited.isMarked(n)) { + this.canonicalize(n, visited); + } + } + } + private void canonicalize(Node n, NodeBitMap visited) { + visited.mark(n); + for (Node input : n.inputs()) { + if (input == null) { + continue; + } + if (!visited.isNew(input) && !visited.isMarked(input)) { + canonicalize(input, visited); + } + } + + CanonicalizerOp op = n.lookup(CanonicalizerOp.class); + if (op != null) { + Node canonical = op.canonical(n); + if (canonical != n) { + n.replace(canonical); + C1XMetrics.NodesCanonicalized++; + } + } } public interface CanonicalizerOp extends Op { diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/C1XMetrics.java --- a/graal/GraalCompiler/src/com/sun/c1x/C1XMetrics.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/C1XMetrics.java Tue Jun 07 19:21:23 2011 +0200 @@ -62,6 +62,7 @@ public static int UniqueValueIdsAssigned; public static int FrameStatesCreated; public static int FrameStateValuesCreated; + public static int NodesCanonicalized; public static void print() { printClassFields(C1XMetrics.class); diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java --- a/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/C1XOptions.java Tue Jun 07 19:21:23 2011 +0200 @@ -128,4 +128,6 @@ // Assembler settings public static boolean CommentedAssembly = ____; public static boolean PrintLIRWithAssembly = ____; + + public static boolean OptCanonicalizer = true; } diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/GraphBuilder.java Tue Jun 07 19:21:23 2011 +0200 @@ -563,7 +563,18 @@ private void genShiftOp(CiKind kind, int opcode) { Value s = frameState.ipop(); Value x = frameState.pop(kind); - frameState.push(kind, append(new Shift(opcode, x, s, graph))); + Shift v; + switch(opcode){ + case ISHL: + case LSHL: v = new LeftShift(kind, x, s, graph); break; + case ISHR: + case LSHR: v = new RightShift(kind, x, s, graph); break; + case IUSHR: + case LUSHR: v = new UnsignedRightShift(kind, x, s, graph); break; + default: + throw new CiBailout("should not reach"); + } + frameState.push(kind, append(v)); } private void genLogicOp(CiKind kind, int opcode) { @@ -586,7 +597,7 @@ private void genCompareOp(CiKind kind, int opcode, CiKind resultKind) { Value y = frameState.pop(kind); Value x = frameState.pop(kind); - Value value = append(new Materialize(opcode, resultKind, x, y, graph)); + Value value = append(new NormalizeCompare(opcode, resultKind, x, y, graph)); if (!resultKind.isVoid()) { frameState.ipush(value); } @@ -611,7 +622,7 @@ private void ifNode(Value x, Condition cond, Value y) { assert !x.isDeleted() && !y.isDeleted(); - If ifNode = new If(x, cond, y, graph); + If ifNode = new If(new Compare(x, cond, y, graph), graph); append(ifNode); Instruction tsucc = createTargetAt(stream().readBranchDest(), frameState); ifNode.setBlockSuccessor(0, tsucc); diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/graph/IR.java --- a/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/graph/IR.java Tue Jun 07 19:21:23 2011 +0200 @@ -26,6 +26,7 @@ import java.util.*; import com.oracle.graal.graph.*; +import com.oracle.max.graal.opt.*; import com.oracle.max.graal.schedule.*; import com.sun.c1x.*; import com.sun.c1x.debug.*; @@ -84,6 +85,11 @@ Graph graph = compilation.graph; + if (C1XOptions.OptCanonicalizer) { + new CanonicalizerPhase().apply(graph); + verifyAndPrint("After canonicalization"); + } + // Split critical edges. List nodes = graph.getNodes(); for (int i = 0; i < nodes.size(); ++i) { diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/Compare.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Compare.java Tue Jun 07 19:21:23 2011 +0200 @@ -0,0 +1,141 @@ + +/* + * Copyright (c) 2011, 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.ir; + +import com.oracle.graal.graph.*; +import com.sun.c1x.debug.*; +import com.sun.c1x.util.*; +import com.sun.cri.ci.*; + +public final class Compare extends Value { + + private static final int INPUT_COUNT = 2; + private static final int INPUT_X = 0; + private static final int INPUT_Y = 1; + + private static final int SUCCESSOR_COUNT = 0; + + @Override + protected int inputCount() { + return super.inputCount() + INPUT_COUNT; + } + + @Override + protected int successorCount() { + return super.successorCount() + SUCCESSOR_COUNT; + } + + /** + * The instruction that produces the first input to this comparison. + */ + public Value x() { + return (Value) inputs().get(super.inputCount() + INPUT_X); + } + + public Value setX(Value n) { + return (Value) inputs().set(super.inputCount() + INPUT_X, n); + } + + /** + * The instruction that produces the second input to this comparison. + */ + public Value y() { + return (Value) inputs().get(super.inputCount() + INPUT_Y); + } + + public Value setY(Value n) { + return (Value) inputs().set(super.inputCount() + INPUT_Y, n); + } + + Condition condition; + boolean unorderedIsTrue; + + /** + * Constructs a new If instruction. + * @param x the instruction producing the first input to the instruction + * @param condition the condition (comparison operation) + * @param y the instruction that produces the second input to this instruction + * @param graph + */ + public Compare(Value x, Condition condition, Value y, Graph graph) { + super(CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph); + assert (x == null && y == null) || Util.archKindsEqual(x, y); + this.condition = condition; + setX(x); + setY(y); + } + + /** + * Gets the condition (comparison operation) for this instruction. + * @return the condition + */ + public Condition condition() { + return condition; + } + + /** + * Checks whether unordered inputs mean true or false. + * @return {@code true} if unordered inputs produce true + */ + public boolean unorderedIsTrue() { + return unorderedIsTrue; + } + + /** + * Swaps the operands to this if and reverses the condition (e.g. > goes to <=). + * @see Condition#mirror() + */ + public void swapOperands() { + condition = condition.mirror(); + Value t = x(); + setX(y()); + setY(t); + } + + @Override + public void accept(ValueVisitor v) { + } + + @Override + public void print(LogStream out) { + out.print("comp "). + print(x()). + print(' '). + print(condition().operator). + print(' '). + print(y()); + } + + @Override + public String shortName() { + return "Comp " + condition.operator; + } + + @Override + public Node copy(Graph into) { + Compare x = new Compare(null, condition, null, into); + x.unorderedIsTrue = unorderedIsTrue; + return x; + } +} diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/If.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/If.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/If.java Tue Jun 07 19:21:23 2011 +0200 @@ -33,9 +33,8 @@ */ public final class If extends BlockEnd { - private static final int INPUT_COUNT = 2; - private static final int INPUT_X = 0; - private static final int INPUT_Y = 1; + private static final int INPUT_COUNT = 1; + private static final int INPUT_COMPARE = 0; private static final int SUCCESSOR_COUNT = 0; @@ -52,57 +51,17 @@ /** * The instruction that produces the first input to this comparison. */ - public Value x() { - return (Value) inputs().get(super.inputCount() + INPUT_X); - } - - public Value setX(Value n) { - return (Value) inputs().set(super.inputCount() + INPUT_X, n); - } - - /** - * The instruction that produces the second input to this comparison. - */ - public Value y() { - return (Value) inputs().get(super.inputCount() + INPUT_Y); - } - - public Value setY(Value n) { - return (Value) inputs().set(super.inputCount() + INPUT_Y, n); + public Compare compare() { + return (Compare) inputs().get(super.inputCount() + INPUT_COMPARE); } - Condition condition; - boolean unorderedIsTrue; - - /** - * Constructs a new If instruction. - * @param x the instruction producing the first input to the instruction - * @param condition the condition (comparison operation) - * @param y the instruction that produces the second input to this instruction - * @param graph - */ - public If(Value x, Condition condition, Value y, Graph graph) { - super(CiKind.Illegal, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph); - assert (x == null && y == null) || Util.archKindsEqual(x, y); - this.condition = condition; - setX(x); - setY(y); + public Value setCompare(Compare n) { + return (Value) inputs().set(super.inputCount() + INPUT_COMPARE, n); } - /** - * Gets the condition (comparison operation) for this instruction. - * @return the condition - */ - public Condition condition() { - return condition; - } - - /** - * Checks whether unordered inputs mean true or false. - * @return {@code true} if unordered inputs produce true - */ - public boolean unorderedIsTrue() { - return unorderedIsTrue; + public If(Compare compare, Graph graph) { + super(CiKind.Illegal, 2, INPUT_COUNT, SUCCESSOR_COUNT, graph); + setCompare(compare); } /** @@ -130,38 +89,6 @@ return blockSuccessor(istrue ? 0 : 1); } - /** - * Gets the successor of this instruction for the unordered case. - * @return the successor for unordered inputs - */ - public Instruction unorderedSuccessor() { - return successor(unorderedIsTrue()); - } - - /** - * Swaps the operands to this if and reverses the condition (e.g. > goes to <=). - * @see Condition#mirror() - */ - public void swapOperands() { - condition = condition.mirror(); - Value t = x(); - setX(y()); - setY(t); - } - - /** - * Swaps the successor blocks to this if and negates the condition (e.g. == goes to !=) - * @see Condition#negate() - */ - public void swapSuccessors() { - unorderedIsTrue = !unorderedIsTrue; - condition = condition.negate(); - Instruction t = blockSuccessor(0); - Instruction f = blockSuccessor(1); - setBlockSuccessor(0, f); - setBlockSuccessor(1, t); - } - @Override public void accept(ValueVisitor v) { v.visitIf(this); @@ -170,11 +97,11 @@ @Override public void print(LogStream out) { out.print("if "). - print(x()). + print(compare().x()). print(' '). - print(condition().operator). + print(compare().condition().operator). print(' '). - print(y()). + print(compare().y()). print(" then "). print(blockSuccessors().get(0)). print(" else "). @@ -183,13 +110,11 @@ @Override public String shortName() { - return "If " + condition.operator; + return "If " + compare().condition.operator; } @Override public Node copy(Graph into) { - If x = new If(null, condition, null, into); - x.unorderedIsTrue = unorderedIsTrue; - return x; + return new If(compare(), into); } } diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/LeftShift.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/LeftShift.java Tue Jun 07 19:21:23 2011 +0200 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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.ir; + +import com.oracle.graal.graph.*; +import com.sun.cri.bytecode.*; +import com.sun.cri.ci.*; + + +public final class LeftShift extends Shift { + + /** + * @param opcode + * @param kind + * @param x + * @param y + * @param graph + */ + public LeftShift(CiKind kind, Value x, Value y, Graph graph) { + super(kind, kind == CiKind.Int ? Bytecodes.ISHL : Bytecodes.LSHL, x, y, graph); + } + + @Override + public String shortName() { + return "<<"; + } + + @Override + public Node copy(Graph into) { + LeftShift ls = new LeftShift(kind, null, null, graph()); + return ls; + } + +} diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/Materialize.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Materialize.java Tue Jun 07 19:19:14 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +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.ir; - -import com.oracle.graal.graph.*; -import com.sun.c1x.debug.*; -import com.sun.cri.bytecode.*; -import com.sun.cri.ci.*; - -/** - * The {@code CompareOp} instruction represents comparisons such as equals, not equal, etc. - */ -public final class Materialize extends Binary { - - private static final int INPUT_COUNT = 0; - private static final int SUCCESSOR_COUNT = 0; - - /** - * Creates a new compare operation. - * @param opcode the bytecode opcode - * @param kind the result kind - * @param x the first input - * @param y the second input - */ - public Materialize(int opcode, CiKind kind, Value x, Value y, Graph graph) { - super(kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph); - } - - @Override - public void accept(ValueVisitor v) { - v.visitMaterialize(this); - } - - @Override - public void print(LogStream out) { - out.print(x()). - print(' '). - print(Bytecodes.operator(opcode)). - print(' '). - print(y()); - } - - @Override - public Node copy(Graph into) { - Materialize x = new Materialize(opcode, kind, null, null, into); - return x; - } -} diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/NormalizeCompare.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/NormalizeCompare.java Tue Jun 07 19:21:23 2011 +0200 @@ -0,0 +1,67 @@ +/* + * 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.ir; + +import com.oracle.graal.graph.*; +import com.sun.c1x.debug.*; +import com.sun.cri.bytecode.*; +import com.sun.cri.ci.*; + +/** + * Returns -1, 0, or 1 if either x > y, x == y, or x < y. + */ +public final class NormalizeCompare extends Binary { + + private static final int INPUT_COUNT = 0; + private static final int SUCCESSOR_COUNT = 0; + + /** + * Creates a new compare operation. + * @param opcode the bytecode opcode + * @param kind the result kind + * @param x the first input + * @param y the second input + */ + public NormalizeCompare(int opcode, CiKind kind, Value x, Value y, Graph graph) { + super(kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph); + } + + @Override + public void accept(ValueVisitor v) { + v.visitMaterialize(this); + } + + @Override + public void print(LogStream out) { + out.print(x()). + print(' '). + print(Bytecodes.operator(opcode)). + print(' '). + print(y()); + } + + @Override + public Node copy(Graph into) { + return new NormalizeCompare(opcode, kind, null, null, into); + } +} diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/Or.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Or.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Or.java Tue Jun 07 19:21:23 2011 +0200 @@ -23,6 +23,7 @@ package com.sun.c1x.ir; import com.oracle.graal.graph.*; +import com.oracle.max.graal.opt.CanonicalizerPhase.CanonicalizerOp; import com.sun.cri.bytecode.*; import com.sun.cri.ci.*; @@ -31,6 +32,7 @@ * */ public final class Or extends Logic { + private static final OrCanonicalizerOp CANONICALIZER = new OrCanonicalizerOp(); /** * @param opcode @@ -54,4 +56,61 @@ return x; } + @SuppressWarnings("unchecked") + @Override + public T lookup(Class clazz) { + if (clazz == CanonicalizerOp.class) { + return (T) CANONICALIZER; + } + return super.lookup(clazz); + } + + private static class OrCanonicalizerOp implements CanonicalizerOp { + @Override + public Node canonical(Node node) { + assert node instanceof Or; + Or or = (Or) node; + CiKind kind = or.kind; + Graph graph = or.graph(); + Value x = or.x(); + Value y = or.y(); + if (x == y) { + return x; + } + if (x.isConstant() && !y.isConstant()) { + or.swapOperands(); + Value t = y; + y = x; + x = t; + } + if (x.isConstant()) { + if (kind == CiKind.Int) { + return Constant.forInt(x.asConstant().asInt() | y.asConstant().asInt(), graph); + } else { + assert kind == CiKind.Long; + return Constant.forLong(x.asConstant().asLong() | y.asConstant().asLong(), graph); + } + } else if (y.isConstant()) { + if (kind == CiKind.Int) { + int c = y.asConstant().asInt(); + if (c == -1) { + return Constant.forInt(-1, graph); + } + if (c == 0) { + return x; + } + } else { + assert kind == CiKind.Long; + long c = y.asConstant().asLong(); + if (c == -1) { + return Constant.forLong(-1, graph); + } + if (c == 0) { + return x; + } + } + } + return or; + } + } } diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/RightShift.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/RightShift.java Tue Jun 07 19:21:23 2011 +0200 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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.ir; + +import com.oracle.graal.graph.*; +import com.sun.cri.bytecode.*; +import com.sun.cri.ci.*; + + +public final class RightShift extends Shift { + + /** + * @param opcode + * @param kind + * @param x + * @param y + * @param graph + */ + public RightShift(CiKind kind, Value x, Value y, Graph graph) { + super(kind, kind == CiKind.Int ? Bytecodes.ISHR : Bytecodes.LSHR, x, y, graph); + } + + @Override + public String shortName() { + return ">>"; + } + + @Override + public Node copy(Graph into) { + RightShift rs = new RightShift(kind, null, null, graph()); + return rs; + } + +} diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/Shift.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Shift.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Shift.java Tue Jun 07 19:21:23 2011 +0200 @@ -24,13 +24,12 @@ import com.oracle.graal.graph.*; import com.sun.c1x.debug.*; -import com.sun.cri.bytecode.*; import com.sun.cri.ci.*; /** * The {@code ShiftOp} class represents shift operations. */ -public final class Shift extends Binary { +public abstract class Shift extends Binary { private static final int INPUT_COUNT = 0; private static final int SUCCESSOR_COUNT = 0; @@ -41,12 +40,8 @@ * @param x the first input value * @param y the second input value */ - public Shift(int opcode, Value x, Value y, Graph graph) { - super(x.kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph); - } - - private Shift(CiKind kind, int opcode, Graph graph) { - super(kind, opcode, null, null, INPUT_COUNT, SUCCESSOR_COUNT, graph); + public Shift(CiKind kind, int opcode, Value x, Value y, Graph graph) { + super(kind, opcode, x, y, INPUT_COUNT, SUCCESSOR_COUNT, graph); } @Override @@ -56,12 +51,9 @@ @Override public void print(LogStream out) { - out.print(x()).print(' ').print(Bytecodes.operator(opcode)).print(' ').print(y()); + out.print(x()).print(' ').print(this.shortName()).print(' ').print(y()); } @Override - public Node copy(Graph into) { - Shift x = new Shift(kind, opcode, into); - return x; - } + public abstract String shortName(); } diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/UnsignedRightShift.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/UnsignedRightShift.java Tue Jun 07 19:21:23 2011 +0200 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 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.ir; + +import com.oracle.graal.graph.*; +import com.sun.cri.bytecode.*; +import com.sun.cri.ci.*; + + +public final class UnsignedRightShift extends Shift { + + /** + * @param opcode + * @param kind + * @param x + * @param y + * @param graph + */ + public UnsignedRightShift(CiKind kind, Value x, Value y, Graph graph) { + super(kind, kind == CiKind.Int ? Bytecodes.IUSHR : Bytecodes.LUSHR, x, y, graph); + } + + @Override + public String shortName() { + return ">>>"; + } + + @Override + public Node copy(Graph into) { + UnsignedRightShift x = new UnsignedRightShift(kind, null, null, graph()); + return x; + } + +} diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/ValueVisitor.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/ValueVisitor.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/ValueVisitor.java Tue Jun 07 19:21:23 2011 +0200 @@ -35,7 +35,7 @@ public abstract void visitArrayLength(ArrayLength i); public abstract void visitMerge(Merge i); public abstract void visitCheckCast(CheckCast i); - public abstract void visitMaterialize(Materialize i); + public abstract void visitMaterialize(NormalizeCompare i); public abstract void visitConstant(Constant i); public abstract void visitConvert(Convert i); public abstract void visitExceptionObject(ExceptionObject i); diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/ir/Xor.java --- a/graal/GraalCompiler/src/com/sun/c1x/ir/Xor.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Xor.java Tue Jun 07 19:21:23 2011 +0200 @@ -23,10 +23,12 @@ package com.sun.c1x.ir; import com.oracle.graal.graph.*; +import com.oracle.max.graal.opt.CanonicalizerPhase.CanonicalizerOp; import com.sun.cri.bytecode.*; import com.sun.cri.ci.*; public final class Xor extends Logic { + private static final XorCanonicalizerOp CANONICALIZER = new XorCanonicalizerOp(); /** * @param opcode @@ -50,4 +52,60 @@ return x; } + @SuppressWarnings("unchecked") + @Override + public T lookup(Class clazz) { + if (clazz == CanonicalizerOp.class) { + return (T) CANONICALIZER; + } + return super.lookup(clazz); + } + + private static class XorCanonicalizerOp implements CanonicalizerOp { + @Override + public Node canonical(Node node) { + assert node instanceof Xor; + Xor xor = (Xor) node; + CiKind kind = xor.kind; + Graph graph = xor.graph(); + Value x = xor.x(); + Value y = xor.y(); + if (x == y) { + if (kind == CiKind.Int) { + return Constant.forInt(0, graph); + } else { + assert kind == CiKind.Long; + return Constant.forLong(0L, graph); + } + } + if (x.isConstant() && !y.isConstant()) { + xor.swapOperands(); + Value t = y; + y = x; + x = t; + } + if (x.isConstant()) { + if (kind == CiKind.Int) { + return Constant.forInt(x.asConstant().asInt() ^ y.asConstant().asInt(), graph); + } else { + assert kind == CiKind.Long; + return Constant.forLong(x.asConstant().asLong() ^ y.asConstant().asLong(), graph); + } + } else if (y.isConstant()) { + if (kind == CiKind.Int) { + int c = y.asConstant().asInt(); + if (c == 0) { + return x; + } + } else { + assert kind == CiKind.Long; + long c = y.asConstant().asLong(); + if (c == 0) { + return x; + } + } + } + return xor; + } + } } diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalCompiler/src/com/sun/c1x/target/amd64/AMD64LIRGenerator.java --- a/graal/GraalCompiler/src/com/sun/c1x/target/amd64/AMD64LIRGenerator.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/target/amd64/AMD64LIRGenerator.java Tue Jun 07 19:21:23 2011 +0200 @@ -417,7 +417,7 @@ } @Override - public void visitMaterialize(Materialize x) { + public void visitMaterialize(NormalizeCompare x) { LIRItem left = new LIRItem(x.x(), this); LIRItem right = new LIRItem(x.y(), this); if (!x.kind.isVoid() && x.x().kind.isLong()) { @@ -472,12 +472,12 @@ @Override public void visitIf(If x) { - CiKind kind = x.x().kind; + CiKind kind = x.compare().x().kind; - Condition cond = x.condition(); + Condition cond = x.compare().condition(); - LIRItem xitem = new LIRItem(x.x(), this); - LIRItem yitem = new LIRItem(x.y(), this); + LIRItem xitem = new LIRItem(x.compare().x(), this); + LIRItem yitem = new LIRItem(x.compare().y(), this); LIRItem xin = xitem; LIRItem yin = yitem; @@ -504,8 +504,12 @@ CiValue left = xin.result(); CiValue right = yin.result(); lir.cmp(cond, left, right); - if (x.x().kind.isFloat() || x.x().kind.isDouble()) { - lir.branch(cond, right.kind, getLIRBlock(x.trueSuccessor()), getLIRBlock(x.unorderedSuccessor())); + if (x.compare().x().kind.isFloat() || x.compare().x().kind.isDouble()) { + Instruction unorderedSucc = x.falseSuccessor(); + if (x.compare().unorderedIsTrue()) { + unorderedSucc = x.trueSuccessor(); + } + lir.branch(cond, right.kind, getLIRBlock(x.trueSuccessor()), getLIRBlock(unorderedSucc)); } else { lir.branch(cond, right.kind, getLIRBlock(x.trueSuccessor())); } diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java --- a/graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalGraph/src/com/oracle/graal/graph/NodeArray.java Tue Jun 07 19:21:23 2011 +0200 @@ -47,7 +47,7 @@ @Override public Node set(int index, Node node) { - assert node == Node.Null || node.graph == self().graph : "node is from different graph (" + node.graph + " instead of " + self().graph + ")"; + assert node == Node.Null || node.graph == self().graph : "node is from different graph: (this=" + this + ") and (node=" + node + ")"; assert node == Node.Null || node.id() != Node.DeletedID : "inserted node must not be deleted"; Node old = nodes[index]; diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalGraph/src/com/oracle/graal/graph/NodeBitMap.java --- a/graal/GraalGraph/src/com/oracle/graal/graph/NodeBitMap.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalGraph/src/com/oracle/graal/graph/NodeBitMap.java Tue Jun 07 19:21:23 2011 +0200 @@ -52,6 +52,10 @@ return bitMap.get(node.id()); } + public boolean isNew(Node node) { + return node.id() >= bitMap.size(); + } + public void mark(Node node) { check(node); bitMap.set(node.id()); @@ -64,7 +68,7 @@ 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() + ")"; + assert !isNew(node) : "this node (" + node.id() + ") was added to the graph after creating the node bitmap (" + bitMap.length() + ")"; } @Override diff -r 6d24c27902a2 -r fc75fd3fa5e4 graal/GraalRuntime/src/com/oracle/graal/runtime/VMExitsNative.java --- a/graal/GraalRuntime/src/com/oracle/graal/runtime/VMExitsNative.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalRuntime/src/com/oracle/graal/runtime/VMExitsNative.java Tue Jun 07 19:21:23 2011 +0200 @@ -112,7 +112,7 @@ } catch (Throwable t) { StringWriter out = new StringWriter(); t.printStackTrace(new PrintWriter(out)); - TTY.println("Compilation interrupted:\n" + out.toString()); + TTY.println("Compilation interrupted: (" + name + ")\n" + out.toString()); throw t; } } diff -r 6d24c27902a2 -r fc75fd3fa5e4 src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java --- a/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java Tue Jun 07 19:19:14 2011 +0200 +++ b/src/share/tools/IdealGraphVisualizer/ServerCompiler/src/com/sun/hotspot/igv/servercompiler/ServerCompilerScheduler.java Tue Jun 07 19:21:23 2011 +0200 @@ -542,7 +542,10 @@ for (Node n : nodes) { InputNode inputNode = n.inputNode; - if (inputNode.getProperties().get("name").equals("Root")) { + if(inputNode.getProperties().get("name") == null) { + System.out.println("NO name !! " + inputNode); + } + if (inputNode != null && inputNode.getProperties().get("name") != null && inputNode.getProperties().get("name").equals("Root")) { return n; } else if (inputNode.getId() == 0) { // use as fallback in case no root node is found