Search in sources :

Example 21 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class AArch64ArithmeticLIRGenerator method emitStore.

@Override
public void emitStore(ValueKind<?> lirKind, Value address, Value inputVal, LIRFrameState state) {
    AArch64AddressValue storeAddress = getLIRGen().asAddressValue(address);
    AArch64Kind kind = (AArch64Kind) lirKind.getPlatformKind();
    if (isJavaConstant(inputVal) && kind.isInteger()) {
        JavaConstant c = asJavaConstant(inputVal);
        if (c.isDefaultForKind()) {
            // We can load 0 directly into integer registers
            getLIRGen().append(new StoreConstantOp(kind, storeAddress, c, state));
            return;
        }
    }
    AllocatableValue input = getLIRGen().asAllocatable(inputVal);
    getLIRGen().append(new StoreOp(kind, storeAddress, input, state));
}
Also used : AArch64AddressValue(org.graalvm.compiler.lir.aarch64.AArch64AddressValue) AArch64Kind(jdk.vm.ci.aarch64.AArch64Kind) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) StoreOp(org.graalvm.compiler.lir.aarch64.AArch64Move.StoreOp) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) StoreConstantOp(org.graalvm.compiler.lir.aarch64.AArch64Move.StoreConstantOp)

Example 22 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant 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;
}
Also used : PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) LIRValueUtil.asJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant) LIRValueUtil.isJavaConstant(org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 23 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class ConditionalNode method inferStamp.

@Override
public boolean inferStamp() {
    Stamp valueStamp = trueValue.stamp(NodeView.DEFAULT).meet(falseValue.stamp(NodeView.DEFAULT));
    if (condition instanceof IntegerLessThanNode) {
        IntegerLessThanNode lessThan = (IntegerLessThanNode) condition;
        if (lessThan.getX() == trueValue && lessThan.getY() == falseValue) {
            // this encodes a min operation
            JavaConstant constant = lessThan.getX().asJavaConstant();
            if (constant == null) {
                constant = lessThan.getY().asJavaConstant();
            }
            if (constant != null) {
                IntegerStamp bounds = StampFactory.forInteger(constant.getJavaKind(), constant.getJavaKind().getMinValue(), constant.asLong());
                valueStamp = valueStamp.join(bounds);
            }
        } else if (lessThan.getX() == falseValue && lessThan.getY() == trueValue) {
            // this encodes a max operation
            JavaConstant constant = lessThan.getX().asJavaConstant();
            if (constant == null) {
                constant = lessThan.getY().asJavaConstant();
            }
            if (constant != null) {
                IntegerStamp bounds = StampFactory.forInteger(constant.getJavaKind(), constant.asLong(), constant.getJavaKind().getMaxValue());
                valueStamp = valueStamp.join(bounds);
            }
        }
    }
    return updateStamp(valueStamp);
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 24 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class ObjectScanner method scanMethod.

private void scanMethod(AnalysisMethod method) {
    try {
        StreamSupport.stream(method.getTypeFlow().getGraph().getNodes().spliterator(), false).filter(n -> n instanceof ConstantNode).forEach(n -> {
            ConstantNode cn = (ConstantNode) n;
            JavaConstant c = (JavaConstant) cn.getValue();
            if (c.getJavaKind() == JavaKind.Object) {
                scanConstant(c, method);
            }
        });
    } catch (UnsupportedFeatureException ex) {
        bb.getUnsupportedFeatures().addMessage(method.format("%H.%n(%p)"), method, ex.getMessage(), null, ex);
    }
}
Also used : IdentityHashMap(java.util.IdentityHashMap) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Deque(java.util.Deque) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) JavaConstant(jdk.vm.ci.meta.JavaConstant) JavaKind(jdk.vm.ci.meta.JavaKind) Modifier(java.lang.reflect.Modifier) Map(java.util.Map) StreamSupport(java.util.stream.StreamSupport) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) WordBase(org.graalvm.word.WordBase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 25 with JavaConstant

use of jdk.vm.ci.meta.JavaConstant in project graal by oracle.

the class ObjectScanner method scanField.

/**
 * Scans the value of a field giving a receiver object.
 *
 * @param field the scanned field
 * @param receiver the receiver object
 * @param reason what triggered the scanning
 */
protected final void scanField(AnalysisField field, JavaConstant receiver, Object reason) {
    try {
        JavaConstant fieldValue = bb.getConstantReflectionProvider().readFieldValue(field, receiver);
        if (fieldValue.getJavaKind() == JavaKind.Object && bb.getHostVM().isRelocatedPointer(bb.getSnippetReflectionProvider().asObject(Object.class, fieldValue))) {
            forRelocatedPointerFieldValue(receiver, field, fieldValue);
        } else if (fieldValue.isNull()) {
            forNullFieldValue(receiver, field);
        } else if (fieldValue.getJavaKind() == JavaKind.Object) {
            if (receiver == null) {
                registerRoot(fieldValue, field);
            } else {
                propagateRoot(receiver, fieldValue);
            }
            /* Scan the field value. */
            scanConstant(fieldValue, reason);
            /* Process the field value. */
            forNonNullFieldValue(receiver, field, fieldValue);
        }
    } catch (UnsupportedFeatureException ex) {
        unsupportedFeature(field.format("%H.%n"), ex.getMessage(), reason);
    }
}
Also used : UnsupportedFeatureException(com.oracle.graal.pointsto.constraints.UnsupportedFeatureException) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)122 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)24 Test (org.junit.Test)19 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)15 Stamp (org.graalvm.compiler.core.common.type.Stamp)11 LIRValueUtil.asJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant)11 LIRValueUtil.isJavaConstant (org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant)11 JavaKind (jdk.vm.ci.meta.JavaKind)10 Constant (jdk.vm.ci.meta.Constant)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)7 Condition (org.graalvm.compiler.core.common.calc.Condition)7 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)6 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5