Skip to content

Commit

Permalink
Fix of issue beehive-lab#521 in OpenCL.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin committed Aug 14, 2024
1 parent 9b36b2a commit 1fb38e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ private static CallingConvention getCallingConvention(Type type, JavaType return
LIRKind lirKind = LIRKind.value(target.arch.getPlatformKind(returnKind));

Variable returnParameter = new Variable(lirKind, variableIndex);
variableIndex++;

return new CallingConvention(0, returnParameter, inputParameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import java.util.concurrent.atomic.AtomicBoolean;

import org.graalvm.compiler.core.common.type.ObjectStamp;
import org.graalvm.compiler.core.common.type.StampFactory;
import org.graalvm.compiler.core.common.type.StampPair;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.graph.Graph.Mark;
import org.graalvm.compiler.graph.Node;
Expand Down Expand Up @@ -259,20 +257,22 @@ private void evaluate(final StructuredGraph graph, final Node node, final Object
}
}

private ParameterNode createPrimitiveParameterFromObjectParameter(Object obj, int index, StructuredGraph graph) {
ParameterNode result = null;
switch (obj) {
case Byte objByte -> result = new ParameterNode(index, StampPair.createSingle(StampFactory.forKind(JavaKind.Byte)));
case Character objChar -> result = new ParameterNode(index, StampPair.createSingle(StampFactory.forKind(JavaKind.Char)));
case Short objShort -> result = new ParameterNode(index, StampPair.createSingle(StampFactory.forKind(JavaKind.Short)));
case HalfFloat objHalfFloat -> result = new ParameterNode(index, StampPair.createSingle(StampFactory.forKind(JavaKind.Float)));
case Integer objInteger -> result = new ParameterNode(index, StampPair.createSingle(StampFactory.forKind(JavaKind.Int)));
case Float objFloat -> result = new ParameterNode(index, StampPair.createSingle(StampFactory.forKind(JavaKind.Float)));
case Double objDouble -> result = new ParameterNode(index, StampPair.createSingle(StampFactory.forKind(JavaKind.Double)));
case Long objLong -> result = new ParameterNode(index, StampPair.createSingle(StampFactory.forKind(JavaKind.Long)));
case null, default -> unimplemented("createPrimitiveParameterFromObjectParameter: %s", obj);
}
return result;
private ConstantNode createPrimitiveConstantFromObjectParameter(Object obj, StructuredGraph graph) {
return switch (obj) {
case Boolean objBoolean -> ConstantNode.forBoolean(objBoolean, graph);
case Byte objByte -> ConstantNode.forByte(objByte, graph);
case Character objChar -> ConstantNode.forChar(objChar, graph);
case Short objShort -> ConstantNode.forShort(objShort, graph);
case HalfFloat objHalfFloat -> ConstantNode.forFloat(objHalfFloat.getFloat32(), graph);
case Integer objInteger -> ConstantNode.forInt(objInteger, graph);
case Float objFloat -> ConstantNode.forFloat(objFloat, graph);
case Double objDouble -> ConstantNode.forDouble(objDouble, graph);
case Long objLong -> ConstantNode.forLong(objLong, graph);
case Object object -> {
unimplemented("createPrimitiveConstantFromObjectParameter: %s", obj);
yield null;
}
};
}

private boolean isParameterInvolvedInParallelLoopBound(Node parameterNode) {
Expand Down Expand Up @@ -302,35 +302,34 @@ private void propagateParameters(StructuredGraph graph, ParameterNode parameterN
parameterNode.replaceAtUsages(kernelContextAccessNode);
index++;
} else {
ParameterNode primitiveParameter = createPrimitiveParameterFromObjectParameter(args[parameterNode.index()], parameterNode.index(), graph);
var value = args[parameterNode.index()];
ConstantNode primitiveConstant = createPrimitiveConstantFromObjectParameter(value, graph);

parameterNode.replaceAtAllUsages(primitiveParameter, true);
parameterNode.replaceAtAllUsages(primitiveConstant, true);
parameterNode.safeDelete();

//remove Unbox nodes, they are not needed for constant values and cause compilation errors
graph.getNodes().filter(n -> n instanceof PiNode piNode && piNode.object() == primitiveParameter).snapshot().forEach(node -> {
graph.getNodes().filter(n -> n instanceof PiNode piNode && piNode.object() == primitiveConstant).snapshot().forEach(node -> {
var usagesSnapshot = node.usages().snapshot();
node.replaceAtAllUsages(primitiveParameter, true);
node.replaceAtAllUsages(primitiveConstant, true);
node.safeDelete();

usagesSnapshot.forEach(n -> {
if (n instanceof UnboxNode unboxNode) {
var prev = n.predecessor();

unboxNode.replaceAtAllUsages(primitiveParameter, true);
unboxNode.replaceAtAllUsages(primitiveConstant, true);
graph.removeFixed(unboxNode);

if (prev instanceof FixedGuardNode fixedGuardNode) {
if (fixedGuardNode.condition() instanceof IsNullNode isNullNode && isNullNode.getValue() == primitiveParameter) {
if (fixedGuardNode.condition() instanceof IsNullNode isNullNode && isNullNode.getValue() == primitiveConstant) {
fixedGuardNode.clearInputs();
graph.removeFixed(fixedGuardNode);
}
}
}
});
});

graph.addOrUnique(primitiveParameter);
}
} else {
parameterNode.usages().snapshot().forEach(n -> {
Expand Down

0 comments on commit 1fb38e3

Please sign in to comment.