# HG changeset patch # User Doug Simon # Date 1368720330 -7200 # Node ID cff1e11941c0d254b0d86603554dcb9d94a3b007 # Parent b27184f5f66ba4263d9a7a75c91a1439881c02fb moved temporaries from CallingConvention to ForeignCallLinkage diff -r b27184f5f66b -r cff1e11941c0 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CallingConvention.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CallingConvention.java Thu May 16 17:36:16 2013 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CallingConvention.java Thu May 16 18:05:30 2013 +0200 @@ -27,9 +27,8 @@ import com.oracle.graal.api.meta.*; /** - * A calling convention describes the locations in which the arguments for a call are placed, the - * location in which the return value is placed if the call is not void and any - * {@linkplain #getTemporaries() extra} locations used (and killed) by the call. + * A calling convention describes the locations in which the arguments for a call are placed and the + * location in which the return value is placed if the call is not void. */ public class CallingConvention { @@ -78,11 +77,6 @@ private final AllocatableValue[] argumentLocations; /** - * The locations used (and killed) by the call in addition to the arguments. - */ - private final AllocatableValue[] temporaryLocations; - - /** * Creates a description of the registers and stack locations used by a call. * * @param stackSize amount of stack space (in bytes) required for the stack-based arguments of @@ -92,28 +86,11 @@ * @param argumentLocations the ordered locations in which the arguments are placed */ public CallingConvention(int stackSize, AllocatableValue returnLocation, AllocatableValue... argumentLocations) { - this(AllocatableValue.NONE, stackSize, returnLocation, argumentLocations); - } - - /** - * Creates a description of the registers and stack locations used by a call. - * - * @param temporaryLocations the locations used (and killed) by the call in addition to - * {@code arguments} - * @param stackSize amount of stack space (in bytes) required for the stack-based arguments of - * the call - * @param returnLocation the location for the return value or {@link Value#ILLEGAL} if a void - * call - * @param argumentLocations the ordered locations in which the arguments are placed - */ - public CallingConvention(AllocatableValue[] temporaryLocations, int stackSize, AllocatableValue returnLocation, AllocatableValue... argumentLocations) { assert argumentLocations != null; - assert temporaryLocations != null; assert returnLocation != null; this.argumentLocations = argumentLocations; this.stackSize = stackSize; this.returnLocation = returnLocation; - this.temporaryLocations = temporaryLocations; assert verify(); } @@ -155,17 +132,6 @@ return argumentLocations.clone(); } - /** - * Gets the locations used (and killed) by the call apart from the - * {@linkplain #getArgument(int) arguments}. - */ - public AllocatableValue[] getTemporaries() { - if (temporaryLocations.length == 0) { - return temporaryLocations; - } - return temporaryLocations.clone(); - } - @Override public String toString() { StringBuilder sb = new StringBuilder(); @@ -178,14 +144,6 @@ if (!returnLocation.equals(Value.ILLEGAL)) { sb.append(" -> ").append(returnLocation); } - if (temporaryLocations.length != 0) { - sb.append("; temps="); - sep = ""; - for (Value op : temporaryLocations) { - sb.append(sep).append(op); - sep = ", "; - } - } sb.append("]"); return sb.toString(); } diff -r b27184f5f66b -r cff1e11941c0 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ForeignCallLinkage.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ForeignCallLinkage.java Thu May 16 17:36:16 2013 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/ForeignCallLinkage.java Thu May 16 18:05:30 2013 +0200 @@ -44,6 +44,11 @@ ForeignCallDescriptor getDescriptor(); /** + * Gets the values used/killed by this foreign call. + */ + Value[] getTemporaries(); + + /** * Determines if the foreign call target destroys all registers. * * @return {@code true} if the register allocator must save all live registers around a call to diff -r b27184f5f66b -r cff1e11941c0 graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java --- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Thu May 16 17:36:16 2013 +0200 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Thu May 16 18:05:30 2013 +0200 @@ -784,13 +784,12 @@ } @Override - protected void emitForeignCall(ForeignCallLinkage callTarget, Value result, Value[] arguments, Value[] temps, LIRFrameState info) { - - long maxOffset = callTarget.getMaxCallTargetOffset(); + protected void emitForeignCall(ForeignCallLinkage linkage, Value result, Value[] arguments, Value[] temps, LIRFrameState info) { + long maxOffset = linkage.getMaxCallTargetOffset(); if (maxOffset != (int) maxOffset) { - append(new AMD64Call.DirectFarRuntimeCallOp(this, callTarget, result, arguments, temps, info)); + append(new AMD64Call.DirectFarRuntimeCallOp(this, linkage, result, arguments, temps, info)); } else { - append(new AMD64Call.DirectNearRuntimeCallOp(callTarget, result, arguments, temps, info)); + append(new AMD64Call.DirectNearRuntimeCallOp(linkage, result, arguments, temps, info)); } } diff -r b27184f5f66b -r cff1e11941c0 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Thu May 16 17:36:16 2013 +0200 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/gen/LIRGenerator.java Thu May 16 18:05:30 2013 +0200 @@ -608,9 +608,9 @@ Value result = invokeCc.getReturn(); if (callTarget instanceof DirectCallTargetNode) { - emitDirectCall((DirectCallTargetNode) callTarget, result, parameters, invokeCc.getTemporaries(), callState); + emitDirectCall((DirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState); } else if (callTarget instanceof IndirectCallTargetNode) { - emitIndirectCall((IndirectCallTargetNode) callTarget, result, parameters, invokeCc.getTemporaries(), callState); + emitIndirectCall((IndirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState); } else { throw GraalInternalError.shouldNotReachHere(); } @@ -673,7 +673,7 @@ emitMove(loc, arg); argLocations[i] = loc; } - emitForeignCall(linkage, linkageCc.getReturn(), argLocations, linkageCc.getTemporaries(), state); + emitForeignCall(linkage, linkageCc.getReturn(), argLocations, linkage.getTemporaries(), state); if (isLegal(linkageCc.getReturn())) { return emitMove(linkageCc.getReturn()); diff -r b27184f5f66b -r cff1e11941c0 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu May 16 17:36:16 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu May 16 18:05:30 2013 +0200 @@ -186,9 +186,9 @@ private LIRFrameState currentRuntimeCallInfo; @Override - protected void emitForeignCall(ForeignCallLinkage callTarget, Value result, Value[] arguments, Value[] temps, LIRFrameState info) { + protected void emitForeignCall(ForeignCallLinkage linkage, Value result, Value[] arguments, Value[] temps, LIRFrameState info) { currentRuntimeCallInfo = info; - super.emitForeignCall(callTarget, result, arguments, temps, info); + super.emitForeignCall(linkage, result, arguments, temps, info); } protected AMD64SaveRegistersOp emitSaveRegisters(Register[] savedRegisters, StackSlot[] savedRegisterLocations) { diff -r b27184f5f66b -r cff1e11941c0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java Thu May 16 17:36:16 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotForeignCallLinkage.java Thu May 16 18:05:30 2013 +0200 @@ -31,6 +31,7 @@ import com.oracle.graal.api.code.CallingConvention.Type; import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.target.*; +import com.oracle.graal.debug.*; import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.hotspot.stubs.*; import com.oracle.graal.word.*; @@ -41,9 +42,9 @@ public class HotSpotForeignCallLinkage implements ForeignCallLinkage, InvokeTarget { /** - * Constants for specifying whether a call destroys or preserves registers. A call will always - * destroy {@link HotSpotForeignCallLinkage#getCallingConvention() its} - * {@linkplain CallingConvention#getTemporaries() temporary} registers. + * Constants for specifying whether a foreign call destroys or preserves registers. A foreign + * call will always destroy {@link HotSpotForeignCallLinkage#getCallingConvention() its} + * {@linkplain ForeignCallLinkage#getTemporaries() temporary} registers. */ public enum RegisterEffect { DESTROYS_REGISTERS, PRESERVES_REGISTERS @@ -81,13 +82,18 @@ /** * The calling convention for this call. */ - private CallingConvention cc; + private final CallingConvention cc; private final RegisterEffect effect; private final Transition transition; /** + * The locations defined/killed by the call. + */ + private Value[] temporaries = AllocatableValue.NONE; + + /** * Creates a {@link HotSpotForeignCallLinkage}. * * @param descriptor the descriptor of the call @@ -135,13 +141,30 @@ @Override public String toString() { - return (stub == null ? descriptor.toString() : stub) + "@0x" + Long.toHexString(address) + ":" + cc; + StringBuilder sb = new StringBuilder(stub == null ? descriptor.toString() : stub.toString()); + sb.append("@0x").append(Long.toHexString(address)).append(':').append(cc); + if (temporaries != null && temporaries.length != 0) { + sb.append("; temps="); + String sep = ""; + for (Value op : temporaries) { + sb.append(sep).append(op); + sep = ","; + } + } + return sb.toString(); } public CallingConvention getCallingConvention() { return cc; } + public Value[] getTemporaries() { + if (temporaries.length == 0) { + return temporaries; + } + return temporaries.clone(); + } + public long getMaxCallTargetOffset() { return graalRuntime().getCompilerToVM().getMaxCallTargetOffset(address); } @@ -168,13 +191,14 @@ InstalledCode code = stub.getCode(backend); Set destroyedRegisters = stub.getDestroyedRegisters(); - AllocatableValue[] temporaryLocations = new AllocatableValue[destroyedRegisters.size()]; - int i = 0; - for (Register reg : destroyedRegisters) { - temporaryLocations[i++] = reg.asValue(); + if (!destroyedRegisters.isEmpty()) { + AllocatableValue[] temporaryLocations = new AllocatableValue[destroyedRegisters.size()]; + int i = 0; + for (Register reg : destroyedRegisters) { + temporaryLocations[i++] = reg.asValue(); + } + temporaries = temporaryLocations; } - // Update calling convention with temporaries - cc = new CallingConvention(temporaryLocations, cc.getStackSize(), cc.getReturn(), cc.getArguments()); address = code.getStart(); } } diff -r b27184f5f66b -r cff1e11941c0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/RuntimeCallStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/RuntimeCallStub.java Thu May 16 17:36:16 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/RuntimeCallStub.java Thu May 16 18:05:30 2013 +0200 @@ -83,7 +83,7 @@ } /** - * Gets the linkage information for the runtime call. + * Gets the linkage information for the HotSpot runtime call. */ public HotSpotForeignCallLinkage getTargetLinkage() { return target;