use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class AndNode method canonical.
private static ValueNode canonical(AndNode self, BinaryOp<And> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
return forX;
}
if (forX.isConstant() && !forY.isConstant()) {
return new AndNode(forY, forX);
}
if (forY.isConstant()) {
Constant c = forY.asConstant();
if (op.isNeutral(c)) {
return forX;
}
if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getJavaKind().isNumericInteger()) {
long rawY = ((PrimitiveConstant) c).asLong();
long mask = CodeUtil.mask(PrimitiveStamp.getBits(stamp));
if ((rawY & mask) == 0) {
return ConstantNode.forIntegerStamp(stamp, 0);
}
if (forX instanceof SignExtendNode) {
SignExtendNode ext = (SignExtendNode) forX;
if (rawY == ((1L << ext.getInputBits()) - 1)) {
return new ZeroExtendNode(ext.getValue(), ext.getResultBits());
}
}
IntegerStamp xStamp = (IntegerStamp) forX.stamp(view);
if (((xStamp.upMask() | xStamp.downMask()) & ~rawY) == 0) {
// No bits are set which are outside the mask, so the mask will have no effect.
return forX;
}
}
return reassociate(self != null ? self : (AndNode) new AndNode(forX, forY).maybeCommuteInputs(), ValueNode.isConstantPredicate(), forX, forY, view);
}
if (forX instanceof NotNode && forY instanceof NotNode) {
return new NotNode(OrNode.create(((NotNode) forX).getValue(), ((NotNode) forY).getValue(), view));
}
return self != null ? self : new AndNode(forX, forY).maybeCommuteInputs();
}
use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class XorNode method canonical.
private static ValueNode canonical(XorNode self, BinaryOp<Xor> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
return ConstantNode.forPrimitive(stamp, op.getZero(forX.stamp(view)));
}
if (forX.isConstant() && !forY.isConstant()) {
return new XorNode(forY, forX);
}
if (forY.isConstant()) {
Constant c = forY.asConstant();
if (op.isNeutral(c)) {
return forX;
}
if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getJavaKind().isNumericInteger()) {
long rawY = ((PrimitiveConstant) c).asLong();
long mask = CodeUtil.mask(PrimitiveStamp.getBits(stamp));
if ((rawY & mask) == mask) {
return new NotNode(forX);
}
}
return reassociate(self != null ? self : (XorNode) new XorNode(forX, forY).maybeCommuteInputs(), ValueNode.isConstantPredicate(), forX, forY, view);
}
return self != null ? self : new XorNode(forX, forY).maybeCommuteInputs();
}
use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class FloatStamp method stampForConstant.
private static FloatStamp stampForConstant(Constant constant) {
FloatStamp result;
PrimitiveConstant value = (PrimitiveConstant) constant;
switch(value.getJavaKind()) {
case Float:
if (Float.isNaN(value.asFloat())) {
result = new FloatStamp(32, Double.NaN, Double.NaN, false);
} else {
result = new FloatStamp(32, value.asFloat(), value.asFloat(), !Float.isNaN(value.asFloat()));
}
break;
case Double:
if (Double.isNaN(value.asDouble())) {
result = new FloatStamp(64, Double.NaN, Double.NaN, false);
} else {
result = new FloatStamp(64, value.asDouble(), value.asDouble(), !Double.isNaN(value.asDouble()));
}
break;
default:
throw GraalError.shouldNotReachHere();
}
if (result.isConstant()) {
return result;
}
return null;
}
use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class ConstantNode method forPrimitive.
/**
* Returns a node for a primitive of a given type.
*/
public static ConstantNode forPrimitive(Stamp stamp, Constant constant) {
if (stamp instanceof IntegerStamp) {
PrimitiveConstant primitive = (PrimitiveConstant) constant;
assert primitive.getJavaKind().isNumericInteger() && stamp.getStackKind() == primitive.getJavaKind().getStackKind();
IntegerStamp istamp = (IntegerStamp) stamp;
return forIntegerBits(istamp.getBits(), primitive);
} else if (stamp instanceof FloatStamp) {
PrimitiveConstant primitive = (PrimitiveConstant) constant;
assert primitive.getJavaKind().isNumericFloat() && stamp.getStackKind() == primitive.getJavaKind();
return forConstant(primitive, null);
} else {
assert !(stamp instanceof AbstractObjectStamp);
return new ConstantNode(constant, stamp.constant(constant, null));
}
}
use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class UnsafeAutomaticSubstitutionProcessor method subNodeComputesLog2.
/**
* Check if the SubNode computes log2 of one of it's operands. The order of operands is not
* assumed; both permutations are checked.
*/
private static boolean subNodeComputesLog2(SubNode subNode, Invoke numberOfLeadingZerosInvokeNode) {
ValueNode xValueNode = subNode.getX();
ValueNode yValueNode = subNode.getY();
if (xValueNode.isJavaConstant() && xValueNode.asJavaConstant().getJavaKind() == JavaKind.Int) {
PrimitiveConstant xValueConstant = (PrimitiveConstant) xValueNode.asJavaConstant();
if (xValueConstant.asInt() == 31) {
assert yValueNode.equals(numberOfLeadingZerosInvokeNode);
return true;
}
}
if (yValueNode.isJavaConstant() && yValueNode.asJavaConstant().getJavaKind() == JavaKind.Int) {
PrimitiveConstant yValueConstant = (PrimitiveConstant) yValueNode.asJavaConstant();
if (yValueConstant.asInt() == 31) {
assert xValueNode.equals(numberOfLeadingZerosInvokeNode);
return true;
}
}
return false;
}
Aggregations