changeset 18475:96528e410fab

Backed out changeset 42854d32b658
author Andreas Woess <andreas.woess@jku.at>
date Thu, 20 Nov 2014 17:25:52 +0100
parents 42854d32b658
children 2e2148013010
files graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java
diffstat 1 files changed, 43 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java	Thu Nov 20 14:15:14 2014 +0100
+++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java	Thu Nov 20 17:25:52 2014 +0100
@@ -48,9 +48,26 @@
     private static final DebugMetric METRIC_GLOBAL_VALUE_NUMBERING_HITS = Debug.metric("GlobalValueNumberingHits");
 
     private final boolean canonicalizeReads;
+    private final CustomCanonicalizer customCanonicalizer;
+
+    public abstract static class CustomCanonicalizer {
+
+        public Node canonicalize(Node node) {
+            return node;
+        }
+
+        @SuppressWarnings("unused")
+        public void simplify(Node node, SimplifierTool tool) {
+        }
+    }
 
     public CanonicalizerPhase(boolean canonicalizeReads) {
+        this(canonicalizeReads, null);
+    }
+
+    public CanonicalizerPhase(boolean canonicalizeReads, CustomCanonicalizer customCanonicalizer) {
         this.canonicalizeReads = canonicalizeReads;
+        this.customCanonicalizer = customCanonicalizer;
     }
 
     public boolean getCanonicalizeReads() {
@@ -59,7 +76,7 @@
 
     @Override
     protected void run(StructuredGraph graph, PhaseContext context) {
-        new Instance(context, canonicalizeReads).run(graph);
+        new Instance(context, canonicalizeReads, customCanonicalizer).run(graph);
     }
 
     /**
@@ -71,7 +88,7 @@
     }
 
     public void applyIncremental(StructuredGraph graph, PhaseContext context, Mark newNodesMark, boolean dumpGraph) {
-        new Instance(context, canonicalizeReads, newNodesMark).apply(graph, dumpGraph);
+        new Instance(context, canonicalizeReads, newNodesMark, customCanonicalizer).apply(graph, dumpGraph);
     }
 
     /**
@@ -83,7 +100,7 @@
     }
 
     public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable<? extends Node> workingSet, boolean dumpGraph) {
-        new Instance(context, canonicalizeReads, workingSet).apply(graph, dumpGraph);
+        new Instance(context, canonicalizeReads, workingSet, customCanonicalizer).apply(graph, dumpGraph);
     }
 
     public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable<? extends Node> workingSet, Mark newNodesMark) {
@@ -91,36 +108,38 @@
     }
 
     public void applyIncremental(StructuredGraph graph, PhaseContext context, Iterable<? extends Node> workingSet, Mark newNodesMark, boolean dumpGraph) {
-        new Instance(context, canonicalizeReads, workingSet, newNodesMark).apply(graph, dumpGraph);
+        new Instance(context, canonicalizeReads, workingSet, newNodesMark, customCanonicalizer).apply(graph, dumpGraph);
     }
 
     private static final class Instance extends Phase {
 
         private final Mark newNodesMark;
         private final PhaseContext context;
+        private final CustomCanonicalizer customCanonicalizer;
         private final Iterable<? extends Node> initWorkingSet;
         private final boolean canonicalizeReads;
 
         private NodeWorkList workList;
         private Tool tool;
 
-        private Instance(PhaseContext context, boolean canonicalizeReads) {
-            this(context, canonicalizeReads, null, null);
+        private Instance(PhaseContext context, boolean canonicalizeReads, CustomCanonicalizer customCanonicalizer) {
+            this(context, canonicalizeReads, null, null, customCanonicalizer);
         }
 
-        private Instance(PhaseContext context, boolean canonicalizeReads, Iterable<? extends Node> workingSet) {
-            this(context, canonicalizeReads, workingSet, null);
+        private Instance(PhaseContext context, boolean canonicalizeReads, Iterable<? extends Node> workingSet, CustomCanonicalizer customCanonicalizer) {
+            this(context, canonicalizeReads, workingSet, null, customCanonicalizer);
         }
 
-        private Instance(PhaseContext context, boolean canonicalizeReads, Mark newNodesMark) {
-            this(context, canonicalizeReads, null, newNodesMark);
+        private Instance(PhaseContext context, boolean canonicalizeReads, Mark newNodesMark, CustomCanonicalizer customCanonicalizer) {
+            this(context, canonicalizeReads, null, newNodesMark, customCanonicalizer);
         }
 
-        private Instance(PhaseContext context, boolean canonicalizeReads, Iterable<? extends Node> workingSet, Mark newNodesMark) {
+        private Instance(PhaseContext context, boolean canonicalizeReads, Iterable<? extends Node> workingSet, Mark newNodesMark, CustomCanonicalizer customCanonicalizer) {
             super("Canonicalizer");
             this.newNodesMark = newNodesMark;
             this.context = context;
             this.canonicalizeReads = canonicalizeReads;
+            this.customCanonicalizer = customCanonicalizer;
             this.initWorkingSet = workingSet;
         }
 
@@ -208,6 +227,18 @@
             return false;
         }
 
+        public boolean tryCanonicalize(final Node node, NodeClass nodeClass) {
+            if (customCanonicalizer != null) {
+                Node canonical = customCanonicalizer.canonicalize(node);
+                if (performReplacement(node, canonical)) {
+                    return true;
+                } else {
+                    customCanonicalizer.simplify(node, tool);
+                }
+            }
+            return baseTryCanonicalize(node, nodeClass);
+        }
+
         private static AutoCloseable getCanonicalizeableContractAssertion(Node node) {
             boolean needsAssertion = false;
             assert (needsAssertion = true) == true;
@@ -222,7 +253,7 @@
             }
         }
 
-        public boolean tryCanonicalize(final Node node, NodeClass nodeClass) {
+        public boolean baseTryCanonicalize(final Node node, NodeClass nodeClass) {
             if (nodeClass.isCanonicalizable()) {
                 METRIC_CANONICALIZATION_CONSIDERED_NODES.increment();
                 try (Scope s = Debug.scope("CanonicalizeNode", node)) {