Skip to content

Commit

Permalink
Updating Bytecode DSL and use MaterializedLocalAccessor
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Oct 23, 2024
1 parent 4674492 commit d7503af
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion mx.trufflesom/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{
"name": "truffle",
"subdir": True,
"version": "3f874aee628ffeb8e5ba65a28d3e5aa612cbfbe3",
"version": "084ca7ee41dd2bd24a597475decf9f4180913c78",
"urls": [{"url": "https://github.com/oracle/graal", "kind": "git"}],
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ public void replaceAfterScopeChange(final ScopeAdaptationVisitor inliner) {
@Override
public void constructOperation(final OpBuilder opBuilder, boolean resultUsed) {
if (self instanceof NonLocalArgumentReadNode arg) {
opBuilder.dsl.beginNonLocalReadField(getFieldIndex());
getSelf().accept(opBuilder);
opBuilder.dsl.endNonLocalReadField();
opBuilder.dsl.emitNonLocalReadField(getFieldIndex(), arg.contextLevel);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.oracle.truffle.api.bytecode.EpilogReturn;
import com.oracle.truffle.api.bytecode.GenerateBytecode;
import com.oracle.truffle.api.bytecode.LocalAccessor;
import com.oracle.truffle.api.bytecode.MaterializedLocalAccessor;
import com.oracle.truffle.api.bytecode.Operation;
import com.oracle.truffle.api.bytecode.OperationProxy;
import com.oracle.truffle.api.bytecode.Variadic;
Expand Down Expand Up @@ -489,32 +490,39 @@ public static Object readObject(

@Operation
@ConstantOperand(type = int.class)
@ConstantOperand(type = int.class)
@ImportStatic(FieldAccessorNode.class)
public static final class NonLocalReadField {
@Specialization(rewriteOn = UnexpectedResultException.class)
public static long readLong(
public static long readLong(final VirtualFrame frame,
@SuppressWarnings("unused") final int fieldIdx,
final SObject self,
final int contextLevel,
@Cached("createRead(fieldIdx)") final AbstractReadFieldNode read)
throws UnexpectedResultException {
return read.readLong(self);
MaterializedFrame ctx = ContextualNode.determineContext(frame, contextLevel);
SObject rcvr = (SObject) ctx.getArguments()[0];
return read.readLong(rcvr);
}

@Specialization(rewriteOn = UnexpectedResultException.class)
public static double readDouble(
public static double readDouble(final VirtualFrame frame,
@SuppressWarnings("unused") final int fieldIdx,
final SObject self,
final int contextLevel,
@Cached("createRead(fieldIdx)") final AbstractReadFieldNode read)
throws UnexpectedResultException {
return read.readDouble(self);
MaterializedFrame ctx = ContextualNode.determineContext(frame, contextLevel);
SObject rcvr = (SObject) ctx.getArguments()[0];
return read.readDouble(rcvr);
}

@Specialization
public static Object readObject(
public static Object readObject(final VirtualFrame frame,
@SuppressWarnings("unused") final int fieldIdx,
final SObject self,
final int contextLevel,
@Cached("createRead(fieldIdx)") final AbstractReadFieldNode read) {
return read.read(self);
MaterializedFrame ctx = ContextualNode.determineContext(frame, contextLevel);
SObject rcvr = (SObject) ctx.getArguments()[0];
return read.read(rcvr);
}
}

Expand Down Expand Up @@ -677,13 +685,13 @@ private static String concatStr(final String a, final String b) {
}

@Operation
@ConstantOperand(type = LocalAccessor.class)
@ConstantOperand(type = MaterializedLocalAccessor.class)
@ConstantOperand(type = int.class)
@ImportStatic(ContextualNode.class)
public static final class IncNonLocalVarWithExp {
@Specialization
public static long increment(final VirtualFrame frame,
final LocalAccessor accessor,
final MaterializedLocalAccessor accessor,
final int contextLevel,
final long incValue,
@Cached(value = "determineContextNode(frame, contextLevel)",
Expand All @@ -708,11 +716,11 @@ public static long increment(final VirtualFrame frame,

@Specialization
public static double increment(final VirtualFrame frame,
final LocalAccessor accessor,
final int contextLevel,
final double incValue,
@Cached(value = "determineContextNode(frame, contextLevel)",
adopt = false) BytecodeNode bytecodeNode) {
final MaterializedLocalAccessor accessor,
final int contextLevel,
final double incValue,
@Cached(value = "determineContextNode(frame, contextLevel)",
adopt = false) BytecodeNode bytecodeNode) {
MaterializedFrame ctx = ContextualNode.determineContext(frame, contextLevel);
try {
double currentValue = accessor.getDouble(bytecodeNode, ctx);
Expand All @@ -727,11 +735,11 @@ public static double increment(final VirtualFrame frame,

@Specialization
public static String concatStrings(final VirtualFrame frame,
final LocalAccessor accessor,
final int contextLevel,
final String incValue,
@Cached(value = "determineContextNode(frame, contextLevel)",
adopt = false) BytecodeNode bytecodeNode) {
final MaterializedLocalAccessor accessor,
final int contextLevel,
final String incValue,
@Cached(value = "determineContextNode(frame, contextLevel)",
adopt = false) BytecodeNode bytecodeNode) {
MaterializedFrame ctx = ContextualNode.determineContext(frame, contextLevel);
String currentValue = (String) accessor.getObject(bytecodeNode, ctx);
String result = concatStr(currentValue, incValue);
Expand Down Expand Up @@ -763,13 +771,13 @@ public static long increment(final VirtualFrame frame,

@ImportStatic(ContextualNode.class)
@Operation
@ConstantOperand(type = LocalAccessor.class)
@ConstantOperand(type = MaterializedLocalAccessor.class)
@ConstantOperand(type = long.class)
@ConstantOperand(type = int.class)
public static final class IncNonLocalVarWithValue {
@Specialization
public static long increment(final VirtualFrame frame,
final LocalAccessor accessor,
final MaterializedLocalAccessor accessor,
final long incValue,
final int contextLevel,
@Cached(value = "determineContextNode(frame, contextLevel)",
Expand Down

0 comments on commit d7503af

Please sign in to comment.