1 /* 2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 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.lir.sparc; 24 25 import static org.graalvm.compiler.asm.sparc.SPARCAssembler.BPCC; 26 import static org.graalvm.compiler.asm.sparc.SPARCAssembler.Annul.NOT_ANNUL; 27 import static org.graalvm.compiler.asm.sparc.SPARCAssembler.BranchPredict.PREDICT_TAKEN; 28 import static org.graalvm.compiler.asm.sparc.SPARCAssembler.CC.Xcc; 29 import static org.graalvm.compiler.asm.sparc.SPARCAssembler.ConditionFlag.Always; 30 31 import org.graalvm.compiler.asm.sparc.SPARCMacroAssembler; 32 import org.graalvm.compiler.lir.LIRInstructionClass; 33 import org.graalvm.compiler.lir.LabelRef; 34 import org.graalvm.compiler.lir.StandardOp.JumpOp; 35 import org.graalvm.compiler.lir.asm.CompilationResultBuilder; 36 37 public final class SPARCJumpOp extends JumpOp implements SPARCDelayedControlTransfer, SPARCLIRInstructionMixin { 38 public static final LIRInstructionClass<SPARCJumpOp> TYPE = LIRInstructionClass.create(SPARCJumpOp.class); 39 public static final SizeEstimate SIZE = SizeEstimate.create(2); 40 41 private boolean emitDone = false; 42 private int delaySlotPosition = -1; 43 private final SPARCLIRInstructionMixinStore store; 44 45 public SPARCJumpOp(LabelRef destination) { 46 super(TYPE, destination); 47 this.store = new SPARCLIRInstructionMixinStore(SIZE); 48 } 49 50 @Override 51 public void emitControlTransfer(CompilationResultBuilder crb, SPARCMacroAssembler masm) { 52 assert !emitDone; 53 if (!crb.isSuccessorEdge(destination())) { 54 BPCC.emit(masm, Xcc, Always, NOT_ANNUL, PREDICT_TAKEN, destination().label()); 55 delaySlotPosition = masm.position(); 56 } 57 emitDone = true; 58 } 59 60 @Override 61 public void emitCode(CompilationResultBuilder crb) { 62 if (!crb.isSuccessorEdge(destination())) { 63 if (!emitDone) { 64 SPARCMacroAssembler masm = (SPARCMacroAssembler) crb.asm; 65 masm.jmp(destination().label()); 66 } else { 67 int disp = crb.asm.position() - delaySlotPosition; 68 assert disp == 4 : disp; 69 } 70 } 71 } 72 73 @Override 74 public void resetState() { 75 delaySlotPosition = -1; 76 emitDone = false; 77 } 78 79 @Override 80 public SPARCLIRInstructionMixinStore getSPARCLIRInstructionStore() { 81 return store; 82 } 83 }