Skip to content

Commit

Permalink
[GR-4916] Fix problem with move from Constant to StackSlot.
Browse files Browse the repository at this point in the history
  • Loading branch information
dougxc committed Jul 13, 2017
2 parents 2d4662b + 02b78ce commit a37b749
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public LIRInstruction createLoad(AllocatableValue dst, Constant src) {
}
}

@Override
public LIRInstruction createStackLoad(AllocatableValue result, Constant input) {
return createLoad(result, input);
}

@Override
public boolean canInlineConstant(Constant con) {
if (con instanceof JavaConstant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@

package org.graalvm.compiler.core.amd64;

import static jdk.vm.ci.code.ValueUtil.isRegister;
import static org.graalvm.compiler.lir.LIRValueUtil.asConstant;
import static org.graalvm.compiler.lir.LIRValueUtil.isConstantValue;
import static org.graalvm.compiler.lir.LIRValueUtil.isStackSlotValue;
import static jdk.vm.ci.code.ValueUtil.isRegister;

import org.graalvm.compiler.core.common.NumUtil;
import org.graalvm.compiler.core.common.type.DataPointerConstant;
import org.graalvm.compiler.debug.GraalError;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.amd64.AMD64AddressValue;
import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;
import org.graalvm.compiler.lir.amd64.AMD64Move;
import org.graalvm.compiler.lir.amd64.AMD64Move.AMD64StackMove;
import org.graalvm.compiler.lir.amd64.AMD64Move.LeaDataOp;
import org.graalvm.compiler.lir.amd64.AMD64Move.LeaOp;
Expand Down Expand Up @@ -69,6 +71,17 @@ public boolean canInlineConstant(Constant con) {
return false;
}

@Override
public boolean allowConstantToStackMove(Constant constant) {
if (constant instanceof DataPointerConstant) {
return false;
}
if (constant instanceof JavaConstant && !AMD64Move.canMoveConst2Stack(((JavaConstant) constant))) {
return false;
}
return true;
}

@Override
public AMD64LIRInstruction createMove(AllocatableValue dst, Value src) {
if (src instanceof AMD64AddressValue) {
Expand Down Expand Up @@ -97,4 +110,13 @@ public AMD64LIRInstruction createLoad(AllocatableValue dst, Constant src) {
throw GraalError.shouldNotReachHere(String.format("unsupported constant: %s", src));
}
}

@Override
public LIRInstruction createStackLoad(AllocatableValue result, Constant input) {
if (input instanceof JavaConstant) {
return new MoveFromConstOp(result, (JavaConstant) input);
} else {
throw GraalError.shouldNotReachHere(String.format("unsupported constant for stack load: %s", input));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ public LIRInstruction createLoad(AllocatableValue dst, Constant src) {
}
}

@Override
public LIRInstruction createStackLoad(AllocatableValue result, Constant input) {
if (input instanceof DataPointerConstant) {
throw GraalError.shouldNotReachHere("unsupported constant for stack load: " + input);
}
return createLoad(result, input);
}

@Override
public boolean canInlineConstant(Constant con) {
if (con instanceof JavaConstant) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package org.graalvm.compiler.hotspot.amd64;

import org.graalvm.compiler.core.amd64.AMD64MoveFactory;
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;

import jdk.vm.ci.hotspot.HotSpotCompressedNullConstant;
Expand Down Expand Up @@ -57,7 +58,7 @@ public boolean allowConstantToStackMove(Constant value) {
if (value instanceof HotSpotConstant) {
return ((HotSpotConstant) value).isCompressed();
}
return true;
return super.allowConstantToStackMove(value);
}

@Override
Expand All @@ -72,4 +73,19 @@ public AMD64LIRInstruction createLoad(AllocatableValue dst, Constant src) {
return super.createLoad(dst, src);
}
}

@Override
public LIRInstruction createStackLoad(AllocatableValue dst, Constant src) {
if (HotSpotCompressedNullConstant.COMPRESSED_NULL.equals(src)) {
return super.createStackLoad(dst, JavaConstant.INT_0);
} else if (src instanceof HotSpotObjectConstant) {
assert ((HotSpotConstant) src).isCompressed();
return new AMD64HotSpotMove.HotSpotLoadObjectConstantOp(dst, (HotSpotObjectConstant) src);
} else if (src instanceof HotSpotMetaspaceConstant) {
assert ((HotSpotConstant) src).isCompressed();
return new AMD64HotSpotMove.HotSpotLoadMetaspaceConstantOp(dst, (HotSpotMetaspaceConstant) src);
} else {
return super.createStackLoad(dst, src);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,28 @@ public static void const2reg(CompilationResultBuilder crb, AMD64MacroAssembler m
}
}

public static boolean canMoveConst2Stack(JavaConstant input) {
switch (input.getJavaKind().getStackKind()) {
case Int:
break;
case Long:
break;
case Float:
break;
case Double:
break;
case Object:
if (input.isNull()) {
return true;
} else {
return false;
}
default:
return false;
}
return true;
}

public static void const2stack(CompilationResultBuilder crb, AMD64MacroAssembler masm, Value result, JavaConstant input) {
AMD64Address dest = (AMD64Address) crb.asAddress(result);
final long imm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
import org.graalvm.compiler.lir.LIRInstruction;
import org.graalvm.compiler.lir.LIRValueUtil;
import org.graalvm.compiler.lir.gen.LIRGenerationResult;
import org.graalvm.util.Equivalence;
import org.graalvm.util.EconomicSet;
import org.graalvm.util.Equivalence;

import jdk.vm.ci.meta.AllocatableValue;
import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.Value;
Expand Down Expand Up @@ -296,7 +297,12 @@ private LIRInstruction insertMove(Constant fromOpr, Interval toInterval) {
assert insertIdx != -1 : "must setup insert position first";

AllocatableValue toOpr = toInterval.operand;
LIRInstruction move = getAllocator().getSpillMoveFactory().createLoad(toOpr, fromOpr);
LIRInstruction move;
if (LIRValueUtil.isStackSlotValue(toInterval.location())) {
move = getAllocator().getSpillMoveFactory().createStackLoad(toOpr, fromOpr);
} else {
move = getAllocator().getSpillMoveFactory().createLoad(toOpr, fromOpr);
}
insertionBuffer.append(insertIdx, move);

DebugContext debug = allocator.getDebug();
Expand Down Expand Up @@ -482,7 +488,8 @@ public void addMapping(Interval fromInterval, Interval toInterval) {
}

assert !fromInterval.operand.equals(toInterval.operand) : "from and to interval equal: " + fromInterval;
assert LIRKind.verifyMoveKinds(toInterval.kind(), fromInterval.kind(), allocator.getRegisterAllocationConfig()) : String.format("Kind mismatch: %s vs. %s, from=%s, to=%s", fromInterval.kind(),
assert LIRKind.verifyMoveKinds(toInterval.kind(), fromInterval.kind(), allocator.getRegisterAllocationConfig()) : String.format("Kind mismatch: %s vs. %s, from=%s, to=%s",
fromInterval.kind(),
toInterval.kind(), fromInterval, toInterval);
mappingFrom.add(fromInterval);
mappingFromOpr.add(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private void emitBlock(AbstractBlockBase<?> block) {
afterOp.accept(op);
}
} catch (GraalError e) {
throw e.addContext("lir instruction", block + "@" + op.id() + " " + op + "\n" + Arrays.toString(lir.codeEmittingOrder()));
throw e.addContext("lir instruction", block + "@" + op.id() + " " + op.getClass().getName() + " " + op + "\n" + Arrays.toString(lir.codeEmittingOrder()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public interface MoveFactory {
LIRInstruction createStackMove(AllocatableValue result, AllocatableValue input);

LIRInstruction createLoad(AllocatableValue result, Constant input);

LIRInstruction createStackLoad(AllocatableValue result, Constant input);
}

abstract class BlockScope implements AutoCloseable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public LIRInstruction createLoad(AllocatableValue result, Constant input) {
return inst;
}

@Override
public LIRInstruction createStackLoad(AllocatableValue result, Constant input) {
LIRInstruction inst = inner.createStackLoad(result, input);
assert LoadConstantOp.isLoadConstantOp(inst) && checkResult(inst, result, null);
return inst;
}

/** Closure for {@link VerifyingMoveFactory#checkResult}. */
@SuppressWarnings("unused")
private static class CheckClosure {
Expand Down

0 comments on commit a37b749

Please sign in to comment.