# HG changeset patch # User Doug Simon # Date 1409252139 -7200 # Node ID 9cf849d5b3f9bc090ffb92b26dcaec5016da78cb # Parent 81eb0d77e9f98b01f610e942ec0b12bdd79f6caa reverted matcher to use Class keys instead of NodeClass keys diff -r 81eb0d77e9f9 -r 9cf849d5b3f9 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java Thu Aug 28 18:07:52 2014 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/NodeLIRBuilder.java Thu Aug 28 20:55:39 2014 +0200 @@ -94,7 +94,7 @@ private ValueNode currentInstruction; private ValueNode lastInstructionPrinted; // Debugging only - private Map> matchRules; + private Map, List> matchRules; public NodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool gen) { this.gen = gen; @@ -277,7 +277,7 @@ continue; } // See if this node is the root of any MatchStatements - List statements = matchRules.get(node.getNodeClass()); + List statements = matchRules.get(node.getClass()); if (statements != null) { for (MatchStatement statement : statements) { if (statement.generate(this, index, node, nodes)) { diff -r 81eb0d77e9f9 -r 9cf849d5b3f9 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchPattern.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchPattern.java Thu Aug 28 18:07:52 2014 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchPattern.java Thu Aug 28 20:55:39 2014 +0200 @@ -151,8 +151,22 @@ this(null, name, singleUser); } + /** + * Gets the {@link Node} class instantiated for a given canonical {@link Node} class depending + * on whether or not generated node classes are enabled. + */ + @SuppressWarnings("unchecked") + private static Class asInstantiatedClass(Class nodeClass) { + if (nodeClass != null && Node.USE_GENERATED_NODES) { + Class res = (Class) NodeClass.get(nodeClass).getGenClass(); + assert res != null : nodeClass; + return res; + } + return nodeClass; + } + public MatchPattern(Class nodeClass, String name, boolean singleUser) { - this.nodeClass = nodeClass; + this.nodeClass = asInstantiatedClass(nodeClass); this.name = name; this.singleUser = singleUser; this.patterns = EMPTY_PATTERNS; @@ -161,7 +175,7 @@ private MatchPattern(Class nodeClass, String name, boolean singleUser, MatchPattern[] patterns, Position[] inputs) { assert inputs == null || inputs.length == patterns.length; - this.nodeClass = nodeClass; + this.nodeClass = asInstantiatedClass(nodeClass); this.name = name; this.singleUser = singleUser; this.patterns = patterns; @@ -185,7 +199,7 @@ } private Result matchType(ValueNode node) { - if (nodeClass != null && !node.getNodeClass().is(nodeClass)) { + if (nodeClass != null && node.getClass() != nodeClass) { return Result.WRONG_CLASS(node, this); } return Result.OK; diff -r 81eb0d77e9f9 -r 9cf849d5b3f9 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchRuleRegistry.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchRuleRegistry.java Thu Aug 28 18:07:52 2014 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchRuleRegistry.java Thu Aug 28 20:55:39 2014 +0200 @@ -79,7 +79,7 @@ return result; } - private static final HashMap, Map>> registry = new HashMap<>(); + private static final HashMap, Map, List>> registry = new HashMap<>(); /** * Collect all the {@link MatchStatement}s defined by the superclass chain of theClass. @@ -87,12 +87,12 @@ * @param theClass * @return the set of {@link MatchStatement}s applicable to theClass. */ - public synchronized static Map> lookup(Class theClass) { - Map> result = registry.get(theClass); + public synchronized static Map, List> lookup(Class theClass) { + Map, List> result = registry.get(theClass); if (result == null) { NodeClassLookup lookup = new DefaultNodeClassLookup(); - Map> rules = createRules(theClass, lookup); + Map, List> rules = createRules(theClass, lookup); registry.put(theClass, rules); assert registry.get(theClass) == rules; result = rules; @@ -100,7 +100,7 @@ if (LogVerbose.getValue()) { try (Scope s = Debug.scope("MatchComplexExpressions")) { Debug.log("Match rules for %s", theClass.getSimpleName()); - for (Entry> entry : result.entrySet()) { + for (Entry, List> entry : result.entrySet()) { Debug.log(" For node class: %s", entry.getKey()); for (MatchStatement statement : entry.getValue()) { Debug.log(" %s", statement.getPattern()); @@ -120,7 +120,7 @@ * This is a separate, public method so that external clients can create rules with a custom * lookup and without the default caching behavior. */ - public static Map> createRules(Class theClass, NodeClassLookup lookup) { + public static Map, List> createRules(Class theClass, NodeClassLookup lookup) { HashMap, MatchStatementSet> matchSets = new HashMap<>(); Iterable sl = Services.load(MatchStatementSet.class); for (MatchStatementSet rules : sl) { @@ -129,14 +129,14 @@ // Walk the class hierarchy collecting lists and merge them together. The subclass // rules are first which gives them preference over earlier rules. - Map> rules = new HashMap<>(); + Map, List> rules = new HashMap<>(); Class currentClass = theClass; do { MatchStatementSet matchSet = matchSets.get(currentClass); if (matchSet != null) { List statements = matchSet.statements(lookup); for (MatchStatement statement : statements) { - NodeClass nodeClass = NodeClass.get(statement.getPattern().nodeClass()); + Class nodeClass = statement.getPattern().nodeClass(); List current = rules.get(nodeClass); if (current == null) { current = new ArrayList<>();