Skip to content

Commit 564d754

Browse files
committed
Combine local clear check & load into one operation
1 parent 2b74a70 commit 564d754

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/bytecode_dsl/RootNodeCompiler.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -980,10 +980,7 @@ private void emitNameFastOperation(String mangled, NameOperation op, Builder b)
980980
BytecodeLocal local = locals.get(mangled);
981981
switch (op) {
982982
case Read:
983-
b.beginBlock();
984-
b.emitCheckUnboundLocal(local, varnames.get(mangled));
985-
b.emitLoadLocal(local);
986-
b.endBlock();
983+
b.emitCheckAndLoadLocal(local, varnames.get(mangled));
987984
break;
988985
case Delete:
989986
b.emitDeleteLocal(local, varnames.get(mangled));

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

+37-3
Original file line numberDiff line numberDiff line change
@@ -3952,12 +3952,45 @@ private static void handleException(VirtualFrame frame, PException e, Node inlin
39523952
}
39533953
}
39543954

3955+
/**
3956+
* Loads a user-defined local variable. Unlike a built-in LoadLocal, this operation raises an
3957+
* unbound local error if the local has not been set.
3958+
* <p>
3959+
* This operation makes use of Truffle's boxing overloads. When an operation tries to quicken
3960+
* this one for boxing elimination, the correct overload will be selected.
3961+
*/
39553962
@Operation
39563963
@ConstantOperand(type = LocalAccessor.class)
39573964
@ConstantOperand(type = int.class)
3958-
public static final class CheckUnboundLocal {
3959-
@Specialization
3960-
public static void doObject(VirtualFrame frame, LocalAccessor accessor, int index,
3965+
public static final class CheckAndLoadLocal {
3966+
@Specialization(rewriteOn = UnexpectedResultException.class)
3967+
public static int doInt(VirtualFrame frame, LocalAccessor accessor, int index,
3968+
@Bind PBytecodeDSLRootNode rootNode,
3969+
@Bind BytecodeNode bytecodeNode,
3970+
@Bind Node inliningTarget,
3971+
@Shared @Cached InlinedBranchProfile localUnboundProfile) throws UnexpectedResultException {
3972+
if (accessor.isCleared(bytecodeNode, frame)) {
3973+
localUnboundProfile.enter(inliningTarget);
3974+
throw raiseUnbound(rootNode, inliningTarget, index);
3975+
}
3976+
return accessor.getInt(bytecodeNode, frame);
3977+
}
3978+
3979+
@Specialization(rewriteOn = UnexpectedResultException.class)
3980+
public static boolean doBoolean(VirtualFrame frame, LocalAccessor accessor, int index,
3981+
@Bind PBytecodeDSLRootNode rootNode,
3982+
@Bind BytecodeNode bytecodeNode,
3983+
@Bind Node inliningTarget,
3984+
@Shared @Cached InlinedBranchProfile localUnboundProfile) throws UnexpectedResultException {
3985+
if (accessor.isCleared(bytecodeNode, frame)) {
3986+
localUnboundProfile.enter(inliningTarget);
3987+
throw raiseUnbound(rootNode, inliningTarget, index);
3988+
}
3989+
return accessor.getBoolean(bytecodeNode, frame);
3990+
}
3991+
3992+
@Specialization(replaces = {"doInt", "doBoolean"})
3993+
public static Object doObject(VirtualFrame frame, LocalAccessor accessor, int index,
39613994
@Bind PBytecodeDSLRootNode rootNode,
39623995
@Bind BytecodeNode bytecodeNode,
39633996
@Bind Node inliningTarget,
@@ -3966,6 +3999,7 @@ public static void doObject(VirtualFrame frame, LocalAccessor accessor, int inde
39663999
localUnboundProfile.enter(inliningTarget);
39674000
throw raiseUnbound(rootNode, inliningTarget, index);
39684001
}
4002+
return accessor.getObject(bytecodeNode, frame);
39694003
}
39704004
}
39714005

0 commit comments

Comments
 (0)