Skip to content

Commit 0f43dee

Browse files
committed
Limit loop explosion.
1 parent e092b6f commit 0f43dee

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PClosureRootNode.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,37 @@
4949

5050
public abstract class PClosureRootNode extends PRootNode {
5151
@CompilerDirectives.CompilationFinal(dimensions = 1) protected final FrameSlot[] freeVarSlots;
52+
private final int length;
5253

5354
protected PClosureRootNode(TruffleLanguage<?> language, FrameDescriptor frameDescriptor, FrameSlot[] freeVarSlots) {
5455
super(language, frameDescriptor);
5556
this.freeVarSlots = freeVarSlots;
57+
this.length = freeVarSlots != null ? freeVarSlots.length : 0;
5658
}
5759

58-
@ExplodeLoop
5960
protected void addClosureCellsToLocals(Frame frame) {
6061
PCell[] closure = PArguments.getClosure(frame);
6162
if (closure != null) {
6263
assert freeVarSlots != null : "closure root node: the free var slots cannot be null when the closure is not null";
6364
assert closure.length == freeVarSlots.length : "closure root node: the closure must have the same length as the free var slots array";
64-
for (int i = 0; i < freeVarSlots.length; i++) {
65-
frame.setObject(freeVarSlots[i], closure[i]);
65+
if (freeVarSlots.length < 32) {
66+
addClosureCellsToLocalsExploded(frame, closure);
67+
} else {
68+
addClosureCellsToLocalsLoop(frame, closure);
6669
}
6770
}
6871
}
72+
73+
protected void addClosureCellsToLocalsLoop(Frame frame, PCell[] closure) {
74+
for (int i = 0; i < length; i++) {
75+
frame.setObject(freeVarSlots[i], closure[i]);
76+
}
77+
}
78+
79+
@ExplodeLoop
80+
protected void addClosureCellsToLocalsExploded(Frame frame, PCell[] closure) {
81+
for (int i = 0; i < length; i++) {
82+
frame.setObject(freeVarSlots[i], closure[i]);
83+
}
84+
}
6985
}

0 commit comments

Comments
 (0)