changeset 16053:87e11e4c031f

pea: unittest to test escape analysis around nested loops
author Bernhard Urban <bernhard.urban@jku.at>
date Fri, 06 Jun 2014 11:17:29 +0200
parents 80b0bd9e29c8
children 45bd621d9bb9 87414e322d45
files graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/optimize/NestedLoop_EA.java
diffstat 1 files changed, 133 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/optimize/NestedLoop_EA.java	Fri Jun 06 11:17:29 2014 +0200
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2011, 2012, 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.graal.jtt.optimize;
+
+import java.util.*;
+
+import org.junit.*;
+
+import com.oracle.graal.compiler.common.*;
+import com.oracle.graal.jtt.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.virtual.*;
+import com.oracle.graal.phases.*;
+import com.oracle.graal.phases.common.*;
+import com.oracle.graal.phases.tiers.*;
+import com.oracle.graal.virtual.phases.ea.*;
+
+public class NestedLoop_EA extends JTTTest {
+
+    @Override
+    protected Suites createSuites() {
+        Suites suites = super.createSuites();
+        ListIterator<BasePhase<? super HighTierContext>> position = suites.getHighTier().findPhase(PartialEscapePhase.class);
+        CanonicalizerPhase canonicalizer = new CanonicalizerPhase(!GraalOptions.ImmutableCode.getValue());
+        // incremental canonicalizer of PEA is missing some important canonicalization (TODO?)
+        position.add(canonicalizer);
+        position.add(new PartialEscapePhase(true, canonicalizer));
+        return suites;
+    }
+
+    static class Frame {
+        Object objects[] = new Object[10];
+    }
+
+    final static int RESULT_SLOT = 0;
+    final static int K_SLOT = 1;
+    final static int I_SLOT = 2;
+    final static int ARG_SLOT = 3;
+    final static int STACK_BASE = 4;
+
+    static class Pointer {
+        public int sp = STACK_BASE;
+    }
+
+    public static int simpleLoop(int arg) {
+        Frame f = new Frame();
+        Pointer p = new Pointer();
+        f.objects[ARG_SLOT] = arg;
+        f.objects[RESULT_SLOT] = 0;
+        f.objects[K_SLOT] = 0;
+        for (; (int) f.objects[K_SLOT] < (int) f.objects[ARG_SLOT];) {
+
+            f.objects[RESULT_SLOT] = (int) f.objects[RESULT_SLOT] + 5;
+
+            f.objects[++p.sp] = f.objects[K_SLOT];
+            f.objects[++p.sp] = 1;
+            int result = (int) f.objects[p.sp] + (int) f.objects[p.sp - 1];
+            p.sp--;
+            f.objects[p.sp] = result;
+            f.objects[K_SLOT] = (int) f.objects[p.sp];
+            p.sp--;
+        }
+        return (int) f.objects[RESULT_SLOT];
+    }
+
+    @Test
+    public void run0() throws Throwable {
+        runTest("simpleLoop", 5);
+    }
+
+    public static int nestedLoop(int arg) {
+        Frame f = new Frame();
+        Pointer p = new Pointer();
+        f.objects[ARG_SLOT] = arg;
+        f.objects[RESULT_SLOT] = 0;
+        f.objects[K_SLOT] = 0;
+        for (; (int) f.objects[K_SLOT] < (int) f.objects[ARG_SLOT];) {
+
+            f.objects[I_SLOT] = 0;
+            for (; (int) f.objects[I_SLOT] < (int) f.objects[ARG_SLOT];) {
+                f.objects[RESULT_SLOT] = (int) f.objects[RESULT_SLOT] + 5;
+
+                f.objects[++p.sp] = f.objects[I_SLOT];
+                f.objects[++p.sp] = 1;
+                int result = (int) f.objects[p.sp] + (int) f.objects[p.sp - 1];
+                p.sp--;
+                f.objects[p.sp] = result;
+                f.objects[I_SLOT] = (int) f.objects[p.sp];
+                p.sp--;
+            }
+
+            f.objects[++p.sp] = f.objects[K_SLOT];
+            f.objects[++p.sp] = 1;
+            int result = (int) f.objects[p.sp] + (int) f.objects[p.sp - 1];
+            p.sp--;
+            f.objects[p.sp] = result;
+            f.objects[K_SLOT] = (int) f.objects[p.sp];
+            p.sp--;
+        }
+        return (int) f.objects[RESULT_SLOT];
+    }
+
+    @Test
+    public void run1() throws Throwable {
+        runTest("nestedLoop", 5);
+    }
+
+    @Override
+    protected boolean checkHighTierGraph(StructuredGraph graph) {
+        assert graph.getNodes().filter(CommitAllocationNode.class).count() == 0 : "all allocations should be virtualized";
+        return true;
+    }
+}