use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class GraphBuilderContext method addPush.
/**
* Adds a node with a non-void kind to the graph, pushes it to the stack. If the returned node
* is a {@link StateSplit} with a null {@linkplain StateSplit#stateAfter() frame state}, the
* frame state is initialized.
*
* @param kind the kind to use when type checking this operation
* @param value the value to add to the graph and push to the stack
* @return a node equivalent to {@code value} in the graph
*/
default <T extends ValueNode> T addPush(JavaKind kind, T value) {
T equivalentValue = value.graph() != null ? value : append(value);
push(kind, equivalentValue);
if (equivalentValue instanceof StateSplit) {
StateSplit stateSplit = (StateSplit) equivalentValue;
if (stateSplit.stateAfter() == null && stateSplit.hasSideEffect()) {
setStateAfter(stateSplit);
}
}
return equivalentValue;
}
use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class GraphUtil method removeFixedWithUnusedInputs.
public static void removeFixedWithUnusedInputs(FixedWithNextNode fixed) {
if (fixed instanceof StateSplit) {
FrameState stateAfter = ((StateSplit) fixed).stateAfter();
if (stateAfter != null) {
((StateSplit) fixed).setStateAfter(null);
if (stateAfter.hasNoUsages()) {
killWithUnusedFloatingInputs(stateAfter);
}
}
}
unlinkFixedNode(fixed);
killWithUnusedFloatingInputs(fixed);
}
use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class SchedulingTest2 method testValueProxyInputs.
@Test
public void testValueProxyInputs() {
StructuredGraph graph = parseEager("testSnippet", AllowAssumptions.YES);
DebugContext debug = graph.getDebug();
ReturnNode returnNode = graph.getNodes(ReturnNode.TYPE).first();
BeginNode beginNode = graph.add(new BeginNode());
returnNode.replaceAtPredecessor(beginNode);
beginNode.setNext(returnNode);
debug.dump(DebugContext.BASIC_LEVEL, graph, "Graph");
SchedulePhase schedulePhase = new SchedulePhase(SchedulingStrategy.EARLIEST_WITH_GUARD_ORDER);
schedulePhase.apply(graph);
ScheduleResult schedule = graph.getLastSchedule();
BlockMap<List<Node>> blockToNodesMap = schedule.getBlockToNodesMap();
NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
assertDeepEquals(2, schedule.getCFG().getBlocks().length);
for (BinaryArithmeticNode<?> node : graph.getNodes().filter(BinaryArithmeticNode.class)) {
if (node instanceof AddNode) {
assertTrue(node.toString() + " expected: " + nodeToBlock.get(beginNode) + " but was: " + nodeToBlock.get(node), nodeToBlock.get(node) != nodeToBlock.get(beginNode));
}
}
for (FrameState fs : graph.getNodes(FrameState.TYPE)) {
Block block = nodeToBlock.get(fs);
assertTrue(fs.toString(), block == schedule.getCFG().getStartBlock());
for (Node usage : fs.usages()) {
if (usage instanceof StateSplit && ((StateSplit) usage).stateAfter() == fs) {
assertTrue(usage.toString(), nodeToBlock.get(usage) == block);
if (usage != block.getBeginNode()) {
List<Node> map = blockToNodesMap.get(block);
assertTrue(map.indexOf(fs) + " < " + map.indexOf(usage), map.indexOf(fs) < map.indexOf(usage));
}
}
}
}
PhaseContext context = new PhaseContext(getProviders());
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, context);
MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
new GuardLoweringPhase().apply(graph, midContext);
FrameStateAssignmentPhase phase = new FrameStateAssignmentPhase();
phase.apply(graph);
schedulePhase.apply(graph);
schedule = graph.getLastSchedule();
blockToNodesMap = schedule.getBlockToNodesMap();
nodeToBlock = schedule.getNodeToBlockMap();
for (FrameState fs : graph.getNodes(FrameState.TYPE)) {
Block block = nodeToBlock.get(fs);
assertTrue(fs.toString(), block == schedule.getCFG().getStartBlock());
for (Node usage : fs.usages()) {
if ((usage instanceof StateSplit && ((StateSplit) usage).stateAfter() == fs) || (usage instanceof DeoptDuring && ((DeoptDuring) usage).stateDuring() == fs)) {
assertTrue(usage.toString(), nodeToBlock.get(usage) == block);
if (usage != block.getBeginNode()) {
List<Node> map = blockToNodesMap.get(block);
assertTrue(map.indexOf(fs) + " < " + map.indexOf(usage), map.indexOf(fs) < map.indexOf(usage));
}
}
}
}
}
use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class CFGPrinter method printNode.
private void printNode(Node node, boolean unscheduled) {
assert !printedNodes.isMarked(node);
printedNodes.mark(node);
if (!(node instanceof ValuePhiNode)) {
for (Node input : node.inputs()) {
if (!inFixedSchedule(input) && !printedNodes.isMarked(input)) {
printNode(input, true);
}
}
}
if (unscheduled) {
assert lir == null && schedule == null : "unscheduled nodes can only be present before LIR generation";
out.print("f ").print(HOVER_START).print("u").print(HOVER_SEP).print("unscheduled").print(HOVER_END).println(COLUMN_END);
} else if (node instanceof FixedWithNextNode) {
out.print("f ").print(HOVER_START).print("#").print(HOVER_SEP).print("fixed with next").print(HOVER_END).println(COLUMN_END);
} else if (node instanceof FixedNode) {
out.print("f ").print(HOVER_START).print("*").print(HOVER_SEP).print("fixed").print(HOVER_END).println(COLUMN_END);
} else if (node instanceof FloatingNode) {
out.print("f ").print(HOVER_START).print("~").print(HOVER_SEP).print("floating").print(HOVER_END).println(COLUMN_END);
}
out.print("tid ").print(nodeToString(node)).println(COLUMN_END);
if (nodeLirGenerator != null) {
Value operand = nodeLirGenerator.hasOperand(node) ? nodeLirGenerator.operand(node) : null;
if (operand != null) {
out.print("result ").print(operand.toString()).println(COLUMN_END);
}
}
if (node instanceof StateSplit) {
StateSplit stateSplit = (StateSplit) node;
if (stateSplit.stateAfter() != null) {
String state = stateToString(stateSplit.stateAfter());
out.print("st ").print(HOVER_START).print("st").print(HOVER_SEP).print(state).print(HOVER_END).println(COLUMN_END);
}
}
Map<Object, Object> props = new TreeMap<>(node.getDebugProperties());
out.print("d ").print(HOVER_START).print("d").print(HOVER_SEP);
out.println("=== Debug Properties ===");
for (Map.Entry<Object, Object> entry : props.entrySet()) {
out.print(entry.getKey().toString()).print(": ").print(entry.getValue() == null ? "[null]" : entry.getValue().toString()).println();
}
out.println("=== Inputs ===");
printNamedNodes(node, node.inputPositions().iterator(), "", "\n", null);
out.println("=== Succesors ===");
printNamedNodes(node, node.successorPositions().iterator(), "", "\n", null);
out.println("=== Usages ===");
if (!node.hasNoUsages()) {
for (Node usage : node.usages()) {
out.print(nodeToString(usage)).print(" ");
}
out.println();
}
out.println("=== Predecessor ===");
out.print(nodeToString(node.predecessor())).print(" ");
out.print(HOVER_END).println(COLUMN_END);
out.print("instruction ");
out.print(HOVER_START).print(node.getNodeClass().shortName()).print(HOVER_SEP).print(node.getClass().getName()).print(HOVER_END).print(" ");
printNamedNodes(node, node.inputPositions().iterator(), "", "", "#NDF");
printNamedNodes(node, node.successorPositions().iterator(), "#", "", "#NDF");
for (Map.Entry<Object, Object> entry : props.entrySet()) {
String key = entry.getKey().toString();
if (key.startsWith("data.") && !key.equals("data.stamp")) {
out.print(key.substring("data.".length())).print(": ").print(entry.getValue() == null ? "[null]" : entry.getValue().toString()).print(" ");
}
}
out.print(COLUMN_END).print(' ').println(COLUMN_END);
}
use of org.graalvm.compiler.nodes.StateSplit in project graal by oracle.
the class InliningUtil method handleMissingAfterExceptionFrameState.
public static FrameState handleMissingAfterExceptionFrameState(FrameState nonReplaceableFrameState, Invoke invoke, EconomicMap<Node, Node> replacements, boolean alwaysDuplicateStateAfter) {
StructuredGraph graph = nonReplaceableFrameState.graph();
NodeWorkList workList = graph.createNodeWorkList();
workList.add(nonReplaceableFrameState);
for (Node node : workList) {
FrameState fs = (FrameState) node;
for (Node usage : fs.usages().snapshot()) {
if (!usage.isAlive()) {
continue;
}
if (usage instanceof FrameState) {
workList.add(usage);
} else {
StateSplit stateSplit = (StateSplit) usage;
FixedNode fixedStateSplit = stateSplit.asNode();
if (fixedStateSplit instanceof AbstractMergeNode) {
AbstractMergeNode merge = (AbstractMergeNode) fixedStateSplit;
while (merge.isAlive()) {
AbstractEndNode end = merge.forwardEnds().first();
DeoptimizeNode deoptimizeNode = addDeoptimizeNode(graph, DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler);
end.replaceAtPredecessor(deoptimizeNode);
GraphUtil.killCFG(end);
}
} else if (fixedStateSplit instanceof ExceptionObjectNode) {
// The target invoke does not have an exception edge. This means that the
// bytecode parser made the wrong assumption of making an
// InvokeWithExceptionNode for the partial intrinsic exit. We therefore
// replace the InvokeWithExceptionNode with a normal
// InvokeNode -- the deoptimization occurs when the invoke throws.
InvokeWithExceptionNode oldInvoke = (InvokeWithExceptionNode) fixedStateSplit.predecessor();
FrameState oldFrameState = oldInvoke.stateAfter();
InvokeNode newInvoke = oldInvoke.replaceWithInvoke();
newInvoke.setStateAfter(oldFrameState.duplicate());
if (replacements != null) {
replacements.put(oldInvoke, newInvoke);
}
handleAfterBciFrameState(newInvoke.stateAfter(), invoke, alwaysDuplicateStateAfter);
} else {
FixedNode deoptimizeNode = addDeoptimizeNode(graph, DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler);
if (fixedStateSplit instanceof AbstractBeginNode) {
deoptimizeNode = BeginNode.begin(deoptimizeNode);
}
fixedStateSplit.replaceAtPredecessor(deoptimizeNode);
GraphUtil.killCFG(fixedStateSplit);
}
}
}
}
return nonReplaceableFrameState;
}
Aggregations