Search in sources :

Example 1 with ConstantNode

use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.

the class IntegerSwitchNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    NodeView view = NodeView.from(tool);
    if (blockSuccessorCount() == 1) {
        tool.addToWorkList(defaultSuccessor());
        graph().removeSplitPropagate(this, defaultSuccessor());
    } else if (value() instanceof ConstantNode) {
        killOtherSuccessors(tool, successorIndexAtKey(value().asJavaConstant().asInt()));
    } else if (tryOptimizeEnumSwitch(tool)) {
        return;
    } else if (tryRemoveUnreachableKeys(tool, value().stamp(view))) {
        return;
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) NodeView(org.graalvm.compiler.nodes.NodeView)

Example 2 with ConstantNode

use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.

the class RawLoadNode method canonical.

@Override
public Node canonical(CanonicalizerTool tool) {
    if (!isAnyLocationForced() && getLocationIdentity().isAny()) {
        ValueNode targetObject = object();
        if (offset().isConstant() && targetObject.isConstant() && !targetObject.isNullConstant()) {
            ConstantNode objectConstant = (ConstantNode) targetObject;
            ResolvedJavaType type = StampTool.typeOrNull(objectConstant);
            if (type != null && type.isArray()) {
                JavaConstant arrayConstant = objectConstant.asJavaConstant();
                if (arrayConstant != null) {
                    int stableDimension = objectConstant.getStableDimension();
                    if (stableDimension > 0) {
                        NodeView view = NodeView.from(tool);
                        long constantOffset = offset().asJavaConstant().asLong();
                        Constant constant = stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), arrayConstant, constantOffset);
                        boolean isDefaultStable = objectConstant.isDefaultStable();
                        if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
                            return ConstantNode.forConstant(stamp(view), constant, stableDimension - 1, isDefaultStable, tool.getMetaAccess());
                        }
                    }
                }
            }
        }
    }
    return super.canonical(tool);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Constant(jdk.vm.ci.meta.Constant) JavaConstant(jdk.vm.ci.meta.JavaConstant) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) NodeView(org.graalvm.compiler.nodes.NodeView) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 3 with ConstantNode

use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.

the class VirtualFrameAccessorNode method insertDeoptimization.

protected void insertDeoptimization(VirtualizerTool tool) {
    /*
         * Escape analysis does not allow insertion of a DeoptimizeNode. We work around this
         * restriction by inserting an always-failing guard, which will be canonicalized to a
         * DeoptimizeNode later on.
         */
    LogicNode condition = LogicConstantNode.contradiction();
    tool.addNode(condition);
    JavaConstant speculation = graph().getSpeculationLog().speculate(frame.getIntrinsifyAccessorsSpeculation());
    tool.addNode(new FixedGuardNode(condition, DeoptimizationReason.RuntimeConstraint, DeoptimizationAction.InvalidateRecompile, speculation, false));
    if (getStackKind() == JavaKind.Void) {
        tool.delete();
    } else {
        /*
             * Even though all usages will be eventually dead, we need to provide a valid
             * replacement value for now.
             */
        ConstantNode unusedValue = ConstantNode.forConstant(JavaConstant.defaultForKind(getStackKind()), tool.getMetaAccessProvider());
        tool.addNode(unusedValue);
        tool.replaceWith(unusedValue);
    }
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 4 with ConstantNode

use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.

the class LoadJavaMirrorWithKlassPhase method getClassConstantReplacement.

private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) {
    if (constant instanceof HotSpotObjectConstant) {
        ConstantReflectionProvider constantReflection = context.getConstantReflection();
        ResolvedJavaType type = constantReflection.asJavaType(constant);
        if (type != null) {
            MetaAccessProvider metaAccess = context.getMetaAccess();
            Stamp stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Class.class)));
            if (type instanceof HotSpotResolvedObjectType) {
                ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph);
                ValueNode getClass = graph.unique(new HubGetClassNode(metaAccess, klass));
                if (((HotSpotObjectConstant) constant).isCompressed()) {
                    return HotSpotCompressionNode.compress(getClass, oopEncoding);
                } else {
                    return getClass;
                }
            } else {
                /*
                     * Primitive classes are more difficult since they don't have a corresponding
                     * Klass* so get them from Class.TYPE for the java box type.
                     */
                HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type;
                ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getJavaKind().toBoxedJavaClass());
                ConstantNode clazz = ConstantNode.forConstant(context.getConstantReflection().asJavaClass(boxingClass), metaAccess, graph);
                HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields();
                HotSpotResolvedJavaField typeField = null;
                for (HotSpotResolvedJavaField f : a) {
                    if (f.getName().equals("TYPE")) {
                        typeField = f;
                        break;
                    }
                }
                if (typeField == null) {
                    throw new GraalError("Can't find TYPE field in class");
                }
                if (oopEncoding != null) {
                    stamp = HotSpotNarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding);
                }
                AddressNode address = graph.unique(new OffsetAddressNode(clazz, ConstantNode.forLong(typeField.offset(), graph)));
                ValueNode read = graph.unique(new FloatingReadNode(address, FINAL_LOCATION, null, stamp));
                if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) {
                    return read;
                } else {
                    return HotSpotCompressionNode.uncompress(read, oopEncoding);
                }
            }
        }
    }
    return null;
}
Also used : KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotNarrowOopStamp(org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) HotSpotResolvedPrimitiveType(jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) GraalError(org.graalvm.compiler.debug.GraalError) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 5 with ConstantNode

use of org.graalvm.compiler.nodes.ConstantNode in project graal by oracle.

the class CallSiteTargetNode method lower.

@Override
public void lower(LoweringTool tool) {
    ConstantNode target = tryFold(getCallSite(), tool.getMetaAccess(), graph().getAssumptions());
    if (target != null) {
        graph().replaceFixedWithFloating(this, target);
    } else {
        InvokeNode invoke = createInvoke();
        graph().replaceFixedWithFixed(this, invoke);
        invoke.lower(tool);
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode)

Aggregations

ConstantNode (org.graalvm.compiler.nodes.ConstantNode)100 ValueNode (org.graalvm.compiler.nodes.ValueNode)46 JavaConstant (jdk.vm.ci.meta.JavaConstant)32 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)28 Stamp (org.graalvm.compiler.core.common.type.Stamp)23 Test (org.junit.Test)15 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)14 Node (org.graalvm.compiler.graph.Node)14 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)13 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)13 PhiNode (org.graalvm.compiler.nodes.PhiNode)12 LogicNode (org.graalvm.compiler.nodes.LogicNode)11 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)10 ArrayList (java.util.ArrayList)9 JavaKind (jdk.vm.ci.meta.JavaKind)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 Constant (jdk.vm.ci.meta.Constant)8 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)8 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 LogicConstantNode (org.graalvm.compiler.nodes.LogicConstantNode)7