changeset 4579:854145ec9866

Fix boxing elimination for boxed constants. Remove redundant "inlining" in dump message.
author Andreas Woess <andreas.woess@jku.at>
date Mon, 13 Feb 2012 17:01:14 +0100
parents b70d180ec022
children a1c86aaef8f5
files graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/BoxingEliminationPhase.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/extended/UnboxNode.java graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java
diffstat 5 files changed, 64 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/BoxingEliminationPhase.java	Mon Feb 13 14:02:30 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/BoxingEliminationPhase.java	Mon Feb 13 17:01:14 2012 +0100
@@ -57,7 +57,7 @@
     private void tryEliminate(StructuredGraph graph, UnboxNode unboxNode, Map<PhiNode, PhiNode> phiReplacements) {
         ValueNode unboxedValue = unboxedValue(unboxNode.source(), unboxNode.destinationKind(), phiReplacements);
         if (unboxedValue != null) {
-            assert unboxedValue.kind() == unboxNode.destinationKind();
+            assert unboxedValue.kind() == unboxNode.kind();
             unboxNode.replaceAtUsages(unboxedValue);
             graph.removeFixed(unboxNode);
         }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Mon Feb 13 14:02:30 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/phases/InliningPhase.java	Mon Feb 13 17:01:14 2012 +0100
@@ -88,7 +88,7 @@
                     try {
                         info.inline(graph, runtime, this);
                         Debug.log("inlining %f: %s", info.weight, info);
-                        Debug.dump(graph, "after inlining %s", info);
+                        Debug.dump(graph, "after %s", info);
                         // get the new nodes here, the canonicalizer phase will reset the mark
                         newNodes = graph.getNewNodes();
                         if (GraalOptions.OptCanonicalizer) {
--- a/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Mon Feb 13 14:02:30 2012 +0100
+++ b/graal/com.oracle.max.graal.debug/src/com/oracle/max/graal/debug/Debug.java	Mon Feb 13 17:01:14 2012 +0100
@@ -156,7 +156,7 @@
         }
     }
 
-    public static DebugConfig fixedConfig(final boolean isLogEnabled, final boolean isDumpEnabled, final boolean isMeterEnabled, final boolean isTimerEnabled, final List<DebugDumpHandler> dumpHandlers) {
+    public static DebugConfig fixedConfig(final boolean isLogEnabled, final boolean isDumpEnabled, final boolean isMeterEnabled, final boolean isTimerEnabled, final Collection<? extends DebugDumpHandler> dumpHandlers) {
         return new DebugConfig() {
 
             @Override
--- a/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/extended/UnboxNode.java	Mon Feb 13 14:02:30 2012 +0100
+++ b/graal/com.oracle.max.graal.nodes/src/com/oracle/max/graal/nodes/extended/UnboxNode.java	Mon Feb 13 17:01:14 2012 +0100
@@ -34,10 +34,12 @@
 public final class UnboxNode extends FixedWithNextNode implements Node.IterableNodeType, Canonicalizable {
 
     @Input private ValueNode source;
+    @Data private CiKind destinationKind;
 
     public UnboxNode(CiKind kind, ValueNode source) {
         super(StampFactory.forKind(kind));
         this.source = source;
+        this.destinationKind = kind;
         assert kind != CiKind.Object : "can only unbox to primitive";
         assert source.kind() == CiKind.Object : "can only unbox objects";
     }
@@ -47,7 +49,7 @@
     }
 
     public CiKind destinationKind() {
-        return this.kind();
+        return destinationKind;
     }
 
     public void expand(BoxingMethodPool pool) {
@@ -63,7 +65,7 @@
             CiConstant constant = source.asConstant();
             Object o = constant.asObject();
             if (o != null) {
-                switch (kind()) {
+                switch (destinationKind) {
                     case Boolean:
                         return ConstantNode.forBoolean((Boolean) o, graph());
                     case Byte:
@@ -81,7 +83,7 @@
                     case Double:
                         return ConstantNode.forDouble((Long) o, graph());
                     default:
-                        assert false;
+                        ValueUtil.shouldNotReachHere();
                 }
             }
         }
--- a/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java	Mon Feb 13 14:02:30 2012 +0100
+++ b/graal/com.oracle.max.graal.tests/src/com/oracle/max/graal/compiler/tests/BoxingEliminationTest.java	Mon Feb 13 17:01:14 2012 +0100
@@ -41,20 +41,24 @@
  * graph of the method that just has a "return 1" statement in it.
  */
 public class BoxingEliminationTest extends GraphTest {
-
+    private static final Short s = 2;
     private static final String REFERENCE_SNIPPET = "referenceSnippet";
 
     @SuppressWarnings("all")
-    public static int referenceSnippet(int a) {
+    public static short referenceSnippet(short a) {
         return 1;
     }
 
-    public static Integer boxedInteger() {
+    public static Short boxedShort() {
         return 1;
     }
 
     public static Object boxedObject() {
-        return 1;
+        return (short) 1;
+    }
+
+    public static Short constantBoxedShort() {
+        return s;
     }
 
     @Test
@@ -63,8 +67,8 @@
     }
 
     @SuppressWarnings("all")
-    public static int test1Snippet(int a) {
-        return boxedInteger();
+    public static short test1Snippet(short a) {
+        return boxedShort();
     }
 
     @Test
@@ -73,8 +77,8 @@
     }
 
     @SuppressWarnings("all")
-    public static int test2Snippet(int a) {
-        return (Integer) boxedObject();
+    public static short test2Snippet(short a) {
+        return (Short) boxedObject();
     }
     @Test
     public void test3() {
@@ -82,39 +86,54 @@
     }
 
     @SuppressWarnings("all")
-    public static int test3Snippet(int a) {
-        int b = boxedInteger();
+    public static short test3Snippet(short a) {
+        short b = boxedShort();
         if (b < 0) {
-            b = boxedInteger();
+            b = boxedShort();
         }
         return b;
     }
 
-    private void test(String snippet) {
-        StructuredGraph graph = parse(snippet);
-        BoxingMethodPool pool = new BoxingMethodPool(runtime());
-        IdentifyBoxingPhase identifyBoxingPhase = new IdentifyBoxingPhase(pool);
-        PhasePlan phasePlan = getDefaultPhasePlan();
-        phasePlan.addPhase(PhasePosition.AFTER_PARSING, identifyBoxingPhase);
-        identifyBoxingPhase.apply(graph);
-        LocalNode local = graph.getNodes(LocalNode.class).iterator().next();
-        ConstantNode constant = ConstantNode.forInt(0, graph);
-        for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
-            n.replaceFirstInput(local, constant);
-        }
-        Collection<Invoke> hints = new ArrayList<>();
-        for (Invoke invoke : graph.getInvokes()) {
-            hints.add(invoke);
-        }
-        new InliningPhase(null, runtime(), hints, null, phasePlan).apply(graph);
-        new CanonicalizerPhase(null, runtime(), null).apply(graph);
-        Debug.dump(graph, "Graph");
-        new BoxingEliminationPhase().apply(graph);
-        Debug.dump(graph, "Graph");
-        new ExpandBoxingNodesPhase(pool).apply(graph);
-        new CanonicalizerPhase(null, runtime(), null).apply(graph);
-        new DeadCodeEliminationPhase().apply(graph);
-        StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET);
-        assertEquals(referenceGraph, graph);
+    @Test
+    public void test4() {
+        test("test4Snippet");
+    }
+
+    @SuppressWarnings("all")
+    public static short test4Snippet(short a) {
+        return constantBoxedShort();
+    }
+
+    private void test(final String snippet) {
+        Debug.scope("BoxingEliminationTest", new DebugDumpScope(snippet), new Runnable() {
+            @Override
+            public void run() {
+                StructuredGraph graph = parse(snippet);
+                BoxingMethodPool pool = new BoxingMethodPool(runtime());
+                IdentifyBoxingPhase identifyBoxingPhase = new IdentifyBoxingPhase(pool);
+                PhasePlan phasePlan = getDefaultPhasePlan();
+                phasePlan.addPhase(PhasePosition.AFTER_PARSING, identifyBoxingPhase);
+                identifyBoxingPhase.apply(graph);
+                LocalNode local = graph.getNodes(LocalNode.class).iterator().next();
+                ConstantNode constant = ConstantNode.forShort((short) 0, graph);
+                for (Node n : local.usages().filter(isNotA(FrameState.class)).snapshot()) {
+                    n.replaceFirstInput(local, constant);
+                }
+                Collection<Invoke> hints = new ArrayList<>();
+                for (Invoke invoke : graph.getInvokes()) {
+                    hints.add(invoke);
+                }
+                new InliningPhase(null, runtime(), hints, null, phasePlan).apply(graph);
+                new CanonicalizerPhase(null, runtime(), null).apply(graph);
+                Debug.dump(graph, "Graph");
+                new BoxingEliminationPhase().apply(graph);
+                Debug.dump(graph, "Graph");
+                new ExpandBoxingNodesPhase(pool).apply(graph);
+                new CanonicalizerPhase(null, runtime(), null).apply(graph);
+                new DeadCodeEliminationPhase().apply(graph);
+                StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET);
+                assertEquals(referenceGraph, graph);
+            }
+        });
     }
 }