Skip to content

Commit bcc5ffe

Browse files
thomaswuesteve-s
authored andcommitted
Improve specializations for CheckAndLoadLocal node.
1 parent d6fbfa2 commit bcc5ffe

File tree

1 file changed

+24
-38
lines changed

1 file changed

+24
-38
lines changed

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

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,6 @@
291291
import com.oracle.truffle.api.nodes.RootNode;
292292
import com.oracle.truffle.api.nodes.UnexpectedResultException;
293293
import com.oracle.truffle.api.object.DynamicObject;
294-
import com.oracle.truffle.api.profiles.InlinedBranchProfile;
295294
import com.oracle.truffle.api.profiles.InlinedConditionProfile;
296295
import com.oracle.truffle.api.source.Source;
297296
import com.oracle.truffle.api.source.SourceSection;
@@ -3550,67 +3549,54 @@ static void doInteropException(AbstractTruffleException exception) {
35503549
@ConstantOperand(type = LocalAccessor.class)
35513550
@ConstantOperand(type = int.class)
35523551
public static final class CheckAndLoadLocal {
3553-
@Specialization(rewriteOn = UnexpectedResultException.class)
3552+
3553+
@Specialization(rewriteOn = UnexpectedResultException.class, guards = "!accessor.isCleared(bytecodeNode, frame)")
35543554
public static int doInt(VirtualFrame frame, LocalAccessor accessor, int index,
3555-
@Bind PBytecodeDSLRootNode rootNode,
3556-
@Bind BytecodeNode bytecodeNode,
3557-
@Bind Node inliningTarget,
3558-
@Shared @Cached InlinedBranchProfile localUnboundProfile) throws UnexpectedResultException {
3559-
if (accessor.isCleared(bytecodeNode, frame)) {
3560-
localUnboundProfile.enter(inliningTarget);
3561-
throw raiseUnbound(rootNode, inliningTarget, index);
3562-
}
3555+
@Bind BytecodeNode bytecodeNode) throws UnexpectedResultException {
35633556
return accessor.getInt(bytecodeNode, frame);
35643557
}
35653558

3566-
@Specialization(rewriteOn = UnexpectedResultException.class)
3559+
@Specialization(rewriteOn = UnexpectedResultException.class, guards = "!accessor.isCleared(bytecodeNode, frame)")
35673560
public static boolean doBoolean(VirtualFrame frame, LocalAccessor accessor, int index,
3568-
@Bind PBytecodeDSLRootNode rootNode,
3569-
@Bind BytecodeNode bytecodeNode,
3570-
@Bind Node inliningTarget,
3571-
@Shared @Cached InlinedBranchProfile localUnboundProfile) throws UnexpectedResultException {
3572-
if (accessor.isCleared(bytecodeNode, frame)) {
3573-
localUnboundProfile.enter(inliningTarget);
3574-
throw raiseUnbound(rootNode, inliningTarget, index);
3575-
}
3561+
@Bind BytecodeNode bytecodeNode) throws UnexpectedResultException {
35763562
return accessor.getBoolean(bytecodeNode, frame);
35773563
}
35783564

3579-
@Specialization(replaces = {"doInt", "doBoolean"})
3565+
@Specialization(replaces = {"doInt", "doBoolean"}, guards = "!accessor.isCleared(bytecodeNode, frame)")
35803566
public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int index,
3581-
@Bind PBytecodeDSLRootNode rootNode,
3582-
@Bind BytecodeNode bytecodeNode,
3583-
@Bind Node inliningTarget,
3584-
@Shared @Cached InlinedBranchProfile localUnboundProfile) {
3585-
if (accessor.isCleared(bytecodeNode, frame)) {
3586-
localUnboundProfile.enter(inliningTarget);
3587-
throw raiseUnbound(rootNode, inliningTarget, index);
3588-
}
3567+
@Bind BytecodeNode bytecodeNode) {
35893568
return accessor.getObject(bytecodeNode, frame);
35903569
}
3570+
3571+
@Fallback
3572+
public static Object doFallback(VirtualFrame frame, LocalAccessor accessor, int index,
3573+
@Bind BytecodeNode bytecodeNode, @Bind Node inliningTarget) {
3574+
throw raiseUnbound(bytecodeNode, inliningTarget, index);
3575+
}
35913576
}
35923577

35933578
@Operation(storeBytecodeIndex = true)
35943579
@ConstantOperand(type = LocalAccessor.class)
35953580
@ConstantOperand(type = int.class)
35963581
public static final class DeleteLocal {
3597-
@Specialization
3582+
3583+
@Specialization(guards = "!accessor.isCleared(bytecodeNode, frame)")
35983584
public static void doObject(VirtualFrame frame, LocalAccessor accessor, int index,
3599-
@Bind PBytecodeDSLRootNode rootNode,
36003585
@Bind BytecodeNode bytecodeNode,
3601-
@Bind Node inliningTarget,
3602-
@Cached InlinedBranchProfile localUnboundProfile) {
3603-
if (accessor.isCleared(bytecodeNode, frame)) {
3604-
localUnboundProfile.enter(inliningTarget);
3605-
throw raiseUnbound(rootNode, inliningTarget, index);
3606-
}
3586+
@Bind Node inliningTarget) {
36073587
accessor.clear(bytecodeNode, frame);
36083588
}
3589+
3590+
@Fallback
3591+
public static void doFallback(VirtualFrame frame, LocalAccessor accessor, int index,
3592+
@Bind BytecodeNode bytecodeNode, @Bind Node inliningTarget) {
3593+
throw raiseUnbound(bytecodeNode, inliningTarget, index);
3594+
}
36093595
}
36103596

36113597
@TruffleBoundary
3612-
private static PException raiseUnbound(PBytecodeDSLRootNode rootNode, Node inliningTarget, int index) {
3613-
TruffleString localName = rootNode.getCodeUnit().varnames[index];
3598+
private static PException raiseUnbound(BytecodeNode bytecodeNode, Node inliningTarget, int index) {
3599+
TruffleString localName = ((PBytecodeDSLRootNode) bytecodeNode.getRootNode()).getCodeUnit().varnames[index];
36143600
throw PRaiseNode.raiseStatic(inliningTarget, PythonBuiltinClassType.UnboundLocalError, ErrorMessages.LOCAL_VAR_REFERENCED_BEFORE_ASSIGMENT, localName);
36153601
}
36163602

0 commit comments

Comments
 (0)