use of org.graalvm.compiler.graph.iterators.NodeIterable in project graal by oracle.
the class ConditionAnchoringTest method test.
public void test(String name, int ids) {
StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
NodeIterable<RawLoadNode> unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
assertThat(unsafeNodes, hasCount(1));
// lower unsafe load
PhaseContext context = new PhaseContext(getProviders());
LoweringPhase lowering = new LoweringPhase(new CanonicalizerPhase(), StandardLoweringStage.HIGH_TIER);
lowering.apply(graph, context);
unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
NodeIterable<ConditionAnchorNode> conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
NodeIterable<ReadNode> reads = graph.getNodes().filter(ReadNode.class);
assertThat(unsafeNodes, isEmpty());
assertThat(conditionAnchors, hasCount(1));
// 2 * ids id reads, 1 'field' access
assertThat(reads, hasCount(2 * ids + 1));
// float reads and canonicalize to give a chance to conditions to GVN
FloatingReadPhase floatingReadPhase = new FloatingReadPhase();
floatingReadPhase.apply(graph);
CanonicalizerPhase canonicalizerPhase = new CanonicalizerPhase();
canonicalizerPhase.apply(graph, context);
NodeIterable<FloatingReadNode> floatingReads = graph.getNodes().filter(FloatingReadNode.class);
// 1 id read, 1 'field' access
assertThat(floatingReads, hasCount(ids + 1));
new ConditionalEliminationPhase(false).apply(graph, context);
floatingReads = graph.getNodes().filter(FloatingReadNode.class).filter(n -> ((FloatingReadNode) n).getLocationIdentity() instanceof ObjectLocationIdentity);
conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
assertThat(floatingReads, hasCount(1));
assertThat(conditionAnchors, isEmpty());
FloatingReadNode readNode = floatingReads.first();
assertThat(readNode.getGuard(), instanceOf(BeginNode.class));
assertThat(readNode.getGuard().asNode().predecessor(), instanceOf(IfNode.class));
}
use of org.graalvm.compiler.graph.iterators.NodeIterable in project graal by oracle.
the class UnsafeAutomaticSubstitutionProcessor method extractValueStoreField.
/**
* If the value produced by valueNode is stored into a static final field then that field is
* returned. If the field is either not static or not final the method returns null and the
* reason is recorded in the unsuccessfulReasons parameter.
*/
private static ResolvedJavaField extractValueStoreField(ValueNode valueNode, List<String> unsuccessfulReasons) {
ResolvedJavaField offsetField = null;
NodeIterable<Node> valueNodeUsages = valueNode.usages();
NodeIterable<StoreFieldNode> valueNodeStoreFieldUsages = valueNodeUsages.filter(StoreFieldNode.class);
NodeIterable<SignExtendNode> valueNodeSignExtendUsages = valueNodeUsages.filter(SignExtendNode.class);
if (valueNodeStoreFieldUsages.count() == 1) {
offsetField = valueNodeStoreFieldUsages.first().field();
} else if (valueNodeSignExtendUsages.count() == 1) {
SignExtendNode signExtendNode = valueNodeSignExtendUsages.first();
NodeIterable<StoreFieldNode> signExtendFieldStoreUsages = signExtendNode.usages().filter(StoreFieldNode.class);
if (signExtendFieldStoreUsages.count() == 1) {
offsetField = signExtendFieldStoreUsages.first().field();
}
}
if (offsetField != null) {
if (offsetField.isStatic() && offsetField.isFinal()) {
return offsetField;
} else {
if (!offsetField.isStatic()) {
unsuccessfulReasons.add("The offset field " + offsetField.format("%H.%n") + " is not static.");
}
if (!offsetField.isFinal()) {
unsuccessfulReasons.add("The offset field " + offsetField.format("%H.%n") + " is not final.");
}
}
} else {
String producer;
String operation;
if (valueNode instanceof Invoke) {
Invoke invokeNode = (Invoke) valueNode;
producer = "call to " + invokeNode.callTarget().targetMethod().format("%H.%n(%p)");
operation = "call";
} else if (valueNode instanceof SubNode) {
producer = "subtraction operation " + valueNode;
operation = "subtraction";
} else {
throw VMError.shouldNotReachHere();
}
String message = "Could not determine the field where the value produced by the " + producer + " is stored. The " + operation + " is not directly followed by a field store or by a sign extend node followed directly by a field store. ";
unsuccessfulReasons.add(message);
}
return null;
}
use of org.graalvm.compiler.graph.iterators.NodeIterable in project graal by oracle.
the class LoopFragment method toHirExits.
public static NodeIterable<AbstractBeginNode> toHirExits(final Iterable<Block> blocks) {
return new NodeIterable<AbstractBeginNode>() {
@Override
public Iterator<AbstractBeginNode> iterator() {
final Iterator<Block> it = blocks.iterator();
return new Iterator<AbstractBeginNode>() {
@Override
public void remove() {
throw new UnsupportedOperationException();
}
/**
* Return the true LoopExitNode for this loop or the BeginNode for the block.
*/
@Override
public AbstractBeginNode next() {
Block next = it.next();
LoopExitNode exit = next.getLoopExit();
if (exit != null) {
return exit;
}
return next.getBeginNode();
}
@Override
public boolean hasNext() {
return it.hasNext();
}
};
}
};
}
Aggregations