diff --git a/compiler/src/org.graalvm.compiler.core.aarch64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64AddSubShiftTest.java b/compiler/src/org.graalvm.compiler.core.aarch64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64AddSubShiftTest.java index 8d2d8af239f2..1e0579e026e1 100644 --- a/compiler/src/org.graalvm.compiler.core.aarch64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64AddSubShiftTest.java +++ b/compiler/src/org.graalvm.compiler.core.aarch64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64AddSubShiftTest.java @@ -26,11 +26,16 @@ package org.graalvm.compiler.core.aarch64.test; +import org.graalvm.compiler.lir.LIRInstruction; import org.graalvm.compiler.lir.aarch64.AArch64ArithmeticOp; import org.junit.Assert; import org.junit.Test; +import java.util.function.Predicate; + public class AArch64AddSubShiftTest extends AArch64MatchRuleTest { + private static final Predicate predicate = op -> (op instanceof AArch64ArithmeticOp.AddSubShiftOp); + /** * addSubShift match rule test for add operation with int type. */ @@ -66,12 +71,11 @@ private static int addShiftInt(int input) { @Test public void testAddShiftInt() { int expected = addShiftInt(123); - Result result = executeActual(getResolvedJavaMethod("addShiftInt"), null, 123); int actual = (int) result.returnValue; Assert.assertEquals(expected, actual); - checkLIR(AArch64ArithmeticOp.AddSubShiftOp.class, 6); + checkLIR("addShiftInt", predicate, 6); } /** @@ -109,12 +113,11 @@ private static long addShiftLong(long input) { @Test public void testAddShiftLong() { long expected = addShiftLong(1234567); - Result result = executeActual(getResolvedJavaMethod("addShiftLong"), null, (long) 1234567); long actual = (long) result.returnValue; Assert.assertEquals(expected, actual); - checkLIR(AArch64ArithmeticOp.AddSubShiftOp.class, 6); + checkLIR("addShiftLong", predicate, 6); } /** @@ -143,12 +146,11 @@ private static int subShiftInt(int input0, int input1) { @Test public void testSubShiftInt() { int expected = subShiftInt(123, 456); - Result result = executeActual(getResolvedJavaMethod("subShiftInt"), null, 123, 456); int actual = (int) result.returnValue; Assert.assertEquals(expected, actual); - checkLIR(AArch64ArithmeticOp.AddSubShiftOp.class, 3); + checkLIR("subShiftInt", predicate, 3); } /** @@ -177,11 +179,10 @@ private static long subShiftLong(long input0, long input1) { @Test public void testSubShiftLong() { long expected = subShiftLong(1234567, 123); - Result result = executeActual(getResolvedJavaMethod("subShiftLong"), null, (long) 1234567, (long) 123); long actual = (long) result.returnValue; Assert.assertEquals(expected, actual); - checkLIR(AArch64ArithmeticOp.AddSubShiftOp.class, 3); + checkLIR("subShiftLong", predicate, 3); } } diff --git a/compiler/src/org.graalvm.compiler.core.aarch64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64MatchRuleTest.java b/compiler/src/org.graalvm.compiler.core.aarch64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64MatchRuleTest.java index 5aadfb696c2d..4eb4ca81fc62 100644 --- a/compiler/src/org.graalvm.compiler.core.aarch64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64MatchRuleTest.java +++ b/compiler/src/org.graalvm.compiler.core.aarch64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64MatchRuleTest.java @@ -27,51 +27,15 @@ package org.graalvm.compiler.core.aarch64.test; import jdk.vm.ci.aarch64.AArch64; -import jdk.vm.ci.code.TargetDescription; -import org.graalvm.compiler.core.test.GraalCompilerTest; -import org.graalvm.compiler.lir.LIR; -import org.graalvm.compiler.lir.LIRInstruction; -import org.graalvm.compiler.lir.aarch64.AArch64LIRInstruction; -import org.graalvm.compiler.lir.gen.LIRGenerationResult; -import org.graalvm.compiler.lir.phases.LIRPhase; -import org.graalvm.compiler.lir.phases.LIRSuites; -import org.graalvm.compiler.lir.phases.PreAllocationOptimizationPhase; -import org.graalvm.compiler.options.OptionValues; -import org.junit.Assert; +import org.graalvm.compiler.core.test.MatchRuleTest; import org.junit.Before; import static org.junit.Assume.assumeTrue; -public abstract class AArch64MatchRuleTest extends GraalCompilerTest { - private LIR lir; - +public abstract class AArch64MatchRuleTest extends MatchRuleTest { @Before public void checkAArch64() { assumeTrue("skipping AArch64 specific test", getTarget().arch instanceof AArch64); } - @Override - protected LIRSuites createLIRSuites(OptionValues options) { - LIRSuites suites = super.createLIRSuites(options); - suites.getPreAllocationOptimizationStage().appendPhase(new CheckPhase()); - return suites; - } - - private class CheckPhase extends LIRPhase { - @Override - protected void run(TargetDescription target, LIRGenerationResult lirGenRes, - PreAllocationOptimizationPhase.PreAllocationOptimizationContext context) { - lir = lirGenRes.getLIR(); - } - } - - protected void checkLIR(Class op, int expected) { - int actualOpNum = 0; - for (LIRInstruction ins : lir.getLIRforBlock(lir.codeEmittingOrder()[0])) { - if (ins.getClass() == op) { - actualOpNum++; - } - } - Assert.assertEquals(expected, actualOpNum); - } } diff --git a/compiler/src/org.graalvm.compiler.core.amd64.test/src/org/graalvm/compiler/core/amd64/test/MatchRuleTest.java b/compiler/src/org.graalvm.compiler.core.amd64.test/src/org/graalvm/compiler/core/amd64/test/AMD64MatchRuleTest.java similarity index 73% rename from compiler/src/org.graalvm.compiler.core.amd64.test/src/org/graalvm/compiler/core/amd64/test/MatchRuleTest.java rename to compiler/src/org.graalvm.compiler.core.amd64.test/src/org/graalvm/compiler/core/amd64/test/AMD64MatchRuleTest.java index 4774338431bd..8c7139ab495c 100644 --- a/compiler/src/org.graalvm.compiler.core.amd64.test/src/org/graalvm/compiler/core/amd64/test/MatchRuleTest.java +++ b/compiler/src/org.graalvm.compiler.core.amd64.test/src/org/graalvm/compiler/core/amd64/test/AMD64MatchRuleTest.java @@ -26,24 +26,16 @@ import static org.junit.Assume.assumeTrue; +import org.graalvm.compiler.core.test.MatchRuleTest; import org.graalvm.compiler.lir.LIR; import org.graalvm.compiler.lir.LIRInstruction; import org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer.MemoryConstOp; -import org.graalvm.compiler.lir.gen.LIRGenerationResult; -import org.graalvm.compiler.lir.jtt.LIRTest; -import org.graalvm.compiler.lir.phases.LIRPhase; -import org.graalvm.compiler.lir.phases.LIRSuites; -import org.graalvm.compiler.lir.phases.PreAllocationOptimizationPhase.PreAllocationOptimizationContext; -import org.graalvm.compiler.options.OptionValues; import org.junit.Before; import org.junit.Test; import jdk.vm.ci.amd64.AMD64; -import jdk.vm.ci.code.TargetDescription; - -public class MatchRuleTest extends LIRTest { - private LIR lir; +public class AMD64MatchRuleTest extends MatchRuleTest { @Before public void checkAMD64() { assumeTrue("skipping AMD64 specific test", getTarget().arch instanceof AMD64); @@ -57,13 +49,6 @@ public static int test1Snippet(TestClass o, TestClass b, TestClass c) { } } - @Override - protected LIRSuites createLIRSuites(OptionValues options) { - LIRSuites suites = super.createLIRSuites(options); - suites.getPreAllocationOptimizationStage().appendPhase(new CheckPhase()); - return suites; - } - /** * Verifies, if the match rules in AMD64NodeMatchRules do work on the graphs by compiling and * checking if the expected LIR instruction show up. @@ -71,6 +56,7 @@ protected LIRSuites createLIRSuites(OptionValues options) { @Test public void test1() { compile(getResolvedJavaMethod("test1Snippet"), null); + LIR lir = getLIR(); boolean found = false; for (LIRInstruction ins : lir.getLIRforBlock(lir.codeEmittingOrder()[0])) { if (ins instanceof MemoryConstOp && ((MemoryConstOp) ins).getOpcode().toString().equals("CMP")) { @@ -91,11 +77,4 @@ public TestClass(int x) { this.x = x; } } - - public class CheckPhase extends LIRPhase { - @Override - protected void run(TargetDescription target, LIRGenerationResult lirGenRes, PreAllocationOptimizationContext context) { - lir = lirGenRes.getLIR(); - } - } } diff --git a/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MatchRuleTest.java b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MatchRuleTest.java new file mode 100644 index 000000000000..dba10bf33633 --- /dev/null +++ b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/MatchRuleTest.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package org.graalvm.compiler.core.test; + +import org.graalvm.compiler.lir.LIR; +import org.graalvm.compiler.lir.LIRInstruction; +import org.graalvm.compiler.lir.gen.LIRGenerationResult; +import org.graalvm.compiler.lir.phases.LIRPhase; +import org.graalvm.compiler.lir.phases.LIRSuites; +import org.graalvm.compiler.lir.phases.PreAllocationOptimizationPhase.PreAllocationOptimizationContext; +import org.graalvm.compiler.options.OptionValues; + +import jdk.vm.ci.code.TargetDescription; +import org.junit.Assert; + +import java.util.function.Predicate; + +public abstract class MatchRuleTest extends GraalCompilerTest { + private LIR lir; + + protected LIR getLIR() { + return lir; + } + + @Override + protected LIRSuites createLIRSuites(OptionValues options) { + LIRSuites suites = super.createLIRSuites(options); + suites.getPreAllocationOptimizationStage().appendPhase(new CheckPhase()); + return suites; + } + + public class CheckPhase extends LIRPhase { + @Override + protected void run(TargetDescription target, LIRGenerationResult lirGenRes, PreAllocationOptimizationContext context) { + lir = lirGenRes.getLIR(); + } + } + + protected void checkLIR(String methodName, Predicate predicate, int expected) { + compile(getResolvedJavaMethod(methodName), null); + int actualOpNum = 0; + for (LIRInstruction ins : lir.getLIRforBlock(lir.codeEmittingOrder()[0])) { + if (predicate.test(ins)) { + actualOpNum++; + } + } + Assert.assertEquals(expected, actualOpNum); + } + +} diff --git a/compiler/src/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/NodeLIRBuilder.java b/compiler/src/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/NodeLIRBuilder.java index 669023c7963d..c21bc4659a2f 100644 --- a/compiler/src/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/NodeLIRBuilder.java +++ b/compiler/src/org.graalvm.compiler.core/src/org/graalvm/compiler/core/gen/NodeLIRBuilder.java @@ -366,6 +366,7 @@ public void doBlock(Block block, StructuredGraph graph, BlockMap> blo for (int i = 0; i < nodes.size(); i++) { Node node = nodes.get(i); if (node instanceof ValueNode) { + setSourcePosition(node.getNodeSourcePosition()); DebugContext debug = node.getDebug(); ValueNode valueNode = (ValueNode) node; if (trace) { @@ -468,7 +469,6 @@ protected void emitNode(ValueNode node) { if (node.getDebug().isLogEnabled() && node.stamp(NodeView.DEFAULT).isEmpty()) { node.getDebug().log("This node has an empty stamp, we are emitting dead code(?): %s", node); } - setSourcePosition(node.getNodeSourcePosition()); if (node instanceof LIRLowerable) { ((LIRLowerable) node).generate(this); } else {