Search in sources :

Example 16 with AddNode

use of org.graalvm.compiler.nodes.calc.AddNode 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;
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) AArch64Address(org.graalvm.compiler.asm.aarch64.AArch64Address) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 17 with AddNode

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

the class InstrumentPhase method insertCounter.

protected static void insertCounter(StructuredGraph graph, PhaseContext context, JavaConstant tableConstant, FixedWithNextNode targetNode, int slotIndex) {
    assert (tableConstant != null);
    TypeReference typeRef = TypeReference.createExactTrusted(context.getMetaAccess().lookupJavaType(tableConstant));
    ConstantNode table = graph.unique(new ConstantNode(tableConstant, StampFactory.object(typeRef, true)));
    ConstantNode rawIndex = graph.unique(ConstantNode.forInt(slotIndex));
    LoadIndexedNode load = graph.add(new LoadIndexedNode(null, table, rawIndex, JavaKind.Long));
    ConstantNode one = graph.unique(ConstantNode.forLong(1L));
    ValueNode add = graph.unique(new AddNode(load, one));
    StoreIndexedNode store = graph.add(new StoreIndexedNode(table, rawIndex, JavaKind.Long, add));
    graph.addAfterFixed(targetNode, load);
    graph.addAfterFixed(load, store);
}
Also used : StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 18 with AddNode

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

the class CheckcastArrayCopyCallNode method computeBase.

private ValueNode computeBase(ValueNode base, ValueNode pos) {
    FixedWithNextNode basePtr = graph().add(new GetObjectAddressNode(base));
    graph().addBeforeFixed(this, basePtr);
    int shift = CodeUtil.log2(getArrayIndexScale(JavaKind.Object));
    ValueNode extendedPos = IntegerConvertNode.convert(pos, StampFactory.forKind(runtime.getTarget().wordJavaKind), graph(), NodeView.DEFAULT);
    ValueNode scaledIndex = graph().unique(new LeftShiftNode(extendedPos, ConstantNode.forInt(shift, graph())));
    ValueNode offset = graph().unique(new AddNode(scaledIndex, ConstantNode.forIntegerBits(PrimitiveStamp.getBits(scaledIndex.stamp(NodeView.DEFAULT)), getArrayBaseOffset(JavaKind.Object), graph())));
    return graph().unique(new OffsetAddressNode(basePtr, offset));
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) GetObjectAddressNode(org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode) AbstractMemoryCheckpoint(org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint)

Example 19 with AddNode

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

the class AddressOfVMThreadLocalNode method lower.

@Override
public void lower(LoweringTool tool) {
    assert threadLocalInfo.offset >= 0;
    ValueNode base = holder;
    if (base.getStackKind() == JavaKind.Object) {
        base = graph().unique(new FloatingWordCastNode(FrameAccess.getWordStamp(), base));
    }
    assert base.getStackKind() == FrameAccess.getWordKind();
    ConstantNode offset = ConstantNode.forIntegerKind(FrameAccess.getWordKind(), threadLocalInfo.offset, graph());
    ValueNode address = graph().unique(new AddNode(base, offset));
    replaceAtUsagesAndDelete(address);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) FloatingWordCastNode(com.oracle.svm.core.graal.nodes.FloatingWordCastNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Example 20 with AddNode

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

the class CEntryPointSupport method registerEntryPointContextPlugins.

private static void registerEntryPointContextPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, CEntryPointContext.class);
    r.register0("getCurrentIsolateThread", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (SubstrateOptions.MultiThreaded.getValue()) {
                b.addPush(JavaKind.Object, ReadRegisterFixedNode.forIsolateThread());
            } else if (SubstrateOptions.SpawnIsolates.getValue()) {
                ValueNode heapBase = b.add(ReadRegisterFixedNode.forHeapBase());
                ConstantNode addend = b.add(ConstantNode.forIntegerKind(FrameAccess.getWordKind(), CEntryPointSetup.SINGLE_ISOLATE_TO_SINGLE_THREAD_ADDEND));
                b.addPush(JavaKind.Object, new AddNode(heapBase, addend));
            } else {
                b.addPush(JavaKind.Object, ConstantNode.forIntegerKind(FrameAccess.getWordKind(), CEntryPointSetup.SINGLE_THREAD_SENTINEL.rawValue()));
            }
            return true;
        }
    });
    r.register0("getCurrentIsolate", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (SubstrateOptions.SpawnIsolates.getValue()) {
                b.addPush(JavaKind.Object, ReadRegisterFixedNode.forHeapBase());
            } else {
                b.addPush(JavaKind.Object, ConstantNode.forIntegerKind(FrameAccess.getWordKind(), CEntryPointSetup.SINGLE_ISOLATE_SENTINEL.rawValue()));
            }
            return true;
        }
    });
    r.register1("isCurrentThreadAttachedTo", Isolate.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
            b.addPush(JavaKind.Boolean, new CEntryPointUtilityNode(UtilityAction.IsAttached, isolate));
            return true;
        }
    });
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) CEntryPointUtilityNode(com.oracle.svm.core.graal.nodes.CEntryPointUtilityNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) AddNode(org.graalvm.compiler.nodes.calc.AddNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

AddNode (org.graalvm.compiler.nodes.calc.AddNode)27 ValueNode (org.graalvm.compiler.nodes.ValueNode)17 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)6 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)6 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)5 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)4 Node (org.graalvm.compiler.graph.Node)4 PhiNode (org.graalvm.compiler.nodes.PhiNode)4 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)4 Test (org.junit.Test)4 JavaConstant (jdk.vm.ci.meta.JavaConstant)3 GetObjectAddressNode (org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode)3 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)3 Block (org.graalvm.compiler.nodes.cfg.Block)3 SchedulePhase (org.graalvm.compiler.phases.schedule.SchedulePhase)3 AMD64AddressNode (org.graalvm.compiler.core.amd64.AMD64AddressNode)2 Stamp (org.graalvm.compiler.core.common.type.Stamp)2 FrameState (org.graalvm.compiler.nodes.FrameState)2 NodeView (org.graalvm.compiler.nodes.NodeView)2