use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class AMD64HotSpotLIRGenerator method emitCCall.
@Override
public void emitCCall(long address, CallingConvention nativeCallingConvention, Value[] args, int numberOfFloatingPointArguments) {
Value[] argLocations = new Value[args.length];
getResult().getFrameMapBuilder().callsMethod(nativeCallingConvention);
// TODO(mg): in case a native function uses floating point varargs, the ABI requires that
// RAX contains the length of the varargs
PrimitiveConstant intConst = JavaConstant.forInt(numberOfFloatingPointArguments);
AllocatableValue numberOfFloatingPointArgumentsRegister = AMD64.rax.asValue(LIRKind.value(AMD64Kind.DWORD));
emitMoveConstant(numberOfFloatingPointArgumentsRegister, intConst);
for (int i = 0; i < args.length; i++) {
Value arg = args[i];
AllocatableValue loc = nativeCallingConvention.getArgument(i);
emitMove(loc, arg);
argLocations[i] = loc;
}
Value ptr = emitLoadConstant(LIRKind.value(AMD64Kind.QWORD), JavaConstant.forLong(address));
append(new AMD64CCall(nativeCallingConvention.getReturn(), ptr, numberOfFloatingPointArgumentsRegister, argLocations));
}
use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class SubstrateMemoryAccessProviderImpl method readPrimitiveConstant.
@Override
public JavaConstant readPrimitiveConstant(JavaKind kind, Constant baseConstant, long displacement, int bits) {
SignedWord offset = WordFactory.signed(displacement);
long rawValue;
if (baseConstant instanceof SubstrateObjectConstant) {
Object baseObject = ((SubstrateObjectConstant) baseConstant).getObject();
assert baseObject != null : "SubstrateObjectConstant does not wrap null value";
switch(bits) {
case Byte.SIZE:
rawValue = BarrieredAccess.readByte(baseObject, offset);
break;
case Short.SIZE:
rawValue = BarrieredAccess.readShort(baseObject, offset);
break;
case Integer.SIZE:
rawValue = BarrieredAccess.readInt(baseObject, offset);
break;
case Long.SIZE:
rawValue = BarrieredAccess.readLong(baseObject, offset);
break;
default:
throw shouldNotReachHere();
}
} else if (baseConstant instanceof PrimitiveConstant) {
PrimitiveConstant prim = (PrimitiveConstant) baseConstant;
if (!prim.getJavaKind().isNumericInteger()) {
return null;
}
Pointer basePointer = WordFactory.unsigned(prim.asLong());
if (basePointer.equal(0)) {
return null;
}
switch(bits) {
case Byte.SIZE:
rawValue = basePointer.readByte(offset);
break;
case Short.SIZE:
rawValue = basePointer.readShort(offset);
break;
case Integer.SIZE:
rawValue = basePointer.readInt(offset);
break;
case Long.SIZE:
rawValue = basePointer.readLong(offset);
break;
default:
throw shouldNotReachHere();
}
} else {
return null;
}
return toConstant(kind, rawValue);
}
use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class AArch64LIRGenerator method isCompareConstant.
/**
* Checks whether value can be used directly with a gpCompare instruction. This is <b>not</b>
* the same as {@link AArch64ArithmeticLIRGenerator#isArithmeticConstant(JavaConstant)}, because
* 0.0 is a valid compare constant for floats, while there are no arithmetic constants for
* floats.
*
* @param value any type. Non null.
* @return true if value can be used directly in comparison instruction, false otherwise.
*/
public boolean isCompareConstant(Value value) {
if (isJavaConstant(value)) {
JavaConstant constant = asJavaConstant(value);
if (constant instanceof PrimitiveConstant) {
final long longValue = constant.asLong();
long maskedValue;
switch(constant.getJavaKind()) {
case Boolean:
case Byte:
maskedValue = longValue & 0xFF;
break;
case Char:
case Short:
maskedValue = longValue & 0xFFFF;
break;
case Int:
maskedValue = longValue & 0xFFFF_FFFF;
break;
case Long:
maskedValue = longValue;
break;
default:
throw GraalError.shouldNotReachHere();
}
return AArch64MacroAssembler.isArithmeticImmediate(maskedValue);
} else {
return constant.isDefaultForKind();
}
}
return false;
}
use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class SubNode method canonical.
private static ValueNode canonical(SubNode subNode, BinaryOp<Sub> op, Stamp stamp, ValueNode forX, ValueNode forY, NodeView view) {
SubNode self = subNode;
if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY)) {
Constant zero = op.getZero(forX.stamp(view));
if (zero != null) {
return ConstantNode.forPrimitive(stamp, zero);
}
}
boolean associative = op.isAssociative();
if (associative) {
if (forX instanceof AddNode) {
AddNode x = (AddNode) forX;
if (x.getY() == forY) {
// (a + b) - b
return x.getX();
}
if (x.getX() == forY) {
// (a + b) - a
return x.getY();
}
} else if (forX instanceof SubNode) {
SubNode x = (SubNode) forX;
if (x.getX() == forY) {
// (a - b) - a
return NegateNode.create(x.getY(), view);
}
}
if (forY instanceof AddNode) {
AddNode y = (AddNode) forY;
if (y.getX() == forX) {
// a - (a + b)
return NegateNode.create(y.getY(), view);
}
if (y.getY() == forX) {
// b - (a + b)
return NegateNode.create(y.getX(), view);
}
} else if (forY instanceof SubNode) {
SubNode y = (SubNode) forY;
if (y.getX() == forX) {
// a - (a - b)
return y.getY();
}
}
}
if (forY.isConstant()) {
Constant c = forY.asConstant();
if (op.isNeutral(c)) {
return forX;
}
if (associative && self != null) {
ValueNode reassociated = reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
if (reassociated != self) {
return reassociated;
}
}
if (c instanceof PrimitiveConstant && ((PrimitiveConstant) c).getJavaKind().isNumericInteger()) {
long i = ((PrimitiveConstant) c).asLong();
if (i < 0 || ((IntegerStamp) StampFactory.forKind(forY.getStackKind())).contains(-i)) {
// commutative, so prefer add when it fits.
return BinaryArithmeticNode.add(forX, ConstantNode.forIntegerStamp(stamp, -i), view);
}
}
} else if (forX.isConstant()) {
Constant c = forX.asConstant();
if (ArithmeticOpTable.forStamp(stamp).getAdd().isNeutral(c)) {
/*
* Note that for floating point numbers, + and - have different neutral elements. We
* have to test for the neutral element of +, because we are doing this
* transformation: 0 - x == (-x) + 0 == -x.
*/
return NegateNode.create(forY, view);
}
if (associative && self != null) {
return reassociate(self, ValueNode.isConstantPredicate(), forX, forY, view);
}
}
if (forY instanceof NegateNode) {
return BinaryArithmeticNode.add(forX, ((NegateNode) forY).getValue(), view);
}
return self != null ? self : new SubNode(forX, forY);
}
use of jdk.vm.ci.meta.PrimitiveConstant in project graal by oracle.
the class OrNode method canonical.
private static ValueNode canonical(OrNode self, BinaryOp<Or> 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 OrNode(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 ConstantNode.forIntegerStamp(stamp, mask);
}
}
return reassociate(self != null ? self : (OrNode) new OrNode(forX, forY).maybeCommuteInputs(), ValueNode.isConstantPredicate(), forX, forY, view);
}
if (forX instanceof NotNode && forY instanceof NotNode) {
return new NotNode(AndNode.create(((NotNode) forX).getValue(), ((NotNode) forY).getValue(), view));
}
return self != null ? self : new OrNode(forX, forY).maybeCommuteInputs();
}
Aggregations