1 /* 2 * Copyright (c) 2013, 2018, 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 24 25 package org.graalvm.compiler.lir.sparc; 26 27 import org.graalvm.compiler.core.common.LIRKind; 28 import org.graalvm.compiler.lir.framemap.FrameMap; 29 30 import jdk.vm.ci.code.CodeCacheProvider; 31 import jdk.vm.ci.code.RegisterConfig; 32 import jdk.vm.ci.code.StackSlot; 33 import jdk.vm.ci.meta.ValueKind; 34 import jdk.vm.ci.sparc.SPARC; 35 import jdk.vm.ci.sparc.SPARCKind; 36 37 /** 38 * SPARC specific frame map. 39 * 40 * This is the format of a SPARC stack frame: 41 * 42 * <pre> 43 * Base Contents 44 * : : ----- 45 * caller | incoming overflow argument n | ^ 46 * frame : ... : | positive 47 * | incoming overflow argument 0 | | offsets 48 * +--------------------------------+ | 49 * | | | 50 * : register save area : | 51 * | | | 52 * ---------+--------------------------------+--------------------------- 53 * | spill slot 0 | | negative ^ ^ 54 * : ... : v offsets | | 55 * | spill slot n | ----- total | 56 * +--------------------------------+ frame | 57 * current | alignment padding | size | 58 * frame +--------------------------------+ ----- | | 59 * | outgoing overflow argument n | ^ | frame 60 * : ... : | positive | size 61 * | outgoing overflow argument 0 | | offsets | | 62 * +--------------------------------+ | | | 63 * | return address | | | | 64 * +--------------------------------+ | | | 65 * | | | | | 66 * : callee save area : | | | 67 * | | | v v 68 * %sp--> +--------------------------------+--------------------------- 69 * 70 * </pre> 71 * 72 * The spill slot area also includes stack allocated memory blocks (ALLOCA blocks). The size of such 73 * a block may be greater than the size of a normal spill slot or the word size. 74 * <p> 75 * A runtime can reserve space at the beginning of the overflow argument area. The calling 76 * convention can specify that the first overflow stack argument is not at offset 0, but at a 77 * specified offset. Use {@link CodeCacheProvider#getMinimumOutgoingSize()} to make sure that 78 * call-free methods also have this space reserved. Then the VM can use the memory at offset 0 79 * relative to the stack pointer. 80 */ 81 public final class SPARCFrameMap extends FrameMap { 82 83 public SPARCFrameMap(CodeCacheProvider codeCache, RegisterConfig registerConfig, ReferenceMapBuilderFactory referenceMapFactory) { 84 super(codeCache, registerConfig, referenceMapFactory); 85 // Initial spill size is set to register save area size (SPARC register window) 86 initialSpillSize = 0; 87 spillSize = initialSpillSize; 88 } 89 90 @Override 91 public int totalFrameSize() { 92 return frameSize(); 93 } 94 95 @Override 96 public int currentFrameSize() { 97 return alignFrameSize(SPARC.REGISTER_SAFE_AREA_SIZE + outgoingSize + spillSize); 98 } 99 100 /** 101 * In SPARC we have spill slots word aligned. 102 */ 103 @Override 104 public int spillSlotSize(ValueKind<?> kind) { 105 return kind.getPlatformKind().getSizeInBytes(); 106 } 107 108 @Override 109 public int offsetForStackSlot(StackSlot slot) { 110 // @formatter:off 111 assert (!slot.getRawAddFrameSize() && slot.getRawOffset() < outgoingSize + SPARC.REGISTER_SAFE_AREA_SIZE) || 112 (slot.getRawAddFrameSize() && slot.getRawOffset() < 0 && -slot.getRawOffset() <= spillSize) || 113 (slot.getRawAddFrameSize() && slot.getRawOffset() >= 0) : 114 String.format("RawAddFrameSize: %b RawOffset: 0x%x spillSize: 0x%x outgoingSize: 0x%x", slot.getRawAddFrameSize(), slot.getRawOffset(), spillSize, outgoingSize); 115 // @formatter:on 116 return super.offsetForStackSlot(slot); 117 } 118 119 @Override 120 public boolean frameNeedsAllocating() { 121 return super.frameNeedsAllocating() || spillSize > 0; 122 } 123 124 public StackSlot allocateDeoptimizationRescueSlot() { 125 assert spillSize == initialSpillSize : "Deoptimization rescue slot must be the first stack slot"; 126 return allocateSpillSlot(LIRKind.value(SPARCKind.XWORD)); 127 } 128 }