use of org.graalvm.compiler.phases.common.SnippetFrameStateAssignment.NodeStateAssignment in project graal by oracle.
the class PlaceholderLogicNode method assignNecessaryFrameStates.
private void assignNecessaryFrameStates(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates, FixedNode replaceeGraphCFGPredecessor) {
FrameState stateAfter = null;
if (replacee instanceof StateSplit && ((StateSplit) replacee).hasSideEffect()) {
stateAfter = ((StateSplit) replacee).stateAfter();
GraalError.guarantee(stateAfter != null, "Statesplit with side-effect %s needs a framestate", replacee);
} else {
/*
* We dont have a state split as a replacee, thus we take the prev state as the state
* after for the node in the snippet.
*/
stateAfter = GraphUtil.findLastFrameState(replaceeGraphCFGPredecessor);
}
final ExceptionObjectNode exceptionObject;
if (replacee instanceof WithExceptionNode) {
WithExceptionNode withExceptionNode = (WithExceptionNode) replacee;
if (withExceptionNode.exceptionEdge() instanceof ExceptionObjectNode) {
exceptionObject = (ExceptionObjectNode) withExceptionNode.exceptionEdge();
} else {
GraalError.guarantee(withExceptionNode.exceptionEdge() instanceof UnreachableBeginNode, "Unexpected exception edge %s", withExceptionNode.exceptionEdge());
exceptionObject = null;
}
} else {
exceptionObject = null;
}
NodeMap<NodeStateAssignment> assignedStateMappings = frameStateAssignment.getStateMapping();
MapCursor<Node, NodeStateAssignment> stateAssignments = assignedStateMappings.getEntries();
while (stateAssignments.advance()) {
Node nodeRequiringState = stateAssignments.getKey();
if (nodeRequiringState instanceof DeoptBciSupplier) {
if (replacee instanceof DeoptBciSupplier) {
((DeoptBciSupplier) duplicates.get(nodeRequiringState)).setBci(((DeoptBciSupplier) replacee).bci());
}
}
NodeStateAssignment assignment = stateAssignments.getValue();
switch(assignment) {
case AFTER_BCI:
setReplaceeGraphStateAfter(nodeRequiringState, replacee, duplicates, stateAfter);
break;
case AFTER_EXCEPTION_BCI:
if (nodeRequiringState instanceof ExceptionObjectNode) {
ExceptionObjectNode newExceptionObject = (ExceptionObjectNode) duplicates.get(nodeRequiringState);
rewireExceptionFrameState(exceptionObject, newExceptionObject, newExceptionObject);
} else if (nodeRequiringState instanceof MergeNode) {
MergeNode mergeNode = (MergeNode) duplicates.get(nodeRequiringState);
rewireExceptionFrameState(exceptionObject, getExceptionValueFromMerge(mergeNode), mergeNode);
} else {
GraalError.shouldNotReachHere("Unexpected exception state node: " + nodeRequiringState);
}
break;
case BEFORE_BCI:
FrameState stateBeforeSnippet = GraphUtil.findLastFrameState(replaceeGraphCFGPredecessor);
((StateSplit) duplicates.get(nodeRequiringState)).setStateAfter(stateBeforeSnippet.duplicate());
break;
case INVALID:
/*
* We cannot assign a proper frame state for this snippet's node since there are
* effects which cannot be represented by a single state at the node
*/
throw GraalError.shouldNotReachHere("Invalid snippet replacing a node before frame state assignment with node " + nodeRequiringState + " for replacee " + replacee);
default:
throw GraalError.shouldNotReachHere("Unknown StateAssigment:" + assignment);
}
replacee.graph().getDebug().dump(DebugContext.VERY_DETAILED_LEVEL, replacee.graph(), "After duplicating after state for node %s in snippet", duplicates.get(nodeRequiringState));
}
}
Aggregations