changeset 21077:4cba24bef2ee

Truffle-DSL: fix unnecessary cast in generated isIdentical for types used just in cached expressions .
author Christian Humer <christian.humer@gmail.com>
date Wed, 22 Apr 2015 15:04:01 +0200
parents 8f67ddf0dd3b
children 9cc0395dcd36 355ebfa2ba95
files graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/CachedTest.java graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java
diffstat 2 files changed, 25 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/CachedTest.java	Wed Apr 22 11:00:26 2015 +0200
+++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/CachedTest.java	Wed Apr 22 15:04:01 2015 +0200
@@ -40,6 +40,7 @@
 import com.oracle.truffle.api.dsl.test.CachedTestFactory.TestMultipleCachesFactory;
 import com.oracle.truffle.api.dsl.test.CachedTestFactory.UnboundCacheFactory;
 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
+import com.oracle.truffle.api.nodes.*;
 
 @SuppressWarnings("unused")
 public class CachedTest {
@@ -263,6 +264,26 @@
 
     }
 
+    /*
+     * Node should not produce any warnings in isIdentical of the generated code. Unnecessary casts
+     * were generated for isIdentical on the fast path.
+     */
+    @NodeChildren({@NodeChild, @NodeChild})
+    static class RegressionTestWarningInIsIdentical extends ValueNode {
+
+        @Specialization(guards = {"cachedName == name"})
+        protected Object directAccess(String receiver, String name, //
+                        @Cached("name") String cachedName, //
+                        @Cached("create(receiver, name)") Object callHandle) {
+            return receiver;
+        }
+
+        protected static Object create(String receiver, String name) {
+            return receiver;
+        }
+
+    }
+
     @NodeChild
     static class TestMultipleCaches extends ValueNode {
 
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java	Wed Apr 22 11:00:26 2015 +0200
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/generator/NodeGenFactory.java	Wed Apr 22 15:04:01 2015 +0200
@@ -1981,7 +1981,7 @@
         } else {
             castGuards = new HashSet<>();
             for (TypeGuard castGuard : group.getTypeGuards()) {
-                if (isTypeGuardUsedInAnyGuardOrCacheBelow(group, currentValues, castGuard)) {
+                if (isTypeGuardUsedInAnyGuardOrCacheBelow(group, currentValues, castGuard, execution.isFastPath())) {
                     castGuards.add(castGuard);
                 }
             }
@@ -2059,7 +2059,7 @@
         return true;
     }
 
-    private boolean isTypeGuardUsedInAnyGuardOrCacheBelow(SpecializationGroup group, LocalContext currentValues, TypeGuard typeGuard) {
+    private boolean isTypeGuardUsedInAnyGuardOrCacheBelow(SpecializationGroup group, LocalContext currentValues, TypeGuard typeGuard, boolean fastPath) {
         String localName = currentValues.getValue(typeGuard.getSignatureIndex()).getName();
 
         SpecializationData specialization = group.getSpecialization();
@@ -2068,7 +2068,7 @@
                 return true;
             }
         }
-        if (specialization != null) {
+        if (!fastPath && specialization != null) {
             for (CacheExpression cache : specialization.getCaches()) {
                 if (isVariableBoundIn(specialization, cache.getExpression(), localName, currentValues)) {
                     return true;
@@ -2077,7 +2077,7 @@
         }
 
         for (SpecializationGroup child : group.getChildren()) {
-            if (isTypeGuardUsedInAnyGuardOrCacheBelow(child, currentValues, typeGuard)) {
+            if (isTypeGuardUsedInAnyGuardOrCacheBelow(child, currentValues, typeGuard, fastPath)) {
                 return true;
             }
         }