use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class SnippetTemplate method updateStamps.
private void updateStamps(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates) {
for (ValueNode node : placeholderStampedNodes) {
ValueNode dup = (ValueNode) duplicates.get(node);
Stamp replaceeStamp = replacee.stamp(NodeView.DEFAULT);
if (node instanceof Placeholder) {
Placeholder placeholderDup = (Placeholder) dup;
placeholderDup.makeReplacement(replaceeStamp);
} else {
dup.setStamp(replaceeStamp);
}
}
for (ParameterNode paramNode : snippet.getNodes(ParameterNode.TYPE)) {
for (Node usage : paramNode.usages()) {
Node usageDup = duplicates.get(usage);
propagateStamp(usageDup);
}
}
}
use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class ExplodeLoopNode method findLoopBegin.
public LoopBeginNode findLoopBegin() {
Node currentNext = next();
ArrayList<Node> succs = new ArrayList<>();
while (!(currentNext instanceof LoopBeginNode)) {
assert currentNext != null : "cannot find loop after " + this;
for (Node n : currentNext.cfgSuccessors()) {
succs.add(n);
}
if (succs.size() == 1 && succs.get(0) != currentNext) {
currentNext = succs.get(0);
} else {
return null;
}
}
return (LoopBeginNode) currentNext;
}
use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class RuntimeStrengthenStampsPhase method registerDeoptEntries.
private static void registerDeoptEntries(CallTreeNode node) {
for (FrameState frameState : node.graph.getNodes(FrameState.TYPE)) {
if (node.level > 0 && frameState.usages().count() == 1 && frameState.usages().first() == node.graph.start()) {
/*
* During method inlining, the FrameState associated with the StartNode disappears.
* Therefore, this frame state cannot be a deoptimization target.
*/
continue;
}
/*
* We need to make sure that all inlined caller frames are available for deoptimization
* too.
*/
for (FrameState inlineState = frameState; inlineState != null; inlineState = inlineState.outerFrameState()) {
if (inlineState.bci >= 0) {
CompilationInfoSupport.singleton().registerDeoptEntry(inlineState.getMethod(), inlineState.bci, inlineState.duringCall(), inlineState.rethrowException());
}
}
}
for (Node n : node.graph.getNodes()) {
/*
* graph.getInvokes() only iterates invokes that have a MethodCallTarget, so by using it
* we would miss invocations that are already intrinsified to an indirect call.
*/
if (n instanceof Invoke) {
Invoke invoke = (Invoke) n;
/*
* The FrameState for the invoke (which is visited by the above loop) is the state
* after the call (where deoptimization that happens after the call has returned
* will continue execution). We also need to register the state during the call
* (where deoptimization while the call is on the stack will continue execution).
*
* Note that the bci of the Invoke and the bci of the FrameState of the Invoke are
* different: the Invoke has the bci of the invocation bytecode, the FrameState has
* the bci of the next bytecode after the invoke.
*/
CompilationInfoSupport.singleton().registerDeoptEntry(invoke.stateAfter().getMethod(), invoke.bci(), true, false);
}
}
}
use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class SimplifyingGraphDecoder method canonicalizeFixedNode.
/**
* Canonicalizes the provided node, which was originally a {@link FixedNode} but can already be
* canonicalized (and therefore be a non-fixed node).
*
* @param methodScope The current method.
* @param node The node to be canonicalized.
*/
protected Node canonicalizeFixedNode(MethodScope methodScope, Node node) {
if (node instanceof LoadFieldNode) {
LoadFieldNode loadFieldNode = (LoadFieldNode) node;
return loadFieldNode.canonical(canonicalizerTool);
} else if (node instanceof FixedGuardNode) {
FixedGuardNode guard = (FixedGuardNode) node;
if (guard.getCondition() instanceof LogicConstantNode) {
LogicConstantNode condition = (LogicConstantNode) guard.getCondition();
if (condition.getValue() == guard.isNegated()) {
DeoptimizeNode deopt = new DeoptimizeNode(guard.getAction(), guard.getReason(), guard.getSpeculation());
if (guard.stateBefore() != null) {
deopt.setStateBefore(guard.stateBefore());
}
return deopt;
} else {
return null;
}
}
return node;
} else if (node instanceof IfNode) {
IfNode ifNode = (IfNode) node;
if (ifNode.condition() instanceof LogicNegationNode) {
ifNode.eliminateNegation();
}
if (ifNode.condition() instanceof LogicConstantNode) {
boolean condition = ((LogicConstantNode) ifNode.condition()).getValue();
AbstractBeginNode survivingSuccessor = ifNode.getSuccessor(condition);
AbstractBeginNode deadSuccessor = ifNode.getSuccessor(!condition);
graph.removeSplit(ifNode, survivingSuccessor);
assert deadSuccessor.next() == null : "must not be parsed yet";
deadSuccessor.safeDelete();
}
return node;
} else if (node instanceof LoadIndexedNode) {
LoadIndexedNode loadIndexedNode = (LoadIndexedNode) node;
return loadIndexedNode.canonical(canonicalizerTool);
} else if (node instanceof ArrayLengthNode) {
ArrayLengthNode arrayLengthNode = (ArrayLengthNode) node;
return arrayLengthNode.canonical(canonicalizerTool);
} else if (node instanceof IntegerSwitchNode && ((IntegerSwitchNode) node).value().isConstant()) {
IntegerSwitchNode switchNode = (IntegerSwitchNode) node;
int value = switchNode.value().asJavaConstant().asInt();
AbstractBeginNode survivingSuccessor = switchNode.successorAtKey(value);
List<Node> allSuccessors = switchNode.successors().snapshot();
graph.removeSplit(switchNode, survivingSuccessor);
for (Node successor : allSuccessors) {
if (successor != survivingSuccessor) {
assert ((AbstractBeginNode) successor).next() == null : "must not be parsed yet";
successor.safeDelete();
}
}
return node;
} else if (node instanceof Canonicalizable) {
return ((Canonicalizable) node).canonical(canonicalizerTool);
} else {
return node;
}
}
use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class SimplifyingGraphDecoder method handleCanonicalization.
private void handleCanonicalization(LoopScope loopScope, int nodeOrderId, FixedNode node, Node c) {
assert c != node : "unnecessary call";
Node canonical = c == null ? canonicalizeFixedNodeToNull(node) : c;
if (!canonical.isAlive()) {
assert !canonical.isDeleted();
canonical = graph.addOrUniqueWithInputs(canonical);
if (canonical instanceof FixedWithNextNode) {
graph.addBeforeFixed(node, (FixedWithNextNode) canonical);
} else if (canonical instanceof ControlSinkNode) {
FixedWithNextNode predecessor = (FixedWithNextNode) node.predecessor();
predecessor.setNext((ControlSinkNode) canonical);
List<Node> successorSnapshot = node.successors().snapshot();
node.safeDelete();
for (Node successor : successorSnapshot) {
successor.safeDelete();
}
} else {
assert !(canonical instanceof FixedNode);
}
}
if (!node.isDeleted()) {
GraphUtil.unlinkFixedNode((FixedWithNextNode) node);
node.replaceAtUsagesAndDelete(canonical);
}
assert lookupNode(loopScope, nodeOrderId) == node;
registerNode(loopScope, nodeOrderId, canonical, true, false);
}
Aggregations