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
24
25 package org.graalvm.compiler.lir.aarch64;
26
27 import static jdk.vm.ci.code.ValueUtil.asAllocatableValue;
28 import static jdk.vm.ci.code.ValueUtil.asRegister;
29 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.HINT;
30 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
31
32 import java.util.function.Function;
33
34 import jdk.vm.ci.meta.AllocatableValue;
35 import org.graalvm.compiler.asm.Label;
36 import org.graalvm.compiler.core.common.NumUtil;
37 import org.graalvm.compiler.asm.aarch64.AArch64Assembler;
38 import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag;
39 import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ExtendType;
40 import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
41 import org.graalvm.compiler.code.CompilationResult.JumpTable;
42 import org.graalvm.compiler.core.common.LIRKind;
43 import org.graalvm.compiler.core.common.calc.Condition;
44 import org.graalvm.compiler.debug.GraalError;
45 import org.graalvm.compiler.lir.ConstantValue;
46 import org.graalvm.compiler.lir.LIRInstructionClass;
47 import org.graalvm.compiler.lir.LabelRef;
48 import org.graalvm.compiler.lir.Opcode;
49 import org.graalvm.compiler.lir.StandardOp;
50 import org.graalvm.compiler.lir.SwitchStrategy;
51 import org.graalvm.compiler.lir.SwitchStrategy.BaseSwitchClosure;
52 import org.graalvm.compiler.lir.Variable;
53 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
54
55 import jdk.vm.ci.aarch64.AArch64Kind;
56 import jdk.vm.ci.code.Register;
57 import jdk.vm.ci.meta.Constant;
58 import jdk.vm.ci.meta.JavaConstant;
59 import jdk.vm.ci.meta.Value;
60
61 public class AArch64ControlFlow {
62
63 public abstract static class AbstractBranchOp extends AArch64BlockEndOp implements StandardOp.BranchOp {
64 private final LabelRef trueDestination;
65 private final LabelRef falseDestination;
66
67 private final double trueDestinationProbability;
68
69 private AbstractBranchOp(LIRInstructionClass<? extends AbstractBranchOp> c, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) {
70 super(c);
71 this.trueDestination = trueDestination;
72 this.falseDestination = falseDestination;
73 this.trueDestinationProbability = trueDestinationProbability;
74 }
75
76 protected abstract void emitBranch(CompilationResultBuilder crb, AArch64MacroAssembler masm, LabelRef target, boolean negate);
77
78 @Override
79 public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
80 /*
81 * Explanation: Depending on what the successor edge is, we can use the fall-through to
|
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
24
25 package org.graalvm.compiler.lir.aarch64;
26
27 import static jdk.vm.ci.aarch64.AArch64.lr;
28 import static jdk.vm.ci.code.ValueUtil.asAllocatableValue;
29 import static jdk.vm.ci.code.ValueUtil.asRegister;
30 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.HINT;
31 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.ILLEGAL;
32 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
33
34 import java.util.function.Function;
35
36 import jdk.vm.ci.meta.AllocatableValue;
37 import org.graalvm.compiler.asm.Label;
38 import org.graalvm.compiler.asm.aarch64.AArch64Assembler;
39 import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag;
40 import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ExtendType;
41 import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
42 import org.graalvm.compiler.code.CompilationResult.JumpTable;
43 import org.graalvm.compiler.core.common.LIRKind;
44 import org.graalvm.compiler.core.common.NumUtil;
45 import org.graalvm.compiler.core.common.calc.Condition;
46 import org.graalvm.compiler.debug.GraalError;
47 import org.graalvm.compiler.lir.ConstantValue;
48 import org.graalvm.compiler.lir.LIRInstructionClass;
49 import org.graalvm.compiler.lir.LabelRef;
50 import org.graalvm.compiler.lir.Opcode;
51 import org.graalvm.compiler.lir.StandardOp;
52 import org.graalvm.compiler.lir.StandardOp.BlockEndOp;
53 import org.graalvm.compiler.lir.SwitchStrategy;
54 import org.graalvm.compiler.lir.SwitchStrategy.BaseSwitchClosure;
55 import org.graalvm.compiler.lir.Variable;
56 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
57
58 import jdk.vm.ci.aarch64.AArch64Kind;
59 import jdk.vm.ci.code.Register;
60 import jdk.vm.ci.meta.Constant;
61 import jdk.vm.ci.meta.JavaConstant;
62 import jdk.vm.ci.meta.Value;
63
64 public class AArch64ControlFlow {
65 public static final class ReturnOp extends AArch64BlockEndOp implements BlockEndOp {
66 public static final LIRInstructionClass<ReturnOp> TYPE = LIRInstructionClass.create(ReturnOp.class);
67 @Use({REG, ILLEGAL}) protected Value x;
68
69 public ReturnOp(Value x) {
70 super(TYPE);
71 this.x = x;
72 }
73
74 @Override
75 protected void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
76 crb.frameContext.leave(crb);
77 masm.ret(lr);
78 }
79 }
80
81 public abstract static class AbstractBranchOp extends AArch64BlockEndOp implements StandardOp.BranchOp {
82 private final LabelRef trueDestination;
83 private final LabelRef falseDestination;
84
85 private final double trueDestinationProbability;
86
87 private AbstractBranchOp(LIRInstructionClass<? extends AbstractBranchOp> c, LabelRef trueDestination, LabelRef falseDestination, double trueDestinationProbability) {
88 super(c);
89 this.trueDestination = trueDestination;
90 this.falseDestination = falseDestination;
91 this.trueDestinationProbability = trueDestinationProbability;
92 }
93
94 protected abstract void emitBranch(CompilationResultBuilder crb, AArch64MacroAssembler masm, LabelRef target, boolean negate);
95
96 @Override
97 public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
98 /*
99 * Explanation: Depending on what the successor edge is, we can use the fall-through to
|