changeset 14059:ff5aca1b2878

Merge.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 25 Feb 2014 18:17:08 +0100
parents d451a134a545 (current diff) 0354f629431a (diff)
children 96946b41aae7
files
diffstat 4 files changed, 157 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java	Tue Feb 25 18:16:59 2014 +0100
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraalCompilerTest.java	Tue Feb 25 18:17:08 2014 +0100
@@ -83,10 +83,20 @@
     private final Backend backend;
     private final Suites suites;
 
+    private static boolean substitutionsInstalled;
+
+    private void installSubstitutions() {
+        if (!substitutionsInstalled) {
+            this.providers.getReplacements().registerSubstitutions(InjectProfileDataSubstitutions.class);
+            substitutionsInstalled = true;
+        }
+    }
+
     public GraalCompilerTest() {
         this.backend = Graal.getRequiredCapability(RuntimeProvider.class).getHostBackend();
         this.providers = getBackend().getProviders();
         this.suites = backend.getSuites().createSuites();
+        installSubstitutions();
     }
 
     /**
@@ -106,6 +116,7 @@
         }
         this.providers = backend.getProviders();
         this.suites = backend.getSuites().createSuites();
+        installSubstitutions();
     }
 
     @BeforeClass
@@ -643,4 +654,27 @@
     protected Replacements getReplacements() {
         return getProviders().getReplacements();
     }
+
+    /**
+     * Inject a probability for a branch condition into the profiling information of this test case.
+     * 
+     * @param p the probability that cond is true
+     * @param cond the condition of the branch
+     * @return cond
+     */
+    protected static boolean branchProbability(double p, boolean cond) {
+        return cond;
+    }
+
+    /**
+     * Inject an iteration count for a loop condition into the profiling information of this test
+     * case.
+     * 
+     * @param i the iteration count of the loop
+     * @param cond the condition of the loop
+     * @return cond
+     */
+    protected static boolean iterationCount(double i, boolean cond) {
+        return cond;
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/InjectProfileDataSubstitutions.java	Tue Feb 25 18:17:08 2014 +0100
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2014, 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.compiler.test;
+
+import com.oracle.graal.api.replacements.*;
+import com.oracle.graal.nodes.extended.*;
+
+@ClassSubstitution(GraalCompilerTest.class)
+class InjectProfileDataSubstitutions {
+
+    @MethodSubstitution
+    public static boolean branchProbability(double p, boolean cond) {
+        return BranchProbabilityNode.probability(p, cond);
+    }
+
+    @MethodSubstitution
+    public static boolean iterationCount(double i, boolean cond) {
+        return BranchProbabilityNode.probability(1. - 1. / i, cond);
+    }
+}
--- a/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/IntegerStampTest.java	Tue Feb 25 18:16:59 2014 +0100
+++ b/graal/com.oracle.graal.nodes.test/src/com/oracle/graal/nodes/test/IntegerStampTest.java	Tue Feb 25 18:17:08 2014 +0100
@@ -260,4 +260,68 @@
     public void testAnd() {
         assertEquals(new IntegerStamp(32, false, Integer.MIN_VALUE, 0x40000000L, 0, 0xc0000000L), StampTool.and(StampFactory.forKind(Kind.Int), StampFactory.forConstant(Constant.forInt(0xc0000000))));
     }
+
+    private static void testSignExtendShort(long lower, long upper) {
+        Stamp shortStamp = StampFactory.forInteger(16, false, lower, upper);
+        Stamp intStamp = StampTool.signExtend(shortStamp, 32);
+        assertEquals(StampFactory.forInteger(32, false, lower, upper), intStamp);
+    }
+
+    @Test
+    public void testSignExtend() {
+        testSignExtendShort(5, 7);
+        testSignExtendShort(0, 42);
+        testSignExtendShort(-42, -1);
+        testSignExtendShort(-42, 0);
+        testSignExtendShort(-1, 1);
+        testSignExtendShort(Short.MIN_VALUE, Short.MAX_VALUE);
+    }
+
+    private static void testZeroExtendShort(long lower, long upper, long newLower, long newUpper) {
+        Stamp shortStamp = StampFactory.forInteger(16, false, lower, upper);
+        Stamp intStamp = StampTool.zeroExtend(shortStamp, 32);
+        assertEquals(StampFactory.forInteger(32, false, newLower, newUpper), intStamp);
+    }
+
+    @Test
+    public void testZeroExtend() {
+        testZeroExtendShort(5, 7, 5, 7);
+        testZeroExtendShort(0, 42, 0, 42);
+        testZeroExtendShort(-42, -1, 0xFFFF - 41, 0xFFFF);
+        testZeroExtendShort(-42, 0, 0, 0xFFFF);
+        testZeroExtendShort(-1, 1, 0, 0xFFFF);
+        testZeroExtendShort(Short.MIN_VALUE, Short.MAX_VALUE, 0, 0xFFFF);
+    }
+
+    private static void testSignExtendChar(long lower, long upper, long newLower, long newUpper) {
+        Stamp charStamp = StampFactory.forInteger(16, true, lower, upper);
+        Stamp uintStamp = StampTool.signExtend(charStamp, 32);
+        assertEquals(StampFactory.forInteger(32, true, newLower, newUpper), uintStamp);
+    }
+
+    @Test
+    public void testSignExtendUnsigned() {
+        testSignExtendChar(5, 7, 5, 7);
+        testSignExtendChar(0, 42, 0, 42);
+        testSignExtendChar(5, 0xF000, 5, 0xFFFFF000L);
+        testSignExtendChar(0, 0xF000, 0, 0xFFFFF000L);
+        testSignExtendChar(0xF000, Character.MAX_VALUE, 0xFFFFF000L, 0xFFFFFFFFL);
+        testSignExtendChar(Character.MIN_VALUE, Character.MAX_VALUE, 0, 0xFFFFFFFFL);
+    }
+
+    private static void testZeroExtendChar(long lower, long upper) {
+        Stamp charStamp = StampFactory.forInteger(16, true, lower, upper);
+        Stamp uintStamp = StampTool.zeroExtend(charStamp, 32);
+        assertEquals(StampFactory.forInteger(32, true, lower, upper), uintStamp);
+    }
+
+    @Test
+    public void testZeroExtendUnsigned() {
+        testZeroExtendChar(5, 7);
+        testZeroExtendChar(0, 42);
+        testZeroExtendChar(5, 0xF000);
+        testZeroExtendChar(0, 0xF000);
+        testZeroExtendChar(0xF000, Character.MAX_VALUE);
+        testZeroExtendChar(Character.MIN_VALUE, Character.MAX_VALUE);
+    }
 }
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java	Tue Feb 25 18:16:59 2014 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/type/StampTool.java	Tue Feb 25 18:17:08 2014 +0100
@@ -329,7 +329,17 @@
             long downMask = SignExtendNode.signExtend(inputStamp.downMask(), inputBits) & defaultMask;
             long upMask = SignExtendNode.signExtend(inputStamp.upMask(), inputBits) & defaultMask;
 
