Skip to content

Commit

Permalink
compiler: ArrayCopyWithDelayedLoweringNode should store its lowering …
Browse files Browse the repository at this point in the history
…stage
  • Loading branch information
zapster committed Sep 20, 2021
1 parent bfdae82 commit ce17861
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public boolean areDeoptsFixed() {
public boolean requiresValueProxies() {
return this != AFTER_FSA;
}

public boolean reachedStage(GuardsStage stage) {
return this.ordinal() >= stage.ordinal();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.graalvm.compiler.nodes.NamedLocationIdentity;
import org.graalvm.compiler.nodes.NodeView;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.nodes.StructuredGraph.GuardsStage;
import org.graalvm.compiler.nodes.java.ArrayLengthNode;
import org.graalvm.compiler.nodes.spi.LoweringTool;
import org.graalvm.compiler.nodes.type.StampTool;
Expand Down Expand Up @@ -137,7 +138,8 @@ public void arraycopyExactSnippet(Object src, int srcPos, Object dest, int destP
elementKindCounter.inc();
elementKindCopiedCounter.add(length);

ArrayCopyWithDelayedLoweringNode.arraycopy(nonNullSrc, srcPos, nonNullDest, destPos, length, WorkSnippetID.exactArraycopyWithSlowPathWork, elementKind);
// Don't lower until floating guards are fixed.
ArrayCopyWithDelayedLoweringNode.arraycopy(nonNullSrc, srcPos, nonNullDest, destPos, length, WorkSnippetID.exactArraycopyWithSlowPathWork, GuardsStage.FIXED_DEOPTS, elementKind);
}

/**
Expand Down Expand Up @@ -176,7 +178,8 @@ public void arraycopyCheckcastSnippet(Object src, int srcPos, Object dest, int d
checkLimits(nonNullSrc, srcPos, nonNullDest, destPos, length, counters);
incrementLengthCounter(length, counters);

ArrayCopyWithDelayedLoweringNode.arraycopy(nonNullSrc, srcPos, nonNullDest, destPos, length, WorkSnippetID.checkcastArraycopyWithSlowPathWork, elementKind);
// Don't lower until frame states are assigned to deoptimization points.
ArrayCopyWithDelayedLoweringNode.arraycopy(nonNullSrc, srcPos, nonNullDest, destPos, length, WorkSnippetID.checkcastArraycopyWithSlowPathWork, GuardsStage.AFTER_FSA, elementKind);
}

/**
Expand All @@ -192,7 +195,8 @@ public void arraycopyGenericSnippet(Object src, int srcPos, Object dest, int des
checkLimits(nonNullSrc, srcPos, nonNullDest, destPos, length, counters);
incrementLengthCounter(length, counters);

ArrayCopyWithDelayedLoweringNode.arraycopy(nonNullSrc, srcPos, nonNullDest, destPos, length, WorkSnippetID.genericArraycopyWithSlowPathWork, elementKind);
// Don't lower until frame states are assigned to deoptimization points.
ArrayCopyWithDelayedLoweringNode.arraycopy(nonNullSrc, srcPos, nonNullDest, destPos, length, WorkSnippetID.genericArraycopyWithSlowPathWork, GuardsStage.AFTER_FSA, elementKind);
}

/**
Expand Down Expand Up @@ -551,26 +555,11 @@ public void lower(ArrayCopyNode arraycopy, boolean mayExpandThisArraycopy, Lower
}

public void lower(ArrayCopyWithDelayedLoweringNode arraycopy, LoweringTool tool) {
lower(arraycopy, false, tool);
}

public void lower(ArrayCopyWithDelayedLoweringNode arraycopy, boolean mayExpandArraycopyLoops, LoweringTool tool) {
StructuredGraph graph = arraycopy.graph();

SnippetInfo snippetInfo = getSnippet(arraycopy.getSnippet());
if (snippetInfo == exactArraycopyWithSlowPathWork && mayExpandArraycopyLoops) {
if (!graph.getGuardsStage().areDeoptsFixed()) {
// Don't lower until floating guards are fixed.
return;
}
} else {
if (!graph.getGuardsStage().areFrameStatesAtDeopts()) {
// Don't lower until frame states are assigned to deoptimization points.
return;
}
if (!arraycopy.reachedLoweringStage()) {
return;
}

Arguments args = new Arguments(snippetInfo, graph.getGuardsStage(), tool.getLoweringStage());
Arguments args = new Arguments(getSnippet(arraycopy.getSnippet()), arraycopy.graph().getGuardsStage(), tool.getLoweringStage());
args.add("src", arraycopy.getSource());
args.add("srcPos", arraycopy.getSourcePosition());
args.add("dest", arraycopy.getDestination());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.nodeinfo.InputType;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.type.StampTool;
import org.graalvm.compiler.replacements.nodes.BasicArrayCopyNode;
Expand All @@ -41,32 +42,28 @@
* is delayed to avoid unfavorable interaction with other phases (floating guards, frame state
* assignment, etc.).
*
* Depending on the {@link #snippet}, lowering is delayed until either
* {@linkplain org.graalvm.compiler.nodes.StructuredGraph.GuardsStage#areDeoptsFixed() floating
* guards are fixed} or
* {@linkplain org.graalvm.compiler.nodes.StructuredGraph.GuardsStage#areFrameStatesAtDeopts() frame
* states are assigned to deoptimization points}. See
* {@link ArrayCopySnippets.Templates#lower(ArrayCopyWithDelayedLoweringNode, boolean, org.graalvm.compiler.nodes.spi.LoweringTool)}
* for more details.
*
* @see ArrayCopyNode
* @see ArrayCopySnippets
*/
@NodeInfo(allowedUsageTypes = InputType.Memory)
public final class ArrayCopyWithDelayedLoweringNode extends BasicArrayCopyNode {

public static final NodeClass<ArrayCopyWithDelayedLoweringNode> TYPE = NodeClass.create(ArrayCopyWithDelayedLoweringNode.class);

private final ArrayCopySnippets.WorkSnippetID snippet;
private final StructuredGraph.GuardsStage delayUntil;

public ArrayCopyWithDelayedLoweringNode(ValueNode src, ValueNode srcPos, ValueNode dest, ValueNode destPos, ValueNode length, ArrayCopySnippets.WorkSnippetID snippet, JavaKind elementKind) {
public ArrayCopyWithDelayedLoweringNode(ValueNode src, ValueNode srcPos, ValueNode dest, ValueNode destPos, ValueNode length, ArrayCopySnippets.WorkSnippetID snippet,
StructuredGraph.GuardsStage delayUntil, JavaKind elementKind) {
super(TYPE, src, srcPos, dest, destPos, length, elementKind, BytecodeFrame.INVALID_FRAMESTATE_BCI);
assert StampTool.isPointerNonNull(src) && StampTool.isPointerNonNull(dest) : "must have been null checked";
this.snippet = snippet;
this.delayUntil = delayUntil;
}

@NodeIntrinsic
public static native void arraycopy(Object nonNullSrc, int srcPos, Object nonNullDest, int destPos, int length, @ConstantNodeParameter ArrayCopySnippets.WorkSnippetID snippet,
@ConstantNodeParameter JavaKind elementKind);
@ConstantNodeParameter StructuredGraph.GuardsStage delayUntil, @ConstantNodeParameter JavaKind elementKind);

public ArrayCopySnippets.WorkSnippetID getSnippet() {
return snippet;
Expand All @@ -75,4 +72,8 @@ public ArrayCopySnippets.WorkSnippetID getSnippet() {
public void setBci(int bci) {
this.bci = bci;
}

public boolean reachedLoweringStage() {
return graph().getGuardsStage().reachedStage(delayUntil);
}
}

0 comments on commit ce17861

Please sign in to comment.