changeset 9482:37345671860c

Better handling of array access nodes in Word type rewriter
author Christian Wimmer <christian.wimmer@oracle.com>
date Wed, 01 May 2013 11:29:19 -0700
parents 1964cf13c376
children e577da5a49f2
files graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java
diffstat 1 files changed, 21 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java	Wed May 01 11:27:45 2013 -0700
+++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java	Wed May 01 11:29:19 2013 -0700
@@ -103,9 +103,27 @@
             }
         }
 
-        for (LoadIndexedNode load : graph.getNodes().filter(LoadIndexedNode.class).snapshot()) {
-            if (isWord(load)) {
-                load.setStamp(StampFactory.forKind(wordKind));
+        for (AccessIndexedNode node : graph.getNodes().filter(AccessIndexedNode.class).snapshot()) {
+            ValueNode array = node.array();
+            if (array.objectStamp().type() == null) {
+                // There are cases where the array does not have a known type yet. Assume it is not
+                // a word type.
+                continue;
+            }
+            assert array.objectStamp().type().isArray();
+            if (isWord(array.objectStamp().type().getComponentType())) {
+                /*
+                 * The elementKind of the node is a final field, and other information such as the
+                 * stamp depends on elementKind. Therefore, just create a new node and replace the
+                 * old one.
+                 */
+                if (node instanceof LoadIndexedNode) {
+                    graph.replaceFixedWithFixed(node, graph.add(new LoadIndexedNode(node.array(), node.index(), wordKind)));
+                } else if (node instanceof StoreIndexedNode) {
+                    graph.replaceFixedWithFixed(node, graph.add(new StoreIndexedNode(node.array(), node.index(), wordKind, ((StoreIndexedNode) node).value())));
+                } else {
+                    throw GraalInternalError.shouldNotReachHere();
+                }
             }
         }
 
@@ -309,16 +327,6 @@
         if (node.stamp() == StampFactory.forWord()) {
             return true;
         }
-        if (node instanceof LoadIndexedNode) {
-            ValueNode array = ((LoadIndexedNode) node).array();
-            if (array.objectStamp().type() == null) {
-                // There are cases where the array does not have a known type yet. Assume it is not
-                // a word type.
-                // TODO disallow LoadIndexedNode for word arrays?
-                return false;
-            }
-            return isWord(array.objectStamp().type().getComponentType());
-        }
         if (node.kind() == Kind.Object) {
             return isWord(node.objectStamp().type());
         }