use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class IntrinsicContext method createFrameState.
public FrameState createFrameState(StructuredGraph graph, SideEffectsState sideEffects, StateSplit forStateSplit, NodeSourcePosition sourcePosition) {
assert forStateSplit != graph.start();
if (forStateSplit.hasSideEffect()) {
if (sideEffects.isAfterSideEffect()) {
// Only the last side effect on any execution path in a replacement
// can inherit the stateAfter of the replaced node
FrameState invalid = graph.add(new FrameState(INVALID_FRAMESTATE_BCI));
if (graph.trackNodeSourcePosition()) {
invalid.setNodeSourcePosition(sourcePosition);
}
for (StateSplit lastSideEffect : sideEffects.sideEffects()) {
lastSideEffect.setStateAfter(invalid);
}
}
sideEffects.addSideEffect(forStateSplit);
FrameState frameState;
if (forStateSplit instanceof ExceptionObjectNode) {
frameState = graph.add(new FrameState(AFTER_EXCEPTION_BCI, (ExceptionObjectNode) forStateSplit));
} else {
frameState = graph.add(new FrameState(AFTER_BCI));
}
if (graph.trackNodeSourcePosition()) {
frameState.setNodeSourcePosition(sourcePosition);
}
return frameState;
} else {
if (forStateSplit instanceof AbstractMergeNode) {
// Merge nodes always need a frame state
if (sideEffects.isAfterSideEffect()) {
// A merge after one or more side effects
FrameState frameState = graph.add(new FrameState(AFTER_BCI));
if (graph.trackNodeSourcePosition()) {
frameState.setNodeSourcePosition(sourcePosition);
}
return frameState;
} else {
// A merge before any side effects
FrameState frameState = graph.add(new FrameState(BEFORE_BCI));
if (graph.trackNodeSourcePosition()) {
frameState.setNodeSourcePosition(sourcePosition);
}
return frameState;
}
} else {
// Other non-side-effects do not need a state
return null;
}
}
}
use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class InliningUtil method fixFrameStates.
private static void fixFrameStates(StructuredGraph graph, MergeNode originalMerge, PhiNode returnPhi) {
// It is possible that some of the frame states that came from AFTER_BCI reference a Phi
// node that was created to merge multiple returns. This can create cycles
// (see GR-3949 and GR-3957).
// To detect this, we follow the control paths starting from the merge node,
// split the Phi node inputs at merges and assign the proper input to each frame state.
NodeMap<Node> seen = new NodeMap<>(graph);
ArrayDeque<Node> workList = new ArrayDeque<>();
ArrayDeque<ValueNode> valueList = new ArrayDeque<>();
workList.push(originalMerge);
valueList.push(returnPhi);
while (!workList.isEmpty()) {
Node current = workList.pop();
ValueNode currentValue = valueList.pop();
if (seen.containsKey(current)) {
continue;
}
seen.put(current, current);
if (current instanceof StateSplit && current != originalMerge) {
StateSplit stateSplit = (StateSplit) current;
FrameState state = stateSplit.stateAfter();
if (state != null && state.values().contains(returnPhi)) {
int index = 0;
FrameState duplicate = state.duplicate();
for (ValueNode value : state.values()) {
if (value == returnPhi) {
duplicate.values().set(index, currentValue);
}
index++;
}
stateSplit.setStateAfter(duplicate);
GraphUtil.tryKillUnused(state);
}
}
if (current instanceof AbstractMergeNode) {
AbstractMergeNode currentMerge = (AbstractMergeNode) current;
for (EndNode pred : currentMerge.cfgPredecessors()) {
ValueNode newValue = currentValue;
if (currentMerge.isPhiAtMerge(currentValue)) {
PhiNode currentPhi = (PhiNode) currentValue;
newValue = currentPhi.valueAt(pred);
}
workList.push(pred);
valueList.push(newValue);
}
} else if (current.predecessor() != null) {
workList.push(current.predecessor());
valueList.push(currentValue);
}
}
}
use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class GraphUtil method approxSourceStackTraceElement.
/**
* Gets an approximate source code location for a node if possible.
*
* @return the StackTraceElements if an approximate source location is found, null otherwise
*/
public static StackTraceElement[] approxSourceStackTraceElement(Node node) {
NodeSourcePosition position = node.getNodeSourcePosition();
if (position != null) {
// positions.
return approxSourceStackTraceElement(position);
}
ArrayList<StackTraceElement> elements = new ArrayList<>();
Node n = node;
while (n != null) {
if (n instanceof MethodCallTargetNode) {
elements.add(((MethodCallTargetNode) n).targetMethod().asStackTraceElement(-1));
n = ((MethodCallTargetNode) n).invoke().asNode();
}
if (n instanceof StateSplit) {
FrameState state = ((StateSplit) n).stateAfter();
elements.addAll(Arrays.asList(approxSourceStackTraceElement(state)));
break;
}
n = n.predecessor();
}
return elements.toArray(new StackTraceElement[elements.size()]);
}
use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class SnippetTemplate method rewireFrameStates.
protected void rewireFrameStates(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates) {
if (replacee instanceof StateSplit) {
for (StateSplit sideEffectNode : sideEffectNodes) {
assert ((StateSplit) replacee).hasSideEffect();
Node sideEffectDup = duplicates.get(sideEffectNode.asNode());
((StateSplit) sideEffectDup).setStateAfter(((StateSplit) replacee).stateAfter());
}
}
}
use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class CompileQueue method insertDeoptTests.
/**
* Inserts a call to {@link DeoptTester#deoptTest} right after FixedWithNextNode StateSplits.
*
* @param method method that is being augmented with deopt test calls
* @param graph The graph of a deoptimizable method or the corresponding deopt target method.
*/
private static void insertDeoptTests(HostedMethod method, StructuredGraph graph) {
for (Node node : graph.getNodes()) {
if (node instanceof FixedWithNextNode && node instanceof StateSplit && !(node instanceof InvokeNode) && !(node instanceof ForeignCallNode) && !(node instanceof DeoptTestNode) && !(method.isSynchronized() && node instanceof StartNode)) {
FixedWithNextNode fixedWithNext = (FixedWithNextNode) node;
FixedNode next = fixedWithNext.next();
DeoptTestNode testNode = graph.add(new DeoptTestNode());
fixedWithNext.setNext(null);
testNode.setNext(next);
fixedWithNext.setNext(testNode);
}
}
}
Aggregations