Search in sources :

Example 11 with SignExtendNode

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

the class SPARCIntegerCompareCanonicalizationPhase method min32.

private static void min32(CompareNode enode, ValueNode v) {
    Stamp s = v.stamp(NodeView.DEFAULT);
    if (s instanceof IntegerStamp) {
        int bits = ((IntegerStamp) s).getBits();
        if (bits != 32 && bits != 64) {
            if (bits <= 32) {
                bits = 32;
            } else {
                bits = 64;
            }
            ValueNode replacement;
            if (v instanceof ConstantNode) {
                JavaConstant newConst;
                if (bits == 32) {
                    newConst = JavaConstant.forInt(v.asJavaConstant().asInt());
                } else if (bits == 64) {
                    newConst = JavaConstant.forLong(v.asJavaConstant().asLong());
                } else {
                    throw GraalError.shouldNotReachHere();
                }
                long mask = CodeUtil.mask(bits);
                replacement = v.graph().addOrUnique(new ConstantNode(newConst, IntegerStamp.stampForMask(bits, newConst.asLong() & mask, newConst.asLong() & mask)));
            } else {
                replacement = v.graph().addOrUnique(new SignExtendNode(v, bits));
            }
            v.replaceAtUsages(replacement, x -> x == enode);
        }
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaConstant(jdk.vm.ci.meta.JavaConstant)

Example 12 with SignExtendNode

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

the class DefaultJavaLoweringProvider method createArrayAddress.

public AddressNode createArrayAddress(StructuredGraph graph, ValueNode array, JavaKind elementKind, ValueNode index) {
    ValueNode wordIndex;
    if (target.wordSize > 4) {
        wordIndex = graph.unique(new SignExtendNode(index, target.wordSize * 8));
    } else {
        assert target.wordSize == 4 : "unsupported word size";
        wordIndex = index;
    }
    int shift = CodeUtil.log2(arrayScalingFactor(elementKind));
    ValueNode scaledIndex = graph.unique(new LeftShiftNode(wordIndex, ConstantNode.forInt(shift, graph)));
    int base = arrayBaseOffset(elementKind);
    ValueNode offset = graph.unique(new AddNode(scaledIndex, ConstantNode.forIntegerKind(target.wordJavaKind, base, graph)));
    return graph.unique(new OffsetAddressNode(array, offset));
}
Also used : SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) 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)

Example 13 with SignExtendNode

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

the class PointerTest method assertWrite.

private void assertWrite(StructuredGraph graph, boolean indexConvert, LocationIdentity locationIdentity) {
    WordCastNode cast = (WordCastNode) graph.start().next();
    JavaWriteNode write = (JavaWriteNode) cast.next();
    Assert.assertEquals(graph.getParameter(2), write.value());
    Assert.assertEquals(BytecodeFrame.AFTER_BCI, write.stateAfter().bci);
    OffsetAddressNode address = (OffsetAddressNode) write.getAddress();
    Assert.assertEquals(cast, address.getBase());
    Assert.assertEquals(graph.getParameter(0), cast.getInput());
    Assert.assertEquals(target.wordJavaKind, cast.stamp(NodeView.DEFAULT).getStackKind());
    Assert.assertEquals(locationIdentity, write.getLocationIdentity());
    if (indexConvert) {
        SignExtendNode convert = (SignExtendNode) address.getOffset();
        Assert.assertEquals(convert.getInputBits(), 32);
        Assert.assertEquals(convert.getResultBits(), 64);
        Assert.assertEquals(graph.getParameter(1), convert.getValue());
    } else {
        Assert.assertEquals(graph.getParameter(1), address.getOffset());
    }
    ReturnNode ret = (ReturnNode) write.next();
    Assert.assertEquals(null, ret.result());
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) WordCastNode(org.graalvm.compiler.word.WordCastNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode)

Aggregations

SignExtendNode (org.graalvm.compiler.nodes.calc.SignExtendNode)13 ValueNode (org.graalvm.compiler.nodes.ValueNode)8 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)6 ZeroExtendNode (org.graalvm.compiler.nodes.calc.ZeroExtendNode)5 JavaKind (jdk.vm.ci.meta.JavaKind)3 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)3 Stamp (org.graalvm.compiler.core.common.type.Stamp)3 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)3 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)3 FloatConvertNode (org.graalvm.compiler.nodes.calc.FloatConvertNode)3 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 Node (org.graalvm.compiler.graph.Node)2 LogicNode (org.graalvm.compiler.nodes.LogicNode)2 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)2 AddNode (org.graalvm.compiler.nodes.calc.AddNode)2 IntegerEqualsNode (org.graalvm.compiler.nodes.calc.IntegerEqualsNode)2 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)2 NarrowNode (org.graalvm.compiler.nodes.calc.NarrowNode)2