public class SnippetTemplate extends Object
Snippet.ConstantParameter parameters.
Snippet templates can be managed in a cache maintained by SnippetTemplate.AbstractTemplates.
WithExceptionNodeWithExceptionNode is more complicated than for normal (fixed) nodes, because
of the exception edge.
UnwindNodeWithException node
will be lowered via a snippet.
...
|
pred
|
WithException <--- // to be lowered
/ \
[next] / \ [exceptionEdge]
/ \
Begin ExceptionObject
| |
nextSucc exceptionSucc
| |
... ...
StartNode and ending with a
ReturnNode and or an UnwindNode. For simplicity, multiple ReturnNodes are merged and replaced by a single return
node.
The following is the simplest possible example for a snippet with an UnwindNode. The
snippet consists of an @code InvokeWithException'}.
Start'
|
InvokeWithException'
/ \
[next] / \ [exceptionEdge]
/ \
Begin' ExceptionObject'
| |
Return' Unwind'
WithException node in the replacee graph is replaced by
the snippet graph. The Start' is connected to the predecessor, the Return' to the
next edge, and the Unwind' to the
exception edge.
...
|
pred
|
InvokeWithException'
/ \
[next] / \ [exceptionEdge]
/ \
Begin' ExceptionObject'
| |
Begin ExceptionObject
| |
nextSucc exceptionSucc
| |
... ...
It is important to note that we do not yet remove the original Begin and
WithException node, although they are no longer needed. Doing so would require support
from the LoweringPhase, which might still hold references to these nodes for subsequent
lowering rounds. Simplifications and
lowering will take care of removing these nodes.
...
|
pred
|
InvokeWithException'
/ \
[next] / \ [exceptionEdge]
/ \
Begin' ExceptionObject'
| |
nextSucc exceptionSucc
| |
... ...
UnwindNodeWithExceptionNode
are nodes where the exception edge is an
UnreachableBeginNode followed by an
UnreachableControlSinkNode. This pattern is used to encode
that we have proven that the WithExceptionNode will never throw an exception.
...
|
pred
|
WithException <--- // to be lowered
/ \
[next] / \ [exceptionEdge]
/ \
Begin UnreachableBegin
| |
nextSucc UnreachableControlSink
|
...
Start'
|
InvokeWithException'
/ \
[next] / \ [exceptionEdge]
/ \
Begin' ExceptionObject'
| |
Return' Unwind'
ExceptionObject' from the snippet graph, and attach the
original UnreachableBegin directly to the exception producing instruction from the
snippet (the InvokeWithException' node in this example).
...
|
pred
|
InvokeWithException'
/ \
[next] / \ [exceptionEdge]
/ \
Begin' UnreachableBegin
| |
Begin UnreachableControlSink
|
nextSucc
|
...
UnwindNodeWithExceptionNode.
...
|
pred
|
WithException <--- // to be lowered
/ \
[next] / \ [exceptionEdge]
/ \
Begin ExceptionObject
| |
nextSucc exceptionSucc
| |
... ...
NonThrowingWork' node.
Start'
|
NonThrowingWork'
|
Return'
LoweringPhase. Thus, we introduce an artificial
PlaceholderWithException' that connects to the
exception edge. This placeholder node removes the
exception edge and itself in a subsequent canonicalization.
...
|
pred
|
NonThrowingWork'
|
PlaceholderWithException'
/ \
[next] / \ [exceptionEdge]
/ \
Begin' ExceptionObject'
| |
Begin ExceptionObject
| |
nextSucc exceptionSucc
| |
... ...
...
|
pred
|
NonThrowingWork'
|
nextSucc
|
...
| Modifier and Type | Class and Description |
|---|---|
static class |
SnippetTemplate.AbstractTemplates
Base class for snippet classes.
|
static class |
SnippetTemplate.Arguments
Values that are bound to the snippet method parameters.
|
static class |
SnippetTemplate.EagerSnippetInfo |
protected static class |
SnippetTemplate.LazySnippetInfo |
static class |
SnippetTemplate.SnippetInfo
Holds the
ResolvedJavaMethod of the snippet, together with some information about the
method that needs to be computed only once. |
static interface |
SnippetTemplate.UsageReplacer
Logic for replacing a snippet-lowered node at its usages with the return value of the
snippet.
|
| Modifier and Type | Field and Description |
|---|---|
static SnippetTemplate.UsageReplacer |
DEFAULT_REPLACER
Represents the default
usage replacer logic which simply delegates to
Node.replaceAtUsages(Node). |
| Modifier | Constructor and Description |
|---|---|
protected |
SnippetTemplate(OptionValues options,
DebugContext debug,
Providers providers,
SnippetTemplate.Arguments args,
boolean trackNodeSourcePosition,
Node replacee,
PhaseSuite<Providers> midTierPhases)
Creates a snippet template.
|
| Modifier and Type | Method and Description |
|---|---|
StructuredGraph |
copySpecializedGraph(DebugContext debugForCopy)
Gets a copy of the specialized graph.
|
static void |
explodeLoops(StructuredGraph snippetCopy,
CoreProviders providers) |
protected JavaConstant |
forBoxed(Object argument,
JavaKind localKind)
Converts a Java boxed value to a
JavaConstant of the right kind. |
protected Object[] |
getConstantArgs(SnippetTemplate.Arguments args) |
Node |
getReturnValue(org.graalvm.collections.UnmodifiableEconomicMap<Node,Node> duplicates) |
boolean |
hasSideEffects() |
org.graalvm.collections.UnmodifiableEconomicMap<Node,Node> |
instantiate(MetaAccessProvider metaAccess,
FixedNode replacee,
SnippetTemplate.UsageReplacer replacer,
SnippetTemplate.Arguments args)
Replaces a given fixed node with this specialized snippet.
|
org.graalvm.collections.UnmodifiableEconomicMap<Node,Node> |
instantiate(MetaAccessProvider metaAccess,
FixedNode replacee,
SnippetTemplate.UsageReplacer replacer,
SnippetTemplate.Arguments args,
boolean killReplacee)
Replaces a given fixed node with this specialized snippet.
|
void |
instantiate(MetaAccessProvider metaAccess,
FloatingNode replacee,
SnippetTemplate.UsageReplacer replacer,
LoweringTool tool,
SnippetTemplate.Arguments args)
Replaces a given floating node with this specialized snippet.
|
void |
instantiate(MetaAccessProvider metaAccess,
FloatingNode replacee,
SnippetTemplate.UsageReplacer replacer,
SnippetTemplate.Arguments args)
Replaces a given floating node with this specialized snippet.
|
static void |
replaceExceptionObjectNode(AbstractBeginNode originalExceptionEdge,
FixedWithNextNode replacementUnwindPath)
Replaces the original
ExceptionObjectNode with the exception handling path from the
snippet. |
protected void |
rewireFrameStates(ValueNode replacee,
org.graalvm.collections.UnmodifiableEconomicMap<Node,Node> duplicates,
FixedNode replaceeGraphCFGPredecessor) |
void |
setMayRemoveLocation(boolean mayRemoveLocation) |
String |
toString() |
public static final SnippetTemplate.UsageReplacer DEFAULT_REPLACER
usage replacer logic which simply delegates to
Node.replaceAtUsages(Node).protected SnippetTemplate(OptionValues options, DebugContext debug, Providers providers, SnippetTemplate.Arguments args, boolean trackNodeSourcePosition, Node replacee, PhaseSuite<Providers> midTierPhases)
public static void explodeLoops(StructuredGraph snippetCopy, CoreProviders providers)
protected Object[] getConstantArgs(SnippetTemplate.Arguments args)
public boolean hasSideEffects()
protected JavaConstant forBoxed(Object argument, JavaKind localKind)
JavaConstant of the right kind. This adjusts for the
limitation that a Local's kind is a stack kind
and so cannot be used for re-boxing primitives smaller than an int.argument - a Java boxed valuelocalKind - the kind of the Local to which argument will be boundpublic Node getReturnValue(org.graalvm.collections.UnmodifiableEconomicMap<Node,Node> duplicates)
public org.graalvm.collections.UnmodifiableEconomicMap<Node,Node> instantiate(MetaAccessProvider metaAccess, FixedNode replacee, SnippetTemplate.UsageReplacer replacer, SnippetTemplate.Arguments args)
metaAccess - replacee - the node that will be replacedreplacer - object that replaces the usages of replaceeargs - the arguments to be bound to the flattened positional parameters of the snippetpublic org.graalvm.collections.UnmodifiableEconomicMap<Node,Node> instantiate(MetaAccessProvider metaAccess, FixedNode replacee, SnippetTemplate.UsageReplacer replacer, SnippetTemplate.Arguments args, boolean killReplacee)
metaAccess - replacee - the node that will be replacedreplacer - object that replaces the usages of replaceeargs - the arguments to be bound to the flattened positional parameters of the snippetkillReplacee - is true, the replacee node is deletedpublic static void replaceExceptionObjectNode(AbstractBeginNode originalExceptionEdge, FixedWithNextNode replacementUnwindPath)
ExceptionObjectNode with the exception handling path from the
snippet. Ideally, this should simply be the following:
graph.replaceFixedWithFixed(originalExceptionEdge, replacementUnwindPath);Unfortunately, removing control flow paths during lowering might confuse the lowering phase. So until this is fixed (GR-34538), instead of deleting the original
ExceptionObjectNode, we keep it and insert the new exception handling path just
before it. ExceptionObjectNode.lower(org.graalvm.compiler.nodes.spi.LoweringTool) will notice this situation later and delete the
node.originalExceptionEdge - the ExceptionObjectNode that should be deletedreplacementUnwindPath - the replacement for the original ExceptionObjectNodeExceptionObjectNode.lower(org.graalvm.compiler.nodes.spi.LoweringTool)public StructuredGraph copySpecializedGraph(DebugContext debugForCopy)
public void instantiate(MetaAccessProvider metaAccess,
FloatingNode replacee,
SnippetTemplate.UsageReplacer replacer,
LoweringTool tool,
SnippetTemplate.Arguments args)
metaAccess - replacee - the node that will be replacedreplacer - object that replaces the usages of replaceetool - lowering tool used to insert the snippet into the control-flowargs - the arguments to be bound to the flattened positional parameters of the snippetpublic void instantiate(MetaAccessProvider metaAccess,
FloatingNode replacee,
SnippetTemplate.UsageReplacer replacer,
SnippetTemplate.Arguments args)
metaAccess - replacee - the node that will be replacedreplacer - object that replaces the usages of replaceeargs - the arguments to be bound to the flattened positional parameters of the snippetprotected void rewireFrameStates(ValueNode replacee, org.graalvm.collections.UnmodifiableEconomicMap<Node,Node> duplicates, FixedNode replaceeGraphCFGPredecessor)
public void setMayRemoveLocation(boolean mayRemoveLocation)