use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.
the class EarlyReadEliminationTest method testBadLoop2.
@Test
public void testBadLoop2() {
ValueNode result = getReturn("testBadLoop2Snippet", false).result();
assertDeepEquals(1, result.graph().getNodes().filter(LoadFieldNode.class).count());
assertTrue(result instanceof LoadFieldNode);
}
use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.
the class EarlyReadEliminationTest method testSimpleConflict.
@Test
public void testSimpleConflict() {
ValueNode result = getReturn("testSimpleConflictSnippet", false).result();
assertFalse(result.isConstant());
assertTrue(result instanceof LoadFieldNode);
}
use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.
the class IfNode method tryEliminateBoxedReferenceEquals.
/**
* Attempts to replace the following pattern:
*
* <pre>
* Integer x = ...;
* Integer y = ...;
* if ((x == y) || x.equals(y)) { ... }
* </pre>
*
* with:
*
* <pre>
* Integer x = ...;
* Integer y = ...;
* if (x.equals(y)) { ... }
* </pre>
*
* whenever the probability that the reference check will pass is relatively small.
*
* See GR-1315 for more information.
*/
private boolean tryEliminateBoxedReferenceEquals(SimplifierTool tool) {
if (!(condition instanceof ObjectEqualsNode)) {
return false;
}
MetaAccessProvider meta = tool.getMetaAccess();
ObjectEqualsNode equalsCondition = (ObjectEqualsNode) condition;
ValueNode x = equalsCondition.getX();
ValueNode y = equalsCondition.getY();
ResolvedJavaType integerType = meta.lookupJavaType(Integer.class);
// At least one argument for reference equal must be a boxed primitive.
NodeView view = NodeView.from(tool);
if (!x.stamp(view).javaType(meta).equals(integerType) && !y.stamp(view).javaType(meta).equals(integerType)) {
return false;
}
// no sense to eliminate it.
if (getTrueSuccessorProbability() > 0.4) {
return false;
}
// True branch must be empty.
if (trueSuccessor instanceof BeginNode || trueSuccessor instanceof LoopExitNode) {
if (trueSuccessor.next() instanceof EndNode) {
// Empty true branch.
} else {
return false;
}
} else {
return false;
}
// False branch must only check the unboxed values.
UnboxNode unbox = null;
FixedGuardNode unboxCheck = null;
for (FixedNode node : falseSuccessor.getBlockNodes()) {
if (!(node instanceof BeginNode || node instanceof UnboxNode || node instanceof FixedGuardNode || node instanceof EndNode || node instanceof LoadFieldNode || node instanceof LoopExitNode)) {
return false;
}
if (node instanceof UnboxNode) {
if (unbox == null) {
unbox = (UnboxNode) node;
} else {
return false;
}
}
if (!(node instanceof FixedGuardNode)) {
continue;
}
FixedGuardNode fixed = (FixedGuardNode) node;
if (!(fixed.condition() instanceof IntegerEqualsNode)) {
continue;
}
IntegerEqualsNode equals = (IntegerEqualsNode) fixed.condition();
if ((isUnboxedFrom(meta, view, equals.getX(), x) && isUnboxedFrom(meta, view, equals.getY(), y)) || (isUnboxedFrom(meta, view, equals.getX(), y) && isUnboxedFrom(meta, view, equals.getY(), x))) {
unboxCheck = fixed;
}
}
if (unbox == null || unboxCheck == null) {
return false;
}
// Falsify the reference check.
setCondition(graph().addOrUniqueWithInputs(LogicConstantNode.contradiction()));
return true;
}
use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.
the class VerifyUsageWithEquals method isAssignableToRestrictedType.
/**
* Determines whether the type of {@code node} is assignable to the {@link #restrictedClass}.
*/
private boolean isAssignableToRestrictedType(ValueNode node, MetaAccessProvider metaAccess) {
if (node.stamp(NodeView.DEFAULT) instanceof ObjectStamp) {
ResolvedJavaType restrictedType = metaAccess.lookupJavaType(restrictedClass);
ResolvedJavaType nodeType = StampTool.typeOrNull(node);
if (nodeType == null && node instanceof LoadFieldNode) {
nodeType = (ResolvedJavaType) ((LoadFieldNode) node).field().getType();
}
if (nodeType == null && node instanceof Invoke) {
ResolvedJavaMethod target = ((Invoke) node).callTarget().targetMethod();
nodeType = (ResolvedJavaType) target.getSignature().getReturnType(target.getDeclaringClass());
}
if (nodeType == null && node instanceof UncheckedInterfaceProvider) {
nodeType = StampTool.typeOrNull(((UncheckedInterfaceProvider) node).uncheckedStamp());
}
if (nodeType != null && restrictedType.isAssignableFrom(nodeType)) {
return true;
}
}
return false;
}
Aggregations