Skip to content

Commit 6fd5ee4

Browse files
committed
Add workaround for reporting loop counts in tier 1
1 parent df29c2d commit 6fd5ee4

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/bytecode/PBytecodeRootNode.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,11 @@ Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, Frame stackFr
742742
Object globals = PArguments.getGlobals(virtualFrame);
743743
Object locals = PArguments.getSpecialArgument(virtualFrame);
744744

745-
int loopCount = 0;
745+
/*
746+
* We use an array as a workaround for not being able to specify which local variables are
747+
* loop constants (GR-35338).
748+
*/
749+
int[] loopCount = new int[]{0};
746750
int stackTop = initialStackTop;
747751
int bci = initialBci;
748752

@@ -1007,8 +1011,8 @@ Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, Frame stackFr
10071011
break;
10081012
}
10091013
case OpCodesConstants.RETURN_VALUE: {
1010-
if (CompilerDirectives.inInterpreter() && loopCount > 0) {
1011-
LoopNode.reportLoopCount(this, loopCount);
1014+
if (CompilerDirectives.hasNextTier() && loopCount[0] > 0) {
1015+
LoopNode.reportLoopCount(this, loopCount[0]);
10121016
}
10131017
Object value = stackFrame.getObject(stackTop);
10141018
if (isGeneratorOrCoroutine) {
@@ -1158,8 +1162,8 @@ Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, Frame stackFr
11581162
case OpCodesConstants.JUMP_BACKWARD: {
11591163
oparg |= Byte.toUnsignedInt(localBC[bci + 1]);
11601164
bci -= oparg;
1161-
if (CompilerDirectives.inInterpreter()) {
1162-
loopCount++;
1165+
if (CompilerDirectives.hasNextTier()) {
1166+
loopCount[0]++;
11631167
}
11641168
if (CompilerDirectives.inInterpreter() && BytecodeOSRNode.pollOSRBackEdge(osrNode)) {
11651169
/*
@@ -1174,8 +1178,8 @@ Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, Frame stackFr
11741178
*/
11751179
Object osrResult = BytecodeOSRNode.tryOSR(osrNode, bci, stackTop, null, virtualFrame);
11761180
if (osrResult != null) {
1177-
if (CompilerDirectives.inInterpreter() && loopCount > 0) {
1178-
LoopNode.reportLoopCount(this, loopCount);
1181+
if (CompilerDirectives.hasNextTier() && loopCount[0] > 0) {
1182+
LoopNode.reportLoopCount(this, loopCount[0]);
11791183
}
11801184
return osrResult;
11811185
}
@@ -1293,8 +1297,8 @@ Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, Frame stackFr
12931297
throw bytecodeEndExcHandler(stackFrame, stackTop);
12941298
}
12951299
case OpCodesConstants.YIELD_VALUE: {
1296-
if (CompilerDirectives.inInterpreter() && loopCount > 0) {
1297-
LoopNode.reportLoopCount(this, loopCount);
1300+
if (CompilerDirectives.hasNextTier() && loopCount[0] > 0) {
1301+
LoopNode.reportLoopCount(this, loopCount[0]);
12981302
}
12991303
Object value = stackFrame.getObject(stackTop);
13001304
stackFrame.setObject(stackTop--, null);
@@ -1410,8 +1414,8 @@ Object executeFromBci(VirtualFrame virtualFrame, Frame localFrame, Frame stackFr
14101414
clearFrameSlots(localFrame, stackoffset, initialStackTop);
14111415
}
14121416
}
1413-
if (CompilerDirectives.inInterpreter() && loopCount > 0) {
1414-
LoopNode.reportLoopCount(this, loopCount);
1417+
if (CompilerDirectives.hasNextTier() && loopCount[0] > 0) {
1418+
LoopNode.reportLoopCount(this, loopCount[0]);
14151419
}
14161420
if (e == pe) {
14171421
throw pe;

0 commit comments

Comments
 (0)