# HG changeset patch # User Thomas Wuerthinger # Date 1309446190 -7200 # Node ID 6930b31c2fd52a61928063c96e6ec0aebe88de2f # Parent 00ad6539b7dcf30e57cc62485459158cafc4b64c Introduced Materialize node. InstanceOf no longer produces a value. diff -r 00ad6539b7dc -r 6930b31c2fd5 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 Thu Jun 30 16:49:13 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java Thu Jun 30 17:03:10 2011 +0200 @@ -354,20 +354,6 @@ } @Override - public void visitInstanceOf(InstanceOf x) { - LIRBlock trueSuccessor = new LIRBlock(new Label(), null); - emitInstanceOf(x, trueSuccessor, null); - - CiValue result = createResultVariable(x); - lir.move(CiConstant.FALSE, result); - Label label = new Label(); - lir.branch(Condition.TRUE, label); - lir.branchDestination(trueSuccessor.label); - lir.move(CiConstant.TRUE, result); - lir.branchDestination(label); - } - - @Override public void visitMonitorEnter(MonitorEnter x) { XirArgument obj = toXirArgument(x.object()); XirArgument lockAddress = toXirArgument(x.lockAddress()); @@ -1150,7 +1136,7 @@ * @param x an instruction that produces a result * @return the variable assigned to hold the result produced by {@code x} */ - protected CiVariable createResultVariable(Value x) { + public CiVariable createResultVariable(Value x) { CiVariable operand = newVariable(x.kind); setResult(x, operand); return operand; diff -r 00ad6539b7dc -r 6930b31c2fd5 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 Thu Jun 30 16:49:13 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/InstanceOf.java Thu Jun 30 17:03:10 2011 +0200 @@ -43,12 +43,11 @@ * @param graph */ public InstanceOf(Constant targetClassInstruction, Value object, Graph graph) { - super(targetClassInstruction, object, CiKind.Int, INPUT_COUNT, SUCCESSOR_COUNT, graph); + super(targetClassInstruction, object, CiKind.Illegal, INPUT_COUNT, SUCCESSOR_COUNT, graph); } @Override public void accept(ValueVisitor v) { - v.visitInstanceOf(this); } @Override diff -r 00ad6539b7dc -r 6930b31c2fd5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MaterializeNode.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/MaterializeNode.java Thu Jun 30 17:03:10 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.oracle.max.graal.compiler.ir; + +import com.oracle.max.asm.*; +import com.oracle.max.graal.compiler.debug.*; +import com.oracle.max.graal.compiler.gen.*; +import com.oracle.max.graal.compiler.lir.*; +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 Convert} class represents a conversion between primitive types. + */ +public final class MaterializeNode extends FloatingNode { + + private static final int INPUT_COUNT = 1; + private static final int INPUT_VALUE = 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 which produces the input value to this instruction. + */ + public Node value() { + return inputs().get(super.inputCount() + INPUT_VALUE); + } + + public void setValue(Value n) { + inputs().set(super.inputCount() + INPUT_VALUE, n); + } + + /** + * Constructs a new Convert instance. + * @param opcode the bytecode representing the operation + * @param value the instruction producing the input value + * @param kind the result type of this instruction + * @param graph + */ + public MaterializeNode(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 Materialize); + } + + @SuppressWarnings("unchecked") + @Override + public T lookup(Class clazz) { + if (clazz == LIRGenerator.LIRGeneratorOp.class) { + return (T) LIR_GENERATOR_OP; + } + return super.lookup(clazz); + } + + public static final LIRGenerator.LIRGeneratorOp LIR_GENERATOR_OP = new LIRGenerator.LIRGeneratorOp() { + + @Override + public void generate(Node n, LIRGenerator generator) { + LIRBlock trueSuccessor = new LIRBlock(new Label(), null); + generator.emitBooleanBranch(((Materialize) n).value(), trueSuccessor, null); + CiValue result = generator.createResultVariable((Value) n); + LIRList lir = generator.lir(); + lir.move(CiConstant.FALSE, result); + Label label = new Label(); + lir.branch(Condition.TRUE, label); + lir.branchDestination(trueSuccessor.label); + lir.move(CiConstant.TRUE, result); + lir.branchDestination(label); + } + }; + + @Override + public void print(LogStream out) { + out.print("materialize(").print(value().toString()).print(')'); + } + + @Override + public Node copy(Graph into) { + return new Materialize(null, into); + } +} diff -r 00ad6539b7dc -r 6930b31c2fd5 graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java --- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java Thu Jun 30 16:49:13 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java Thu Jun 30 17:03:10 2011 +0200 @@ -44,7 +44,6 @@ public abstract void visitAnchor(Anchor i); public abstract void visitIf(If i); public abstract void visitIfOp(Conditional i); - public abstract void visitInstanceOf(InstanceOf i); public abstract void visitInvoke(Invoke i); public abstract void visitLoadField(LoadField i); public abstract void visitLoadIndexed(LoadIndexed i); diff -r 00ad6539b7dc -r 6930b31c2fd5 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 Thu Jun 30 16:49:13 2011 +0200 +++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java Thu Jun 30 17:03:10 2011 +0200 @@ -754,7 +754,7 @@ Constant typeInstruction = genTypeOrDeopt(RiType.Representation.ObjectHub, type, isInitialized, cpi); Value object = frameState.apop(); if (typeInstruction != null) { - frameState.ipush(append(new InstanceOf(typeInstruction, object, graph))); + frameState.ipush(append(new Materialize(new InstanceOf(typeInstruction, object, graph), graph))); } else { frameState.ipush(appendConstant(CiConstant.INT_0)); }