7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.core.amd64.test; 24 25 import static org.junit.Assume.assumeTrue; 26 27 import org.junit.Before; 28 import org.junit.Test; 29 30 import org.graalvm.compiler.lir.LIR; 31 import org.graalvm.compiler.lir.LIRInstruction; 32 import org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer.MemoryConstOp; 33 import org.graalvm.compiler.lir.gen.LIRGenerationResult; 34 import org.graalvm.compiler.lir.jtt.LIRTest; 35 import org.graalvm.compiler.lir.phases.LIRPhase; 36 import org.graalvm.compiler.lir.phases.PreAllocationOptimizationPhase.PreAllocationOptimizationContext; 37 38 import jdk.vm.ci.amd64.AMD64; 39 import jdk.vm.ci.code.TargetDescription; 40 41 public class MatchRuleTest extends LIRTest { 42 private static LIR lir; 43 44 @Before 45 public void checkAMD64() { 46 assumeTrue("skipping AMD64 specific test", getTarget().arch instanceof AMD64); 47 } 48 49 public static int test1Snippet(TestClass o, TestClass b, TestClass c) { 50 if (o.x == 42) { 51 return b.z; 52 } else { 53 return c.y; 54 } 55 } 56 57 /** 58 * Verifies, if the match rules in AMD64NodeMatchRules do work on the graphs by compiling and 59 * checking if the expected LIR instruction show up. 60 */ 61 @Test 62 public void test1() { 63 getLIRSuites().getPreAllocationOptimizationStage().appendPhase(new CheckPhase()); 64 compile(getResolvedJavaMethod("test1Snippet"), null); 65 boolean found = false; 66 for (LIRInstruction ins : lir.getLIRforBlock(lir.codeEmittingOrder()[0])) { 67 if (ins instanceof MemoryConstOp && ((MemoryConstOp) ins).getOpcode().toString().equals("CMP")) { 68 assertFalse("MemoryConstOp expected only once in first block", found); 69 found = true; 70 } 71 } 72 assertTrue("Memory compare must be in the LIR", found); 73 } 74 75 public static class TestClass { 76 public int x; 77 public int y; 78 public int z; 79 80 public TestClass(int x) { 81 super(); 82 this.x = x; 83 } 84 } 85 86 public static class CheckPhase extends LIRPhase<PreAllocationOptimizationContext> { 87 @Override 88 protected void run(TargetDescription target, LIRGenerationResult lirGenRes, PreAllocationOptimizationContext context) { 89 lir = lirGenRes.getLIR(); 90 } 91 } 92 } | 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.core.amd64.test; 24 25 import static org.junit.Assume.assumeTrue; 26 27 import org.graalvm.compiler.lir.LIR; 28 import org.graalvm.compiler.lir.LIRInstruction; 29 import org.graalvm.compiler.lir.amd64.AMD64BinaryConsumer.MemoryConstOp; 30 import org.graalvm.compiler.lir.gen.LIRGenerationResult; 31 import org.graalvm.compiler.lir.jtt.LIRTest; 32 import org.graalvm.compiler.lir.phases.LIRPhase; 33 import org.graalvm.compiler.lir.phases.LIRSuites; 34 import org.graalvm.compiler.lir.phases.PreAllocationOptimizationPhase.PreAllocationOptimizationContext; 35 import org.graalvm.compiler.options.OptionValues; 36 import org.junit.Before; 37 import org.junit.Test; 38 39 import jdk.vm.ci.amd64.AMD64; 40 import jdk.vm.ci.code.TargetDescription; 41 42 public class MatchRuleTest extends LIRTest { 43 private LIR lir; 44 45 @Before 46 public void checkAMD64() { 47 assumeTrue("skipping AMD64 specific test", getTarget().arch instanceof AMD64); 48 } 49 50 public static int test1Snippet(TestClass o, TestClass b, TestClass c) { 51 if (o.x == 42) { 52 return b.z; 53 } else { 54 return c.y; 55 } 56 } 57 58 @Override 59 protected LIRSuites createLIRSuites(OptionValues options) { 60 LIRSuites suites = super.createLIRSuites(options); 61 suites.getPreAllocationOptimizationStage().appendPhase(new CheckPhase()); 62 return suites; 63 } 64 65 /** 66 * Verifies, if the match rules in AMD64NodeMatchRules do work on the graphs by compiling and 67 * checking if the expected LIR instruction show up. 68 */ 69 @Test 70 public void test1() { 71 compile(getResolvedJavaMethod("test1Snippet"), null); 72 boolean found = false; 73 for (LIRInstruction ins : lir.getLIRforBlock(lir.codeEmittingOrder()[0])) { 74 if (ins instanceof MemoryConstOp && ((MemoryConstOp) ins).getOpcode().toString().equals("CMP")) { 75 assertFalse("MemoryConstOp expected only once in first block", found); 76 found = true; 77 } 78 } 79 assertTrue("Memory compare must be in the LIR", found); 80 } 81 82 public static class TestClass { 83 public int x; 84 public int y; 85 public int z; 86 87 public TestClass(int x) { 88 super(); 89 this.x = x; 90 } 91 } 92 93 public class CheckPhase extends LIRPhase<PreAllocationOptimizationContext> { 94 @Override 95 protected void run(TargetDescription target, LIRGenerationResult lirGenRes, PreAllocationOptimizationContext context) { 96 lir = lirGenRes.getLIR(); 97 } 98 } 99 } |