Search in sources :

Example 1 with NodeVisitor

use of com.oracle.truffle.api.nodes.NodeVisitor in project graal by oracle.

the class CachedReachableFallbackTest method countGuardNodes.

private static int countGuardNodes(Node searchNode) {
    AtomicInteger count = new AtomicInteger(0);
    searchNode.accept(new NodeVisitor() {

        public boolean visit(Node node) {
            if (node instanceof GuardNode) {
                count.incrementAndGet();
                return false;
            }
            return true;
        }
    });
    return count.get();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Node(com.oracle.truffle.api.nodes.Node) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor)

Example 2 with NodeVisitor

use of com.oracle.truffle.api.nodes.NodeVisitor in project graal by oracle.

the class InputFilterTest method assertCleanedUp.

private void assertCleanedUp(String code) {
    // first we capture all root nodes used by the code.
    Set<RootNode> rootNodes = new HashSet<>();
    EventBinding<?> binding = instrumenter.attachExecutionEventListener(SourceSectionFilter.ANY, new ExecutionEventListener() {

        public void onEnter(EventContext c, VirtualFrame frame) {
            addRoot(c);
        }

        @TruffleBoundary
        private void addRoot(EventContext c) {
            rootNodes.add(c.getInstrumentedNode().getRootNode());
        }

        public void onReturnValue(EventContext c, VirtualFrame frame, Object result) {
        }

        public void onReturnExceptional(EventContext c, VirtualFrame frame, Throwable exception) {
        }
    });
    execute(code);
    binding.dispose();
    // we execute again to let the instrumentation wrappers be cleaned up
    execute(code);
    for (RootNode root : rootNodes) {
        // all frame slots got removed
        assertEquals(new HashSet<>(), root.getFrameDescriptor().getIdentifiers());
        // no wrappers left
        root.accept(new NodeVisitor() {

            public boolean visit(Node node) {
                if (node instanceof WrapperNode) {
                    throw new AssertionError();
                }
                return true;
            }
        });
    }
}
Also used : RootNode(com.oracle.truffle.api.nodes.RootNode) WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) Node(com.oracle.truffle.api.nodes.Node) RootNode(com.oracle.truffle.api.nodes.RootNode) WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) ExecutionEventListener(com.oracle.truffle.api.instrumentation.ExecutionEventListener) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) EventContext(com.oracle.truffle.api.instrumentation.EventContext) VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) HashSet(java.util.HashSet)

Example 3 with NodeVisitor

use of com.oracle.truffle.api.nodes.NodeVisitor in project graal by oracle.

the class DefaultNearestNodeSearch method findFirstNode.

private static Node findFirstNode(Node contextNode, Set<Class<? extends Tag>> tags) {
    Node[] first = new Node[] { null };
    contextNode.accept(new NodeVisitor() {

        @Override
        public boolean visit(Node node) {
            if (isTaggedWith(node, tags)) {
                first[0] = node;
                return false;
            }
            return true;
        }
    });
    return first[0];
}
Also used : WrapperNode(com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode) Node(com.oracle.truffle.api.nodes.Node) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor)

Example 4 with NodeVisitor

use of com.oracle.truffle.api.nodes.NodeVisitor in project graal by oracle.

the class SLLexicalScope method collectArgs.

private static Map<String, FrameSlot> collectArgs(Node block) {
    // Arguments are pushed to frame slots at the beginning of the function block.
    // To collect argument slots, search for SLReadArgumentNode inside of
    // SLWriteLocalVariableNode.
    Map<String, FrameSlot> args = new LinkedHashMap<>(4);
    NodeUtil.forEachChild(block, new NodeVisitor() {

        // The current write node containing a slot
        private SLWriteLocalVariableNode wn;

        @Override
        public boolean visit(Node node) {
            // When there is a write node, search for SLReadArgumentNode among its children:
            if (node instanceof SLWriteLocalVariableNode) {
                wn = (SLWriteLocalVariableNode) node;
                boolean all = NodeUtil.forEachChild(node, this);
                wn = null;
                return all;
            } else if (wn != null && (node instanceof SLReadArgumentNode)) {
                FrameSlot slot = wn.getSlot();
                String name = Objects.toString(slot.getIdentifier());
                assert !args.containsKey(name) : name + " argument exists already.";
                args.put(name, slot);
                return true;
            } else if (wn == null && (node instanceof SLStatementNode)) {
                // A different SL node - we're done.
                return false;
            } else {
                return NodeUtil.forEachChild(node, this);
            }
        }
    });
    return args;
}
Also used : FrameSlot(com.oracle.truffle.api.frame.FrameSlot) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) SLEvalRootNode(com.oracle.truffle.sl.nodes.SLEvalRootNode) SLBlockNode(com.oracle.truffle.sl.nodes.controlflow.SLBlockNode) SLStatementNode(com.oracle.truffle.sl.nodes.SLStatementNode) LinkedHashMap(java.util.LinkedHashMap) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor)

Example 5 with NodeVisitor

use of com.oracle.truffle.api.nodes.NodeVisitor in project graal by oracle.

the class SLGraalRuntimeBuiltin method findCallsTo.

/**
 * Finds all {@link DirectCallNode} instances calling a certain original {@link CallTarget} in a
 * given {@link RootNode}.
 */
@TruffleBoundary
protected static final Set<DirectCallNode> findCallsTo(RootNode root, OptimizedCallTarget originalCallTarget) {
    final Set<DirectCallNode> allCallNodes = new HashSet<>();
    root.accept(new NodeVisitor() {

        @Override
        public boolean visit(Node node) {
            if (node instanceof DirectCallNode) {
                DirectCallNode callNode = (DirectCallNode) node;
                if (callNode.getCallTarget() == originalCallTarget || callNode.getClonedCallTarget() == originalCallTarget) {
                    allCallNodes.add(callNode);
                }
            }
            return true;
        }
    });
    return allCallNodes;
}
Also used : Node(com.oracle.truffle.api.nodes.Node) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) SLBuiltinNode(com.oracle.truffle.sl.builtins.SLBuiltinNode) RootNode(com.oracle.truffle.api.nodes.RootNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) HashSet(java.util.HashSet) NodeVisitor(com.oracle.truffle.api.nodes.NodeVisitor) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

Node (com.oracle.truffle.api.nodes.Node)11 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)11 RootNode (com.oracle.truffle.api.nodes.RootNode)7 WrapperNode (com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode)3 SLEvalRootNode (com.oracle.truffle.sl.nodes.SLEvalRootNode)3 SLStatementNode (com.oracle.truffle.sl.nodes.SLStatementNode)3 SLBlockNode (com.oracle.truffle.sl.nodes.controlflow.SLBlockNode)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)2 FrameSlot (com.oracle.truffle.api.frame.FrameSlot)2 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 Test (org.junit.Test)2 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)1 EventContext (com.oracle.truffle.api.instrumentation.EventContext)1 ExecutionEventListener (com.oracle.truffle.api.instrumentation.ExecutionEventListener)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 SLBuiltinNode (com.oracle.truffle.sl.builtins.SLBuiltinNode)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1