1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2018, Arm Limited and affiliates. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 */ 24 25 26 27 package org.graalvm.compiler.core.aarch64.test; 28 29 import jdk.vm.ci.aarch64.AArch64; 30 import jdk.vm.ci.code.TargetDescription; 31 import org.graalvm.compiler.core.test.GraalCompilerTest; 32 import org.graalvm.compiler.lir.LIR; 33 import org.graalvm.compiler.lir.LIRInstruction; 34 import org.graalvm.compiler.lir.aarch64.AArch64LIRInstruction; 35 import org.graalvm.compiler.lir.gen.LIRGenerationResult; 36 import org.graalvm.compiler.lir.phases.LIRPhase; 37 import org.graalvm.compiler.lir.phases.LIRSuites; 38 import org.graalvm.compiler.lir.phases.PreAllocationOptimizationPhase; 39 import org.graalvm.compiler.options.OptionValues; 40 import org.junit.Assert; 41 import org.junit.Before; 42 43 import static org.junit.Assume.assumeTrue; 44 45 public abstract class AArch64MatchRuleTest extends GraalCompilerTest { 46 private LIR lir; 47 48 @Before 49 public void checkAArch64() { 50 assumeTrue("skipping AArch64 specific test", getTarget().arch instanceof AArch64); 51 } 52 53 @Override 54 protected LIRSuites createLIRSuites(OptionValues options) { 55 LIRSuites suites = super.createLIRSuites(options); 56 suites.getPreAllocationOptimizationStage().appendPhase(new CheckPhase()); 57 return suites; 58 } 59 60 private class CheckPhase extends LIRPhase<PreAllocationOptimizationPhase.PreAllocationOptimizationContext> { 61 @Override 62 protected void run(TargetDescription target, LIRGenerationResult lirGenRes, 63 PreAllocationOptimizationPhase.PreAllocationOptimizationContext context) { 64 lir = lirGenRes.getLIR(); 65 } 66 } 67 68 protected void checkLIR(Class<? extends AArch64LIRInstruction> op, int expected) { 69 int actualOpNum = 0; 70 for (LIRInstruction ins : lir.getLIRforBlock(lir.codeEmittingOrder()[0])) { 71 if (ins.getClass() == op) { 72 actualOpNum++; 73 } 74 } 75 Assert.assertEquals(expected, actualOpNum); 76 } 77 }