# HG changeset patch # User Thomas Wuerthinger # Date 1309951114 -7200 # Node ID eb120717a534217672f1f4fdbbdd5f52be39339a # Parent f855f0e93791a51a9c0291ae67924e5cf249553f Added NegateBooleanNode, removed negate() method from BooleanNode, removed NotInstanceOf. diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Wed Jul 06 11:59:26 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Wed Jul 06 13:18:34 2011 +0200 @@ -478,12 +478,12 @@ } public void emitBooleanBranch(Node node, LIRBlock trueSuccessor, LIRBlock falseSuccessor, LIRDebugInfo info) { - if (node instanceof Compare) { + if (node instanceof NegateBooleanNode) { + emitBooleanBranch(((NegateBooleanNode) node).value(), falseSuccessor, trueSuccessor, info); + } else if (node instanceof Compare) { emitCompare((Compare) node, trueSuccessor, falseSuccessor); } else if (node instanceof InstanceOf) { emitInstanceOf((TypeCheck) node, trueSuccessor, falseSuccessor, info); - } else if (node instanceof NotInstanceOf) { - emitInstanceOf((TypeCheck) node, falseSuccessor, trueSuccessor, info); } else { throw Util.unimplemented(node.toString()); } @@ -1576,7 +1576,7 @@ x.clearOperand(); } - protected CiValue setResult(Value x, CiVariable operand) { + public CiValue setResult(Value x, CiVariable operand) { x.setOperand(operand); if (GraalOptions.DetailedAsserts) { operands.recordResult(operand, x); diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/BooleanNode.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/BooleanNode.java Wed Jul 06 11:59:26 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/BooleanNode.java Wed Jul 06 13:18:34 2011 +0200 @@ -31,9 +31,4 @@ public BooleanNode(CiKind kind, int inputCount, int successorCount, Graph graph) { super(kind, inputCount, successorCount, graph); } - - - public BooleanNode negate() { - throw new IllegalStateException(); - } } diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/CastNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/CastNode.java Wed Jul 06 13:18:34 2011 +0200 @@ -0,0 +1,82 @@ +/* + * 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.oracle.max.graal.compiler.ir; + +import com.oracle.max.graal.compiler.debug.*; +import com.oracle.max.graal.compiler.gen.*; +import com.oracle.max.graal.graph.*; +import com.sun.cri.ci.*; + + +public final class CastNode extends FloatingNode { + private static final int INPUT_COUNT = 1; + private static final int INPUT_NODE = 0; + + private static final int SUCCESSOR_COUNT = 0; + + /** + * The instruction that produces the object tested against null. + */ + public Value value() { + return (Value) inputs().get(super.inputCount() + INPUT_NODE); + } + + public void setValue(Value n) { + inputs().set(super.inputCount() + INPUT_NODE, n); + } + + public CastNode(CiKind kind, Value n, Graph graph) { + super(kind, INPUT_COUNT, SUCCESSOR_COUNT, graph); + setValue(n); + } + + @Override + public void accept(ValueVisitor v) { + } + + + @SuppressWarnings("unchecked") + @Override + public T lookup(Class clazz) { + if (clazz == LIRGenerator.LIRGeneratorOp.class) { + return (T) new LIRGenerator.LIRGeneratorOp() { + @Override + public void generate(Node n, LIRGenerator generator) { + CastNode conv = (CastNode) n; + conv.setOperand(generator.load(conv.value())); + } + }; + } + return super.lookup(clazz); + } + + @Override + public void print(LogStream out) { + out.print("cast node ").print(value().toString()); + } + + @Override + public Node copy(Graph into) { + return new CastNode(kind, null, into); + } +} diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/CheckCast.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/CheckCast.java Wed Jul 06 11:59:26 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/CheckCast.java Wed Jul 06 13:18:34 2011 +0200 @@ -91,7 +91,6 @@ @Override public Node copy(Graph into) { - CheckCast x = new CheckCast(null, null, into); - return x; + return new CheckCast(null, null, into); } } diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Compare.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Compare.java Wed Jul 06 11:59:26 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Compare.java Wed Jul 06 13:18:34 2011 +0200 @@ -157,11 +157,6 @@ return x; } - @Override - public BooleanNode negate() { - return new Compare(x(), condition.negate(), y(), graph()); - } - private static CanonicalizerOp CANONICALIZER = new CanonicalizerOp() { @Override public Node canonical(Node node) { @@ -197,7 +192,7 @@ } BooleanNode result = materializeNode.value(); if (isFalseCheck) { - result = result.negate(); + result = new NegateBooleanNode(result, compare.graph()); } if (GraalOptions.TraceCanonicalizer) { TTY.println("Removed materialize replacing with " + result); diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Constant.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Constant.java Wed Jul 06 11:59:26 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/Constant.java Wed Jul 06 13:18:34 2011 +0200 @@ -55,14 +55,6 @@ v.visitConstant(this); } - @Override - public BooleanNode negate() { - if (kind != CiKind.Boolean) { - throw new IllegalStateException(); - } - return Constant.forBoolean(!value.asBoolean(), graph()); - } - /** * Creates an instruction for a double constant. * @param d the double value for which to create the instruction diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/InstanceOf.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/InstanceOf.java Wed Jul 06 11:59:26 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/InstanceOf.java Wed Jul 06 13:18:34 2011 +0200 @@ -36,13 +36,15 @@ private static final int INPUT_COUNT = 0; private static final int SUCCESSOR_COUNT = 0; + private boolean nullIsTrue; + /** * Constructs a new InstanceOf instruction. * @param targetClass the target class of the instanceof check * @param object the instruction producing the object input to this instruction * @param graph */ - public InstanceOf(Constant targetClassInstruction, Value object, Graph graph) { + public InstanceOf(Constant targetClassInstruction, Value object, boolean nullIsTrue, Graph graph) { super(targetClassInstruction, object, CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph); } @@ -66,12 +68,7 @@ } @Override - public BooleanNode negate() { - return new NotInstanceOf(targetClassInstruction(), object(), graph()); - } - - @Override public Node copy(Graph into) { - return new InstanceOf(null, null, into); + return new InstanceOf(null, null, nullIsTrue, into); } } diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/NegateBooleanNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/NegateBooleanNode.java Wed Jul 06 13:18:34 2011 +0200 @@ -0,0 +1,111 @@ +/* + * 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.oracle.max.graal.compiler.ir; + +import com.oracle.max.graal.compiler.debug.*; +import com.oracle.max.graal.compiler.phases.CanonicalizerPhase.CanonicalizerOp; +import com.oracle.max.graal.graph.*; +import com.sun.cri.ci.*; + +/** + * The {@code ArrayLength} instruction gets the length of an array. + */ +public final class NegateBooleanNode extends BooleanNode { + private static final int INPUT_COUNT = 1; + private static final int INPUT_NODE = 0; + + 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 array object. + */ + public Value value() { + return (Value) inputs().get(super.inputCount() + INPUT_NODE); + } + + public Value setValue(Value n) { + return (Value) inputs().set(super.inputCount() + INPUT_NODE, n); + } + + /** + * Constructs a new ArrayLength instruction. + * @param array the instruction producing the array + * @param newFrameState the state after executing this instruction + */ + public NegateBooleanNode(Value value, Graph graph) { + super(CiKind.Int, INPUT_COUNT, SUCCESSOR_COUNT, graph); + setValue(value); + } + + @Override + public void accept(ValueVisitor v) { + } + + @Override + public boolean valueEqual(Node i) { + return i instanceof NegateBooleanNode; + } + + @Override + public void print(LogStream out) { + out.print(value()).print("!"); + } + + @Override + public Node copy(Graph into) { + return new NegateBooleanNode(null, into); + } + + @SuppressWarnings("unchecked") + @Override + public T lookup(Class clazz) { + if (clazz == CanonicalizerOp.class) { + return (T) CANONICALIZER; + } + return super.lookup(clazz); + } + + private static final CanonicalizerOp CANONICALIZER = new CanonicalizerOp() { + @Override + public Node canonical(Node node) { + NegateBooleanNode negateNode = (NegateBooleanNode) node; + Value value = negateNode.value(); + if (value instanceof NegateBooleanNode) { + return ((NegateBooleanNode) value).value(); + } else if (value instanceof Constant) { + return Constant.forBoolean(!value.asConstant().asBoolean(), node.graph()); + } + return negateNode; + } + }; +} diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/NotInstanceOf.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/NotInstanceOf.java Wed Jul 06 11:59:26 2011 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,77 +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.oracle.max.graal.compiler.ir; - -import com.oracle.max.graal.compiler.debug.*; -import com.oracle.max.graal.compiler.util.*; -import com.oracle.max.graal.graph.*; -import com.sun.cri.bytecode.*; -import com.sun.cri.ci.*; - -/** - * The {@code InstanceOf} instruction represents an instanceof test. - */ -public final class NotInstanceOf extends TypeCheck { - - private static final int INPUT_COUNT = 0; - private static final int SUCCESSOR_COUNT = 0; - - /** - * Constructs a new InstanceOf instruction. - * @param targetClass the target class of the instanceof check - * @param object the instruction producing the object input to this instruction - * @param graph - */ - public NotInstanceOf(Constant targetClassInstruction, Value object, Graph graph) { - super(targetClassInstruction, object, CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph); - } - - @Override - public void accept(ValueVisitor v) { - } - - @Override - public int valueNumber() { - return Util.hash1(Bytecodes.INSTANCEOF, object()); - } - - @Override - public boolean valueEqual(Node i) { - return i instanceof NotInstanceOf; - } - - @Override - public void print(LogStream out) { - out.print("instanceof(").print(object()).print(") ").print(CiUtil.toJavaName(targetClass())); - } - - @Override - public BooleanNode negate() { - return new InstanceOf(targetClassInstruction(), object(), graph()); - } - - @Override - public Node copy(Graph into) { - return new NotInstanceOf(null, null, into); - } -} diff -r f855f0e93791 -r eb120717a534 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java Wed Jul 06 11:59:26 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java Wed Jul 06 13:18:34 2011 +0200 @@ -734,8 +734,12 @@ Constant typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi); Value object = frameState.apop(); if (typeInstruction != null) { -// append(new FixedGuard(new InstanceOf(typeInstruction, object, graph), graph)); -// frameState.apush(object); +// InstanceOf instanceOf = new InstanceOf(typeInstruction, object, true, graph); +// FixedGuard fixedGuard = new FixedGuard(instanceOf, graph); +// append(fixedGuard); +// CastNode castNode = new CastNode(object.kind, object, graph); +// castNode.inputs().add(fixedGuard); +// frameState.apush(castNode); frameState.apush(new CheckCast(typeInstruction, object, graph)); } else { frameState.apush(appendConstant(CiConstant.NULL_OBJECT)); @@ -749,7 +753,7 @@ Constant typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi); Value object = frameState.apop(); if (typeInstruction != null) { - frameState.ipush(append(new MaterializeNode(new InstanceOf(typeInstruction, object, graph), graph))); + frameState.ipush(append(new MaterializeNode(new InstanceOf(typeInstruction, object, false, graph), graph))); } else { frameState.ipush(appendConstant(CiConstant.INT_0)); }