use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class IntegerAddExactNode method canonicalXconstant.
private static ConstantNode canonicalXconstant(ValueNode forX, ValueNode forY) {
JavaConstant xConst = forX.asJavaConstant();
JavaConstant yConst = forY.asJavaConstant();
if (xConst != null && yConst != null) {
assert xConst.getJavaKind() == yConst.getJavaKind();
try {
if (xConst.getJavaKind() == JavaKind.Int) {
return ConstantNode.forInt(Math.addExact(xConst.asInt(), yConst.asInt()));
} else {
assert xConst.getJavaKind() == JavaKind.Long;
return ConstantNode.forLong(Math.addExact(xConst.asLong(), yConst.asLong()));
}
} catch (ArithmeticException ex) {
// The operation will result in an overflow exception, so do not canonicalize.
}
}
return null;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class IntegerMulExactNode method canonicalXconstant.
private ValueNode canonicalXconstant(ValueNode forX, ValueNode forY) {
JavaConstant xConst = forX.asJavaConstant();
JavaConstant yConst = forY.asJavaConstant();
assert xConst.getJavaKind() == yConst.getJavaKind();
try {
if (xConst.getJavaKind() == JavaKind.Int) {
return ConstantNode.forInt(Math.multiplyExact(xConst.asInt(), yConst.asInt()));
} else {
assert xConst.getJavaKind() == JavaKind.Long;
return ConstantNode.forLong(Math.multiplyExact(xConst.asLong(), yConst.asLong()));
}
} catch (ArithmeticException ex) {
// The operation will result in an overflow exception, so do not canonicalize.
}
return this;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class AMD64NodeMatchRules method ifCompareLogicCas.
@MatchRule("(If (ObjectEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (PointerEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (FloatEquals=compare value LogicCompareAndSwap=cas))")
@MatchRule("(If (IntegerEquals=compare value LogicCompareAndSwap=cas))")
public ComplexMatchResult ifCompareLogicCas(IfNode root, CompareNode compare, ValueNode value, LogicCompareAndSwapNode cas) {
JavaConstant constant = value.asJavaConstant();
assert compare.condition() == CanonicalCondition.EQ;
if (constant != null && cas.usages().count() == 1) {
long constantValue = constant.asLong();
boolean successIsTrue;
if (constantValue == 0) {
successIsTrue = false;
} else if (constantValue == 1) {
successIsTrue = true;
} else {
return null;
}
return builder -> {
LIRKind kind = getLirKind(cas);
LabelRef trueLabel = getLIRBlock(root.trueSuccessor());
LabelRef falseLabel = getLIRBlock(root.falseSuccessor());
double trueLabelProbability = root.probability(root.trueSuccessor());
Value expectedValue = operand(cas.getExpectedValue());
Value newValue = operand(cas.getNewValue());
AMD64AddressValue address = (AMD64AddressValue) operand(cas.getAddress());
Condition condition = successIsTrue ? Condition.EQ : Condition.NE;
getLIRGeneratorTool().emitCompareAndSwapBranch(kind, address, expectedValue, newValue, condition, trueLabel, falseLabel, trueLabelProbability);
return null;
};
}
return null;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class AArch64AddressLoweringByUse method improve.
protected boolean improve(AArch64Kind kind, AArch64AddressNode ret) {
AArch64Address.AddressingMode mode = ret.getAddressingMode();
// if we have already set a displacement or set to base only mode then we are done
if (isDisplacementMode(mode) || isBaseOnlyMode(mode)) {
return false;
}
ValueNode base = ret.getBase();
ValueNode index = ret.getIndex();
// avoid a constant or null base if possible
if (base == null) {
ret.setBase(index);
ret.setIndex(base);
return true;
}
// as we ought not to see two JavaConstant values
if (base.isJavaConstant() && base.asJavaConstant().getJavaKind().isNumericInteger() && index != null && !index.isJavaConstant()) {
ret.setBase(index);
ret.setIndex(base);
return true;
}
// if the base is an add then move it up
if (index == null && base instanceof AddNode) {
AddNode add = (AddNode) base;
ret.setBase(add.getX());
ret.setIndex(add.getY());
return true;
}
// we can try to fold a JavaConstant index into a displacement
if (index != null && index.isJavaConstant()) {
JavaConstant javaConstant = index.asJavaConstant();
if (javaConstant.getJavaKind().isNumericInteger()) {
long disp = javaConstant.asLong();
mode = immediateMode(kind, disp);
if (isDisplacementMode(mode)) {
index = null;
// we can fold this in as a displacement
// but first see if we can pull up any additional
// constants added into the base
boolean tryNextBase = (base instanceof AddNode);
while (tryNextBase) {
AddNode add = (AddNode) base;
tryNextBase = false;
ValueNode child = add.getX();
if (child.isJavaConstant() && child.asJavaConstant().getJavaKind().isNumericInteger()) {
long newDisp = disp + child.asJavaConstant().asLong();
AArch64Address.AddressingMode newMode = immediateMode(kind, newDisp);
if (newMode != AArch64Address.AddressingMode.REGISTER_OFFSET) {
disp = newDisp;
mode = newMode;
base = add.getY();
ret.setBase(base);
tryNextBase = (base instanceof AddNode);
}
} else {
child = add.getY();
if (child.isJavaConstant() && child.asJavaConstant().getJavaKind().isNumericInteger()) {
long newDisp = disp + child.asJavaConstant().asLong();
AArch64Address.AddressingMode newMode = immediateMode(kind, newDisp);
if (newMode != AArch64Address.AddressingMode.REGISTER_OFFSET) {
disp = newDisp;
mode = newMode;
base = add.getX();
ret.setBase(base);
tryNextBase = (base instanceof AddNode);
}
}
}
}
if (disp != 0) {
// ok now set the displacement in place of an index
ret.setIndex(null);
int scaleFactor = computeScaleFactor(kind, mode);
ret.setDisplacement(disp, scaleFactor, mode);
} else {
// reset to base register only
ret.setIndex(null);
ret.setDisplacement(0, 1, AArch64Address.AddressingMode.BASE_REGISTER_ONLY);
}
return true;
}
}
}
// nope cannot improve this any more
return false;
}
use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.
the class SPARCOP3Op method emitOp3.
public static void emitOp3(SPARCMacroAssembler masm, Op3s op3, Value rs1, Value rs2, Value rd) {
assert isRegister(rs1) : rs1;
if (isJavaConstant(rs2)) {
JavaConstant constant = asJavaConstant(rs2);
long simm13;
if (constant.isNull()) {
simm13 = 0;
} else {
// Cast is safe, as isSimm13 assertion is done
simm13 = constant.asLong();
}
assert isSimm13(constant);
SPARCAssembler.Op3Op.emit(masm, op3, asRegister(rs1), (int) simm13, asRegister(rd));
} else if (isRegister(rs2)) {
SPARCAssembler.Op3Op.emit(masm, op3, asRegister(rs1), asRegister(rs2), asRegister(rd));
} else {
throw shouldNotReachHere(String.format("Got values a: %s b: %s", rs1, rs2));
}
}
Aggregations