# HG changeset patch # User twisti # Date 1375304664 25200 # Node ID 563c6d1994c0c6abc0b425bb6050752e7bf9ea97 # Parent 4bd4bf0b47f4f13993f0d10e89b2bdb16321c45c added architecture specific frame maps diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILBackend.java --- a/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILBackend.java Tue Jul 30 16:42:51 2013 -0700 +++ b/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILBackend.java Wed Jul 31 14:04:24 2013 -0700 @@ -23,7 +23,6 @@ package com.oracle.graal.compiler.hsail; import static com.oracle.graal.api.code.CallingConvention.Type.*; - import static com.oracle.graal.api.code.ValueUtil.*; import com.oracle.graal.api.code.*; @@ -35,6 +34,7 @@ import com.oracle.graal.debug.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; +import com.oracle.graal.lir.hsail.*; import com.oracle.graal.nodes.*; import com.oracle.graal.hsail.*; @@ -60,6 +60,11 @@ } @Override + public FrameMap newFrameMap() { + return new HSAILFrameMap(runtime(), target, runtime().lookupRegisterConfig()); + } + + @Override public LIRGenerator newLIRGenerator(StructuredGraph graph, FrameMap frameMap, CallingConvention cc, LIR lir) { return new HSAILLIRGenerator(graph, runtime(), target, frameMap, cc, lir); } diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXBackend.java --- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXBackend.java Tue Jul 30 16:42:51 2013 -0700 +++ b/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXBackend.java Wed Jul 31 14:04:24 2013 -0700 @@ -30,6 +30,7 @@ import com.oracle.graal.compiler.target.*; import com.oracle.graal.lir.*; import com.oracle.graal.lir.asm.*; +import com.oracle.graal.lir.ptx.*; import com.oracle.graal.nodes.*; /** @@ -42,6 +43,11 @@ } @Override + public FrameMap newFrameMap() { + return new PTXFrameMap(runtime(), target, runtime().lookupRegisterConfig()); + } + + @Override public LIRGenerator newLIRGenerator(StructuredGraph graph, FrameMap frameMap, CallingConvention cc, LIR lir) { return new PTXLIRGenerator(graph, runtime(), target, frameMap, cc, lir); } diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java Tue Jul 30 16:42:51 2013 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/target/Backend.java Wed Jul 31 14:04:24 2013 -0700 @@ -47,9 +47,7 @@ return runtime; } - public FrameMap newFrameMap() { - return new FrameMap(runtime, target, runtime.lookupRegisterConfig()); - } + public abstract FrameMap newFrameMap(); public abstract LIRGenerator newLIRGenerator(StructuredGraph graph, FrameMap frameMap, CallingConvention cc, LIR lir); diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Tue Jul 30 16:42:51 2013 -0700 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotBackend.java Wed Jul 31 14:04:24 2013 -0700 @@ -63,6 +63,11 @@ } @Override + public FrameMap newFrameMap() { + return new AMD64FrameMap(runtime(), target, runtime().lookupRegisterConfig()); + } + + @Override public LIRGenerator newLIRGenerator(StructuredGraph graph, FrameMap frameMap, CallingConvention cc, LIR lir) { return new AMD64HotSpotLIRGenerator(graph, runtime(), target, frameMap, cc, lir); } diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Tue Jul 30 16:42:51 2013 -0700 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotBackend.java Wed Jul 31 14:04:24 2013 -0700 @@ -60,6 +60,11 @@ } @Override + public FrameMap newFrameMap() { + return new SPARCFrameMap(runtime(), target, runtime().lookupRegisterConfig()); + } + + @Override public LIRGenerator newLIRGenerator(StructuredGraph graph, FrameMap frameMap, CallingConvention cc, LIR lir) { return new SPARCHotSpotLIRGenerator(graph, runtime(), target, frameMap, cc, lir); } @@ -73,7 +78,7 @@ protected static void emitStackOverflowCheck(TargetMethodAssembler tasm, boolean afterFrameInit) { if (StackShadowPages.getValue() > 0) { SPARCMacroAssembler masm = (SPARCMacroAssembler) tasm.asm; - final int frameSize = tasm.frameMap.frameSize(); + final int frameSize = tasm.frameMap.totalFrameSize(); if (frameSize > 0) { int lastFramePage = frameSize / unsafe.pageSize(); // emit multiple stack bangs for methods with frames larger than a page @@ -106,9 +111,7 @@ @Override public void enter(TargetMethodAssembler tasm) { - final int alignment = target.wordSize * 2; - final int frameSize = (tasm.frameMap.frameSize() + (alignment - 1)) & ~(alignment - 1); - assert frameSize % alignment == 0 : "must preserve 2*wordSize alignment"; + final int frameSize = tasm.frameMap.totalFrameSize(); SPARCMacroAssembler masm = (SPARCMacroAssembler) tasm.asm; if (!isStub) { diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir.amd64/src/com/oracle/graal/lir/amd64/AMD64FrameMap.java Wed Jul 31 14:04:24 2013 -0700 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.lir.amd64; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.lir.*; + +/** + * AMD64 specific frame map. + * + * This is the format of an AMD64 stack frame: + * + *
+ *   Base       Contents
+ * 
+ *            :                                :  -----
+ *   caller   | incoming overflow argument n   |    ^
+ *   frame    :     ...                        :    | positive
+ *            | incoming overflow argument 0   |    | offsets
+ *   ---------+--------------------------------+---------------------
+ *            | return address                 |    |            ^
+ *   current  +--------------------------------+    |            |    -----
+ *   frame    |                                |    |            |      ^
+ *            : callee save area               :    |            |      |
+ *            |                                |    |            |      |
+ *            +--------------------------------+    |            |      |
+ *            | spill slot 0                   |    | negative   |      |
+ *            :     ...                        :    v offsets    |      |
+ *            | spill slot n                   |  -----        total  frame
+ *            +--------------------------------+               frame  size
+ *            | alignment padding              |               size     |
+ *            +--------------------------------+  -----          |      |
+ *            | outgoing overflow argument n   |    ^            |      |
+ *            :     ...                        :    | positive   |      |
+ *            | outgoing overflow argument 0   |    | offsets    v      v
+ *    %sp-->  +--------------------------------+---------------------------
+ * 
+ * 
+ * + * The spill slot area also includes stack allocated memory blocks (ALLOCA blocks). The size of such + * a block may be greater than the size of a normal spill slot or the word size. + *

