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();
}
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;
}
});
}
}
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];
}
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;
}
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;
}
Aggregations