Skip to content

Commit

Permalink
HSAIL: support for storing immediates
Browse files Browse the repository at this point in the history
Contributed-by: Eric Caspole <[email protected]>
  • Loading branch information
dougxc committed Feb 6, 2014
1 parent 590620a commit 6f74548
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,13 @@ public final void emitMov(Value dst, Value src) {
}

private void emitAddrOp(String instr, Value reg, HSAILAddress addr) {
emitString(instr + " " + HSAIL.mapRegister(reg) + ", " + mapAddress(addr) + ";");
String storeValue = null;
if (reg instanceof RegisterValue) {
storeValue = HSAIL.mapRegister(reg);
} else if (reg instanceof Constant) {
storeValue = ((Constant) reg).asBoxedValue().toString();
}
emitString(instr + " " + storeValue + ", " + mapAddress(addr) + ";");
}

/**
Expand Down Expand Up @@ -160,10 +166,31 @@ public final void emitStore(Value dest, HSAILAddress addr, String argTypeStr) {
emitAddrOp("st_global_" + argTypeStr, dest, addr);
}

private void storeImmediateImpl(String storeType, String value, HSAILAddress addr) {
emitString("st_global_" + storeType + " " + value + ", " + mapAddress(addr) + ";");
}

public final void emitStoreImmediate(Kind kind, long src, HSAILAddress addr) {
assert (kind != Kind.Float && kind != Kind.Double);
storeImmediateImpl(getArgTypeFromKind(kind), Long.toString(src), addr);
}

public final void emitStoreImmediate(float src, HSAILAddress addr) {
storeImmediateImpl("f32", Float.toString(src), addr);
}

public final void emitStoreImmediate(double src, HSAILAddress addr) {
storeImmediateImpl("f64", Double.toString(src), addr);
}

public final void emitSpillLoad(Value dest, Value src) {
emitString("ld_spill_" + getArgType(dest) + " " + HSAIL.mapRegister(dest) + ", " + mapStackSlot(src, getArgSize(dest)) + ";");
}

public final void emitStore(Value src, HSAILAddress addr) {
emitString("st_global_" + getArgType(src) + " " + HSAIL.mapRegister(src) + ", " + mapAddress(addr) + ";");
}

public final void emitSpillStore(Value src, Value dest) {
int sizestored = getArgSize(src);
if (maxDataTypeSize < sizestored) {
Expand Down Expand Up @@ -206,7 +233,7 @@ public int getArgSize(Value src) {
}
}

public static final String getArgType(Value src) {
private static String getArgType(Value src) {
return getArgTypeFromKind(src.getKind());
}

Expand Down Expand Up @@ -237,6 +264,9 @@ private static String getArgTypeFromKind(Kind kind) {
case Byte:
prefix = "s8";
break;
case NarrowOop:
prefix = "u32";
break;
default:
throw GraalInternalError.shouldNotReachHere();
}
Expand Down Expand Up @@ -506,4 +536,8 @@ public void emitAtomicCas(AllocatableValue result, HSAILAddress address, Allocat
public void emitComment(String comment) {
emitString(comment);
}

public void emitStoreRelease(Value src, HSAILAddress address) {
emitAddrOp("st_global_rel_u" + getArgSize(src), src, address);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@
import sun.misc.*;

import com.oracle.graal.api.code.*;
import static com.oracle.graal.api.code.ValueUtil.asConstant;
import static com.oracle.graal.api.code.ValueUtil.isConstant;
import com.oracle.graal.api.meta.*;
import com.oracle.graal.compiler.hsail.*;
import com.oracle.graal.hotspot.*;
import com.oracle.graal.lir.*;
import com.oracle.graal.lir.hsail.*;
import com.oracle.graal.lir.hsail.HSAILControlFlow.*;
import com.oracle.graal.lir.hsail.HSAILMove.*;
import com.oracle.graal.phases.util.*;
import com.oracle.graal.nodes.*;
import com.oracle.graal.nodes.calc.*;
import com.oracle.graal.nodes.extended.*;
import com.oracle.graal.nodes.java.*;
import com.oracle.graal.phases.util.*;
import com.oracle.graal.graph.*;

/**
* The HotSpot specific portion of the HSAIL LIR generator.
Expand Down Expand Up @@ -79,6 +82,11 @@ private static boolean isCompressCandidate(Access access) {
return access != null && access.isCompressible();
}

@Override
public boolean canStoreConstant(Constant c, boolean isCompressed) {
return true;
}

/**
* Appends either a {@link CompareAndSwapOp} or a {@link CompareAndSwapCompressedOp} depending
* on whether the memory location of a given {@link LoweredCompareAndSwapNode} contains a
Expand Down Expand Up @@ -114,6 +122,13 @@ public void visitCompareAndSwap(LoweredCompareAndSwapNode node, Value address) {
setResult(node, nodeResult);
}

/**
* Returns whether or not the input access should be (de)compressed.
*/
private boolean isCompressedOperation(Kind kind, Access access) {
return access != null && access.isCompressible() && ((kind == Kind.Long && config.useCompressedClassPointers) || (kind == Kind.Object && config.useCompressedOops));
}

