Skip to content

Commit abcdc8d

Browse files
thomaswuesteve-s
authored andcommitted
[GR-68939] Improve specializations for CheckAndLoadLocal node.
PullRequest: graalpython/3965
2 parents c13e6ab + b8af234 commit abcdc8d

File tree

1 file changed

+30
-44
lines changed

1 file changed

+30
-44
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode_dsl/PBytecodeDSLRootNode.java

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@
283283
import com.oracle.truffle.api.exception.AbstractTruffleException;
284284
import com.oracle.truffle.api.frame.Frame;
285285
import com.oracle.truffle.api.frame.FrameDescriptor;
286+
import com.oracle.truffle.api.frame.FrameSlotTypeException;
286287
import com.oracle.truffle.api.frame.MaterializedFrame;
287288
import com.oracle.truffle.api.frame.VirtualFrame;
288289
import com.oracle.truffle.api.nodes.DirectCallNode;
@@ -3537,72 +3538,57 @@ static void doInteropException(AbstractTruffleException exception) {
35373538
* This operation makes use of Truffle's boxing overloads. When an operation tries to quicken
35383539
* this one for boxing elimination, the correct overload will be selected.
35393540
*/
3540-
@Operation(storeBytecodeIndex = true)
3541+
@Operation(storeBytecodeIndex = false)
35413542
@ConstantOperand(type = LocalAccessor.class)
35423543
@ConstantOperand(type = int.class)
35433544
public static final class CheckAndLoadLocal {
3544-
@Specialization(rewriteOn = UnexpectedResultException.class)
3545+
@Specialization(rewriteOn = {FrameSlotTypeException.class, UnexpectedResultException.class})
35453546
public static int doInt(VirtualFrame frame, LocalAccessor accessor, int index,
3546-
@Bind PBytecodeDSLRootNode rootNode,
3547-
@Bind BytecodeNode bytecodeNode,
3548-
@Bind Node inliningTarget,
3549-
@Shared @Cached InlinedBranchProfile localUnboundProfile) throws UnexpectedResultException {
3550-
if (accessor.isCleared(bytecodeNode, frame)) {
3551-
localUnboundProfile.enter(inliningTarget);
3552-
throw raiseUnbound(rootNode, inliningTarget, index);
3553-
}
3547+
@Bind BytecodeNode bytecodeNode) throws UnexpectedResultException {
35543548
return accessor.getInt(bytecodeNode, frame);
35553549
}
35563550

3557-
@Specialization(rewriteOn = UnexpectedResultException.class)
3558-
public static boolean doBoolean(VirtualFrame frame, LocalAccessor accessor, int index,
3559-
@Bind PBytecodeDSLRootNode rootNode,
3560-
@Bind BytecodeNode bytecodeNode,
3561-
@Bind Node inliningTarget,
3562-
@Shared @Cached InlinedBranchProfile localUnboundProfile) throws UnexpectedResultException {
3563-
if (accessor.isCleared(bytecodeNode, frame)) {
3564-
localUnboundProfile.enter(inliningTarget);
3565-
throw raiseUnbound(rootNode, inliningTarget, index);
3566-
}
3567-
return accessor.getBoolean(bytecodeNode, frame);
3551+
@Specialization(replaces = "doInt", rewriteOn = FrameSlotTypeException.class)
3552+
public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int index,
3553+
@Bind BytecodeNode bytecodeNode) {
3554+
return accessor.getObject(bytecodeNode, frame);
35683555
}
35693556

3570-
@Specialization(replaces = {"doInt", "doBoolean"})
3571-
public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int index,
3572-
@Bind PBytecodeDSLRootNode rootNode,
3573-
@Bind BytecodeNode bytecodeNode,
3574-
@Bind Node inliningTarget,
3575-
@Shared @Cached InlinedBranchProfile localUnboundProfile) {
3576-
if (accessor.isCleared(bytecodeNode, frame)) {
3577-
localUnboundProfile.enter(inliningTarget);
3578-
throw raiseUnbound(rootNode, inliningTarget, index);
3557+
@StoreBytecodeIndex
3558+
@Specialization(replaces = "doObject")
3559+
public static Object doObjectOrUnbound(VirtualFrame frame, LocalAccessor accessor, int index,
3560+
@Bind BytecodeNode bytecodeNode) {
3561+
try {
3562+
return accessor.getObject(bytecodeNode, frame);
3563+
} catch (FrameSlotTypeException e) {
3564+
throw raiseUnbound(bytecodeNode, index);
35793565
}
3580-
return accessor.getObject(bytecodeNode, frame);
35813566
}
35823567
}
35833568

3584-
@Operation(storeBytecodeIndex = true)
3569+
@Operation(storeBytecodeIndex = false)
35853570
@ConstantOperand(type = LocalAccessor.class)
35863571
@ConstantOperand(type = int.class)
35873572
public static final class DeleteLocal {
3588-
@Specialization
3573+
3574+
@Specialization(guards = "!accessor.isCleared(bytecodeNode, frame)")
35893575
public static void doObject(VirtualFrame frame, LocalAccessor accessor, int index,
3590-
@Bind PBytecodeDSLRootNode rootNode,
3591-
@Bind BytecodeNode bytecodeNode,
3592-
@Bind Node inliningTarget,
3593-
@Cached InlinedBranchProfile localUnboundProfile) {
3594-
if (accessor.isCleared(bytecodeNode, frame)) {
3595-
localUnboundProfile.enter(inliningTarget);
3596-
throw raiseUnbound(rootNode, inliningTarget, index);
3597-
}
3576+
@Bind BytecodeNode bytecodeNode) {
35983577
accessor.clear(bytecodeNode, frame);
35993578
}
3579+
3580+
@StoreBytecodeIndex
3581+
@Fallback
3582+
public static void doFallback(VirtualFrame frame, LocalAccessor accessor, int index,
3583+
@Bind BytecodeNode bytecodeNode) {
3584+
throw raiseUnbound(bytecodeNode, index);
3585+
}
36003586
}
36013587

36023588
@TruffleBoundary
3603-
private static PException raiseUnbound(PBytecodeDSLRootNode rootNode, Node inliningTarget, int index) {
3604-
TruffleString localName = rootNode.getCodeUnit().varnames[index];
3605-
throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, localName);
3589+
private static PException raiseUnbound(BytecodeNode bytecodeNode, int index) {
3590+
TruffleString localName = ((PBytecodeDSLRootNode) bytecodeNode.getRootNode()).getCodeUnit().varnames[index];
3591+
throw PRaiseNode.raiseStatic(bytecodeNode, PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, localName);
36063592
}
36073593

36083594
@Operation(storeBytecodeIndex = true)

0 commit comments

Comments
 (0)