Search in sources :

Example 66 with ValueNode

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

the class AMD64AddressLoweringTest method convertBaseAndIndexToDisplacement.

@Test
public void convertBaseAndIndexToDisplacement() {
    ValueNode base = graph.unique(const64(1000));
    ValueNode index = graph.unique(const64(10));
    AddressNode result = lowering.lower(base, index);
    assertAddress(result, null, null, Scale.Times1, 1010);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 67 with ValueNode

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

the class AMD64AddressLoweringTest method convertBaseAndShiftedIndexToDisplacement.

@Test
public void convertBaseAndShiftedIndexToDisplacement() {
    ValueNode base = graph.addOrUniqueWithInputs(const64(1000));
    ValueNode index = graph.addOrUniqueWithInputs(new LeftShiftNode(const64(10), const32(1)));
    AddressNode result = lowering.lower(base, index);
    assertAddress(result, null, null, Scale.Times2, 1020);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 68 with ValueNode

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

the class AMD64AddressLoweringTest method convertBaseAndNegatedShiftedIndexToDisplacement.

@Test
public void convertBaseAndNegatedShiftedIndexToDisplacement() {
    ValueNode base = graph.addOrUniqueWithInputs(const64(1000));
    ValueNode index = graph.addOrUniqueWithInputs(new NegateNode(new LeftShiftNode(const64(10), const32(2))));
    AddressNode result = lowering.lower(base, index);
    assertAddress(result, null, null, Scale.Times4, 960);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) NegateNode(org.graalvm.compiler.nodes.calc.NegateNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 69 with ValueNode

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

the class AMD64AddressLoweringTest method convertBaseToDisplacement.

@Test
public void convertBaseToDisplacement() {
    ValueNode constantAddress = graph.addOrUniqueWithInputs(const64(1000));
    AddressNode result = lowering.lower(constantAddress, null);
    assertAddress(result, null, null, Scale.Times1, 1000);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) AMD64AddressNode(org.graalvm.compiler.core.amd64.AMD64AddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) Test(org.junit.Test) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest)

Example 70 with ValueNode

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

the class AMD64AddressLowering method improve.

/**
 * Tries to optimize addresses so that they match the AMD64-specific addressing mode better
 * (base + index * scale + displacement).
 *
 * @param graph the current graph
 * @param debug the current debug context
 * @param ret the address that should be optimized
 * @param isBaseNegated determines if the address base is negated. if so, all values that are
 *            extracted from the base will be negated as well
 * @param isIndexNegated determines if the index is negated. if so, all values that are
 *            extracted from the index will be negated as well
 * @return true if the address was modified
 */
protected boolean improve(StructuredGraph graph, DebugContext debug, AMD64AddressNode ret, boolean isBaseNegated, boolean isIndexNegated) {
    ValueNode newBase = improveInput(ret, ret.getBase(), 0, isBaseNegated);
    if (newBase != ret.getBase()) {
        ret.setBase(newBase);
        return true;
    }
    ValueNode newIdx = improveInput(ret, ret.getIndex(), ret.getScale().log2, isIndexNegated);
    if (newIdx != ret.getIndex()) {
        ret.setIndex(newIdx);
        return true;
    }
    if (ret.getIndex() instanceof LeftShiftNode) {
        LeftShiftNode shift = (LeftShiftNode) ret.getIndex();
        if (shift.getY().isConstant()) {
            int amount = ret.getScale().log2 + shift.getY().asJavaConstant().asInt();
            Scale scale = Scale.fromShift(amount);
            if (scale != null) {
                ret.setIndex(shift.getX());
                ret.setScale(scale);
                return true;
            }
        }
    }
    if (ret.getScale() == Scale.Times1) {
        if (ret.getIndex() == null && ret.getBase() instanceof AddNode) {
            AddNode add = (AddNode) ret.getBase();
            ret.setBase(add.getX());
            ret.setIndex(considerNegation(graph, add.getY(), isBaseNegated));
            return true;
        }
        if (ret.getBase() == null && ret.getIndex() instanceof AddNode) {
            AddNode add = (AddNode) ret.getIndex();
            ret.setBase(considerNegation(graph, add.getX(), isIndexNegated));
            ret.setIndex(add.getY());
            return true;
        }
        if (ret.getBase() instanceof LeftShiftNode && !(ret.getIndex() instanceof LeftShiftNode)) {
            ValueNode tmp = ret.getBase();
            ret.setBase(considerNegation(graph, ret.getIndex(), isIndexNegated != isBaseNegated));
            ret.setIndex(considerNegation(graph, tmp, isIndexNegated != isBaseNegated));
            return true;
        }
    }
    return improveNegation(graph, debug, ret, isBaseNegated, isIndexNegated);
}
Also used : ValueNode(org.graalvm.compiler.nodes.ValueNode) Scale(org.graalvm.compiler.asm.amd64.AMD64Address.Scale) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode)

Aggregations

ValueNode (org.graalvm.compiler.nodes.ValueNode)482 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)104 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)77 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)76 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)69 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)67 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)60 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)52 Node (org.graalvm.compiler.graph.Node)50 JavaKind (jdk.vm.ci.meta.JavaKind)48 Stamp (org.graalvm.compiler.core.common.type.Stamp)48 LogicNode (org.graalvm.compiler.nodes.LogicNode)48 VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)42 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)38 FixedNode (org.graalvm.compiler.nodes.FixedNode)37 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)37 NodeView (org.graalvm.compiler.nodes.NodeView)36 PhiNode (org.graalvm.compiler.nodes.PhiNode)36 Test (org.junit.Test)36