use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class LoopTransformations method updateMainLoopLimit.
private static void updateMainLoopLimit(IfNode preLimit, InductionVariable preIv, LoopFragmentWhole mainLoop) {
// Update the main loops limit test to be different than the post loop
StructuredGraph graph = preLimit.graph();
IfNode mainLimit = mainLoop.getDuplicatedNode(preLimit);
LogicNode ifTest = mainLimit.condition();
CompareNode compareNode = (CompareNode) ifTest;
ValueNode prePhi = preIv.valueNode();
ValueNode mainPhi = mainLoop.getDuplicatedNode(prePhi);
ValueNode preStride = preIv.strideNode();
ValueNode mainStride;
if (preStride instanceof ConstantNode) {
mainStride = preStride;
} else {
mainStride = mainLoop.getDuplicatedNode(preStride);
}
// Fetch the bounds to pose lowering the range by one
ValueNode ub = null;
if (compareNode.getX() == mainPhi) {
ub = compareNode.getY();
} else if (compareNode.getY() == mainPhi) {
ub = compareNode.getX();
} else {
throw GraalError.shouldNotReachHere();
}
// Preloop always performs at least one iteration, so remove that from the main loop.
ValueNode newLimit = sub(graph, ub, mainStride);
// Re-wire the condition with the new limit
compareNode.replaceFirstInput(ub, newLimit);
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class FloatArraysEqualsTest method testStableArray.
public void testStableArray(String methodName) {
ResolvedJavaMethod method = getResolvedJavaMethod(methodName);
Result expected = executeExpected(method, null);
StructuredGraph graph = parseEager(method, AllowAssumptions.YES);
for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class).snapshot()) {
if (getConstantReflection().readArrayLength(constantNode.asJavaConstant()) != null) {
ConstantNode newConstantNode = ConstantNode.forConstant(constantNode.asJavaConstant(), 1, true, getMetaAccess());
newConstantNode = graph.unique(newConstantNode);
constantNode.replaceAndDelete(newConstantNode);
}
}
CompilationResult result = compile(method, graph);
InstalledCode code = addMethod(graph.getDebug(), method, result);
Result actual;
try {
actual = new Result(code.executeVarargs(), null);
} catch (Exception e) {
actual = new Result(null, e);
}
assertEquals(expected, actual);
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class SystemArrayCopyTest method parse.
@Override
protected StructuredGraph parse(StructuredGraph.Builder builder, PhaseSuite<HighTierContext> graphBuilderSuite) {
StructuredGraph graph = super.parse(builder, graphBuilderSuite);
if (argsToBind != null) {
ResolvedJavaMethod m = graph.method();
Object receiver = isStatic(m.getModifiers()) ? null : this;
Object[] args = argsWithReceiver(receiver, argsToBind);
JavaType[] parameterTypes = m.toParameterTypes();
assert parameterTypes.length == args.length;
for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
int index = param.index();
if (args[index] != null) {
JavaConstant c = getSnippetReflection().forBoxed(parameterTypes[index].getJavaKind(), args[index]);
ConstantNode replacement = ConstantNode.forConstant(c, getMetaAccess(), graph);
param.replaceAtUsages(replacement);
}
}
}
return graph;
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class AheadOfTimeCompilationTest method testPrimitiveClassObjectAOT.
@Test
public void testPrimitiveClassObjectAOT() {
StructuredGraph result = compile("getPrimitiveClassObject", true);
NodeIterable<ConstantNode> filter = getConstantNodes(result);
assertDeepEquals(1, filter.count());
Stamp constantStamp = filter.first().stamp(NodeView.DEFAULT);
Assert.assertTrue(constantStamp instanceof KlassPointerStamp);
int expected = runtime().getVMConfig().classMirrorIsHandle ? 3 : 2;
assertDeepEquals(expected, result.getNodes().filter(ReadNode.class).count());
}
use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.
the class AheadOfTimeCompilationTest method testPrimitiveClassObject.
@Test
public void testPrimitiveClassObject() {
StructuredGraph result = compile("getPrimitiveClassObject", false);
NodeIterable<ConstantNode> filter = getConstantNodes(result);
assertDeepEquals(1, filter.count());
JavaConstant c = filter.first().asJavaConstant();
Assert.assertEquals(getSnippetReflection().asObject(Class.class, c), Integer.TYPE);
assertDeepEquals(0, result.getNodes().filter(ReadNode.class).count());
}
Aggregations