@Override
public Variable emitLoad(Kind kind, Value address, Access access) {
HSAILAddressValue loadAddress = asAddressValue(address);
Expand Down Expand Up @@ -141,6 +156,23 @@ public void emitStore(Kind kind, Value address, Value inputVal, Access access) {
if (access instanceof DeoptimizingNode) {
state = state((DeoptimizingNode) access);
}
boolean isCompressed = isCompressedOperation(kind, access);
if (isConstant(inputVal)) {
Constant c = asConstant(inputVal);
if (canStoreConstant(c, isCompressed)) {
if (isCompressed) {
if ((c.getKind() == Kind.Object) && c.isNull()) {
append(new StoreConstantOp(Kind.NarrowOop, storeAddress, c, state));
} else {
throw GraalInternalError.shouldNotReachHere("can't handle: " + access);
}
return;
} else {
append(new StoreConstantOp(kind, storeAddress, c, state));
return;
}
}
}
Variable input = load(inputVal);
if (isCompressCandidate(access) && config.useCompressedOops && kind == Kind.Object) {
Variable scratch = newVariable(Kind.Long);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,56 @@ public void emitMemAccess(HSAILAssembler masm) {
}
}

public static class StoreConstantOp extends MemOp {

protected final Constant input;

public StoreConstantOp(Kind kind, HSAILAddressValue address, Constant input, LIRFrameState state) {
super(kind, address, state);
this.input = input;
}

@Override
public void emitMemAccess(HSAILAssembler masm) {
switch (kind) {
case Boolean:
case Byte:
masm.emitStoreImmediate(kind, input.asLong() & 0xFF, address.toAddress());
break;
case Char:
case Short:
masm.emitStoreImmediate(kind, input.asLong() & 0xFFFF, address.toAddress());
break;
case Int:
case Long:
masm.emitStoreImmediate(kind, input.asLong(), address.toAddress());
break;
case Float:
masm.emitStoreImmediate(input.asFloat(), address.toAddress());
break;
case Double:
masm.emitStoreImmediate(input.asDouble(), address.toAddress());
break;
case Object:
if (input.isNull()) {
masm.emitStoreImmediate(kind, 0L, address.toAddress());
} else {
throw GraalInternalError.shouldNotReachHere("Cannot store 64-bit constants to object ref");
}
break;
case NarrowOop:
if (input.isNull()) {
masm.emitStoreImmediate(kind, 0L, address.toAddress());
} else {
throw GraalInternalError.shouldNotReachHere("Cannot store 64-bit constants to object ref");
}
break;
default:
throw GraalInternalError.shouldNotReachHere();
}
}
}

public static class LoadCompressedPointer extends LoadOp {

private final long base;
Expand Down

0 comments on commit 6f74548

Please sign in to comment.