use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class IntegerSwitchNode method doReplace.
private void doReplace(ValueNode newValue, List<KeyData> newKeyDatas, ArrayList<AbstractBeginNode> newSuccessors, int newDefaultSuccessor, double newDefaultProbability) {
/* Sort the new keys (invariant of the IntegerSwitchNode). */
newKeyDatas.sort(Comparator.comparingInt(k -> k.key));
/* Create the final data arrays. */
int newKeyCount = newKeyDatas.size();
int[] newKeys = new int[newKeyCount];
double[] newKeyProbabilities = new double[newKeyCount + 1];
int[] newKeySuccessors = new int[newKeyCount + 1];
for (int i = 0; i < newKeyCount; i++) {
KeyData keyData = newKeyDatas.get(i);
newKeys[i] = keyData.key;
newKeyProbabilities[i] = keyData.keyProbability;
newKeySuccessors[i] = keyData.keySuccessor;
}
newKeySuccessors[newKeyCount] = newDefaultSuccessor;
newKeyProbabilities[newKeyCount] = newDefaultProbability;
/* Normalize new probabilities so that they sum up to 1. */
double totalProbability = 0;
for (double probability : newKeyProbabilities) {
totalProbability += probability;
}
if (totalProbability > 0) {
for (int i = 0; i < newKeyProbabilities.length; i++) {
newKeyProbabilities[i] /= totalProbability;
}
} else {
for (int i = 0; i < newKeyProbabilities.length; i++) {
newKeyProbabilities[i] = 1.0 / newKeyProbabilities.length;
}
}
/*
* Collect dead successors. Successors have to be cleaned before adding the new node to the
* graph.
*/
List<AbstractBeginNode> deadSuccessors = successors.filter(s -> !newSuccessors.contains(s)).snapshot();
successors.clear();
/*
* Create the new switch node. This is done before removing dead successors as `killCFG`
* could edit some of the inputs (e.g., if `newValue` is a loop-phi of the loop that dies
* while removing successors).
*/
AbstractBeginNode[] successorsArray = newSuccessors.toArray(new AbstractBeginNode[newSuccessors.size()]);
SwitchNode newSwitch = graph().add(new IntegerSwitchNode(newValue, successorsArray, newKeys, newKeyProbabilities, newKeySuccessors));
/* Remove dead successors. */
for (AbstractBeginNode successor : deadSuccessors) {
GraphUtil.killCFG(successor);
}
/* Replace ourselves with the new switch */
((FixedWithNextNode) predecessor()).setNext(newSwitch);
GraphUtil.killWithUnusedFloatingInputs(this);
}
use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class WriteBarrierVerificationPhase method hasAttachedBarrier.
private boolean hasAttachedBarrier(FixedWithNextNode node) {
final Node next = node.next();
final Node previous = node.predecessor();
boolean validatePreBarrier = useG1GC() && (isObjectWrite(node) || !((ArrayRangeWrite) node).isInitialization());
if (node instanceof WriteNode) {
WriteNode writeNode = (WriteNode) node;
if (writeNode.getLocationIdentity().isInit()) {
validatePreBarrier = false;
}
}
if (isObjectWrite(node)) {
return (isObjectBarrier(node, next) || StampTool.isPointerAlwaysNull(getValueWritten(node))) && (!validatePreBarrier || isObjectBarrier(node, previous));
} else if (isObjectArrayRangeWrite(node)) {
return (isArrayBarrier(node, next) || StampTool.isPointerAlwaysNull(getValueWritten(node))) && (!validatePreBarrier || isArrayBarrier(node, previous));
} else {
return true;
}
}
use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class ArrayCopyCallNode method computeBase.
private ValueNode computeBase(ValueNode base, ValueNode pos) {
FixedWithNextNode basePtr = graph().add(new GetObjectAddressNode(base));
graph().addBeforeFixed(this, basePtr);
Stamp wordStamp = StampFactory.forKind(runtime.getTarget().wordJavaKind);
ValueNode wordPos = IntegerConvertNode.convert(pos, wordStamp, graph(), NodeView.DEFAULT);
int shift = CodeUtil.log2(getArrayIndexScale(elementKind));
ValueNode scaledIndex = graph().unique(new LeftShiftNode(wordPos, ConstantNode.forInt(shift, graph())));
ValueNode offset = graph().unique(new AddNode(scaledIndex, ConstantNode.forIntegerStamp(wordStamp, getArrayBaseOffset(elementKind), graph())));
return graph().unique(new OffsetAddressNode(basePtr, offset));
}
use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class ReplaceConstantNodesPhase method insertReplacement.
/**
* Insert the replacement node into the graph. We may need to insert it into a place different
* than the original {@link FloatingNode} since we need to make sure that replacement will have
* a valid state assigned.
*
* @param graph
* @param stateMapper
* @param node
* @param replacement
*/
private static void insertReplacement(StructuredGraph graph, FrameStateMapperClosure stateMapper, FloatingNode node, FixedWithNextNode replacement) {
FixedWithNextNode insertionPoint = findInsertionPoint(graph, stateMapper, node);
graph.addAfterFixed(insertionPoint, replacement);
stateMapper.addState(replacement, stateMapper.getState(insertionPoint));
}
use of org.graalvm.compiler.nodes.FixedWithNextNode in project graal by oracle.
the class ReplaceConstantNodesPhase method handleHotSpotObjectConstant.
/**
* Replace an object constant with an indirect load {@link ResolveConstantNode}. Currently we
* support only strings.
*
* @param graph
* @param stateMapper
* @param node {@link ConstantNode} containing a {@link HotSpotObjectConstant} that needs
* resolution.
*/
private static void handleHotSpotObjectConstant(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
HotSpotObjectConstant constant = (HotSpotObjectConstant) node.asJavaConstant();
HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) constant.getType();
if (type.mirror().equals(String.class)) {
assert !constant.isCompressed() : "No support for replacing compressed oop constants";
FixedWithNextNode replacement = graph.add(new ResolveConstantNode(node));
insertReplacement(graph, stateMapper, node, replacement);
node.replaceAtUsages(replacement, n -> !(n instanceof ResolveConstantNode));
} else {
throw new GraalError("Unsupported object constant type: " + type);
}
}
Aggregations