use of org.graalvm.compiler.graph.spi.Canonicalizable in project graal by oracle.
the class SimplifyingGraphDecoder method canonicalizeFixedNode.
/**
* Canonicalizes the provided node, which was originally a {@link FixedNode} but can already be
* canonicalized (and therefore be a non-fixed node).
*
* @param methodScope The current method.
* @param node The node to be canonicalized.
*/
protected Node canonicalizeFixedNode(MethodScope methodScope, Node node) {
if (node instanceof LoadFieldNode) {
LoadFieldNode loadFieldNode = (LoadFieldNode) node;
return loadFieldNode.canonical(canonicalizerTool);
} else if (node instanceof FixedGuardNode) {
FixedGuardNode guard = (FixedGuardNode) node;
if (guard.getCondition() instanceof LogicConstantNode) {
LogicConstantNode condition = (LogicConstantNode) guard.getCondition();
if (condition.getValue() == guard.isNegated()) {
DeoptimizeNode deopt = new DeoptimizeNode(guard.getAction(), guard.getReason(), guard.getSpeculation());
if (guard.stateBefore() != null) {
deopt.setStateBefore(guard.stateBefore());
}
return deopt;
} else {
return null;
}
}
return node;
} else if (node instanceof IfNode) {
IfNode ifNode = (IfNode) node;
if (ifNode.condition() instanceof LogicNegationNode) {
ifNode.eliminateNegation();
}
if (ifNode.condition() instanceof LogicConstantNode) {
boolean condition = ((LogicConstantNode) ifNode.condition()).getValue();
AbstractBeginNode survivingSuccessor = ifNode.getSuccessor(condition);
AbstractBeginNode deadSuccessor = ifNode.getSuccessor(!condition);
graph.removeSplit(ifNode, survivingSuccessor);
assert deadSuccessor.next() == null : "must not be parsed yet";
deadSuccessor.safeDelete();
}
return node;
} else if (node instanceof LoadIndexedNode) {
LoadIndexedNode loadIndexedNode = (LoadIndexedNode) node;
return loadIndexedNode.canonical(canonicalizerTool);
} else if (node instanceof ArrayLengthNode) {
ArrayLengthNode arrayLengthNode = (ArrayLengthNode) node;
return arrayLengthNode.canonical(canonicalizerTool);
} else if (node instanceof IntegerSwitchNode && ((IntegerSwitchNode) node).value().isConstant()) {
IntegerSwitchNode switchNode = (IntegerSwitchNode) node;
int value = switchNode.value().asJavaConstant().asInt();
AbstractBeginNode survivingSuccessor = switchNode.successorAtKey(value);
List<Node> allSuccessors = switchNode.successors().snapshot();
graph.removeSplit(switchNode, survivingSuccessor);
for (Node successor : allSuccessors) {
if (successor != survivingSuccessor) {
assert ((AbstractBeginNode) successor).next() == null : "must not be parsed yet";
successor.safeDelete();
}
}
return node;
} else if (node instanceof Canonicalizable) {
return ((Canonicalizable) node).canonical(canonicalizerTool);
} else {
return node;
}
}
use of org.graalvm.compiler.graph.spi.Canonicalizable in project graal by oracle.
the class PartialEscapeClosure method processNodeWithScalarReplacedInputs.
/**
* This tries to canonicalize the node based on improved (replaced) inputs.
*/
@SuppressWarnings("unchecked")
private boolean processNodeWithScalarReplacedInputs(ValueNode node, FixedNode insertBefore, BlockT state, GraphEffectList effects) {
ValueNode canonicalizedValue = node;
if (node instanceof Canonicalizable.Unary<?>) {
Canonicalizable.Unary<ValueNode> canonicalizable = (Canonicalizable.Unary<ValueNode>) node;
ObjectState valueObj = getObjectState(state, canonicalizable.getValue());
ValueNode valueAlias = valueObj != null ? valueObj.getMaterializedValue() : getScalarAlias(canonicalizable.getValue());
if (valueAlias != canonicalizable.getValue()) {
canonicalizedValue = (ValueNode) canonicalizable.canonical(tool, valueAlias);
}
} else if (node instanceof Canonicalizable.Binary<?>) {
Canonicalizable.Binary<ValueNode> canonicalizable = (Canonicalizable.Binary<ValueNode>) node;
ObjectState xObj = getObjectState(state, canonicalizable.getX());
ValueNode xAlias = xObj != null ? xObj.getMaterializedValue() : getScalarAlias(canonicalizable.getX());
ObjectState yObj = getObjectState(state, canonicalizable.getY());
ValueNode yAlias = yObj != null ? yObj.getMaterializedValue() : getScalarAlias(canonicalizable.getY());
if (xAlias != canonicalizable.getX() || yAlias != canonicalizable.getY()) {
canonicalizedValue = (ValueNode) canonicalizable.canonical(tool, xAlias, yAlias);
}
} else {
return false;
}
if (canonicalizedValue != node && canonicalizedValue != null) {
if (canonicalizedValue.isAlive()) {
ValueNode alias = getAliasAndResolve(state, canonicalizedValue);
if (alias instanceof VirtualObjectNode) {
addVirtualAlias((VirtualObjectNode) alias, node);
effects.deleteNode(node);
} else {
effects.replaceAtUsages(node, alias, insertBefore);
addScalarAlias(node, alias);
}
} else {
if (!prepareCanonicalNode(canonicalizedValue, state, effects)) {
VirtualUtil.trace(node.getOptions(), debug, "replacement via canonicalization too complex: %s -> %s", node, canonicalizedValue);
return false;
}
if (canonicalizedValue instanceof ControlSinkNode) {
effects.replaceWithSink((FixedWithNextNode) node, (ControlSinkNode) canonicalizedValue);
state.markAsDead();
} else {
effects.replaceAtUsages(node, canonicalizedValue, insertBefore);
addScalarAlias(node, canonicalizedValue);
}
}
VirtualUtil.trace(node.getOptions(), debug, "replaced via canonicalization: %s -> %s", node, canonicalizedValue);
return true;
}
return false;
}
Aggregations