Mercurial > hg > graal-compiler
diff graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java @ 7530:5e3d1a68664e
applied mx eclipseformat to all Java files
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 23 Jan 2013 16:34:57 +0100 |
parents | 570d8e4c6dfb |
children | 727e869891fc |
line wrap: on
line diff
--- a/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java Wed Jan 23 16:34:38 2013 +0100 +++ b/graal/com.oracle.graal.snippets/src/com/oracle/graal/snippets/SnippetTemplate.java Wed Jan 23 16:34:57 2013 +0100 @@ -48,20 +48,21 @@ import com.oracle.graal.word.phases.*; /** - * A snippet template is a graph created by parsing a snippet method and then - * specialized by binding constants to the snippet's {@link ConstantParameter} parameters. - * + * A snippet template is a graph created by parsing a snippet method and then specialized by binding + * constants to the snippet's {@link ConstantParameter} parameters. + * * Snippet templates can be managed in a {@link Cache}. */ public class SnippetTemplate { /** - * A snippet template key encapsulates the method from which a snippet was built - * and the arguments used to specialize the snippet. - * + * A snippet template key encapsulates the method from which a snippet was built and the + * arguments used to specialize the snippet. + * * @see Cache */ public static class Key implements Iterable<Map.Entry<String, Object>> { + public final ResolvedJavaMethod method; private final HashMap<String, Object> map = new HashMap<>(); private int hash; @@ -122,6 +123,7 @@ * Arguments used to instantiate a template. */ public static class Arguments implements Iterable<Map.Entry<String, Object>> { + private final HashMap<String, Object> map = new HashMap<>(); public static Arguments arguments(String name, Object value) { @@ -158,7 +160,6 @@ private final MetaAccessProvider runtime; private final TargetDescription target; - public Cache(MetaAccessProvider runtime, TargetDescription target) { this.runtime = runtime; this.target = target; @@ -171,12 +172,13 @@ SnippetTemplate template = templates.get(key); if (template == null) { template = Debug.scope("SnippetSpecialization", key.method, new Callable<SnippetTemplate>() { + @Override public SnippetTemplate call() throws Exception { return new SnippetTemplate(runtime, assumptions, target, key); } }); - //System.out.println(key + " -> " + template); + // System.out.println(key + " -> " + template); templates.put(key, template); } return template; @@ -184,6 +186,7 @@ } public abstract static class AbstractTemplates<T extends SnippetsInterface> { + protected final Cache cache; protected final MetaAccessProvider runtime; protected final Assumptions assumptions; @@ -334,7 +337,8 @@ do { exploded = false; ExplodeLoopNode explodeLoop = snippetCopy.getNodes().filter(ExplodeLoopNode.class).first(); - if (explodeLoop != null) { // Earlier canonicalization may have removed the loop altogether + if (explodeLoop != null) { // Earlier canonicalization may have removed the loop + // altogether LoopBeginNode loopBegin = explodeLoop.findLoopBegin(); if (loopBegin != null) { LoopEx loop = new LoopsData(snippetCopy).loop(loopBegin); @@ -415,11 +419,10 @@ return true; } if (kind == Kind.Object) { - assert arg == null || type.isInstance(Constant.forObject(arg)) : - method + ": wrong value type for " + name + ": expected " + type.getName() + ", got " + arg.getClass().getName(); + assert arg == null || type.isInstance(Constant.forObject(arg)) : method + ": wrong value type for " + name + ": expected " + type.getName() + ", got " + arg.getClass().getName(); } else { - assert arg != null && kind.toBoxedJavaClass() == arg.getClass() : - method + ": wrong value kind for " + name + ": expected " + kind + ", got " + (arg == null ? "null" : arg.getClass().getSimpleName()); + assert arg != null && kind.toBoxedJavaClass() == arg.getClass() : method + ": wrong value kind for " + name + ": expected " + kind + ", got " + + (arg == null ? "null" : arg.getClass().getSimpleName()); } return true; } @@ -438,10 +441,10 @@ private final StructuredGraph snippet; /** - * The named parameters of this template that must be bound to values during instantiation. - * For a parameter that is still live after specialization, the value in this map is either - * a {@link LocalNode} instance or a {@link LocalNode} array. For an eliminated parameter, - * the value is identical to the key. + * The named parameters of this template that must be bound to values during instantiation. For + * a parameter that is still live after specialization, the value in this map is either a + * {@link LocalNode} instance or a {@link LocalNode} array. For an eliminated parameter, the + * value is identical to the key. */ private final Map<String, Object> parameters; @@ -451,7 +454,8 @@ private final ReturnNode returnNode; /** - * Nodes that inherit the {@link StateSplit#stateAfter()} from the replacee during instantiation. + * Nodes that inherit the {@link StateSplit#stateAfter()} from the replacee during + * instantiation. */ private final List<Node> sideEffectNodes; @@ -467,7 +471,7 @@ /** * Gets the instantiation-time bindings to this template's parameters. - * + * * @return the map that will be used to bind arguments to parameters when inlining this template */ private IdentityHashMap<Node, Node> bind(StructuredGraph replaceeGraph, MetaAccessProvider runtime, SnippetTemplate.Arguments args) { @@ -521,13 +525,13 @@ } /** - * Logic for replacing a snippet-lowered node at its usages with the return value - * of the snippet. An alternative to the - * {@linkplain SnippetTemplate#DEFAULT_REPLACER default} replacement logic can be used to - * handle mismatches between the stamp of the node being lowered and the - * stamp of the snippet's return value. + * Logic for replacing a snippet-lowered node at its usages with the return value of the + * snippet. An alternative to the {@linkplain SnippetTemplate#DEFAULT_REPLACER default} + * replacement logic can be used to handle mismatches between the stamp of the node being + * lowered and the stamp of the snippet's return value. */ public interface UsageReplacer { + /** * Replaces all usages of {@code oldNode} with direct or indirect usages of {@code newNode}. */ @@ -535,10 +539,11 @@ } /** - * Represents the default {@link UsageReplacer usage replacer} logic which - * simply delegates to {@link Node#replaceAtUsages(Node)}. + * Represents the default {@link UsageReplacer usage replacer} logic which simply delegates to + * {@link Node#replaceAtUsages(Node)}. */ public static final UsageReplacer DEFAULT_REPLACER = new UsageReplacer() { + @Override public void replace(ValueNode oldNode, ValueNode newNode) { oldNode.replaceAtUsages(newNode); @@ -547,17 +552,14 @@ /** * Replaces a given fixed node with this specialized snippet. - * + * * @param runtime * @param replacee the node that will be replaced * @param replacer object that replaces the usages of {@code replacee} * @param args the arguments to be bound to the flattened positional parameters of the snippet * @return the map of duplicated nodes (original -> duplicate) */ - public Map<Node, Node> instantiate(MetaAccessProvider runtime, - FixedWithNextNode replacee, - UsageReplacer replacer, - SnippetTemplate.Arguments args) { + public Map<Node, Node> instantiate(MetaAccessProvider runtime, FixedWithNextNode replacee, UsageReplacer replacer, SnippetTemplate.Arguments args) { // Inline the snippet nodes, replacing parameters with the given args in the process String name = snippet.name == null ? "{copy}" : snippet.name + "{copy}"; @@ -623,17 +625,14 @@ /** * Replaces a given floating node with this specialized snippet. - * + * * @param runtime * @param replacee the node that will be replaced * @param replacer object that replaces the usages of {@code replacee} * @param lastFixedNode the CFG of the snippet is inserted after this node * @param args the arguments to be bound to the flattened positional parameters of the snippet */ - public void instantiate(MetaAccessProvider runtime, - FloatingNode replacee, - UsageReplacer replacer, - FixedWithNextNode lastFixedNode, SnippetTemplate.Arguments args) { + public void instantiate(MetaAccessProvider runtime, FloatingNode replacee, UsageReplacer replacer, FixedWithNextNode lastFixedNode, SnippetTemplate.Arguments args) { // Inline the snippet nodes, replacing parameters with the given args in the process String name = snippet.name == null ? "{copy}" : snippet.name + "{copy}"; @@ -692,7 +691,7 @@ Object value = e.getValue(); buf.append(sep); sep = ", "; - if (value == UNUSED_PARAMETER) { + if (value == UNUSED_PARAMETER) { buf.append("<unused> ").append(name); } else if (value instanceof LocalNode) { LocalNode local = (LocalNode) value; @@ -728,10 +727,8 @@ Varargs varargs = (Varargs) key.get(name); assert checkVarargs(method, signature, i, name, varargs); } else { - assert p != null : method + ": parameter " + i + " must be annotated with exactly one of " + - "@" + ConstantParameter.class.getSimpleName() + " or " + - "@" + VarargsParameter.class.getSimpleName() + " or " + - "@" + Parameter.class.getSimpleName(); + assert p != null : method + ": parameter " + i + " must be annotated with exactly one of " + "@" + ConstantParameter.class.getSimpleName() + " or " + "@" + + VarargsParameter.class.getSimpleName() + " or " + "@" + Parameter.class.getSimpleName(); } } if (!key.names().containsAll(expected)) { @@ -741,8 +738,8 @@ if (!expected.containsAll(key.names())) { Set<String> namesCopy = new HashSet<>(key.names()); namesCopy.removeAll(expected); - assert false : "parameter(s) " + namesCopy + " should be annotated with @" + ConstantParameter.class.getSimpleName() + - " or @" + VarargsParameter.class.getSimpleName() + " in " + MetaUtil.format("%H.%n(%p)", method); + assert false : "parameter(s) " + namesCopy + " should be annotated with @" + ConstantParameter.class.getSimpleName() + " or @" + VarargsParameter.class.getSimpleName() + " in " + + MetaUtil.format("%H.%n(%p)", method); } return true; }