use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class GraphUtil method markFixedNodes.
private static void markFixedNodes(FixedNode node, EconomicSet<Node> markedNodes, EconomicMap<AbstractMergeNode, List<AbstractEndNode>> unmarkedMerges) {
NodeStack workStack = new NodeStack();
workStack.push(node);
while (!workStack.isEmpty()) {
Node fixedNode = workStack.pop();
markedNodes.add(fixedNode);
if (fixedNode instanceof AbstractMergeNode) {
unmarkedMerges.removeKey((AbstractMergeNode) fixedNode);
}
while (fixedNode instanceof FixedWithNextNode) {
fixedNode = ((FixedWithNextNode) fixedNode).next();
if (fixedNode != null) {
markedNodes.add(fixedNode);
}
}
if (fixedNode instanceof ControlSplitNode) {
for (Node successor : fixedNode.successors()) {
workStack.push(successor);
}
} else if (fixedNode instanceof AbstractEndNode) {
AbstractEndNode end = (AbstractEndNode) fixedNode;
AbstractMergeNode merge = end.merge();
if (merge != null) {
assert !markedNodes.contains(merge) || (merge instanceof LoopBeginNode && end instanceof LoopEndNode) : merge;
if (merge instanceof LoopBeginNode) {
if (end == ((LoopBeginNode) merge).forwardEnd()) {
workStack.push(merge);
continue;
}
if (markedNodes.contains(merge)) {
continue;
}
}
List<AbstractEndNode> endsSeen = unmarkedMerges.get(merge);
if (endsSeen == null) {
endsSeen = new ArrayList<>(merge.forwardEndCount());
unmarkedMerges.put(merge, endsSeen);
}
endsSeen.add(end);
if (!(end instanceof LoopEndNode) && endsSeen.size() == merge.forwardEndCount()) {
assert merge.forwardEnds().filter(n -> !markedNodes.contains(n)).isEmpty();
// all this merge's forward ends are marked: it needs to be killed
workStack.push(merge);
}
}
}
}
}
use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class IterativeConditionalEliminationPhase method run.
@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph, PhaseContext context) {
HashSetNodeEventListener listener = new HashSetNodeEventListener().exclude(NODE_ADDED);
int count = 0;
while (true) {
try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
new ConditionalEliminationPhase(fullSchedule).apply(graph, context);
}
if (listener.getNodes().isEmpty()) {
break;
}
for (Node node : graph.getNodes()) {
if (node instanceof Simplifiable) {
listener.getNodes().add(node);
}
}
canonicalizer.applyIncremental(graph, context, listener.getNodes());
listener.getNodes().clear();
if (++count > MAX_ITERATIONS) {
throw new RetryableBailoutException("Number of iterations in ConditionalEliminationPhase phase exceeds %d", MAX_ITERATIONS);
}
}
}
use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class AbstractWriteNode method setLastLocationAccess.
@Override
public void setLastLocationAccess(MemoryNode lla) {
Node newLla = ValueNodeUtil.asNode(lla);
updateUsages(lastLocationAccess, newLla);
lastLocationAccess = newLla;
}
use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class SubstrateGraphKit method mergeUnwinds.
/**
* A graph with multiple unwinds is invalid. Merge the various unwind paths.
*/
public void mergeUnwinds() {
List<UnwindNode> unwinds = new ArrayList<>();
for (Node node : getGraph().getNodes()) {
if (node instanceof UnwindNode) {
unwinds.add((UnwindNode) node);
}
}
if (unwinds.size() > 1) {
MergeNode unwindMergeNode = add(new MergeNode());
ValueNode exceptionValue = InliningUtil.mergeValueProducers(unwindMergeNode, unwinds, null, UnwindNode::exception);
UnwindNode unwindReplacement = add(new UnwindNode(exceptionValue));
unwindMergeNode.setNext(unwindReplacement);
FrameStateBuilder exceptionState = getFrameState().copy();
exceptionState.clearStack();
exceptionState.push(JavaKind.Object, exceptionValue);
exceptionState.setRethrowException(true);
unwindMergeNode.setStateAfter(exceptionState.create(BytecodeFrame.AFTER_EXCEPTION_BCI, unwindMergeNode));
}
}
use of org.graalvm.compiler.graph.Node in project graal by oracle.
the class OptimizeExceptionCallsPhase method setBranchProbability.
/**
* Sets the branch probability of the guarding IfNode to a small value. The effect is that the
* exception call block is put at the end of the method. The other block (= the regular path)
* gets the fall-through block of the IfNode. This should give a better performance - and it
* looks nicer in the disassembly.
*/
private static void setBranchProbability(Node endNode) {
Node node = endNode;
Node predecessor = node.predecessor();
// Go "up" the graph until we find an IfNode
while (predecessor != null) {
if (predecessor instanceof IfNode && node instanceof BeginNode) {
// We found an IfNode which branches to our runtime exception call
IfNode ifNode = (IfNode) predecessor;
ifNode.setTrueSuccessorProbability(node == ifNode.trueSuccessor() ? 0.00001 : 0.99999);
return;
}
if (predecessor instanceof MergeNode || predecessor instanceof ControlSplitNode) {
// Any other split or merge is suspicious: we abort
return;
}
node = predecessor;
predecessor = node.predecessor();
}
}
Aggregations