use of org.graalvm.compiler.nodes.NodeView in project graal by oracle.
the class LoadMethodNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool) {
if (hub instanceof LoadHubNode) {
ValueNode object = ((LoadHubNode) hub).getValue();
TypeReference type = StampTool.typeReferenceOrNull(object);
if (type != null) {
if (type.isExact()) {
return resolveExactMethod(tool, type.getType());
}
Assumptions assumptions = graph().getAssumptions();
AssumptionResult<ResolvedJavaMethod> resolvedMethod = type.getType().findUniqueConcreteMethod(method);
if (resolvedMethod != null && resolvedMethod.canRecordTo(assumptions) && !type.getType().isInterface() && method.getDeclaringClass().isAssignableFrom(type.getType())) {
NodeView view = NodeView.from(tool);
resolvedMethod.recordTo(assumptions);
return ConstantNode.forConstant(stamp(view), resolvedMethod.getResult().getEncoding(), tool.getMetaAccess());
}
}
}
if (hub.isConstant()) {
return resolveExactMethod(tool, tool.getConstantReflection().asJavaType(hub.asConstant()));
}
return this;
}
use of org.graalvm.compiler.nodes.NodeView in project graal by oracle.
the class TypeSwitchNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
NodeView view = NodeView.from(tool);
if (value() instanceof ConstantNode) {
Constant constant = value().asConstant();
int survivingEdge = keySuccessorIndex(keyCount());
for (int i = 0; i < keyCount(); i++) {
Constant typeHub = keyAt(i);
Boolean equal = tool.getConstantReflection().constantEquals(constant, typeHub);
if (equal == null) {
/* We don't know if this key is a match or not, so we cannot simplify. */
return;
} else if (equal.booleanValue()) {
survivingEdge = keySuccessorIndex(i);
}
}
killOtherSuccessors(tool, survivingEdge);
}
if (value() instanceof LoadHubNode && ((LoadHubNode) value()).getValue().stamp(view) instanceof ObjectStamp) {
ObjectStamp objectStamp = (ObjectStamp) ((LoadHubNode) value()).getValue().stamp(view);
if (objectStamp.type() != null) {
int validKeys = 0;
for (int i = 0; i < keyCount(); i++) {
if (objectStamp.type().isAssignableFrom(keys[i])) {
validKeys++;
}
}
if (validKeys == 0) {
tool.addToWorkList(defaultSuccessor());
graph().removeSplitPropagate(this, defaultSuccessor());
} else if (validKeys != keys.length) {
ArrayList<AbstractBeginNode> newSuccessors = new ArrayList<>(blockSuccessorCount());
ResolvedJavaType[] newKeys = new ResolvedJavaType[validKeys];
int[] newKeySuccessors = new int[validKeys + 1];
double[] newKeyProbabilities = new double[validKeys + 1];
double totalProbability = 0;
int current = 0;
for (int i = 0; i < keyCount() + 1; i++) {
if (i == keyCount() || objectStamp.type().isAssignableFrom(keys[i])) {
int index = newSuccessors.indexOf(keySuccessor(i));
if (index == -1) {
index = newSuccessors.size();
newSuccessors.add(keySuccessor(i));
}
newKeySuccessors[current] = index;
if (i < keyCount()) {
newKeys[current] = keys[i];
}
newKeyProbabilities[current] = keyProbability(i);
totalProbability += keyProbability(i);
current++;
}
}
if (totalProbability > 0) {
for (int i = 0; i < current; i++) {
newKeyProbabilities[i] /= totalProbability;
}
} else {
for (int i = 0; i < current; i++) {
newKeyProbabilities[i] = 1.0 / current;
}
}
for (int i = 0; i < blockSuccessorCount(); i++) {
AbstractBeginNode successor = blockSuccessor(i);
if (!newSuccessors.contains(successor)) {
tool.deleteBranch(successor);
}
setBlockSuccessor(i, null);
}
AbstractBeginNode[] successorsArray = newSuccessors.toArray(new AbstractBeginNode[newSuccessors.size()]);
TypeSwitchNode newSwitch = graph().add(new TypeSwitchNode(value(), successorsArray, newKeys, newKeyProbabilities, newKeySuccessors, tool.getConstantReflection()));
((FixedWithNextNode) predecessor()).setNext(newSwitch);
GraphUtil.killWithUnusedFloatingInputs(this);
}
}
}
}
use of org.graalvm.compiler.nodes.NodeView in project graal by oracle.
the class FloatEqualsNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
NodeView view = NodeView.from(tool);
ValueNode value = OP.canonical(tool.getConstantReflection(), tool.getMetaAccess(), tool.getOptions(), tool.smallestCompareWidth(), CanonicalCondition.EQ, unorderedIsTrue, forX, forY, view);
if (value != null) {
return value;
}
return this;
}
use of org.graalvm.compiler.nodes.NodeView in project graal by oracle.
the class IntegerBelowNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
NodeView view = NodeView.from(tool);
ValueNode value = OP.canonical(tool.getConstantReflection(), tool.getMetaAccess(), tool.getOptions(), tool.smallestCompareWidth(), OP.getCondition(), false, forX, forY, view);
if (value != null) {
return value;
}
return this;
}
use of org.graalvm.compiler.nodes.NodeView in project graal by oracle.
the class IntegerEqualsNode method canonical.
@Override
public Node canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) {
NodeView view = NodeView.from(tool);
ValueNode value = OP.canonical(tool.getConstantReflection(), tool.getMetaAccess(), tool.getOptions(), tool.smallestCompareWidth(), CanonicalCondition.EQ, false, forX, forY, view);
if (value != null) {
return value;
}
return this;
}
Aggregations