-            return new IntegerStamp(resultBits, inputStamp.isUnsigned(), inputStamp.lowerBound(), inputStamp.upperBound(), downMask, upMask);
+            long lowerBound;
+            long upperBound;
+            if (inputStamp.isUnsigned()) {
+                lowerBound = SignExtendNode.signExtend(inputStamp.lowerBound(), inputBits) & defaultMask;
+                upperBound = SignExtendNode.signExtend(inputStamp.upperBound(), inputBits) & defaultMask;
+            } else {
+                lowerBound = inputStamp.lowerBound();
+                upperBound = inputStamp.upperBound();
+            }
+
+            return new IntegerStamp(resultBits, inputStamp.isUnsigned(), lowerBound, upperBound, downMask, upMask);
         } else {
             return input.illegal();
         }
@@ -343,24 +353,16 @@
 
             long downMask = ZeroExtendNode.zeroExtend(inputStamp.downMask(), inputBits);
             long upMask = ZeroExtendNode.zeroExtend(inputStamp.upMask(), inputBits);
-            long lowerBound;
-            long upperBound;
-            if (inputStamp.lowerBound() < 0) {
-                if (inputStamp.upperBound() >= 0) {
-                    // signed range including 0 and -1
-                    // after sign extension, the whole range from 0 to MAX_INT is possible
-                    return stampForMask(resultBits, downMask, upMask);
-                } else {
-                    // negative range
-                    upperBound = ZeroExtendNode.zeroExtend(inputStamp.lowerBound(), inputBits);
-                    lowerBound = ZeroExtendNode.zeroExtend(inputStamp.upperBound(), inputBits);
-                }
-            } else {
-                // positive range
-                lowerBound = ZeroExtendNode.zeroExtend(inputStamp.lowerBound(), inputBits);
-                upperBound = ZeroExtendNode.zeroExtend(inputStamp.upperBound(), inputBits);
+
+            if (inputStamp.lowerBound() < 0 && inputStamp.upperBound() >= 0) {
+                // signed range including 0 and -1
+                // after sign extension, the whole range from 0 to MAX_INT is possible
+                return stampForMask(resultBits, downMask, upMask);
             }
 
+            long lowerBound = ZeroExtendNode.zeroExtend(inputStamp.lowerBound(), inputBits);
+            long upperBound = ZeroExtendNode.zeroExtend(inputStamp.upperBound(), inputBits);
+
             return new IntegerStamp(resultBits, inputStamp.isUnsigned(), lowerBound, upperBound, downMask, upMask);
         } else {
             return input.illegal();