Search in sources :

Example 6 with ConstantNode

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

the class ReadNode method canonicalizeRead.

public static ValueNode canonicalizeRead(ValueNode read, AddressNode address, LocationIdentity locationIdentity, CanonicalizerTool tool) {
    NodeView view = NodeView.from(tool);
    MetaAccessProvider metaAccess = tool.getMetaAccess();
    if (tool.canonicalizeReads() && address instanceof OffsetAddressNode) {
        OffsetAddressNode objAddress = (OffsetAddressNode) address;
        ValueNode object = objAddress.getBase();
        if (metaAccess != null && object.isConstant() && !object.isNullConstant() && objAddress.getOffset().isConstant()) {
            long displacement = objAddress.getOffset().asJavaConstant().asLong();
            int stableDimension = ((ConstantNode) object).getStableDimension();
            if (locationIdentity.isImmutable() || stableDimension > 0) {
                Constant constant = read.stamp(view).readConstant(tool.getConstantReflection().getMemoryAccessProvider(), object.asConstant(), displacement);
                boolean isDefaultStable = locationIdentity.isImmutable() || ((ConstantNode) object).isDefaultStable();
                if (constant != null && (isDefaultStable || !constant.isDefaultForKind())) {
                    return ConstantNode.forConstant(read.stamp(view), constant, Math.max(stableDimension - 1, 0), isDefaultStable, metaAccess);
                }
            }
        }
        if (locationIdentity.equals(ARRAY_LENGTH_LOCATION)) {
            ValueNode length = GraphUtil.arrayLength(object);
            if (length != null) {
                return length;
            }
        }
        if (locationIdentity instanceof CanonicalizableLocation) {
            CanonicalizableLocation canonicalize = (CanonicalizableLocation) locationIdentity;
            ValueNode result = canonicalize.canonicalizeRead(read, address, object, tool);
            assert result != null && result.stamp(view).isCompatible(read.stamp(view));
            return result;
        }
    }
    return read;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) Constant(jdk.vm.ci.meta.Constant) ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeView(org.graalvm.compiler.nodes.NodeView) CanonicalizableLocation(org.graalvm.compiler.nodes.CanonicalizableLocation) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 7 with ConstantNode

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

the class CompareAndSetVMThreadLocalNode method lower.

@Override
public void lower(LoweringTool tool) {
    assert threadLocalInfo.offset >= 0;
    ConstantNode offset = ConstantNode.forIntegerKind(FrameAccess.getWordKind(), threadLocalInfo.offset, holder.graph());
    AddressNode address = graph().unique(new OffsetAddressNode(holder, offset));
    LogicCompareAndSwapNode atomic = graph().add(new LogicCompareAndSwapNode(address, threadLocalInfo.locationIdentity, expect, update, barrierType));
    atomic.setStateAfter(stateAfter());
    graph().replaceFixedWithFixed(this, atomic);
}
Also used : LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)

Example 8 with ConstantNode

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

the class StoreVMThreadLocalNode method lower.

@Override
public void lower(LoweringTool tool) {
    assert threadLocalInfo.offset >= 0;
    ConstantNode offset = ConstantNode.forIntegerKind(FrameAccess.getWordKind(), threadLocalInfo.offset, graph());
    AddressNode address = graph().unique(new OffsetAddressNode(holder, offset));
    AbstractWriteNode write;
    if (SubstrateOptions.MultiThreaded.getValue()) {
        write = new CInterfaceWriteNode(address, threadLocalInfo.locationIdentity, value, barrierType, threadLocalInfo.name);
    } else {
        write = new JavaWriteNode(threadLocalInfo.storageKind, address, threadLocalInfo.locationIdentity, value, barrierType, true);
    }
    write = graph().add(write);
    write.setStateAfter(stateAfter());
    graph().replaceFixedWithFixed(this, write);
    if (!SubstrateOptions.MultiThreaded.getValue()) {
        tool.getLowerer().lower(write, tool);
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AbstractWriteNode(org.graalvm.compiler.nodes.memory.AbstractWriteNode) CInterfaceWriteNode(com.oracle.svm.core.graal.nodes.CInterfaceWriteNode)

Example 9 with ConstantNode

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

the class HotSpotClassInitializationPlugin method apply.

@Override
public ValueNode apply(GraphBuilderContext builder, ResolvedJavaType type, FrameState frameState) {
    assert shouldApply(builder, type);
    Stamp hubStamp = builder.getStampProvider().createHubStamp((ObjectStamp) StampFactory.objectNonNull());
    ConstantNode hub = builder.append(ConstantNode.forConstant(hubStamp, ((HotSpotResolvedObjectType) type).klass(), builder.getMetaAccess(), builder.getGraph()));
    DeoptimizingFixedWithNextNode result = builder.append(type.isArray() ? new ResolveConstantNode(hub) : new InitializeKlassNode(hub));
    result.setStateBefore(frameState);
    return result;
}
Also used : ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) DeoptimizingFixedWithNextNode(org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode)

Example 10 with ConstantNode

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

the class HotSpotNodePlugin method tryConstantFold.

private static boolean tryConstantFold(GraphBuilderContext b, ResolvedJavaField field, JavaConstant object) {
    ConstantNode result = ConstantFoldUtil.tryConstantFold(b.getConstantFieldProvider(), b.getConstantReflection(), b.getMetaAccess(), field, object, b.getOptions());
    if (result != null) {
        result = b.getGraph().unique(result);
        b.push(field.getJavaKind(), result);
        return true;
    }
    return false;
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode)

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