changeset 3120:6930b31c2fd5

Introduced Materialize node. InstanceOf no longer produces a value.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Thu, 30 Jun 2011 17:03:10 +0200
parents 00ad6539b7dc
children 17d96a6af824
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/InstanceOf.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/MaterializeNode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/ir/ValueVisitor.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/GraphBuilderPhase.java
diffstat 5 files changed, 124 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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
--- /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 extends Op> T lookup(Class<T> 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);
+    }
+}
--- 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);
--- 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));
         }