+ * A runtime can reserve space at the beginning of the overflow argument area. The calling + * convention can specify that the first overflow stack argument is not at offset 0, but at a + * specified offset. Use {@link CodeCacheProvider#getMinimumOutgoingSize()} to make sure that + * call-free methods also have this space reserved. Then the VM can use the memory at offset 0 + * relative to the stack pointer. + */ +public final class AMD64FrameMap extends FrameMap { + + public AMD64FrameMap(CodeCacheProvider runtime, TargetDescription target, RegisterConfig registerConfig) { + super(runtime, target, registerConfig); + } + + @Override + public int offsetToCalleeSaveArea() { + return frameSize() - calleeSaveAreaSize(); + } + + @Override + protected StackSlot allocateNewSpillSlot(PlatformKind kind, int additionalOffset) { + return StackSlot.get(kind, -spillSize + additionalOffset, true); + } +} diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILFrameMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir.hsail/src/com/oracle/graal/lir/hsail/HSAILFrameMap.java Wed Jul 31 14:04:24 2013 -0700 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.lir.hsail; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.lir.*; + +/** + * HSAIL specific frame map. + * + * This is the format of a HSAIL stack frame: + * + *

+ * TODO
+ * 
+ */ +public final class HSAILFrameMap extends FrameMap { + + public HSAILFrameMap(CodeCacheProvider runtime, TargetDescription target, RegisterConfig registerConfig) { + super(runtime, target, registerConfig); + } + + @Override + public int offsetToCalleeSaveArea() { + return frameSize() - calleeSaveAreaSize(); + } + + @Override + protected StackSlot allocateNewSpillSlot(PlatformKind kind, int additionalOffset) { + return StackSlot.get(kind, -spillSize + additionalOffset, true); + } +} diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXFrameMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir.ptx/src/com/oracle/graal/lir/ptx/PTXFrameMap.java Wed Jul 31 14:04:24 2013 -0700 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.lir.ptx; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.lir.*; + +/** + * PTX specific frame map. + * + * This is the format of a PTX stack frame: + * + *
+ * TODO
+ * 
+ */ +public final class PTXFrameMap extends FrameMap { + + public PTXFrameMap(CodeCacheProvider runtime, TargetDescription target, RegisterConfig registerConfig) { + super(runtime, target, registerConfig); + } + + @Override + public int offsetToCalleeSaveArea() { + return frameSize() - calleeSaveAreaSize(); + } + + @Override + protected StackSlot allocateNewSpillSlot(PlatformKind kind, int additionalOffset) { + return StackSlot.get(kind, -spillSize + additionalOffset, true); + } +} diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCFrameMap.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.lir.sparc/src/com/oracle/graal/lir/sparc/SPARCFrameMap.java Wed Jul 31 14:04:24 2013 -0700 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.lir.sparc; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.lir.*; + +/** + * SPARC specific frame map. + * + * This is the format of a SPARC stack frame: + * + *
+ *   Base       Contents
+ * 
+ *            :                                :  -----
+ *   caller   | incoming overflow argument n   |    ^
+ *   frame    :     ...                        :    | positive
+ *            | incoming overflow argument 0   |    | offsets
+ *   ---------+--------------------------------+---------------------
+ *            | spill slot 0                   |    | negative   ^      |
+ *            :     ...                        :    v offsets    |      |
+ *            | spill slot n                   |  -----        total  frame
+ *            +--------------------------------+               frame  size
+ *   current  | alignment padding              |               size     |
+ *   frame    +--------------------------------+  -----          |      |
+ *            | outgoing overflow argument n   |    ^            |      |
+ *            :     ...                        :    | positive   |      |
+ *            | outgoing overflow argument 0   |    | offsets    |      v
+ *            +--------------------------------+    |            |
+ *            | return address                 |    |            |
+ *            +--------------------------------+    |            |    -----
+ *            |                                |    |            |      ^
+ *            : callee save area               :    |            |      |
+ *            |                                |    |            v      |
+ *    %sp-->  +--------------------------------+---------------------------
+ * 
+ * 
+ * + * The spill slot area also includes stack allocated memory blocks (ALLOCA blocks). The size of such + * a block may be greater than the size of a normal spill slot or the word size. + *

+ * A runtime can reserve space at the beginning of the overflow argument area. The calling + * convention can specify that the first overflow stack argument is not at offset 0, but at a + * specified offset. Use {@link CodeCacheProvider#getMinimumOutgoingSize()} to make sure that + * call-free methods also have this space reserved. Then the VM can use the memory at offset 0 + * relative to the stack pointer. + */ +public final class SPARCFrameMap extends FrameMap { + + public SPARCFrameMap(CodeCacheProvider runtime, TargetDescription target, RegisterConfig registerConfig) { + super(runtime, target, registerConfig); + } + + @Override + public int offsetToCalleeSaveArea() { + return 0; + } + + @Override + protected StackSlot allocateNewSpillSlot(PlatformKind kind, int additionalOffset) { + return StackSlot.get(kind, spillSize + additionalOffset, false); + } +} diff -r 4bd4bf0b47f4 -r 563c6d1994c0 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Tue Jul 30 16:42:51 2013 -0700 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/FrameMap.java Wed Jul 31 14:04:24 2013 -0700 @@ -37,46 +37,8 @@ * area and the spill are can grow until then. Therefore, outgoing arguments are indexed from the * stack pointer, while spill slots are indexed from the beginning of the frame (and the total frame * size has to be added to get the actual offset from the stack pointer). - *

- * This is the format of a stack frame: - * - *

- *   Base       Contents
- * 
- *            :                                :  -----
- *   caller   | incoming overflow argument n   |    ^
- *   frame    :     ...                        :    | positive
- *            | incoming overflow argument 0   |    | offsets
- *   ---------+--------------------------------+---------------------
- *            | return address                 |    |            ^
- *   current  +--------------------------------+    |            |    -----
- *   frame    |                                |    |            |      ^
- *            : callee save area               :    |            |      |
- *            |                                |    |            |      |
- *            +--------------------------------+    |            |      |
- *            | spill slot 0                   |    | negative   |      |
- *            :     ...                        :    v offsets    |      |
- *            | spill slot n                   |  -----        total  frame
- *            +--------------------------------+               frame  size
- *            | alignment padding              |               size     |
- *            +--------------------------------+  -----          |      |
- *            | outgoing overflow argument n   |    ^            |      |
- *            :     ...                        :    | positive   |      |
- *            | outgoing overflow argument 0   |    | offsets    v      v
- *    %sp-->  +--------------------------------+---------------------------
- * 
- * 
- * - * The spill slot area also includes stack allocated memory blocks (ALLOCA blocks). The size of such - * a block may be greater than the size of a normal spill slot or the word size. - *

- * A runtime can reserve space at the beginning of the overflow argument area. The calling - * convention can specify that the first overflow stack argument is not at offset 0, but at a - * specified offset. Use {@link CodeCacheProvider#getMinimumOutgoingSize()} to make sure that - * call-free methods also have this space reserved. Then the VM can use the memory at offset 0 - * relative to the stack pointer. */ -public final class FrameMap { +public abstract class FrameMap { public final CodeCacheProvider runtime; public final TargetDescription target; @@ -92,7 +54,7 @@ /** * Size of the area occupied by spill slots and other stack-allocated memory blocks. */ - private int spillSize; + protected int spillSize; /** * Size of the area occupied by outgoing overflow arguments. This value is adjusted as calling @@ -134,7 +96,7 @@ return target.arch.getReturnAddressSize(); } - private int calleeSaveAreaSize() { + protected int calleeSaveAreaSize() { CalleeSaveLayout csl = registerConfig.getCalleeSaveLayout(); return csl != null ? csl.size : 0; } @@ -238,13 +200,12 @@ } /** - * Gets the offset to the stack area where callee-saved registers are stored. + * Gets the offset from the stack pointer to the stack area where callee-saved registers are + * stored. * * @return The offset to the callee save area (in bytes). */ - public int offsetToCalleeSaveArea() { - return frameSize() - calleeSaveAreaSize(); - } + public abstract int offsetToCalleeSaveArea(); /** * Informs the frame map that the compiled code calls a particular method, which may need stack @@ -267,9 +228,16 @@ hasOutgoingStackArguments = hasOutgoingStackArguments || argsSize > 0; } - private StackSlot getSlot(PlatformKind kind, int additionalOffset) { - return StackSlot.get(kind, -spillSize + additionalOffset, true); - } + /** + * Reserves a new spill slot in the frame of the method being compiled. The returned slot is + * aligned on its natural alignment, i.e., an 8-byte spill slot is aligned at an 8-byte + * boundary. + * + * @param kind The kind of the spill slot to be reserved. + * @param additionalOffset + * @return A spill slot denoting the reserved memory area. + */ + protected abstract StackSlot allocateNewSpillSlot(PlatformKind kind, int additionalOffset); /** * Reserves a spill slot in the frame of the method being compiled. The returned slot is aligned @@ -294,7 +262,7 @@ } int size = target.arch.getSizeInBytes(kind); spillSize = NumUtil.roundUp(spillSize + size, size); - return getSlot(kind, 0); + return allocateNewSpillSlot(kind, 0); } private Set freedSlots; @@ -329,15 +297,15 @@ if (refs) { assert size % target.wordSize == 0; - StackSlot result = getSlot(Kind.Object, 0); + StackSlot result = allocateNewSpillSlot(Kind.Object, 0); objectStackBlocks.add(result); for (int i = target.wordSize; i < size; i += target.wordSize) { - objectStackBlocks.add(getSlot(Kind.Object, i)); + objectStackBlocks.add(allocateNewSpillSlot(Kind.Object, i)); } return result; } else { - return getSlot(target.wordKind, 0); + return allocateNewSpillSlot(target.wordKind, 0); } }