Skip to content

Commit f5f1a45

Browse files
committed
Address review feedback
1 parent da2dcd1 commit f5f1a45

File tree

2 files changed

+56
-41
lines changed

2 files changed

+56
-41
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/compiler/QuickeningTypes.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,43 @@
4040
*/
4141
package com.oracle.graal.python.compiler;
4242

43+
import com.oracle.truffle.api.CompilerDirectives;
44+
import com.oracle.truffle.api.frame.FrameSlotKind;
45+
4346
public abstract class QuickeningTypes {
4447
public static final byte OBJECT = 1;
4548
public static final byte INT = 2;
4649
public static final byte LONG = 4;
4750
public static final byte DOUBLE = 8;
4851
public static final byte BOOLEAN = 16;
52+
53+
public static byte fromFrameSlotTag(byte tag) {
54+
if (tag == FrameSlotKind.Object.tag) {
55+
return OBJECT;
56+
} else if (tag == FrameSlotKind.Int.tag) {
57+
return INT;
58+
} else if (tag == FrameSlotKind.Long.tag) {
59+
return LONG;
60+
} else if (tag == FrameSlotKind.Double.tag) {
61+
return DOUBLE;
62+
} else if (tag == FrameSlotKind.Boolean.tag) {
63+
return BOOLEAN;
64+
} else {
65+
throw CompilerDirectives.shouldNotReachHere("Unknown stack item type");
66+
}
67+
}
68+
69+
public static byte fromObjectType(Object object) {
70+
if (object instanceof Integer) {
71+
return INT;
72+
} else if (object instanceof Long) {
73+
return LONG;
74+
} else if (object instanceof Double) {
75+
return DOUBLE;
76+
} else if (object instanceof Boolean) {
77+
return BOOLEAN;
78+
} else {
79+
return OBJECT;
80+
}
81+
}
4982
}

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

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1964,9 +1964,9 @@ private Object bytecodeLoop(VirtualFrame virtualFrame, Frame localFrame, Bytecod
19641964
@ExplodeLoop
19651965
private void unboxVariables(Frame localFrame) {
19661966
/*
1967-
* We keep some variables boxed in the interpreter, but unbox in the compiled code. After
1968-
* OSR we need to unbox existing variables for the compiled code. Should have no effect
1969-
* otherwise.
1967+
* We keep some variables boxed in the interpreter, but unbox in the compiled code. When OSR
1968+
* is entered, we need to unbox existing variables for the compiled code. Should have no
1969+
* effect otherwise.
19701970
*/
19711971
for (int i = 0; i < variableTypes.length; i++) {
19721972
if (variableTypes[i] != 0 && variableTypes[i] != QuickeningTypes.OBJECT && localFrame.isObject(i)) {
@@ -2495,12 +2495,13 @@ private void bytecodeStoreFastAdaptive(VirtualFrame virtualFrame, Frame localFra
24952495
byte itemType = stackType;
24962496
boolean unboxInIntepreter = (variableShouldUnbox[index] & itemType) != 0;
24972497
if (itemType == QuickeningTypes.OBJECT) {
2498-
itemType = objectTypeId(virtualFrame.getObject(stackTop));
2498+
itemType = QuickeningTypes.fromObjectType(virtualFrame.getObject(stackTop));
24992499
}
2500-
if (variableTypes[index] == 0) {
2501-
variableTypes[index] = itemType;
2502-
} else if (variableTypes[index] != itemType) {
2503-
if (variableTypes[index] != QuickeningTypes.OBJECT) {
2500+
byte variableType = variableTypes[index];
2501+
if (variableType == 0) {
2502+
variableType = itemType;
2503+
} else if ((variableType & ~UNBOXED_IN_INTERPRETER) != itemType) {
2504+
if (variableType != QuickeningTypes.OBJECT) {
25042505
variableTypes[index] = QuickeningTypes.OBJECT;
25052506
generalizeVariableStores(index);
25062507
}
@@ -2512,17 +2513,19 @@ private void bytecodeStoreFastAdaptive(VirtualFrame virtualFrame, Frame localFra
25122513
bytecodeStoreFastO(virtualFrame, localFrame, stackTop, index);
25132514
return;
25142515
}
2515-
assert variableTypes[index] == itemType;
25162516
if (itemType == QuickeningTypes.INT) {
25172517
if (unboxInIntepreter && stackType == QuickeningTypes.INT) {
25182518
localBC[bci] = OpCodesConstants.STORE_FAST_I;
2519-
variableTypes[index] |= UNBOXED_IN_INTERPRETER;
2519+
variableType |= UNBOXED_IN_INTERPRETER;
2520+
variableTypes[index] = variableType;
25202521
bytecodeStoreFastI(virtualFrame, localFrame, stackTop, bci, index);
25212522
} else if (unboxInIntepreter) {
25222523
localBC[bci] = OpCodesConstants.STORE_FAST_UNBOX_I;
2523-
variableTypes[index] |= UNBOXED_IN_INTERPRETER;
2524+
variableType |= UNBOXED_IN_INTERPRETER;
2525+
variableTypes[index] = variableType;
25242526
bytecodeStoreFastUnboxI(virtualFrame, localFrame, stackTop, bci, index);
25252527
} else {
2528+
variableTypes[index] = variableType;
25262529
if (stackType == QuickeningTypes.INT) {
25272530
virtualFrame.setObject(stackTop, virtualFrame.getInt(stackTop));
25282531
generalizeInputs(bci);
@@ -2534,13 +2537,16 @@ private void bytecodeStoreFastAdaptive(VirtualFrame virtualFrame, Frame localFra
25342537
} else if (itemType == QuickeningTypes.BOOLEAN) {
25352538
if (unboxInIntepreter && stackType == QuickeningTypes.BOOLEAN) {
25362539
localBC[bci] = OpCodesConstants.STORE_FAST_B;
2537-
variableTypes[index] |= UNBOXED_IN_INTERPRETER;
2540+
variableType |= UNBOXED_IN_INTERPRETER;
2541+
variableTypes[index] = variableType;
25382542
bytecodeStoreFastB(virtualFrame, localFrame, stackTop, bci, index);
25392543
} else if (unboxInIntepreter) {
25402544
localBC[bci] = OpCodesConstants.STORE_FAST_UNBOX_B;
2541-
variableTypes[index] |= UNBOXED_IN_INTERPRETER;
2545+
variableType |= UNBOXED_IN_INTERPRETER;
2546+
variableTypes[index] = variableType;
25422547
bytecodeStoreFastUnboxB(virtualFrame, localFrame, stackTop, bci, index);
25432548
} else {
2549+
variableTypes[index] = variableType;
25442550
if (stackType == QuickeningTypes.BOOLEAN) {
25452551
virtualFrame.setObject(stackTop, virtualFrame.getBoolean(stackTop));
25462552
generalizeInputs(bci);
@@ -2550,11 +2556,13 @@ private void bytecodeStoreFastAdaptive(VirtualFrame virtualFrame, Frame localFra
25502556
}
25512557
return;
25522558
} else if (itemType == QuickeningTypes.OBJECT) {
2559+
variableTypes[index] = variableType;
25532560
localBC[bci] = OpCodesConstants.STORE_FAST_O;
25542561
bytecodeStoreFastO(virtualFrame, localFrame, stackTop, index);
25552562
return;
25562563
}
25572564
// TODO other types
2565+
variableTypes[index] = QuickeningTypes.OBJECT;
25582566
generalizeInputs(bci);
25592567
generalizeVariableStores(index);
25602568
virtualFrame.setObject(stackTop, virtualFrame.getValue(stackTop));
@@ -2790,34 +2798,8 @@ private void bytecodeLoadFastO(VirtualFrame virtualFrame, Frame localFrame, int
27902798
virtualFrame.setObject(stackTop, value);
27912799
}
27922800

2793-
private byte stackSlotTypeToTypeId(VirtualFrame virtualFrame, int stackTop) {
2794-
if (virtualFrame.isObject(stackTop)) {
2795-
return QuickeningTypes.OBJECT;
2796-
} else if (virtualFrame.isInt(stackTop)) {
2797-
return QuickeningTypes.INT;
2798-
} else if (virtualFrame.isLong(stackTop)) {
2799-
return QuickeningTypes.LONG;
2800-
} else if (virtualFrame.isDouble(stackTop)) {
2801-
return QuickeningTypes.DOUBLE;
2802-
} else if (virtualFrame.isBoolean(stackTop)) {
2803-
return QuickeningTypes.BOOLEAN;
2804-
} else {
2805-
throw CompilerDirectives.shouldNotReachHere("Unknown stack item type");
2806-
}
2807-
}
2808-
2809-
private byte objectTypeId(Object object) {
2810-
if (object instanceof Integer) {
2811-
return QuickeningTypes.INT;
2812-
} else if (object instanceof Long) {
2813-
return QuickeningTypes.LONG;
2814-
} else if (object instanceof Double) {
2815-
return QuickeningTypes.DOUBLE;
2816-
} else if (object instanceof Boolean) {
2817-
return QuickeningTypes.BOOLEAN;
2818-
} else {
2819-
return QuickeningTypes.OBJECT;
2820-
}
2801+
private static byte stackSlotTypeToTypeId(VirtualFrame virtualFrame, int stackTop) {
2802+
return QuickeningTypes.fromFrameSlotTag(virtualFrame.getTag(stackTop));
28212803
}
28222804

28232805
private void generalizeInputs(int beginBci) {

0 commit comments

Comments
 (0)