src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchContext.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchContext.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.match;
  24 
  25 import static org.graalvm.compiler.debug.GraalDebugConfig.Options.LogVerbose;
  26 
  27 import java.util.ArrayList;
  28 import java.util.Arrays;
  29 import java.util.List;
  30 
  31 import org.graalvm.compiler.core.gen.NodeLIRBuilder;
  32 import org.graalvm.compiler.core.match.MatchPattern.Result;
  33 import org.graalvm.compiler.debug.Debug;
  34 import org.graalvm.compiler.debug.GraalError;
  35 import org.graalvm.compiler.graph.Node;
  36 import org.graalvm.compiler.nodes.calc.FloatingNode;
  37 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;
  38 import org.graalvm.util.Equivalence;
  39 import org.graalvm.util.EconomicMap;

  40 
  41 /**
  42  * Container for state captured during a match.
  43  */
  44 public class MatchContext {
  45 
  46     private final Node root;
  47 
  48     private final List<Node> nodes;
  49 
  50     private final MatchStatement rule;
  51 
  52     private EconomicMap<String, NamedNode> namedNodes;
  53 
  54     private ArrayList<Node> consumed;
  55 
  56     private int startIndex;
  57 
  58     private int endIndex;
  59 


  93             namedNodes.put(name, current);
  94             return Result.OK;
  95         } else {
  96             if (current.value != value || current.type != type) {
  97                 return Result.namedValueMismatch(value, rule.getPattern());
  98             }
  99             return Result.OK;
 100         }
 101     }
 102 
 103     public Result validate() {
 104         // Ensure that there's no unsafe work in between these operations.
 105         for (int i = startIndex; i <= endIndex; i++) {
 106             Node node = nodes.get(i);
 107             if (node instanceof VirtualObjectNode || node instanceof FloatingNode) {
 108                 // The order of evaluation of these nodes controlled by data dependence so they
 109                 // don't interfere with this match.
 110                 continue;
 111             } else if ((consumed == null || !consumed.contains(node)) && node != root) {
 112                 if (LogVerbose.getValue(root.getOptions())) {
 113                     Debug.log("unexpected node %s", node);

 114                     for (int j = startIndex; j <= endIndex; j++) {
 115                         Node theNode = nodes.get(j);
 116                         Debug.log("%s(%s) %1s", (consumed != null && consumed.contains(theNode) || theNode == root) ? "*" : " ", theNode.getUsageCount(), theNode);
 117                     }
 118                 }
 119                 return Result.notSafe(node, rule.getPattern());
 120             }
 121         }
 122         return Result.OK;
 123     }
 124 
 125     /**
 126      * Mark the interior nodes with INTERIOR_MATCH and set the Value of the root to be the result.
 127      * During final LIR generation it will be evaluated to produce the actual LIR value.
 128      *
 129      * @param result
 130      */
 131     public void setResult(ComplexMatchResult result) {
 132         ComplexMatchValue value = new ComplexMatchValue(result);
 133         if (Debug.isLogEnabled()) {
 134             Debug.log("matched %s %s", rule.getName(), rule.getPattern());
 135             Debug.log("with nodes %s", rule.formatMatch(root));

 136         }
 137         if (consumed != null) {
 138             for (Node node : consumed) {
 139                 // All the interior nodes should be skipped during the normal doRoot calls in
 140                 // NodeLIRBuilder so mark them as interior matches. The root of the match will get a
 141                 // closure which will be evaluated to produce the final LIR.
 142                 builder.setMatchResult(node, ComplexMatchValue.INTERIOR_MATCH);
 143             }
 144         }
 145         builder.setMatchResult(root, value);
 146     }
 147 
 148     /**
 149      * Mark a node as consumed by the match. Consumed nodes will never be evaluated.
 150      *
 151      * @return Result.OK if the node can be safely consumed.
 152      */
 153     public Result consume(Node node) {
 154         assert MatchPattern.isSingleValueUser(node) : "should have already been checked";
 155 




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.core.match;
  24 
  25 import static org.graalvm.compiler.debug.DebugOptions.LogVerbose;
  26 
  27 import java.util.ArrayList;
  28 import java.util.Arrays;
  29 import java.util.List;
  30 
  31 import org.graalvm.compiler.core.gen.NodeLIRBuilder;
  32 import org.graalvm.compiler.core.match.MatchPattern.Result;
  33 import org.graalvm.compiler.debug.DebugContext;
  34 import org.graalvm.compiler.debug.GraalError;
  35 import org.graalvm.compiler.graph.Node;
  36 import org.graalvm.compiler.nodes.calc.FloatingNode;
  37 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode;

  38 import org.graalvm.util.EconomicMap;
  39 import org.graalvm.util.Equivalence;
  40 
  41 /**
  42  * Container for state captured during a match.
  43  */
  44 public class MatchContext {
  45 
  46     private final Node root;
  47 
  48     private final List<Node> nodes;
  49 
  50     private final MatchStatement rule;
  51 
  52     private EconomicMap<String, NamedNode> namedNodes;
  53 
  54     private ArrayList<Node> consumed;
  55 
  56     private int startIndex;
  57 
  58     private int endIndex;
  59 


  93             namedNodes.put(name, current);
  94             return Result.OK;
  95         } else {
  96             if (current.value != value || current.type != type) {
  97                 return Result.namedValueMismatch(value, rule.getPattern());
  98             }
  99             return Result.OK;
 100         }
 101     }
 102 
 103     public Result validate() {
 104         // Ensure that there's no unsafe work in between these operations.
 105         for (int i = startIndex; i <= endIndex; i++) {
 106             Node node = nodes.get(i);
 107             if (node instanceof VirtualObjectNode || node instanceof FloatingNode) {
 108                 // The order of evaluation of these nodes controlled by data dependence so they
 109                 // don't interfere with this match.
 110                 continue;
 111             } else if ((consumed == null || !consumed.contains(node)) && node != root) {
 112                 if (LogVerbose.getValue(root.getOptions())) {
 113                     DebugContext debug = root.getDebug();
 114                     debug.log("unexpected node %s", node);
 115                     for (int j = startIndex; j <= endIndex; j++) {
 116                         Node theNode = nodes.get(j);
 117                         debug.log("%s(%s) %1s", (consumed != null && consumed.contains(theNode) || theNode == root) ? "*" : " ", theNode.getUsageCount(), theNode);
 118                     }
 119                 }
 120                 return Result.notSafe(node, rule.getPattern());
 121             }
 122         }
 123         return Result.OK;
 124     }
 125 
 126     /**
 127      * Mark the interior nodes with INTERIOR_MATCH and set the Value of the root to be the result.
 128      * During final LIR generation it will be evaluated to produce the actual LIR value.
 129      *
 130      * @param result
 131      */
 132     public void setResult(ComplexMatchResult result) {
 133         ComplexMatchValue value = new ComplexMatchValue(result);
 134         DebugContext debug = root.getDebug();
 135         if (debug.isLogEnabled()) {
 136             debug.log("matched %s %s", rule.getName(), rule.getPattern());
 137             debug.log("with nodes %s", rule.formatMatch(root));
 138         }
 139         if (consumed != null) {
 140             for (Node node : consumed) {
 141                 // All the interior nodes should be skipped during the normal doRoot calls in
 142                 // NodeLIRBuilder so mark them as interior matches. The root of the match will get a
 143                 // closure which will be evaluated to produce the final LIR.
 144                 builder.setMatchResult(node, ComplexMatchValue.INTERIOR_MATCH);
 145             }
 146         }
 147         builder.setMatchResult(root, value);
 148     }
 149 
 150     /**
 151      * Mark a node as consumed by the match. Consumed nodes will never be evaluated.
 152      *
 153      * @return Result.OK if the node can be safely consumed.
 154      */
 155     public Result consume(Node node) {
 156         assert MatchPattern.isSingleValueUser(node) : "should have already been checked";
 157 


src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core/src/org/graalvm/compiler/core/match/MatchContext.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File