use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class AMD64HotSpotAddressLowering method signExtend.
/**
* Create a sign extend for {@code input}, or zero extend if {@code input} can be proven
* positive.
*/
private static ValueNode signExtend(ValueNode input, LoopEx loop) {
StructuredGraph graph = input.graph();
if (input instanceof PhiNode) {
EconomicMap<Node, InductionVariable> ivs = loop.getInductionVariables();
InductionVariable inductionVariable = ivs.get(input);
if (inductionVariable != null && inductionVariable instanceof BasicInductionVariable) {
CountedLoopInfo countedLoopInfo = loop.counted();
IntegerStamp initStamp = (IntegerStamp) inductionVariable.initNode().stamp(NodeView.DEFAULT);
if (initStamp.isPositive()) {
if (inductionVariable.isConstantExtremum()) {
long init = inductionVariable.constantInit();
long stride = inductionVariable.constantStride();
long extremum = inductionVariable.constantExtremum();
if (init >= 0 && extremum >= 0) {
long shortestTrip = (extremum - init) / stride + 1;
if (countedLoopInfo.constantMaxTripCount().equals(shortestTrip)) {
return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
}
}
}
if (countedLoopInfo.getCounter() == inductionVariable && inductionVariable.direction() == InductionVariable.Direction.Up && countedLoopInfo.getOverFlowGuard() != null) {
return graph.unique(new ZeroExtendNode(input, INT_BITS, ADDRESS_BITS, true));
}
}
}
}
return input.graph().maybeAddOrUnique(SignExtendNode.create(input, ADDRESS_BITS, NodeView.DEFAULT));
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class BranchProbabilityNode method simplify.
@Override
public void simplify(SimplifierTool tool) {
if (!hasUsages()) {
return;
}
if (probability.isConstant()) {
double probabilityValue = probability.asJavaConstant().asDouble();
if (probabilityValue < 0.0) {
throw new GraalError("A negative probability of " + probabilityValue + " is not allowed!");
} else if (probabilityValue > 1.0) {
throw new GraalError("A probability of more than 1.0 (" + probabilityValue + ") is not allowed!");
} else if (Double.isNaN(probabilityValue)) {
/*
* We allow NaN if the node is in unreachable code that will eventually fall away,
* or else an error will be thrown during lowering since we keep the node around.
*/
return;
}
boolean usageFound = false;
for (IntegerEqualsNode node : this.usages().filter(IntegerEqualsNode.class)) {
assert node.condition() == CanonicalCondition.EQ;
ValueNode other = node.getX();
if (node.getX() == this) {
other = node.getY();
}
if (other.isConstant()) {
double probabilityToSet = probabilityValue;
if (other.asJavaConstant().asInt() == 0) {
probabilityToSet = 1.0 - probabilityToSet;
}
for (IfNode ifNodeUsages : node.usages().filter(IfNode.class)) {
usageFound = true;
ifNodeUsages.setTrueSuccessorProbability(probabilityToSet);
}
if (!usageFound) {
usageFound = node.usages().filter(NodePredicates.isA(FixedGuardNode.class).or(ConditionalNode.class)).isNotEmpty();
}
}
}
if (usageFound) {
ValueNode currentCondition = condition;
replaceAndDelete(currentCondition);
if (tool != null) {
tool.addToWorkList(currentCondition.usages());
}
} else {
if (!isSubstitutionGraph()) {
throw new GraalError("Wrong usage of branch probability injection!");
}
}
}
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class GetClassNode method canonical.
@Override
public ValueNode canonical(CanonicalizerTool tool) {
NodeView view = NodeView.from(tool);
ValueNode folded = tryFold(tool.getMetaAccess(), tool.getConstantReflection(), view, getObject());
return folded == null ? this : folded;
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class GetClassNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode alias = tool.getAlias(getObject());
if (alias instanceof VirtualObjectNode) {
VirtualObjectNode virtual = (VirtualObjectNode) alias;
Constant javaClass = tool.getConstantReflectionProvider().asJavaClass(virtual.type());
tool.replaceWithValue(ConstantNode.forConstant(stamp(NodeView.DEFAULT), javaClass, tool.getMetaAccessProvider(), graph()));
}
}
use of org.graalvm.compiler.nodes.ValueNode in project graal by oracle.
the class InstanceOfNode method virtualize.
@Override
public void virtualize(VirtualizerTool tool) {
ValueNode alias = tool.getAlias(getValue());
TriState fold = tryFold(alias.stamp(NodeView.DEFAULT));
if (fold != TriState.UNKNOWN) {
tool.replaceWithValue(LogicConstantNode.forBoolean(fold.isTrue(), graph()));
}
}
Aggregations