src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64Ternary.java
author dlong
Thu, 14 Nov 2019 12:21:00 -0800
changeset 59095 03fbcd06b4c0
parent 54914 9feb4852536f
permissions -rw-r--r--
8233841: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
54914
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
     1
/*
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
     4
 *
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
     8
 *
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    13
 * accompanied this code).
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    14
 *
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    18
 *
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    21
 * questions.
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    22
 */
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    23
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    24
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    25
package org.graalvm.compiler.lir.amd64;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    26
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    27
import static jdk.vm.ci.code.ValueUtil.asRegister;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    28
import static jdk.vm.ci.code.ValueUtil.isRegister;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    29
import static jdk.vm.ci.code.ValueUtil.isStackSlot;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    30
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.HINT;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    31
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    32
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    33
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    34
import org.graalvm.compiler.asm.amd64.AMD64Address;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    35
import org.graalvm.compiler.asm.amd64.AMD64Assembler.VexRVMOp;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    36
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    37
import org.graalvm.compiler.asm.amd64.AVXKind.AVXSize;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    38
import org.graalvm.compiler.lir.LIRInstructionClass;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    39
import org.graalvm.compiler.lir.Opcode;
59095
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 54914
diff changeset
    40
import org.graalvm.compiler.lir.amd64.vector.AMD64VectorInstruction;
54914
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    41
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    42
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    43
import jdk.vm.ci.meta.AllocatableValue;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    44
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    45
/**
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    46
 * AMD64 LIR instructions that have three inputs and one output.
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    47
 */
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    48
public class AMD64Ternary {
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    49
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    50
    /**
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    51
     * Instruction that has two {@link AllocatableValue} operands.
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    52
     */
59095
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 54914
diff changeset
    53
    public static class ThreeOp extends AMD64VectorInstruction {
54914
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    54
        public static final LIRInstructionClass<ThreeOp> TYPE = LIRInstructionClass.create(ThreeOp.class);
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    55
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    56
        @Opcode private final VexRVMOp opcode;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    57
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    58
        @Def({REG, HINT}) protected AllocatableValue result;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    59
        @Use({REG}) protected AllocatableValue x;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    60
        /**
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    61
         * This argument must be Alive to ensure that result and y are not assigned to the same
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    62
         * register, which would break the code generation by destroying y too early.
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    63
         */
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    64
        @Alive({REG}) protected AllocatableValue y;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    65
        @Alive({REG, STACK}) protected AllocatableValue z;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    66
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    67
        public ThreeOp(VexRVMOp opcode, AVXSize size, AllocatableValue result, AllocatableValue x, AllocatableValue y, AllocatableValue z) {
59095
03fbcd06b4c0 8233841: Update Graal
dlong
parents: 54914
diff changeset
    68
            super(TYPE, size);
54914
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    69
            this.opcode = opcode;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    70
            this.result = result;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    71
            this.x = x;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    72
            this.y = y;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    73
            this.z = z;
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    74
        }
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    75
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    76
        @Override
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    77
        public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    78
            AMD64Move.move(crb, masm, result, x);
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    79
            if (isRegister(z)) {
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    80
                opcode.emit(masm, size, asRegister(result), asRegister(y), asRegister(z));
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    81
            } else {
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    82
                assert isStackSlot(z);
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    83
                opcode.emit(masm, size, asRegister(result), asRegister(y), (AMD64Address) crb.asAddress(z));
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    84
            }
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    85
        }
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    86
    }
9feb4852536f 8223346: Update Graal
jwilhelm
parents:
diff changeset
    87
}