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