use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class IfNode method checkForUnsignedCompare.
/**
* Recognize a couple patterns that can be merged into an unsigned compare.
*
* @param tool
* @return true if a replacement was done.
*/
private boolean checkForUnsignedCompare(SimplifierTool tool) {
assert trueSuccessor().hasNoUsages() && falseSuccessor().hasNoUsages();
if (condition() instanceof IntegerLessThanNode) {
NodeView view = NodeView.from(tool);
IntegerLessThanNode lessThan = (IntegerLessThanNode) condition();
Constant y = lessThan.getY().stamp(view).asConstant();
if (y instanceof PrimitiveConstant && ((PrimitiveConstant) y).asLong() == 0 && falseSuccessor().next() instanceof IfNode) {
IfNode ifNode2 = (IfNode) falseSuccessor().next();
if (ifNode2.condition() instanceof IntegerLessThanNode) {
IntegerLessThanNode lessThan2 = (IntegerLessThanNode) ifNode2.condition();
AbstractBeginNode falseSucc = ifNode2.falseSuccessor();
AbstractBeginNode trueSucc = ifNode2.trueSuccessor();
IntegerBelowNode below = null;
/*
* Convert x >= 0 && x < positive which is represented as !(x < 0) && x <
* <positive> into an unsigned compare.
*/
if (lessThan2.getX() == lessThan.getX() && lessThan2.getY().stamp(view) instanceof IntegerStamp && ((IntegerStamp) lessThan2.getY().stamp(view)).isPositive() && sameDestination(trueSuccessor(), ifNode2.falseSuccessor)) {
below = graph().unique(new IntegerBelowNode(lessThan2.getX(), lessThan2.getY()));
// swap direction
AbstractBeginNode tmp = falseSucc;
falseSucc = trueSucc;
trueSucc = tmp;
} else if (lessThan2.getY() == lessThan.getX() && sameDestination(trueSuccessor(), ifNode2.trueSuccessor)) {
/*
* Convert x >= 0 && x <= positive which is represented as !(x < 0) &&
* !(<positive> > x), into x <| positive + 1. This can only be done for
* constants since there isn't a IntegerBelowEqualThanNode but that doesn't
* appear to be interesting.
*/
JavaConstant positive = lessThan2.getX().asJavaConstant();
if (positive != null && positive.asLong() > 0 && positive.asLong() < positive.getJavaKind().getMaxValue()) {
ConstantNode newLimit = ConstantNode.forIntegerStamp(lessThan2.getX().stamp(view), positive.asLong() + 1, graph());
below = graph().unique(new IntegerBelowNode(lessThan.getX(), newLimit));
}
}
if (below != null) {
ifNode2.setTrueSuccessor(null);
ifNode2.setFalseSuccessor(null);
IfNode newIfNode = graph().add(new IfNode(below, falseSucc, trueSucc, 1 - trueSuccessorProbability));
// Remove the < 0 test.
tool.deleteBranch(trueSuccessor);
graph().removeSplit(this, falseSuccessor);
// Replace the second test with the new one.
ifNode2.predecessor().replaceFirstSuccessor(ifNode2, newIfNode);
ifNode2.safeDelete();
return true;
}
}
}
}
return false;
}
use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class VerifyDebugUsage method verifyDumpLevelParameter.
/**
* The {@code level} arg for the {@code Debug.dump(...)} methods must be a reference to one of
* the {@code Debug.*_LEVEL} constants.
*/
protected Integer verifyDumpLevelParameter(StructuredGraph callerGraph, MethodCallTargetNode debugCallTarget, ResolvedJavaMethod verifiedCallee, ValueNode arg) throws org.graalvm.compiler.phases.VerifyPhase.VerificationError {
// The 'level' arg for the Debug.dump(...) methods must be a reference to one of
// the Debug.*_LEVEL constants.
Constant c = arg.asConstant();
if (c != null) {
Integer dumpLevel = ((PrimitiveConstant) c).asInt();
if (!DebugLevels.contains(dumpLevel)) {
StackTraceElement e = callerGraph.method().asStackTraceElement(debugCallTarget.invoke().bci());
throw new VerificationError("In %s: parameter 0 of call to %s does not match a Debug.*_LEVEL constant: %s.%n", e, verifiedCallee.format("%H.%n(%p)"), dumpLevel);
}
return dumpLevel;
}
StackTraceElement e = callerGraph.method().asStackTraceElement(debugCallTarget.invoke().bci());
throw new VerificationError("In %s: parameter 0 of call to %s must be a constant, not %s.%n", e, verifiedCallee.format("%H.%n(%p)"), arg);
}
Aggregations