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.alloc.trace.lsra; 24 25 import static org.graalvm.compiler.lir.LIRValueUtil.asVirtualStackSlot; 26 import static org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue; 27 import static org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot; 28 import static jdk.vm.ci.code.ValueUtil.asRegister; 29 import static jdk.vm.ci.code.ValueUtil.asStackSlot; 30 import static jdk.vm.ci.code.ValueUtil.isIllegal; 31 import static jdk.vm.ci.code.ValueUtil.isRegister; 32 import static jdk.vm.ci.code.ValueUtil.isStackSlot; 33 34 import java.util.ArrayList; 35 import java.util.Arrays; 36 import java.util.HashSet; 37 import java.util.List; 38 39 import org.graalvm.compiler.core.common.LIRKind; 40 import org.graalvm.compiler.debug.Debug; 41 import org.graalvm.compiler.debug.DebugCounter; 42 import org.graalvm.compiler.debug.GraalError; 43 import org.graalvm.compiler.debug.Indent; 44 import org.graalvm.compiler.lir.LIRInsertionBuffer; 45 import org.graalvm.compiler.lir.LIRInstruction; 46 import org.graalvm.compiler.lir.VirtualStackSlot; 47 import org.graalvm.compiler.lir.alloc.trace.lsra.TraceLinearScanPhase.TraceLinearScan; 48 import org.graalvm.compiler.lir.framemap.FrameMap; 49 import org.graalvm.compiler.lir.framemap.FrameMapBuilderTool; 50 51 import jdk.vm.ci.code.StackSlot; 52 import jdk.vm.ci.meta.AllocatableValue; 53 import jdk.vm.ci.meta.Constant; 54 import jdk.vm.ci.meta.JavaConstant; 55 import jdk.vm.ci.meta.Value; 56 57 /** 58 */ 59 final class TraceLocalMoveResolver { 60 61 private static final DebugCounter cycleBreakingSlotsAllocated = Debug.counter("TraceRA[cycleBreakingSlotsAllocated(local)]"); 62 63 private static final int STACK_SLOT_IN_CALLER_FRAME_IDX = -1; 64 private final TraceLinearScan allocator; 65 66 private int insertIdx; 67 private LIRInsertionBuffer insertionBuffer; // buffer where moves are inserted 68 69 private final List<TraceInterval> mappingFrom; 70 private final List<Constant> mappingFromOpr; 71 private final List<TraceInterval> mappingTo; 72 private final int[] registerBlocked; 73 74 private int[] stackBlocked; 75 private final int firstVirtualStackIndex; 76 77 private int getStackArrayIndex(Value stackSlotValue) { 78 if (isStackSlot(stackSlotValue)) { 79 return getStackArrayIndex(asStackSlot(stackSlotValue)); 80 } 81 if (isVirtualStackSlot(stackSlotValue)) { 82 return getStackArrayIndex(asVirtualStackSlot(stackSlotValue)); 83 } 84 throw GraalError.shouldNotReachHere("value is not a stack slot: " + stackSlotValue); 85 } 86 87 private int getStackArrayIndex(StackSlot stackSlot) { 88 int stackIdx; 89 if (stackSlot.isInCallerFrame()) { 90 // incoming stack arguments can be ignored 91 stackIdx = STACK_SLOT_IN_CALLER_FRAME_IDX; | 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.alloc.trace.lsra; 24 25 import static jdk.vm.ci.code.ValueUtil.asRegister; 26 import static jdk.vm.ci.code.ValueUtil.asStackSlot; 27 import static jdk.vm.ci.code.ValueUtil.isIllegal; 28 import static jdk.vm.ci.code.ValueUtil.isRegister; 29 import static jdk.vm.ci.code.ValueUtil.isStackSlot; 30 import static org.graalvm.compiler.lir.LIRValueUtil.asVirtualStackSlot; 31 import static org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue; 32 import static org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot; 33 34 import java.util.ArrayList; 35 import java.util.Arrays; 36 import java.util.HashSet; 37 import java.util.List; 38 39 import org.graalvm.compiler.core.common.LIRKind; 40 import org.graalvm.compiler.debug.Debug; 41 import org.graalvm.compiler.debug.DebugCounter; 42 import org.graalvm.compiler.debug.GraalError; 43 import org.graalvm.compiler.debug.Indent; 44 import org.graalvm.compiler.lir.LIRInsertionBuffer; 45 import org.graalvm.compiler.lir.LIRInstruction; 46 import org.graalvm.compiler.lir.VirtualStackSlot; 47 import org.graalvm.compiler.lir.alloc.trace.lsra.TraceLinearScanPhase.TraceLinearScan; 48 import org.graalvm.compiler.lir.framemap.FrameMap; 49 import org.graalvm.compiler.lir.framemap.FrameMapBuilderTool; 50 51 import jdk.vm.ci.code.StackSlot; 52 import jdk.vm.ci.meta.AllocatableValue; 53 import jdk.vm.ci.meta.Constant; 54 import jdk.vm.ci.meta.JavaConstant; 55 import jdk.vm.ci.meta.Value; 56 57 /** 58 */ 59 final class TraceLocalMoveResolver { 60 61 private static final DebugCounter cycleBreakingSlotsAllocated = Debug.counter("TraceRA[cycleBreakingSlotsAllocated(local)]"); 62 63 private static final int STACK_SLOT_IN_CALLER_FRAME_IDX = -1; 64 private final TraceLinearScan allocator; 65 66 private int insertIdx; 67 private LIRInsertionBuffer insertionBuffer; // buffer where moves are inserted 68 69 private final ArrayList<TraceInterval> mappingFrom; 70 private final ArrayList<Constant> mappingFromOpr; 71 private final ArrayList<TraceInterval> mappingTo; 72 private final int[] registerBlocked; 73 74 private int[] stackBlocked; 75 private final int firstVirtualStackIndex; 76 77 private int getStackArrayIndex(Value stackSlotValue) { 78 if (isStackSlot(stackSlotValue)) { 79 return getStackArrayIndex(asStackSlot(stackSlotValue)); 80 } 81 if (isVirtualStackSlot(stackSlotValue)) { 82 return getStackArrayIndex(asVirtualStackSlot(stackSlotValue)); 83 } 84 throw GraalError.shouldNotReachHere("value is not a stack slot: " + stackSlotValue); 85 } 86 87 private int getStackArrayIndex(StackSlot stackSlot) { 88 int stackIdx; 89 if (stackSlot.isInCallerFrame()) { 90 // incoming stack arguments can be ignored 91 stackIdx = STACK_SLOT_IN_CALLER_FRAME_IDX; |