Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "addSubShift" rule for AArch64. #738

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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<LIRInstruction> predicate = op -> (op instanceof AArch64ArithmeticOp.AddSubShiftOp);

/**
* addSubShift match rule test for add operation with int type.
*/
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}
}
Expand Up @@ -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<PreAllocationOptimizationPhase.PreAllocationOptimizationContext> {
@Override
protected void run(TargetDescription target, LIRGenerationResult lirGenRes,
PreAllocationOptimizationPhase.PreAllocationOptimizationContext context) {
lir = lirGenRes.getLIR();
}
}

protected void checkLIR(Class<? extends AArch64LIRInstruction> op, int expected) {
int actualOpNum = 0;
for (LIRInstruction ins : lir.getLIRforBlock(lir.codeEmittingOrder()[0])) {
if (ins.getClass() == op) {
actualOpNum++;
}
}
Assert.assertEquals(expected, actualOpNum);
}
}
Expand Up @@ -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);
Expand All @@ -57,20 +49,14 @@ 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.
*/
@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")) {
Expand All @@ -91,11 +77,4 @@ public TestClass(int x) {
this.x = x;
}
}

public class CheckPhase extends LIRPhase<PreAllocationOptimizationContext> {
@Override
protected void run(TargetDescription target, LIRGenerationResult lirGenRes, PreAllocationOptimizationContext context) {
lir = lirGenRes.getLIR();
}
}
}
@@ -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<PreAllocationOptimizationContext> {
@Override
protected void run(TargetDescription target, LIRGenerationResult lirGenRes, PreAllocationOptimizationContext context) {
lir = lirGenRes.getLIR();
}
}

protected void checkLIR(String methodName, Predicate<LIRInstruction> 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);
}

}
Expand Up @@ -366,6 +366,7 @@ public void doBlock(Block block, StructuredGraph graph, BlockMap<List<Node>> 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) {
Expand Down Expand Up @@ -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 {
Expand Down